:root {
  color-scheme: dark;
  --green-950: #06261d;
  --green-900: #092d23;
  --green-800: #123d31;
  --green-700: #245746;
  --gold: #d7af4f;
  --gold-light: #f0d486;
  --ivory: #f6f0e2;
  --ink: #17231d;
  --wood-a: #eadcc4;
  --wood-b: #dfcfb3;
  --line: #766d5f;
  --danger: #a94837;
  font-family: "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ivory);
  background:
    radial-gradient(circle at 15% 10%, rgba(215,175,79,.11), transparent 32rem),
    repeating-radial-gradient(ellipse at 50% 110%, transparent 0 34px, rgba(255,255,255,.025) 35px 37px, transparent 38px 70px),
    var(--green-950);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
.hidden { display: none !important; }
.tutorial-nav {display:flex;gap:8px;flex-wrap:wrap;margin:14px 0;}
.tutorial-board {width:min(100%,380px);margin:16px auto;grid-template-rows:repeat(6,minmax(0,1fr));}
.tutorial-board > .cell {min-width:0;min-height:0;}
.tutorial-perspective, .tutorial-caption {font-weight:700;color:var(--green-800);line-height:1.7;}
.tutorial-side {text-align:center;line-height:1.6;}
.tutorial-board > .cell.territory {background:#e2bd69;}
.tutorial-board > .cell.home-territory {background:#b9cbbb;}
.tutorial-coordinate {position:absolute;top:1px;left:3px;font-size:10px;line-height:1.2;color:#243b2d;}
.tutorial-nav button[aria-pressed="true"] {outline:2px solid var(--gold-light);}
select { font:inherit; background:var(--ivory); color:var(--ink); padding:12px; border:1px solid var(--gold); border-radius:10px; width:100%; }
.setup-grid {display:grid;gap:16px;padding-top:18px;}
.setup-grid label {display:grid;gap:6px;font-weight:700;}
.official-logo {display:block;width:min(100%,260px);height:auto;object-fit:contain;margin:0 auto 18px;}
.hero-card h2 {font-size:clamp(2rem,4vw,3.4rem);}
.audio-settings {display:flex;gap:20px;flex-wrap:wrap;margin:20px 0;}
.audio-settings input {padding:0;accent-color:var(--gold);}
#progressSummary {margin-bottom:16px;line-height:1.8;}
#progressSummary strong {color:var(--gold-light);font-size:1.3rem;}
progress {width:100%;accent-color:var(--gold);height:10px;}
.record-row {padding:12px 0;border-bottom:1px solid #c9b88e;display:grid;gap:8px;}
#recordDetail {white-space:pre-wrap;overflow-wrap:anywhere;line-height:1.7;}
.thinking .status-dot {animation:pulse-thinking 1s ease-in-out infinite;}
.cell.legal-source .stone {outline:3px solid #a23f27;outline-offset:2px;}
.stone.move-arrival {animation:stone-arrival .45s ease-out;}
#resultPanel:not(.hidden) {animation:result-reveal .4s ease-out;}
.intro-overlay {position:fixed;inset:0;z-index:100;background:#06261d;display:grid;place-content:center;justify-items:center;overflow:hidden;}
.intro-overlay img {width:min(90vw,700px);height:auto;object-fit:contain;animation:intro-logo 5.2s both;}
.intro-overlay #startIntroButton {position:absolute;bottom:max(24px,env(safe-area-inset-bottom));left:50%;transform:translateX(-50%);min-width:200px;min-height:56px;max-width:calc(100vw - 48px);padding:12px 32px;border:1px solid #cbaa59;border-radius:12px;background:linear-gradient(#102e24,#071710);color:#f4db97;font-size:1.2rem;font-weight:700;letter-spacing:.16em;box-shadow:0 3px 14px #0005;cursor:pointer;}
.intro-overlay #startIntroButton[hidden] {display:none;}
.intro-overlay #startIntroButton:focus-visible {outline:3px solid #f4db97;outline-offset:4px;}
.intro-overlay #startIntroButton:hover {border-color:#f4db97;}
.intro-stones {position:absolute;top:43%;left:50%;transform:translate(-50%,-50%);display:flex;gap:30px;}
.intro-stones span {width:70px;height:70px;border-radius:50%;box-shadow:0 5px 12px #0008;}
.intro-black {background:radial-gradient(at 30% 25%,#555,#111);animation:intro-black 2.4s both;}
.intro-white {background:radial-gradient(at 30% 25%,#fffbe9,#c4b995);animation:intro-white 2.4s both;}
@keyframes intro-logo {0%,52%{opacity:0}70%,93%,100%{opacity:1}}
@keyframes intro-black {0%{transform:translateX(-120px);opacity:0}63%,90%{transform:translateX(0);opacity:1}100%{opacity:0}}
@keyframes intro-white {0%,45%{transform:translateY(140px);opacity:0}95%{transform:translateY(0);opacity:1}100%{opacity:0}}
@keyframes stone-arrival {from {transform:scale(.8);opacity:.35}to {transform:scale(1);opacity:1}}
@keyframes result-reveal {from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
@keyframes pulse-thinking {50%{opacity:.3}}
@media(prefers-reduced-motion:reduce){*,*::before,*::after {animation:none!important;transition:none!important;}.intro-stones{display:none}}

.site-header {
  max-width: 1240px;
  margin: 0 auto;
  padding: 22px 24px 14px;
  display: flex;
  gap: 14px;
  align-items: center;
  border-bottom: 1px solid rgba(215,175,79,.45);
}
.brand-mark {
  width: 48px; height: 48px; border: 1px solid var(--gold); border-radius: 50%;
  display: grid; place-items: center; color: var(--gold-light); font-family: serif; font-size: 25px;
}
.site-header h1 { margin: 0; line-height: 1; font-family: serif; letter-spacing: .08em; }
.site-header h1 span { margin-left: 8px; font-family: inherit; font-size: .48em; color: var(--gold-light); letter-spacing: .2em; }
.eyebrow { margin: 0 0 5px; color: #b9cdc5; font-size: .75rem; letter-spacing: .13em; }
.gold { color: var(--gold-light); }
.site-header .ghost-button { margin-left: auto; }

main { max-width: 1240px; margin: 0 auto; padding: 32px 24px 64px; }
.home-grid { min-height: 70vh; display: grid; grid-template-columns: 1.35fr .65fr; gap: 26px; align-items: center; }
.hero-card, .rule-summary, .card {
  border: 1px solid rgba(215,175,79,.55);
  background: linear-gradient(145deg, rgba(18,61,49,.95), rgba(8,41,32,.96));
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.24);
}
.hero-card { padding: clamp(28px, 5vw, 62px); }
.hero-card h2 { margin: 10px 0 20px; font-family: serif; font-size: clamp(2.3rem, 5vw, 4.6rem); line-height: 1.15; }
#heroTitle {font-size:clamp(1.65rem,4.6vw,4.6rem);line-height:1.22;max-width:100%;}
#heroTitle .hero-copy-line {display:block;white-space:nowrap;}
#musicCredits a {color:#245647;font-weight:600;text-underline-offset:.15em;}
.lead { max-width: 38rem; color: #d5e1db; line-height: 1.8; }
.home-actions { margin-top: 34px; display: grid; gap: 16px; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
input { min-width: 0; padding: 14px 16px; color: var(--ink); background: var(--ivory); border: 2px solid transparent; border-radius: 12px; }
input:focus { outline: none; border-color: var(--gold); }
.primary-button, .secondary-button, .ghost-button, .danger-button {
  padding: 12px 18px; border-radius: 12px; border: 1px solid transparent; font-weight: 700;
}
.primary-button { color: var(--green-950); background: linear-gradient(#f1d582, #d4aa47); }
.secondary-button { color: var(--green-950); background: var(--ivory); border-color: var(--gold); }
.ghost-button { color: var(--ivory); background: transparent; border-color: rgba(246,240,226,.42); }
.danger-button { color: #fff1eb; background: rgba(169,72,55,.22); border-color: #c66c57; }
.full { width: 100%; }
.message { min-height: 1.5em; color: #ffd4c8; }
.privacy-note { font-size: .8rem; line-height: 1.6; color: #d5e1db; }
.rule-summary { padding: 30px; }
.rule-summary h3 { margin-top: 0; color: var(--gold-light); font-size: 1.5rem; }
.rule-summary ol { padding-left: 1.3rem; line-height: 1.8; }
.rule-summary li + li { margin-top: 12px; }
.store-link { display: inline-block; margin-top: 18px; color: var(--gold-light); }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 22px; }
.game-topbar { grid-column: 1/-1; display: flex; align-items: center; gap: 16px; padding: 10px 0 2px; }
.game-topbar .room-code { margin-left: auto; }
.status-dot { width: 9px; height: 9px; display: inline-block; margin-right: 7px; border-radius: 50%; background: #d9b84c; }
.status-dot.online { background: #68cb88; box-shadow: 0 0 10px #68cb88; }
.match-column { min-width: 0; }
.match-status { padding: 14px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.player-pill { min-width: 0; display: grid; grid-template-columns: auto auto 1fr; gap: 8px; align-items: center; }
.player-pill > :last-child { grid-column: 2/-1; color: #c3d3cc; font-size: .86rem; }
.white-pill { text-align: right; grid-template-columns: 1fr auto auto; }
.white-pill > .stone-mini { grid-column: 3; }
.white-pill > span:nth-child(2) { grid-column: 2; grid-row: 1; }
.white-pill > strong { grid-column: 1; grid-row: 1; }
.white-pill > :last-child { grid-column: 1/3; }
.stone-mini { width: 24px; height: 24px; border-radius: 50%; box-shadow: inset -2px -2px 4px rgba(0,0,0,.35); }
.black-stone { background: #262a28; border: 1px solid #080b09; }
.white-stone { background: #f2ecdc; border: 1px solid #756e61; }
.turn-panel { text-align: center; min-width: 145px; }
.turn-panel p { margin: 0; color: #c0d0c8; font-size: .78rem; }
.turn-panel strong { display: block; margin-top: 4px; color: var(--gold-light); }

.board-card { margin-top: 14px; padding: clamp(12px, 2.5vw, 24px); text-align: center; }
.board-shell { width: min(100%, 650px); margin: 0 auto; }
.column-labels { margin-left: 22px; display: grid; grid-template-columns: repeat(6,1fr); color: var(--gold-light); font-size: .75rem; }
.board-row { display: grid; grid-template-columns: 22px 1fr; }
.row-labels { display: grid; grid-template-rows: repeat(6,1fr); align-items: center; color: var(--gold-light); font-size: .75rem; }
.board { aspect-ratio: 1; display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); grid-template-rows:repeat(6,minmax(0,1fr)); border: 4px solid #4b514c; background: var(--wood-a); touch-action: manipulation; }
.cell { min-width:0;min-height:0;position: relative; border: .5px solid var(--line); background: var(--wood-a); display: grid; place-items: center; padding: 0; border-radius: 0; }
.cell:nth-child(12n+2), .cell:nth-child(12n+4), .cell:nth-child(12n+6),
.cell:nth-child(12n+7), .cell:nth-child(12n+9), .cell:nth-child(12n+11) { background: var(--wood-b); }
.cell.territory { box-shadow: inset 0 0 0 999px rgba(215,175,79,.2); }
.cell.destination::after { content: ""; position: absolute; inset: 10%; border: 4px solid var(--green-700); border-radius: 10px; }
.cell.capture-destination::after { border-color: #a23f27; }
.cell.selected { box-shadow: inset 0 0 0 5px var(--gold); }
.cell.last-from::before, .cell.last-to::before { content: ""; position: absolute; inset: 3px; border: 2px solid rgba(215,175,79,.8); border-radius: 7px; }
/* Android reference: 73..74px ink diameter / 144px cell (~50.9%).
   52% of the cell content box accounts for its border; hit target stays the full cell. */
.stone { width: 52%; aspect-ratio: 1; border-radius: 50%; z-index: 2; box-shadow: 2px 4px 5px rgba(0,0,0,.35), inset -5px -6px 8px rgba(0,0,0,.28), inset 5px 5px 9px rgba(255,255,255,.16); }
.stone.black { background: #292c2a; border: 2px solid #101210; }
.stone.white { background: #f3eedf; border: 2px solid #6c675c; }
.cell.capture-target .stone { outline: 4px solid #a23f27; outline-offset: 3px; }
.instruction { min-height: 1.5em; margin: 14px 0 4px; color: var(--gold-light); font-weight: 700; }
.capture-choices, .decision-panel { margin: 14px auto 0; max-width: 650px; padding: 14px; border: 1px solid rgba(215,175,79,.55); border-radius: 14px; background: rgba(6,38,29,.92); }
.capture-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.capture-choices button { padding: 9px 12px; border: 1px solid var(--gold); border-radius: 10px; background: var(--ivory); color: var(--ink); }
.decision-panel p { margin: 8px 0 14px; }
.decision-panel > div { display: flex; justify-content: center; gap: 10px; }

.side-column { display: grid; gap: 14px; align-content: start; }
.info-card, .history-card { padding: 18px; }
.side-column h3 { margin: 0 0 14px; color: var(--gold-light); }
dl { margin: 0; }
dl div { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.1); }
dt { color: #aac0b7; } dd { margin: 0; text-align: right; }
.history-card { max-height: 330px; overflow: auto; }
.history-card ol { margin: 0; padding-left: 1.8rem; line-height: 1.65; font-size: .9rem; }

dialog { width: min(720px, calc(100% - 32px)); color: var(--ink); background: var(--ivory); border: 2px solid var(--gold); border-radius: 20px; padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.68); }
.dialog-header { display: flex; align-items: center; padding: 20px 24px; background: var(--green-900); color: var(--ivory); }
.dialog-header h2 { margin: 0; }
.dialog-header button { margin-left: auto; border: 0; background: transparent; color: var(--ivory); font-size: 1.8rem; }
.rules-content { padding: 10px 24px 24px; }
.rules-content section { border-bottom: 1px solid #d8c9aa; }
.rules-content h3 { color: var(--green-700); }
.rules-content p { line-height: 1.75; }
#rulesDialog {max-height:calc(100dvh - 24px);overflow:hidden;}
#rulesDialog[open] {display:flex;flex-direction:column;}
#rulesDialog .dialog-header {flex:0 0 auto;}
#rulesDialog .rules-content {overflow:auto;min-height:0;}
#tutorialControls {flex:0 0 auto;background:var(--ivory);padding:8px 24px;}
#tutorialControls > .tutorial-nav {margin:0;}
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); padding: 12px 18px; border-radius: 12px; background: #111; color: white; box-shadow: 0 6px 24px rgba(0,0,0,.4); z-index: 10; }

@media (max-width: 850px) {
  .home-grid, .game-layout { grid-template-columns: 1fr; }
  .home-grid { align-items: stretch; }
  .game-topbar { flex-wrap: wrap; }
  .game-topbar .room-code { margin-left: 0; }
  .side-column { grid-template-columns: 1fr 1fr; }
  .side-column > button { align-self: start; }
}

@media (max-width: 560px) {
  .site-header { padding: 14px 12px 10px; }
  .brand-mark { width: 40px; height: 40px; }
  .site-header h1 { font-size: 1.45rem; }
  .site-header .ghost-button { padding: 8px 11px; }
  main { padding: 18px 10px 40px; }
  .home-grid { min-height: auto; gap: 14px; }
  .hero-card, .rule-summary { padding: 22px; border-radius: 16px; }
  .join-row { grid-template-columns: 1fr; }
  .game-topbar { font-size: .83rem; }
  .game-topbar .ghost-button { width: 100%; }
  .match-status { grid-template-columns: 1fr 1fr; }
  .turn-panel { grid-column: 1/-1; grid-row: 1; }
  .player-pill { grid-row: 2; }
  .board-card { padding: 10px 8px 14px; }
  .board { border-width: 3px; }
  .cell.destination::after { border-width: 3px; border-radius: 6px; }
  .stone { width: 52%; }
  .side-column { grid-template-columns: 1fr; }
  .history-card { max-height: 220px; }
}
.measurement-choices { display: flex; flex-wrap: wrap; gap: 12px; }
.measurement-choices button { flex: 1 1 210px; min-height: 48px; white-space: normal; }
.measurement-choices button[aria-pressed="true"] { outline: 2px solid currentColor; outline-offset: 2px; }
#measurementDialog { overflow-wrap: anywhere; }
