/* Taikyoku: a small shogi board on warm paper. Light by default; house/theme.js sets data-theme="dark" on <html>.
   The pieces keep their pale wood in both themes (like real koma), so their own ink and red stay fixed. */
@font-face { font-family: "TK Kanji"; src: url("kanji.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "TK Kanji X1"; src: url("kanji-x1.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "TK Kanji X2"; src: url("kanji-x2.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --bg: #F8F6F2;
  --paper: #EFE8DC;
  --card: #FFFDF8;
  --ink: #2A2520;
  --muted: #7A6F63;
  --line: #D9CFBF;
  --wood: #E7C98E;
  --wood-dark: #C9A462;
  --grid: #8C6A35;
  --zone: #D9B574;
  --piece: #F6E7C4;
  --piece-hi: #FBF0D6;
  --piece-edge: #B8935A;
  --piece-ink: #2A2520;
  --piece-red: #B3261E;
  --red: #B3261E;
  --accent: #2F5D50;
  --on-accent: #FFFFFF;
  --gold: #C8961E;
  --danger: rgba(179, 38, 30, .18);
  --mv: rgba(47, 93, 80, .55);
  --cap: rgba(47, 93, 80, .7);
  --peek: rgba(179, 38, 30, .55);
  --last: rgba(47, 93, 80, .45);
  --enemy-last: rgba(179, 38, 30, .5);
  --cell: #FBF7EF;
  --ray: #DCE8E3;
  --jray: #E9E2F3;
  --jray-ink: #6B4FA0;
  --special: #F6E1C9;
  --special-ink: #A0531E;
  --field: #FFFFFF;
  --backdrop: rgba(42, 37, 32, .45);
  --kanji: "TK Kanji", "TK Kanji X1", "TK Kanji X2", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #17130F;
  --paper: #221C16;
  --card: #2A231C;
  --ink: #EFE6D8;
  --muted: #A8998A;
  --line: #3D342A;
  --wood: #9A7742;
  --wood-dark: #5E4524;
  --grid: #3B2A14;
  --zone: #82602F;
  --piece: #EAD7AE;
  --piece-hi: #F4E6C6;
  --piece-edge: #A07C48;
  --red: #E98A80;
  --accent: #7CC2AA;
  --on-accent: #10201B;
  --gold: #E8B83E;
  --danger: rgba(233, 110, 98, .3);
  --mv: rgba(20, 52, 44, .7);
  --cap: rgba(20, 52, 44, .85);
  --peek: rgba(140, 24, 18, .7);
  --last: rgba(20, 60, 50, .6);
  --enemy-last: rgba(150, 30, 22, .65);
  --cell: #2E261E;
  --ray: #24403A;
  --jray: #3A3150;
  --jray-ink: #C2A8F0;
  --special: #4A3522;
  --special-ink: #EAA86C;
  --field: #1E1914;
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;
}
.theme-anim, .theme-anim * { transition: background-color .4s, color .4s, border-color .4s !important; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { touch-action: manipulation; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); line-height: 1.45; min-height: 100vh; min-height: 100dvh; -webkit-text-size-adjust: 100%;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
a { color: inherit; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------ page frame (same shape as the other plain-header games) */
.wrap { max-width: 640px; margin: 0 auto; padding: 0 14px; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 0 0; }
.back { text-decoration: none; color: var(--muted); font-size: 0.95rem; white-space: nowrap; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; color: var(--ink); }
@media (hover: hover) { .icon-btn:hover { background: var(--paper); } }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }
.icon-btn.kj-btn { font-family: var(--kanji); font-size: 1.15rem; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 0 8px; }
h1 { font-family: var(--kanji); font-weight: 700; font-size: 2rem; margin: 0; line-height: 1; letter-spacing: .01em; }
.sub { margin: 0; color: var(--muted); font-size: 0.95rem; }

/* ------------------------------------------------------------ status */
.status { text-align: center; }
.objective { margin: 4px auto 6px; font-size: 1.05rem; font-weight: 600; line-height: 1.35; max-width: 34em; }
.objective .kj { font-family: var(--kanji); font-weight: 700; }
.counters { display: flex; justify-content: center; gap: 18px; color: var(--muted); font-size: .9rem; }
.counters b { color: var(--ink); }

/* ------------------------------------------------------------ board */
.board-wrap { margin: 12px auto 6px; width: min(100%, 500px); position: relative; }
.board {
  display: grid; width: 100%; aspect-ratio: 1; background: var(--wood);
  border: 3px solid var(--wood-dark); border-radius: 6px; padding: 2px; gap: 1px;
  background-image: linear-gradient(var(--grid), var(--grid)); background-clip: content-box;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .08); touch-action: manipulation;
}
.sq { position: relative; background: var(--wood); display: flex; align-items: center; justify-content: center; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.board.locked .sq { cursor: default; }
.sq.zone { background: var(--zone); }
.sq.danger::after { content: ""; position: absolute; inset: 0; background: var(--danger); pointer-events: none; }
.sq.last { box-shadow: inset 0 0 0 3px var(--last); }
.sq.enemy-last { box-shadow: inset 0 0 0 3px var(--enemy-last); }
.sq.sel { box-shadow: inset 0 0 0 3px var(--accent); }
.sq .mv { position: absolute; width: 28%; height: 28%; border-radius: 50%; background: var(--mv); pointer-events: none; }
.sq .cap { position: absolute; inset: 7%; border-radius: 50%; border: 3px solid var(--cap); pointer-events: none; }
.sq.peek .mv { background: var(--peek); }
.sq.peek .cap { border-color: var(--peek); }

/* the shogi piece: a pentagon */
.koma {
  position: relative; width: 84%; height: 92%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--kanji); font-weight: 700; color: var(--piece-ink); line-height: 1;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .25));
  transition: transform .18s ease;
}
.koma::before {
  content: ""; position: absolute; inset: 0; background: var(--piece-edge);
  clip-path: polygon(50% 0, 88% 16%, 100% 100%, 0 100%, 12% 16%);
}
.koma::after {
  content: ""; position: absolute; inset: 1.5px; background: linear-gradient(180deg, var(--piece-hi), var(--piece));
  clip-path: polygon(50% 0, 88% 16%, 100% 100%, 0 100%, 12% 16%);
}
.koma > * { position: relative; z-index: 1; }
.koma.enemy { transform: rotate(180deg); }
.koma.promoted .glyphs { color: var(--piece-red); }
.koma.key::before { background: var(--gold); }
.koma.key::after { inset: 3px; }
.koma.blank .glyphs { font-size: 12px; color: #8A7B66; }
.glyphs { display: flex; flex-direction: column; align-items: center; margin-top: 12%; }
.g { display: block; }
.gh { display: flex; }
.gh > span { display: block; transform: scaleX(.55); margin: 0 -.22em; }
.gv { display: flex; flex-direction: column; }
.gv > span { display: block; transform: scaleY(.55); margin: -.22em 0; }

.msg { min-height: 1.4em; margin: 8px 0 0; text-align: center; font-size: .92rem; color: var(--muted); }
.msg.bad { color: var(--red); }
.msg.good { color: var(--accent); font-weight: 600; }

.controls { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0 14px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--paper); padding: 8px 16px; border-radius: 999px; cursor: pointer; min-height: 40px; }
@media (hover: hover) { .btn:hover:not(:disabled) { border-color: var(--muted); } }
.btn:disabled { opacity: .45; cursor: default; }
.toggle { font-size: .9rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; min-height: 40px; }
.toggle input { accent-color: var(--accent); }

/* ------------------------------------------------------------ result card */
.card.done { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin: 0 0 14px; text-align: center; }
.kicker { margin: 0; color: var(--muted); font-weight: 600; }
.big { font-family: var(--kanji); font-weight: 700; font-size: 2rem; line-height: 1.1; margin: 6px 0; }
.res-line { margin: 0 0 14px; }
.go { width: 100%; border: 0; border-radius: 14px; padding: 13px; background: var(--accent); color: var(--on-accent); font-weight: 800; font-size: 1.05rem; cursor: pointer; }
.go.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.rank { margin: 12px 0 0; font-weight: 700; min-height: 1.2em; }
.rank:empty { display: none; }
.lb-link { display: block; margin: 8px auto 0; border: 0; background: none; color: var(--muted); font-weight: 700; font-size: 0.92rem; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 6px 8px; min-height: 40px; }
@media (hover: hover) { .lb-link:hover { color: var(--ink); } }
.fine { color: var(--muted); font-size: 0.88rem; margin: 10px 0 0; }

/* ------------------------------------------------------------ piece card */
.card-area { min-height: 80px; }
.card-hint { text-align: center; color: var(--muted); font-size: .9rem; margin: 6px 0; }
.card.piece { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px; perspective: 900px; }
.card-head { display: flex; gap: 14px; align-items: flex-start; }
.flipper { width: 74px; height: 86px; flex: none; position: relative; cursor: pointer; transform-style: preserve-3d; transition: transform .45s ease; }
.flipper.flipped { transform: rotateY(180deg); }
.flipper .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; align-items: center; justify-content: center; }
.flipper .face.back { transform: rotateY(180deg); }
.flipper .koma { width: 100%; height: 100%; font-size: 26px; }
.flip-note { font-size: .72rem; color: var(--muted); text-align: center; margin-top: 4px; width: 74px; }
.card-title { flex: 1; min-width: 0; }
.card-title h3 { margin: 0; font-size: 1.15rem; }
.card-title .reading { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.card-title .reading .kj { font-family: var(--kanji); font-weight: 700; color: var(--ink); font-size: 1.05rem; margin-right: .35em; }
.card-title .side-txt { margin-top: 6px; }
.gloss { margin: 8px 0 0; padding: 0; list-style: none; font-size: .88rem; }
.gloss li { margin: 2px 0; }
.gloss .kj { font-family: var(--kanji); font-weight: 700; display: inline-block; min-width: 1.4em; }
.card-body { display: grid; grid-template-columns: auto 1fr; gap: 14px; margin-top: 12px; align-items: start; }
@media (max-width: 460px) { .card-body { grid-template-columns: 1fr; } .diagram, .legend { margin-left: auto; margin-right: auto; } }
.diagram { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); width: 168px; }
.diagram > div { aspect-ratio: 1; background: var(--cell); position: relative; display: flex; align-items: center; justify-content: center; font-size: 9px; color: var(--accent); }
.diagram .me { background: var(--ink); }
.diagram .step::after { content: ""; width: 46%; height: 46%; border-radius: 50%; background: var(--accent); }
.diagram .ray { background: var(--ray); }
.diagram .ray::after { content: ""; width: 30%; height: 30%; border-radius: 50%; background: var(--accent); }
.diagram .jump::after { content: ""; width: 46%; height: 46%; border-radius: 50%; border: 2px solid var(--accent); background: transparent; }
.diagram .jray { background: var(--jray); }
.diagram .jray::after { content: ""; width: 30%; height: 30%; border-radius: 50%; border: 2px solid var(--jray-ink); }
.diagram .special { background: var(--special); }
.diagram .special::after { content: "✦"; color: var(--special-ink); font-size: 10px; }
.diagram .lbl { position: absolute; right: 1px; bottom: 0; font-size: 8px; color: var(--ink); }
.legend { font-size: .72rem; color: var(--muted); margin-top: 6px; line-height: 1.5; width: 168px; }
.moves-text { font-size: .93rem; line-height: 1.45; margin: 0; padding-left: 1.1em; }
.moves-text li { margin-bottom: 4px; }
.evo { margin-top: 12px; }
.evo h4 { margin: 0 0 6px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.chip { border: 1px solid var(--line); background: var(--cell); border-radius: 8px; padding: 4px 8px; cursor: pointer; font-size: .82rem; text-align: center; }
.chip .kj { font-family: var(--kanji); font-weight: 700; display: block; font-size: 1rem; }
.chip.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.chain .arr { color: var(--muted); }
.evo-note { font-size: .78rem; color: var(--muted); margin: 6px 0 0; }

/* ------------------------------------------------------------ tray */
.tray-wrap h2 { font-size: .95rem; color: var(--muted); font-weight: 600; margin: 18px 0 8px; text-align: center; }
.tray { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.tile { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 6px 4px 8px; cursor: pointer; text-align: center; position: relative; }
@media (hover: hover) { .tile:hover { border-color: var(--muted); } }
.tile .koma { width: 40px; height: 46px; margin: 0 auto 4px; font-size: 14px; }
.tile .nm { font-size: .72rem; line-height: 1.2; display: block; }
.tile .side { font-size: .65rem; color: var(--muted); }
.tile.new::after { content: "new"; position: absolute; top: 4px; right: 6px; font-size: .6rem; color: var(--red); font-weight: 700; }

/* ------------------------------------------------------------ ads, footer, toast */
.ad-inline { margin-top: 26px; }
.ad-slot { display: block; margin: 0 auto; overflow: hidden; }
.ad-banner { width: 100%; max-width: 728px; min-height: 100px; }
.ad-slot.placeholder { border: 1.5px dashed var(--line); border-radius: 12px; display: grid; place-items: center; color: var(--muted); font-size: 0.85rem; }
.ad-slot.placeholder::before { content: "Ad space " attr(data-size); }
.ad-slot.collapsed { min-height: 0; }
.ad-slot ins[data-ad-status="unfilled"] { display: none !important; }
.ad-label { font-size: 11px; color: var(--muted); text-align: center; margin: 0 0 4px; }
.foot { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 20px; padding: 26px 0 40px; color: var(--muted); font-size: 0.88rem; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------ dialogs (help, stats, and the game's own: promotion, collection) */
.dlg { border: 0; border-radius: 16px; padding: 22px; width: min(440px, calc(100vw - 32px)); max-height: 88vh; background: var(--card); color: var(--ink); }
.dlg.tk-dlg { width: min(520px, calc(100vw - 32px)); }
.dlg::backdrop { background: var(--backdrop); }
.dlg h2 { font-family: var(--kanji); font-weight: 700; margin: 0 0 10px; font-size: 1.4rem; }
.dlg p { color: var(--muted); line-height: 1.5; }
.dlg p b { color: var(--ink); }
.dlg .x { position: absolute; right: 10px; top: 8px; border: 0; background: inherit; font-size: 26px; cursor: pointer; color: var(--muted); width: 44px; height: 44px; }
.dlg .row { display: flex; gap: 10px; }
.dlg .row .go { flex: 1; }
.stats-today { margin: 0 0 12px; color: var(--ink) !important; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 0; }
.stats div { display: flex; flex-direction: column-reverse; background: var(--bg); border-radius: 10px; padding: 10px; }
.stats dt { color: var(--muted); font-size: 0.85rem; }
.stats dd { margin: 0; font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.promo-choice { display: flex; gap: 12px; justify-content: center; margin: 14px 0 4px; }
.promo-choice button { flex: 1; max-width: 170px; border: 1px solid var(--line); background: var(--paper); border-radius: 12px; padding: 12px 8px; cursor: pointer; }
@media (hover: hover) { .promo-choice button:hover { border-color: var(--accent); } }
.promo-choice .koma { width: 52px; height: 60px; margin: 0 auto 6px; font-size: 18px; }
.codex-search { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); color: var(--ink); font: inherit; margin: 6px 0 10px; }
.codex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; }
.codex-grid .tile.locked { opacity: .35; cursor: default; }
.codex-grid .tile.locked .koma .glyphs { visibility: hidden; }

@media (prefers-reduced-motion: reduce) { .flipper, .koma, .toast { transition: none; } }
@media (orientation: landscape) and (max-height: 520px) { .board-wrap { width: min(100%, 500px, calc(100svh - 24px)); } }
