:root {
  /* バウハウス風の 3 色: 墨・生成り・からし（土台）＋朱（差し色） */
  --ink: #16182b;
  --cream: #f4eee1;
  --mustard: #f2b632;
  --vermilion: #e4573d;

  --bg: var(--cream);
  --surface: var(--cream);
  --line: rgba(22, 24, 43, 0.28);
  --brass: var(--mustard);        /* 変数名は据え置き。ロゴ・見出しのアクセント色 */
  --brass-bright: var(--vermilion);
  --fg: var(--ink);
  --muted: rgba(22, 24, 43, 0.6);
  --pc: var(--brass);   /* 手番の色。対局中に main.js が書き換える */
  /* 見出し・ロゴ・数字用の英字ディスプレイフォント（Google Fonts、sw.js が cache-first で保存する）。
     読み込めないときは太めの system-ui にフォールバックする */
  --font-display: 'Orbitron', system-ui, -apple-system, sans-serif;

  --wak-bg: var(--cream);
  --wak-fg: var(--ink);
  --wak-muted: rgba(22, 24, 43, 0.6);
  --wak-line: rgba(22, 24, 43, 0.28);
  --wak-accent: var(--mustard);
  --wak-accent-fg: var(--ink);
  --wak-radius: 4px;
}

* { box-sizing: border-box; }

/* Safari 26 の上下バーの色は html の背景から取られる。body と同じ色にしておく */
html { background-color: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  touch-action: manipulation;
}

/* ---- 押した手ごたえ（すべてのボタンに共通） ---- */
.btn, .pill, .icon-btn, .act, .colorbtn {
  transition: transform 0.12s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.12s, background 0.12s, border-color 0.12s, opacity 0.12s;
}
.btn:active:not(:disabled), .pill:active:not(:disabled),
.icon-btn:active:not(:disabled), .act:active:not(:disabled), .colorbtn:active:not(:disabled) {
  transform: scale(0.94);
}

/* サブのボタン: 生成り地に墨の太枠（バウハウス風のフラット） */
.btn {
  min-height: 48px;
  padding: 0 16px;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
/* メインのボタン: 墨の平面に生成りの文字 */
.btn--main {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--cream);
}
.btn--quiet { background: transparent; }
.btn:disabled { opacity: 0.4; cursor: default; transform: none !important; }
.pill {
  min-height: 40px;
  border: 2px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  border-radius: 0;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.icon-btn {
  width: 44px; height: 44px;
  border: 2px solid var(--ink); border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.credit { text-align: center; font-size: 12px; color: var(--muted); margin: 0; }
.credit a { color: inherit; }

/* ---- 画面の出入り ---- */
@keyframes app-enter { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.title, .game { animation: app-enter 0.4s cubic-bezier(0.2, 0.8, 0.2, 1); }

/* ---- タイトル ---- */
/* 参考デザインの流儀: うすい点の格子の上に、角からはみ出す大きな四分円（からし・朱）を重ねる */
.title {
  position: relative;
  flex: 1; min-height: 0; overflow: hidden auto;
  display: flex; flex-direction: column;
  background:
    radial-gradient(circle at 4px 4px, color-mix(in srgb, var(--ink) 14%, transparent) 1.6px, transparent 1.8px) 0 0 / 28px 28px,
    var(--bg);
}
.title::before, .title::after {
  content: ''; position: absolute; border-radius: 50%; z-index: 0;
}
.title::before { top: -22%; right: -22%; width: min(75vw, 340px); height: min(75vw, 340px); background: var(--mustard); }
.title::after { bottom: -18%; left: -18%; width: min(46vw, 220px); height: min(46vw, 220px); background: var(--vermilion); opacity: 0.9; }
.title__main, .title__foot { position: relative; z-index: 1; }
.title__main {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center; padding: 12px 0;
}
.cage--demo {
  width: min(220px, 60vw); height: auto; aspect-ratio: 240 / 200; margin-bottom: 4px;
}
.title__name {
  margin: 4px 0 0; font-size: 40px; letter-spacing: 0.05em; font-weight: 800; line-height: 1;
  font-family: var(--font-display);
  color: var(--ink);
}
.title__name-accent { color: var(--vermilion); }
.title__lead { margin: 6px 0 16px; color: var(--muted); font-size: 14px; letter-spacing: 0.02em; }
.title__rules { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; }
.title__rules .pill[aria-pressed="true"] { background: var(--ink); color: var(--cream); }
.title__buttons { display: grid; gap: 10px; width: min(280px, 100%); }
.title__foot { display: grid; gap: 12px; padding-top: 12px; }
.title__kit { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }

@media (max-height: 600px) {
  .cage--demo { display: none; }
}

/* ---- 対局 ---- */
.game { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.top {
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--pc) 30%, var(--line));
  transition: border-color 0.3s;
}
.turn { margin: 0; display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 15px; font-weight: 700; font-family: var(--font-display); letter-spacing: 0.02em; }
.turn__dot {
  width: 10px; height: 10px;
  background: var(--pc);
  transform: rotate(45deg);
  transition: background 0.3s;
}
.turn:has(#turn-text:empty) .turn__dot { display: none; }

.scene-wrap {
  position: relative; flex: 1; min-height: 200px; border-radius: 4px; overflow: hidden;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--pc) 26%, var(--line));
  transition: border-color 0.3s;
}
.scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.scene__undo { position: absolute; left: 8px; bottom: 8px; opacity: 0.85; }
.scene__undo:disabled { opacity: 0.3; }

.notice { min-height: 1.4em; margin: 0; text-align: center; font-size: 13px; color: var(--muted); }

.controls { display: grid; gap: 8px; }
.actions { display: grid; grid-template-columns: 1fr; gap: 8px; width: min(200px, 100%); margin: 0 auto; }
.act {
  min-height: 56px; border: 2px solid var(--ink); border-radius: 0;
  background: var(--surface); color: var(--ink);
  font-weight: 700; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.act__icon { font-size: 18px; line-height: 1; }
.act__label { font-size: 12px; }
.act[aria-pressed="true"] {
  background: var(--ink);
  color: var(--cream);
}
.act:disabled { opacity: 0.4; cursor: default; }

.colors { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.colorbtn {
  width: 52px; height: 52px; border-radius: 0; border: 2px solid var(--ink);
  background: var(--c);
  display: flex; align-items: center; justify-content: center;
  cursor: grab; touch-action: none; user-select: none;
}
.colorbtn:disabled { opacity: 0.3; cursor: default; }
.colorbtn__n { font-size: 13px; font-weight: 700; color: rgba(0, 0, 0, 0.62); font-family: var(--font-display); }
/* ドラッグ中、指の下について動く箱の分身。position は JS が毎フレーム書き換える */
.colorbtn--ghost {
  position: fixed; left: 0; top: 0; z-index: 20; pointer-events: none;
  transform: translate(-50%, -130%) scale(1.08);
  border-radius: 0; border: 2px solid var(--ink);
  background: var(--c);
}

.decide { display: flex; justify-content: center; gap: 10px; }
.decide .btn { min-width: 120px; }
.decide .btn--main {
  background: var(--pc);
  border-color: var(--ink);
  color: var(--ink);
}

/* エクストラルールの「倒す」方向えらび */
.tilt-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: min(360px, 100%); margin: 0 auto; }
.tilt-choices .btn { min-width: 96px; flex: 1 1 auto; }

/* ---- 結果（盤の上に、下寄せのカードで重ねる） ---- */
@keyframes result-in { from { opacity: 0; transform: translateY(28px); } to { opacity: 1; transform: none; } }
.result {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  width: min(420px, 100%); margin: 0 auto;
  padding: 18px 16px; border-radius: 0; border: 2px solid var(--ink); border-bottom: 0;
  border-top: 4px solid var(--pc);
  background: var(--surface);
  text-align: center;
  max-height: calc(100% - 12px);
  overflow: hidden auto;
  padding-bottom: max(18px, calc(env(safe-area-inset-bottom) + 12px));
  animation: result-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.result__head { position: relative; margin: 0 0 2px; font-size: 25px; font-weight: 800; letter-spacing: 0.01em; font-family: var(--font-display); color: var(--ink); }
.result__moves { position: relative; margin: 0; font-size: 13px; color: var(--muted); }
.result__buttons { position: relative; display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 8px; margin-top: 14px; }
.result__buttons .btn { padding: 0 6px; white-space: nowrap; }

/* ---- 遊び方・メニュー・CPU 対戦/観戦の設定 ---- */
.help, .menu, .cpu-setup {
  width: min(440px, calc(100% - 24px)); max-height: calc(100dvh - 48px);
  padding: 20px; border: 2px solid var(--ink); border-radius: 0;
  background: var(--surface);
  color: var(--fg); line-height: 1.65; font-size: 15px;
}
.help::backdrop, .menu::backdrop, .cpu-setup::backdrop { background: rgba(0, 0, 0, 0.6); }
.help h2, .menu h2, .cpu-setup h2 { margin: 0 0 10px; font-size: 20px; color: var(--vermilion); }
.help ol { margin: 0; padding-left: 1.3em; }
.help li + li { margin-top: 4px; }
.help__note { margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.help .btn { width: 100%; margin-top: 16px; }
.menu__buttons { display: grid; gap: 8px; margin-top: 8px; }

.setup__label { margin: 14px 0 6px; font-size: 12px; color: var(--muted); }
.setup__label:first-of-type { margin-top: 0; }
.setup__group { display: flex; flex-wrap: wrap; gap: 8px; }
.setup__group .pill[aria-pressed="true"] { background: var(--ink); color: var(--cream); }
.cpu-setup .btn { width: 100%; margin-top: 18px; }

/* ---- 観戦中の操作（一時停止・速さ） ---- */
.spectate-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }

@media (prefers-reduced-motion: reduce) {
  .btn, .pill, .icon-btn, .act, .colorbtn,
  .title, .game, .result { animation: none !important; transition-duration: 0.001s !important; }
}
