:root {
  --bg: #06140f;
  --felt: #12573f;
  --felt-dark: #0b3a2a;
  --line: rgba(0, 0, 0, 0.32);
  --frame: #3a2415;
  --brass: #d6b25e;
  --brass-soft: rgba(214, 178, 94, 0.35);
  --ink: #f4efe2;
  --muted: rgba(244, 239, 226, 0.62);
  --danger: #ff5a5a;
  --good: #7dffb3;
  --flip-ms: 380ms;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.backdrop {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(ellipse 80% 55% at 50% 38%, rgba(32, 140, 98, 0.35), transparent 70%),
    radial-gradient(ellipse 120% 80% at 50% 120%, rgba(214, 178, 94, 0.12), transparent 60%),
    var(--bg);
}
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }

.app {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.title {
  margin: 0; display: flex; align-items: center; gap: 8px;
  font-family: "Dela Gothic One", system-ui, sans-serif; font-weight: 400;
  font-size: clamp(20px, 6vw, 28px); letter-spacing: 0.04em;
  background: linear-gradient(180deg, #fff6d8, var(--brass)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.title-disc { width: 0.8em; height: 0.8em; border-radius: 50%; display: inline-block; }
.title-disc.b { background: radial-gradient(circle at 35% 30%, #555, #0a0a0a 65%); }
.title-disc.w { background: radial-gradient(circle at 35% 30%, #fff, #d9d2c0 70%); }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: 999px; border: 1px solid var(--brass-soft); background: rgba(0, 0, 0, 0.35); cursor: pointer;
  font-size: 13px; font-weight: 700;
}
.pill[aria-pressed="false"] { opacity: 0.55; }

.screen { animation: screen-in 280ms ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }
.screen-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.screen-head h2 { margin: 0; font-size: 18px; }
.pick-me { margin: 0 0 0 auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.pick-me b { font-family: "Dela Gothic One", system-ui; font-weight: 400; font-size: 20px; color: var(--brass); font-variant-numeric: tabular-nums; }
.back { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--brass-soft); background: transparent; cursor: pointer; font-size: 18px; }

.lead { font-size: 18px; line-height: 1.6; margin: 8px 0 18px; color: var(--muted); }
.lead strong { color: var(--ink); }

.menu { display: grid; gap: 10px; margin: 16px 0; }
.btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; padding: 10px 16px; border-radius: 14px; cursor: pointer;
  border: 1px solid var(--brass-soft);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  font-weight: 800; font-size: 16px; transition: transform 120ms ease, filter 120ms ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary {
  border-color: transparent; color: #1b1205;
  background: linear-gradient(180deg, #ffe6a1, var(--brass) 55%, #a8833a);
  box-shadow: 0 6px 24px rgba(214, 178, 94, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(255, 90, 90, 0.5); color: var(--danger); background: transparent; }
.btn.small { min-height: 40px; font-size: 14px; padding: 8px 14px; border-radius: 12px; }
.btn-main { font-size: 18px; }
.btn-sub { font-size: 12px; font-weight: 600; opacity: 0.75; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.row .btn { flex: 1 1 auto; }

.card { border: 1px solid var(--brass-soft); border-radius: 16px; padding: 14px; background: rgba(0, 0, 0, 0.3); }
.account-title { margin: 0; font-weight: 700; font-size: 14px; }
.me-line { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.me-name { font-weight: 800; font-size: 17px; overflow-wrap: anywhere; }
.me-name small, .tag { color: var(--muted); font-weight: 600; font-size: 0.8em; margin-left: 4px; }
.me-rating small { font-size: 11px; color: var(--muted); margin-right: 4px; }
.me-rating b { font-family: "Dela Gothic One", system-ui; font-weight: 400; font-size: 24px; color: var(--brass); }
.me-meta { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.notice { font-size: 12px; color: #ffd98a; margin: 8px 0 0; line-height: 1.5; }
.offline { font-size: 13px; color: var(--muted); margin: 0; }
.hint-text { font-size: 13px; color: var(--muted); min-height: 1.2em; margin: 8px 0; }
.links { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; margin-top: 24px; font-size: 13px; }
.links a { color: var(--muted); }

/* ---------------------------------------------------------------- 盤 */
.scorebar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 10px; }
.side { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; padding: 8px 10px; border-radius: 14px; background: rgba(0, 0, 0, 0.3); border: 1px solid transparent; transition: border-color 200ms; }
.side.white { grid-template-columns: 1fr auto; text-align: right; }
.side.white .side-disc { grid-column: 2; grid-row: 1 / 3; }
.side.white .side-count, .side.white .side-name { grid-column: 1; }
.side.lead-now { border-color: var(--brass); }
.side-disc { grid-row: 1 / 3; width: 28px; height: 28px; border-radius: 50%; }
.black .side-disc { background: radial-gradient(circle at 35% 30%, #5a5a5a, #0b0b0b 62%); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); }
.white .side-disc { background: radial-gradient(circle at 35% 30%, #fff, #d6cfbd 70%); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); }
.side-count { font-family: "Dela Gothic One", system-ui; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.side-count.bump { animation: bump 220ms ease-out; }
@keyframes bump { 40% { transform: scale(1.25); color: var(--brass); } }
.side-name { display: flex; gap: 4px; min-width: 0; font-size: 11px; color: var(--muted); white-space: nowrap; }
.side.white .side-name { justify-content: flex-end; }
.side-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.side-rating { flex-shrink: 0; color: var(--brass); font-variant-numeric: tabular-nums; }
.clock { text-align: center; }
.clock-time { display: block; font-family: "Dela Gothic One", system-ui; font-size: 22px; font-variant-numeric: tabular-nums; }
.clock-time.low { color: var(--danger); }
.clock-mode { font-size: 11px; color: var(--muted); }

.board-wrap {
  position: relative; padding: 10px; border-radius: 18px;
  background: linear-gradient(145deg, #5a3820, var(--frame) 40%, #24160c);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 0 0 1px rgba(214, 178, 94, 0.3);
}
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); aspect-ratio: 1; border-radius: 8px; overflow: hidden;
  background:
    repeating-radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.015) 0 2px, transparent 2px 4px),
    radial-gradient(ellipse at 50% 40%, var(--felt), var(--felt-dark));
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  perspective: 900px;
}
.cell {
  position: relative; border: 0; padding: 0; margin: 0; background: transparent; cursor: pointer;
  box-shadow: inset -1px -1px 0 var(--line);
  display: grid; place-items: center;
}
.cell:nth-child(8n) { box-shadow: inset 0 -1px 0 var(--line); }
.cell:nth-child(n + 57) { box-shadow: inset -1px 0 0 var(--line); }
.cell:last-child { box-shadow: none; }
.cell.hint::before {
  content: ""; width: 22%; height: 22%; border-radius: 50%;
  background: rgba(255, 255, 255, 0.16); box-shadow: 0 0 10px rgba(214, 178, 94, 0.25);
}
.cell.miss { animation: miss 260ms ease-out; }
@keyframes miss {
  0% { background: rgba(255, 70, 70, 0.45); transform: translateX(0); }
  25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
  100% { background: transparent; transform: translateX(0); }
}
.cell.miss-white { animation: miss-white 260ms ease-out; }
@keyframes miss-white { 0% { background: rgba(255, 255, 255, 0.18); } 100% { background: transparent; } }

.disc {
  position: absolute; inset: 9%; transform-style: preserve-3d; pointer-events: none;
  transition: transform var(--flip-ms) cubic-bezier(0.3, 1.4, 0.5, 1);
}
.disc.white { transform: rotateY(180deg); }
.disc .face { position: absolute; inset: 0; border-radius: 50%; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.disc .face.b {
  background: radial-gradient(circle at 34% 28%, #6b6b6b 0, #1c1c1c 38%, #050505 72%);
  box-shadow: 0 3px 4px rgba(0, 0, 0, 0.55), inset 0 -2px 3px rgba(255, 255, 255, 0.08);
}
.disc .face.w {
  transform: rotateY(180deg);
  background: radial-gradient(circle at 34% 28%, #ffffff 0, #f1ecdf 45%, #c9c1ad 85%);
  box-shadow: 0 3px 4px rgba(0, 0, 0, 0.55), inset 0 -2px 3px rgba(0, 0, 0, 0.15);
}
.disc.drop { animation: drop 260ms cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes drop { from { scale: 1.7; opacity: 0; filter: drop-shadow(0 14px 10px rgba(0, 0, 0, 0.6)); } }
.disc.flip { animation: lift var(--flip-ms) ease-out; }
@keyframes lift { 45% { scale: 1.18; filter: drop-shadow(0 0 8px rgba(214, 178, 94, 0.9)); } }
.ripple {
  position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  border: 2px solid var(--brass); animation: ripple 520ms ease-out forwards;
}
.ripple.white { border-color: rgba(255, 255, 255, 0.7); }
@keyframes ripple { from { transform: scale(0.4); opacity: 1; } to { transform: scale(2.2); opacity: 0; } }

.countdown {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: 18px;
  background: rgba(0, 0, 0, 0.35); pointer-events: none;
  font-family: "Dela Gothic One", system-ui; font-size: clamp(80px, 30vw, 160px); color: #fff;
  text-shadow: 0 0 30px rgba(214, 178, 94, 0.8), 0 6px 0 rgba(0, 0, 0, 0.4);
}
.countdown span { animation: count 900ms ease-out forwards; }
@keyframes count { from { transform: scale(1.8); opacity: 0; } 30% { transform: scale(1); opacity: 1; } to { transform: scale(0.9); opacity: 0; } }
.countdown.go span { color: var(--brass); }

.tally { display: flex; justify-content: center; gap: 20px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.tally b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- 結果 */
.outcome {
  text-align: center; margin: 24px 0 8px; font-family: "Dela Gothic One", system-ui; font-size: clamp(56px, 18vw, 96px); line-height: 1;
  background: linear-gradient(180deg, #fff6d8, var(--brass)); -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: outcome 600ms cubic-bezier(0.2, 1.5, 0.4, 1);
}
.outcome.lose { background: linear-gradient(180deg, #ddd, #777); -webkit-background-clip: text; background-clip: text; }
@keyframes outcome { from { transform: scale(0.3) rotate(-8deg); opacity: 0; } }
.final { display: flex; align-items: center; justify-content: center; gap: 14px; font-family: "Dela Gothic One", system-ui; font-size: 40px; }
.final-side { display: inline-flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.final-side .side-disc { width: 34px; height: 34px; display: inline-block; }
.final-vs { color: var(--muted); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0; }
.stats div { background: rgba(0, 0, 0, 0.3); border-radius: 12px; padding: 8px 12px; }
.stats dt { font-size: 11px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-weight: 800; overflow-wrap: anywhere; }
.rating-change { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: 8px 0; }
.rating-label { font-size: 12px; color: var(--muted); }
.rating-value { font-family: "Dela Gothic One", system-ui; font-weight: 400; font-size: 36px; color: var(--brass); }
.rating-delta { font-weight: 800; font-size: 18px; }
.rating-delta.up { color: var(--good); }
.rating-delta.down { color: var(--danger); }
.rating-rank { margin: 0 0 8px; text-align: center; font-size: 13px; color: var(--muted); }
.rating-rank b { font-family: "Dela Gothic One", system-ui; font-weight: 400; font-size: 24px; color: var(--ink); margin: 0 2px; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- 一覧 */
.search input {
  width: 100%; padding: 12px 14px; border-radius: 12px; font-size: 16px;
  border: 1px solid var(--brass-soft); background: rgba(0, 0, 0, 0.35); color: var(--ink);
}
.opponents, .ranking { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 6px; }
.opponent {
  width: 100%; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; text-align: left;
  padding: 12px 14px; border-radius: 12px; border: 1px solid rgba(214, 178, 94, 0.2); background: rgba(0, 0, 0, 0.3); cursor: pointer;
}
.opponent:active { transform: scale(0.98); }
.opponent.cpu { border-style: dashed; }
.opponent-name { font-weight: 800; overflow-wrap: anywhere; }
.opponent-rating { font-family: "Dela Gothic One", system-ui; color: var(--brass); }
.opponent-band { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }
.ranking li { display: grid; grid-template-columns: 3em 1fr auto; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 12px; background: rgba(0, 0, 0, 0.3); }
.ranking li.me { outline: 1px solid var(--brass); }
.rank { font-family: "Dela Gothic One", system-ui; color: var(--muted); }
.ranking li:nth-child(-n + 3) .rank { color: var(--brass); }

/* ---------------------------------------------------------------- 読み込み中・案内 */
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 12px 0; padding: 14px; border-radius: 12px; background: rgba(214, 178, 94, 0.12); border: 1px solid var(--brass-soft); font-weight: 800; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid rgba(214, 178, 94, 0.25); border-top-color: var(--brass); animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.opponents.busy { opacity: 0.45; pointer-events: none; }
.inline-status { font-size: 13px; font-weight: 700; color: var(--good); min-height: 1.2em; margin: 6px 0 0; }
.inline-status.error { color: var(--danger); }
.notice-box { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 217, 138, 0.1); border: 1px solid rgba(255, 217, 138, 0.35); }
.notice-box p { margin: 0 0 8px; font-size: 12px; line-height: 1.6; color: #ffd98a; }
.qr { width: min(220px, 70vw); margin: 12px auto; padding: 10px; border-radius: 12px; background: #fff; }
.qr svg { display: block; width: 100%; height: auto; }
.qr-url { text-align: center; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; margin: 0 0 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brass); }

/* ---------------------------------------------------------------- ダイアログ */
.sheet {
  width: min(calc(100% - 32px), 440px); border: 1px solid var(--brass-soft); border-radius: 18px; padding: 18px;
  background: #0c1f18; color: var(--ink);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px); }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet hr { border: 0; border-top: 1px solid rgba(214, 178, 94, 0.2); margin: 14px 0; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.field input { padding: 12px; border-radius: 10px; font-size: 16px; border: 1px solid var(--brass-soft); background: rgba(0, 0, 0, 0.35); color: var(--ink); }
.turnstile { margin-top: 12px; min-height: 0; }
.merge { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.merge-choice { display: grid; gap: 4px; padding: 12px; border-radius: 12px; border: 1px solid var(--brass-soft); background: rgba(0, 0, 0, 0.3); cursor: pointer; text-align: left; }
.merge-choice b { font-size: 12px; color: var(--brass); }
.merge-choice span { font-size: 13px; overflow-wrap: anywhere; }

.snackbar {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: #f4efe2; color: #111; font-weight: 700; font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); animation: screen-in 200ms ease-out; text-align: center; white-space: pre-line;
}

@media (prefers-reduced-motion: reduce) {
  :root { --flip-ms: 1ms; }
  .disc.drop, .disc.flip, .ripple, .cell.miss, .screen, .outcome, .countdown span { animation-duration: 1ms !important; }
}

.practice-level { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.practice-level select { font: inherit; color: var(--ink); background: #24201c; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.how-to { font-size: 13px; line-height: 1.8; }
.how-to summary { cursor: pointer; font-weight: bold; }
.how-to ul { padding-left: 1.5em; }
.how-to p { margin: 10px 0 0; }
