:root {
  color-scheme: light;
  --ink: #17211e;
  --muted: #52615c;
  --paper: #f6f2e9;
  --paper-deep: #ece5d7;
  --card: #fffdf8;
  --line: #d9d1c3;
  --green-950: #0e2c25;
  --green-900: #173f35;
  --green-800: #1f5647;
  --green-700: #28705b;
  --green-600: #34896f;
  --green-300: #9cc8b6;
  --green-100: #dcece5;
  --amber: #d9a441;
  --danger: #a33d32;
  --shadow: 0 22px 70px rgb(35 49 44 / 12%);
  --stone-black-face: linear-gradient(145deg, #33413c, #08100d);
  --stone-black-shadow: inset 0 1px 1px rgb(255 255 255 / 18%), 0 2px 4px rgb(0 0 0 / 24%);
  --stone-white-face: linear-gradient(145deg, white, #d9d3c6);
  --stone-white-shadow: inset 0 0 0 1px #d0c9bb, 0 2px 4px rgb(0 0 0 / 18%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 12%, rgb(255 255 255 / 65%) 0 9rem, transparent 9.2rem),
    linear-gradient(135deg, var(--paper) 0%, #f1ecdf 100%);
}

button, select, input { font: inherit; }
button, label, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.7rem 1rem;
  color: white;
  background: var(--green-950);
  border-radius: 0.35rem;
  transform: translateY(-140%);
}
.skip-link:focus { transform: translateY(0); }

.site-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 92px;
  border-bottom: 1px solid rgb(23 63 53 / 16%);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  color: var(--ink);
  text-decoration: none;
}
.brand strong { display: block; font-family: Georgia, "Yu Mincho", serif; font-size: 1.25rem; letter-spacing: 0.08em; }
.brand small { display: block; margin-top: 0.14rem; color: var(--muted); font-size: 0.66rem; letter-spacing: 0.05em; }
.brand-mark { position: relative; width: 44px; height: 44px; border-radius: 50%; background: var(--green-900); box-shadow: inset 0 0 0 1px rgb(255 255 255 / 15%); }
.brand-mark i { position: absolute; width: 15px; height: 15px; border-radius: 50%; box-shadow: 0 2px 4px rgb(0 0 0 / 28%); }
.brand-mark i:first-child { top: 9px; left: 9px; background: #101714; }
.brand-mark i:last-child { right: 9px; bottom: 9px; background: #fffdf7; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.66rem 1.05rem;
  border: 1px solid transparent;
  border-radius: 0.55rem;
  cursor: pointer;
  font-weight: 700;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid #e5b858; outline-offset: 3px; }
.button:disabled { cursor: not-allowed; opacity: 0.5; }
.button-primary { color: white; background: var(--green-900); box-shadow: 0 8px 22px rgb(23 63 53 / 22%); }
.button-primary:hover:not(:disabled) { background: var(--green-800); }
.button-secondary { color: var(--green-950); background: white; border-color: var(--line); }
.button-quiet { color: var(--green-900); background: transparent; border-color: rgb(23 63 53 / 22%); }
.button-danger { color: white; background: var(--danger); }
.button-large { width: 100%; min-height: 58px; justify-content: space-between; padding-inline: 1.4rem; font-size: 1rem; }
.button-full { width: 100%; margin-bottom: 0.55rem; }

.setup-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(420px, 0.96fr);
  gap: clamp(2rem, 6vw, 5.8rem);
  align-items: center;
  min-height: calc(100vh - 166px);
  padding: 4.5rem 1.2rem;
}

.eyebrow { margin: 0 0 1rem; color: var(--green-700); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.24em; text-transform: uppercase; }
.intro-panel h1 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: clamp(3rem, 5vw, 4.5rem); font-weight: 400; line-height: 1.04; letter-spacing: -0.045em; }
.intro-panel h1 em { display: inline-block; color: var(--green-700); font-style: normal; white-space: nowrap; }
.lead { max-width: 34rem; margin: 2rem 0 0; color: var(--muted); font-size: 1rem; line-height: 2; }

.intro-board {
  position: relative;
  width: 180px;
  height: 78px;
  margin-top: 3rem;
  border-bottom: 1px solid var(--line);
}
.demo-stone { position: absolute; bottom: 12px; width: 54px; height: 54px; border-radius: 50%; }
.demo-stone-black { left: 8px; background: linear-gradient(145deg, #33413c, #09110e); box-shadow: 0 12px 20px rgb(0 0 0 / 24%); }
.demo-stone-white { left: 56px; z-index: 2; background: linear-gradient(145deg, white, #ddd7ca); box-shadow: 0 12px 20px rgb(0 0 0 / 16%); }
.demo-ring { position: absolute; right: 16px; bottom: 20px; width: 38px; height: 38px; border: 2px dashed var(--green-600); border-radius: 50%; }

.setup-card {
  padding: clamp(1.4rem, 4vw, 2.4rem);
  background: rgb(255 253 248 / 92%);
  border: 1px solid rgb(255 255 255 / 80%);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; padding-bottom: 1.1rem; border-bottom: 1px solid var(--line); }
.section-heading span { font-family: Georgia, "Yu Mincho", serif; font-size: 1.45rem; }
.section-heading small { color: var(--muted); font-size: 0.68rem; }
fieldset { margin: 1.4rem 0 0; padding: 0; border: 0; }
legend, .field-label, .two-fields label, .control-card label { display: block; margin-bottom: 0.65rem; color: var(--muted); font-size: 0.73rem; font-weight: 800; letter-spacing: 0.06em; }

.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.55rem; }
.choice-card { position: relative; display: flex; min-height: 112px; padding: 0.8rem 0.4rem; align-items: center; justify-content: center; flex-direction: column; gap: 0.28rem; text-align: center; border: 1px solid var(--line); border-radius: 0.65rem; cursor: pointer; background: white; }
.choice-card input { position: absolute; opacity: 0; }
.choice-card:has(input:checked) { color: var(--green-950); background: var(--green-100); border-color: var(--green-600); box-shadow: inset 0 0 0 1px var(--green-600); }
.choice-card:has(input:focus-visible) { outline: 3px solid #e5b858; outline-offset: 3px; }
.choice-card strong { font-size: 0.82rem; }
.choice-card small { color: var(--muted); font-size: 0.65rem; }
.choice-icon { display: grid; place-items: center; width: 34px; height: 34px; color: white; background: var(--green-900); border-radius: 50%; font-size: 0.7rem; font-weight: 800; letter-spacing: -0.08em; }

.settings-group { margin-top: 1.3rem; padding-top: 0.1rem; border-top: 1px dashed var(--line); }
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; background: var(--paper-deep); border-radius: 0.6rem; }
.segmented-control label { position: relative; cursor: pointer; }
.segmented-control input { position: absolute; opacity: 0; }
.segmented-control span { display: flex; min-height: 42px; align-items: center; justify-content: center; gap: 0.5rem; border-radius: 0.45rem; font-size: 0.8rem; font-weight: 700; }
.segmented-control input:checked + span { background: white; box-shadow: 0 2px 8px rgb(31 50 43 / 10%); }
.segmented-control input:focus-visible + span { outline: 3px solid #e5b858; }
.mini-stone { display: inline-block; width: 15px; height: 15px; flex: none; border-radius: 50%; }
.black { background: var(--stone-black-face); box-shadow: var(--stone-black-shadow); }
.white { background: var(--stone-white-face); box-shadow: var(--stone-white-shadow); }
select { width: 100%; min-height: 46px; padding: 0.65rem 2.5rem 0.65rem 0.8rem; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 0.55rem; }
.field-label { margin-top: 1rem; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; margin-top: 1rem; }
.setup-card .button-large { margin-top: 1.5rem; }
.storage-note { margin: 0.75rem 0 0; color: var(--muted); font-size: 0.64rem; line-height: 1.6; text-align: center; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 640px) minmax(240px, 300px);
  gap: clamp(1.5rem, 4vw, 3.5rem);
  justify-content: center;
  align-items: start;
  padding: clamp(1.2rem, 3vh, 2rem) 0 3rem;
}
.game-main {
  --game-board-size: min(100%, clamp(300px, 57.5svh, 600px), calc(100vw - 32px));
  min-width: 0;
}
.game-heading { display: flex; width: var(--game-board-size); justify-content: space-between; align-items: center; margin: 0 auto 0.75rem; }
.game-heading .eyebrow { margin-bottom: 0.22rem; }
.game-heading h1 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: clamp(1.8rem, 4vw, 2.5rem); font-weight: 400; }
.turn-pill { display: flex; align-items: center; gap: 0.45rem; padding: 0.55rem 0.8rem; font-size: 0.76rem; font-weight: 800; background: white; border: 1px solid var(--line); border-radius: 999px; }

.score-strip { display: grid; width: var(--game-board-size); grid-template-columns: 1fr auto 1fr; gap: 0.65rem; align-items: center; margin: 0 auto 0.65rem; }
.score-card { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0.8rem; background: rgb(255 255 255 / 65%); border: 1px solid transparent; border-radius: 0.7rem; opacity: 0.72; }
.score-card:last-child { justify-content: flex-end; text-align: right; }
.score-card.is-active { background: white; border-color: var(--green-300); opacity: 1; box-shadow: 0 5px 18px rgb(24 61 51 / 9%); }
.score-stone { display: inline-block; width: 34px; height: 34px; flex: none; border-radius: 50%; }
.score-card span { display: flex; flex-direction: column; }
.score-card small { color: var(--muted); font-size: 0.65rem; font-weight: 700; }
.score-card strong { font-family: Georgia, serif; font-size: 1.35rem; line-height: 1.05; }
.move-counter { text-align: center; }
.move-counter span { display: block; color: var(--muted); font-size: 0.58rem; }
.move-counter strong { font-family: Georgia, serif; font-size: 1.05rem; }

.board-frame { display: grid; grid-template-columns: 1.5rem minmax(0, 1fr); grid-template-rows: 1.5rem minmax(0, 1fr); width: var(--game-board-size); margin-inline: auto; }
.column-labels { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); align-items: center; color: var(--muted); font-size: 0.62rem; font-weight: 800; text-align: center; }
.row-labels { display: grid; grid-template-rows: repeat(8, minmax(0, 1fr)); align-items: center; color: var(--muted); font-size: 0.62rem; font-weight: 800; text-align: center; }
.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--green-700);
  border: clamp(5px, 1.2vw, 10px) solid var(--green-950);
  border-radius: 0.45rem;
  box-shadow: 0 20px 55px rgb(16 50 41 / 23%), inset 0 0 0 1px rgb(255 255 255 / 13%);
}
.board-row { display: contents; }
.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  background: linear-gradient(145deg, #397d67, #2d6f5b);
  border: 0;
  border-right: 1px solid rgb(8 44 35 / 43%);
  border-bottom: 1px solid rgb(8 44 35 / 43%);
  cursor: default;
  perspective: 400px;
}
.board-row .cell:last-child { border-right: 0; }
.board-row:last-child .cell { border-bottom: 0; }
.cell.is-legal { cursor: pointer; background: linear-gradient(145deg, #438a72, #347b64); }
.cell.is-legal:hover { background: #4b957c; }
.cell:focus-visible { z-index: 2; outline: 4px solid #f7c95f; outline-offset: -5px; }
.stone { display: block; width: min(78%, 62px); aspect-ratio: 1 / 1; border-radius: 50%; }
.stone.is-flipped { animation: stone-flip 260ms ease-in-out; backface-visibility: hidden; transform-style: preserve-3d; will-change: transform; }
.stone.is-flipped.black { --flip-from-face: var(--stone-white-face); --flip-from-shadow: var(--stone-white-shadow); --flip-to-face: var(--stone-black-face); --flip-to-shadow: var(--stone-black-shadow); }
.stone.is-flipped.white { --flip-from-face: var(--stone-black-face); --flip-from-shadow: var(--stone-black-shadow); --flip-to-face: var(--stone-white-face); --flip-to-shadow: var(--stone-white-shadow); }
.cell.is-last::after { content: ""; position: absolute; top: 50%; left: 50%; width: 15%; aspect-ratio: 1 / 1; border: 2px solid #efbd4f; border-radius: 50%; transform: translate(-50%, -50%); }
.legal-marker { display: block; width: clamp(7px, 16%, 11px); aspect-ratio: 1 / 1; background: #f8dda0; border: 0; border-radius: 50%; box-shadow: 0 1px 3px rgb(8 44 35 / 32%); opacity: 0.78; }
@keyframes stone-flip {
  0% { background: var(--flip-from-face); box-shadow: var(--flip-from-shadow); transform: rotateY(0deg); }
  49% { background: var(--flip-from-face); box-shadow: var(--flip-from-shadow); transform: rotateY(90deg); }
  50% { background: var(--flip-to-face); box-shadow: var(--flip-to-shadow); transform: rotateY(90deg); }
  100% { background: var(--flip-to-face); box-shadow: var(--flip-to-shadow); transform: rotateY(0deg); }
}

.status-message { display: flex; width: var(--game-board-size); min-height: 44px; align-items: center; gap: 0.45rem; margin: 0.75rem auto 0; padding: 0.55rem 0.7rem; color: var(--green-950); background: rgb(255 255 255 / 68%); border-left: 3px solid var(--green-600); font-size: 0.74rem; line-height: 1.4; }
.status-message[data-kind="pass"], .status-message[data-kind="warning"] { border-color: var(--amber); }
.status-message[data-kind="error"] { border-color: var(--danger); }
.status-icon { flex: none; font-size: 0.5rem; }
#status-text { min-width: 0; overflow-wrap: anywhere; }

.game-sidebar { position: sticky; top: 1.2rem; padding-top: 4.8rem; }
.info-card, .control-card { margin-bottom: 0.9rem; padding: 1.2rem; background: rgb(255 253 248 / 86%); border: 1px solid rgb(217 209 195 / 78%); border-radius: 0.8rem; box-shadow: 0 8px 28px rgb(35 49 44 / 7%); }
.card-label { margin: 0 0 0.7rem; color: var(--green-700); font-size: 0.62rem; font-weight: 900; letter-spacing: 0.16em; text-transform: uppercase; }
.info-card h2 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: 1.45rem; font-weight: 400; }
.info-card > p:last-of-type { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.76rem; }
.thinking { display: flex; align-items: center; gap: 0.2rem; margin-top: 0.85rem; color: var(--green-700); font-size: 0.68rem; font-weight: 800; }
.thinking span { width: 5px; height: 5px; background: currentColor; border-radius: 50%; animation: bounce 900ms infinite alternate; }
.thinking span:nth-child(2) { animation-delay: 160ms; }
.thinking span:nth-child(3) { animation-delay: 320ms; margin-right: 0.25rem; }
@keyframes bounce { to { transform: translateY(-4px); opacity: 0.35; } }
.control-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; margin-bottom: 0.85rem; }
.control-row .button { padding-inline: 0.5rem; font-size: 0.73rem; }
.control-card select { font-size: 0.76rem; }
.keyboard-tip { color: var(--muted); font-size: 0.62rem; line-height: 1.8; text-align: center; }
kbd { display: inline-grid; min-width: 1.3rem; height: 1.3rem; place-items: center; margin: 0 0.05rem; background: white; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 0.2rem; font-size: 0.58rem; }

footer { display: flex; justify-content: space-between; padding: 1.4rem 0 2rem; color: var(--muted); border-top: 1px solid rgb(23 63 53 / 14%); font-size: 0.62rem; letter-spacing: 0.12em; }

.modal { width: min(540px, calc(100% - 32px)); padding: 0; background: transparent; border: 0; }
.modal::backdrop { background: rgb(10 30 25 / 68%); backdrop-filter: blur(5px); }
.modal-content { position: relative; padding: clamp(1.5rem, 5vw, 2.5rem); background: var(--card); border-radius: 1rem; box-shadow: 0 30px 100px rgb(0 0 0 / 28%); }
.modal-small { max-width: 430px; }
.modal h2 { margin: 0 0 0.8rem; font-family: Georgia, "Yu Mincho", serif; font-size: clamp(1.8rem, 5vw, 2.5rem); font-weight: 400; }
.modal p { color: var(--muted); line-height: 1.7; }
.modal-close { position: absolute; top: 1rem; right: 1rem; display: grid; width: 42px; height: 42px; place-items: center; background: transparent; border: 1px solid var(--line); border-radius: 50%; cursor: pointer; font-size: 1.4rem; }
.guide-list { margin: 1.5rem 0; padding: 0; list-style: none; }
.guide-list li { display: grid; grid-template-columns: 2.4rem 1fr; gap: 0.8rem; padding: 0.9rem 0; border-bottom: 1px solid var(--line); }
.guide-list li > span { color: var(--green-600); font-family: Georgia, serif; font-size: 1.15rem; }
.guide-list strong { font-size: 0.9rem; }
.guide-list p { margin: 0.25rem 0 0; font-size: 0.76rem; }
.guide-note { margin-bottom: 1rem; padding: 1rem; background: var(--green-100); border-radius: 0.6rem; }
.guide-note p { margin: 0.3rem 0 0; font-size: 0.76rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.5rem; }
.result-modal { max-width: 470px; text-align: center; }
.result-emblem { display: flex; justify-content: center; margin: -0.5rem 0 1.2rem; }
.result-emblem .score-stone + .score-stone { margin-left: -8px; }
.result-score { color: var(--ink) !important; font-family: Georgia, serif; font-size: 1.3rem; }
.result-modal .modal-actions { justify-content: center; }

@media (max-width: 900px) {
  .setup-layout { grid-template-columns: 1fr; gap: 2.5rem; padding-block: 3rem; }
  .intro-panel { text-align: center; }
  .intro-panel .lead { margin-inline: auto; }
  .intro-board { margin-inline: auto; }
  .setup-card { width: min(580px, 100%); margin: 0 auto; }
  .game-layout { grid-template-columns: minmax(0, 640px); }
  .game-sidebar { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; padding-top: 0; }
  .game-sidebar > * { margin: 0; }
  .keyboard-tip { grid-column: 1 / -1; }
}

@media (max-width: 600px) {
  .site-shell { width: min(100% - 20px, 540px); }
  .site-header { min-height: 72px; }
  .brand small { display: none; }
  .brand-mark { width: 36px; height: 36px; }
  .brand-mark i { width: 12px; height: 12px; }
  .brand-mark i:first-child { top: 7px; left: 7px; }
  .brand-mark i:last-child { right: 7px; bottom: 7px; }
  #open-guide { min-height: 40px; padding: 0.45rem 0.65rem; font-size: 0.72rem; }
  .setup-layout { min-height: auto; padding: 2.3rem 0 3rem; }
  .intro-panel h1 { font-size: clamp(2.3rem, 11.2vw, 3rem); }
  .lead { font-size: 0.88rem; line-height: 1.8; }
  .intro-board { margin-top: 1.8rem; }
  .setup-card { padding: 1.2rem; }
  .section-heading small { display: none; }
  .choice-card { min-height: 100px; }
  .choice-card small { display: none; }
  .game-layout { padding-top: 1.4rem; gap: 1rem; }
  .game-heading { margin-inline: 0.25rem; }
  .turn-pill { padding: 0.45rem 0.6rem; font-size: 0.68rem; }
  .score-strip { gap: 0.2rem; }
  .score-card { gap: 0.4rem; padding: 0.45rem; }
  .score-stone { width: 26px; height: 26px; }
  .score-card small { font-size: 0.56rem; }
  .score-card strong { font-size: 1.1rem; }
  .board-frame { grid-template-columns: 1.1rem 1fr; grid-template-rows: 1.1rem 1fr; }
  .status-message { gap: 0.35rem; padding-inline: 0.55rem; font-size: clamp(0.66rem, 2.9vw, 0.72rem); }
  .game-sidebar { grid-template-columns: 1fr; }
  footer { gap: 1rem; font-size: 0.52rem; }
  footer span:last-child { text-align: right; }
  .stacked-mobile { flex-direction: column; }
  .stacked-mobile .button { width: 100%; }
}

@media (max-width: 360px) {
  .site-shell { width: calc(100% - 12px); }
  .brand strong { font-size: 1rem; }
  .mode-grid { gap: 0.3rem; }
  .choice-card { padding-inline: 0.2rem; }
  .choice-card strong { font-size: 0.72rem; }
  .two-fields { grid-template-columns: 1fr; }
  .game-heading h1 { font-size: 1.5rem; }
  .score-card small { max-width: 58px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .stone.is-flipped { animation: none !important; }
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
