:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --line: #d9d6cc;
  --accent: #2f7d4f;
  --accent-text: #ffffff;
  --accent-soft: #e3f1e8;
  --danger: #b3261e;
  --othello-board: #2f7d4f;
  --othello-line: #1d5634;
  --shogi-board: #e8c27a;
  --shogi-line: #8a6420;
  --piece: #f7e3b5;
  --piece-edge: #9b7a3c;
  --hint: rgba(0, 0, 0, 0.22);
  --last: rgba(255, 214, 0, 0.45);
  --select: rgba(47, 125, 79, 0.45);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1f2226;
    --text: #e8e6e1;
    --muted: #a3a8ae;
    --line: #363a40;
    --accent: #5cb27e;
    --accent-text: #0d1a12;
    --accent-soft: #1f3327;
    --danger: #f08c84;
    --othello-board: #276b43;
    --othello-line: #17432a;
    --shogi-board: #c9a35d;
    --shogi-line: #6e4f17;
    --piece: #f3dfae;
    --piece-edge: #8a6a30;
    --hint: rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a; --surface: #1f2226; --text: #e8e6e1; --muted: #a3a8ae; --line: #363a40;
  --accent: #5cb27e; --accent-text: #0d1a12; --accent-soft: #1f3327; --danger: #f08c84;
  --othello-board: #276b43; --othello-line: #17432a; --shogi-board: #c9a35d; --shogi-line: #6e4f17;
  --piece: #f3dfae; --piece-edge: #8a6a30; --hint: rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.site-header .inner, main, .site-footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
}
.site-header .inner { display: flex; align-items: center; gap: 12px; height: 52px; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand img { width: 24px; height: 24px; }
.crumb { color: var(--muted); font-size: 0.95rem; }
h1 { font-size: 1.6rem; margin: 24px 0 8px; line-height: 1.3; }
.lead { color: var(--muted); margin: 0 0 24px; }
.site-footer { color: var(--muted); font-size: 0.85rem; padding-top: 32px; padding-bottom: 32px; }

/* Game list */
.game-list { list-style: none; padding: 0; margin: 0 0 32px; display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.game-card {
  display: flex; gap: 16px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; color: var(--text); text-decoration: none; height: 100%;
  transition: border-color 0.15s, transform 0.15s;
}
.game-card:hover, .game-card:focus-visible { border-color: var(--accent); transform: translateY(-2px); }
.game-card svg { width: 72px; height: 72px; flex: none; border-radius: 8px; }
.game-card h2 { margin: 0 0 4px; font-size: 1.2rem; }
.game-card p { margin: 0; color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
.tags { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tag { font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

/* Game page */
.game-layout { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr) 280px; align-items: start; margin-bottom: 24px; }
@media (max-width: 760px) { .game-layout { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.panel h2 { font-size: 1rem; margin: 0 0 8px; }
.field { margin-bottom: 12px; }
.field-label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { flex: 1; text-align: center; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 6px 4px; font-size: 0.9rem; border-left: 1px solid var(--line); }
.seg label:first-child span { border-left: 0; }
.seg input:checked + span { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg input:disabled + span { opacity: 0.4; cursor: not-allowed; }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; }
button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.status { font-weight: 600; min-height: 1.7em; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status .thinking::after { content: ""; display: inline-block; width: 1em; animation: dots 1.2s steps(4) infinite; text-align: left; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.status.over { color: var(--accent); }
.board-wrap { width: 100%; max-width: 560px; margin: 0 auto; }
.help { color: var(--muted); font-size: 0.9rem; }
.help h2 { color: var(--text); font-size: 1.1rem; margin-top: 24px; }

/* Othello */
.othello-board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); aspect-ratio: 1;
  background: var(--othello-board); border: 6px solid var(--othello-line); border-radius: 6px;
  gap: 1px; background-clip: padding-box; box-shadow: 0 0 0 1px var(--othello-line) inset;
}
.othello-board { background-color: var(--othello-line); }
.o-cell { background: var(--othello-board); position: relative; border: 0; padding: 0; border-radius: 0; cursor: default; }
.o-cell.can { cursor: pointer; }
.o-cell.can::after {
  content: ""; position: absolute; inset: 38%; border-radius: 50%; background: var(--hint);
}
.o-cell.last { box-shadow: inset 0 0 0 3px var(--last); }
.disc {
  position: absolute; inset: 9%; border-radius: 50%;
  box-shadow: 0 2px 2px rgba(0, 0, 0, 0.35);
  transition: background-color 0.25s;
}
.disc.b { background: radial-gradient(circle at 35% 30%, #4a4a4a, #0b0b0b 70%); }
.disc.w { background: radial-gradient(circle at 35% 30%, #ffffff, #d6d6d6 75%); }
.disc.flip { animation: flip 0.3s ease; }
@keyframes flip { 0% { transform: scaleX(1); } 50% { transform: scaleX(0.05); } 100% { transform: scaleX(1); } }
.score { display: flex; gap: 16px; margin-bottom: 12px; }
.score div { display: flex; align-items: center; gap: 6px; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.score .chip { width: 18px; height: 18px; border-radius: 50%; display: inline-block; border: 1px solid var(--line); }
.chip.b { background: #111; }
.chip.w { background: #fff; }
.score .turn { font-weight: 700; text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 3px; text-underline-offset: 6px; }

/* Shogi */
.shogi-area { display: flex; flex-direction: column; gap: 6px; }
.hand {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-height: 44px;
  padding: 4px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.hand .who { font-size: 0.8rem; color: var(--muted); margin-right: 6px; white-space: nowrap; }
.hand.top { flex-direction: row-reverse; }
.hand.top .who { margin-right: 0; margin-left: 6px; }
.hand button { padding: 0; border: 0; background: none; position: relative; width: 36px; height: 40px; }
.hand button .count { position: absolute; right: -4px; bottom: -2px; font-size: 0.7rem; font-weight: 700; background: var(--text); color: var(--bg); border-radius: 999px; min-width: 16px; line-height: 16px; text-align: center; }
.hand button.sel .pc { outline: 3px solid var(--accent); outline-offset: 1px; }
.files, .ranks { color: var(--muted); font-size: 0.75rem; }
.files { display: grid; grid-template-columns: repeat(9, 1fr); text-align: center; margin-right: 18px; }
.board-row { display: flex; }
.ranks { display: grid; grid-template-rows: repeat(9, 1fr); width: 18px; text-align: center; align-items: center; }
.shogi-board {
  flex: 1; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); aspect-ratio: 9 / 9.8;
  background: var(--shogi-board); border: 2px solid var(--shogi-line); gap: 1px; background-color: var(--shogi-line);
}
.s-cell { background: var(--shogi-board); border: 0; padding: 0; border-radius: 0; position: relative; min-height: 0; min-width: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.s-cell.last { background-image: linear-gradient(var(--last), var(--last)); }
.s-cell.sel { background-image: linear-gradient(var(--select), var(--select)); }
.s-cell.can::after { content: ""; position: absolute; width: 26%; height: 24%; border-radius: 50%; background: var(--hint); pointer-events: none; }
.s-cell.check { box-shadow: inset 0 0 0 3px var(--danger); }
.pc {
  width: 86%; height: 90%; display: flex; align-items: center; justify-content: center;
  background: var(--piece); color: #1a1a1a;
  clip-path: polygon(50% 0, 84% 14%, 100% 100%, 0 100%, 16% 14%);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif; font-weight: 700;
  font-size: clamp(0.8rem, 4.2vw, 1.6rem); line-height: 1; padding-top: 10%;
  filter: drop-shadow(0 1px 0 var(--piece-edge));
}
.pc.small { font-size: 1rem; width: 32px; height: 36px; margin: 2px auto 0; }
.pc.gote { transform: rotate(180deg); padding-top: 0; padding-bottom: 10%; }
.pc.promo { color: #b3261e; }
.pc.two { font-size: clamp(0.55rem, 2.6vw, 1rem); writing-mode: vertical-rl; letter-spacing: -0.1em; }
.kifu { max-height: 220px; overflow-y: auto; font-size: 0.9rem; margin: 0; padding-left: 2.6em; font-variant-numeric: tabular-nums; }
.kifu li.cur { font-weight: 700; color: var(--accent); }

dialog {
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text);
  padding: 20px; max-width: 320px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog p { margin: 0 0 16px; font-weight: 600; }
dialog .buttons { justify-content: flex-end; }
dialog .promo-choice { display: flex; gap: 12px; justify-content: center; margin-bottom: 8px; }
dialog .promo-choice button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* Board squares and hand pieces are disabled when not playable, but must not look faded */
.o-cell:disabled, .s-cell:disabled, .hand button:disabled { opacity: 1; cursor: default; }
