/* Shogi, warm wood and paper: a boxwood board, pale five-sided tiles, promoted pieces in red. Fixed palette. */
:root {
  color-scheme: light;
  --bg: #efe7d8;
  --card: #fffdf7;
  --ink: #2a2318;
  --muted: #7b7060;
  --line: #ded2bc;
  --board: #e8c98d;
  --board-line: #6b4f2a;
  --frame: #4a3320;
  --tile: #f6e4bb;
  --tile-line: #8a6a37;
  --tile-ink: #241d12;
  --promoted: #b3322c;
  --hl: rgba(230, 180, 70, .5);
  --sel: rgba(230, 160, 60, .85);
  --dot: rgba(58, 44, 24, .32);
  --check: #d1453b;
  --gold: #e8a33d;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #e8a33d;
  --tut-accent-ink: #2a2318;
  --tut-bubble: #fffdf7;
  --tut-ink: #2a2318;
  --tut-muted: #7b7060;
  --tut-dim: rgba(30, 24, 14, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- bar ---------- */
.app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 900px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(14px, env(safe-area-inset-left));
}
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 60px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; white-space: nowrap; padding: 12px 2px; }
.back:hover, .back:focus-visible { color: var(--ink); }
.bar-actions { display: flex; gap: 8px; }

.btn {
  min-height: 44px; min-width: 44px; padding: 0 18px; border-radius: 22px;
  border: 0; background: var(--card); color: var(--ink);
  font-weight: 650; cursor: pointer; box-shadow: 0 1px 2px rgba(42, 35, 24, .1), 0 0 0 1px var(--line);
  transition: transform .12s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.icon { padding: 0; width: 44px; font-size: 22px; line-height: 1; letter-spacing: .04em; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--card); box-shadow: none; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.btn:disabled, .row:disabled { opacity: .35; cursor: default; transform: none; }
.btn:focus-visible, .sq:focus-visible, .seg button:focus-visible, .row:focus-visible, .link:focus-visible,
.promo-btn:focus-visible, .hchip:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- game ---------- */
.game {
  flex: 1; min-height: 0;
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 8px; padding-bottom: 10px;
}
.turn {
  justify-self: center; display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 16px; border-radius: 999px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line); font-weight: 650; font-size: 16px; min-height: 40px;
}
.turn.check { box-shadow: 0 0 0 1.5px rgba(209, 69, 59, .6); }
.turn.thinking #turn-text::after { content: ''; display: inline-block; width: 1.1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.toast {
  justify-self: center; min-height: 22px; font-size: 15px; color: var(--muted); text-align: center;
  opacity: 0; transform: translateY(4px); transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }

.side-icon { display: inline-block; flex: none; width: 0; height: 0; border-left: 9px solid transparent; border-right: 9px solid transparent; }
.side-icon.s0 { border-bottom: 14px solid var(--tile-line); }
.side-icon.s1 { border-top: 14px solid var(--tile-line); }
.side-icon.none { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--line); }

/* ---------- hands ---------- */
.hand {
  min-height: 44px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 4px 6px; border-radius: 12px; background: rgba(255, 253, 247, .6); box-shadow: 0 0 0 1px var(--line);
}
.hand.foe { justify-content: flex-start; }
.hand.mine { justify-content: flex-start; }
.hand .empty { color: var(--muted); font-size: 13px; padding: 0 4px; }
.hchip {
  position: relative; min-width: 40px; min-height: 38px; padding: 2px 8px 2px 6px;
  border: 0; border-radius: 9px; background: var(--tile); box-shadow: 0 0 0 1.5px var(--tile-line);
  color: var(--tile-ink); font-weight: 800; font-size: 16px; cursor: default; display: inline-flex; align-items: center; gap: 4px;
}
.hand.mine .hchip { cursor: pointer; }
.hchip .n { font-size: 12px; font-weight: 700; color: var(--muted); }
.hchip[aria-pressed="true"] { background: #f7d49a; box-shadow: 0 0 0 2.5px var(--gold); }
.hand.foe .hchip { opacity: .85; transform: rotate(180deg); }

/* ---------- board ---------- */
.board-wrap { min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.board-frame {
  width: min(100%, calc(100vh - 300px), 560px);
  padding: 2%;
  background: linear-gradient(160deg, #5d4127, var(--frame));
  border-radius: 12px;
  box-shadow: 0 6px 0 #2e2013, 0 16px 30px rgba(42, 35, 24, .22);
}
@supports (container-type: size) {
  .board-wrap { container-type: size; }
  .board-frame { width: min(100cqw, calc(100cqh - 10px), 560px); }
}
.board {
  position: relative; width: 100%; aspect-ratio: 1; border-radius: 2px; overflow: hidden;
  background:
    repeating-linear-gradient(to right, var(--board-line) 0 1px, transparent 1px calc(100% / 9)),
    repeating-linear-gradient(to bottom, var(--board-line) 0 1px, transparent 1px calc(100% / 9)),
    var(--board);
}
.squares, .pieces { position: absolute; inset: 0; }
.pieces { pointer-events: none; }
.sq {
  position: absolute; width: 11.111%; height: 11.111%;
  border: 0; padding: 0; margin: 0; background: transparent; cursor: default;
  display: grid; place-items: center;
}
.sq.last { background: var(--hl); }
.sq.sel { background: var(--sel); }
.sq.mine, .sq.dot, .sq.cap { cursor: pointer; }
.sq.dot::before { content: ''; width: 30%; height: 30%; border-radius: 50%; background: var(--dot); transition: transform .15s; }
.sq.cap::before { content: ''; position: absolute; inset: 0; background: radial-gradient(circle, transparent 0 58%, var(--dot) 59%); }
@media (hover: hover) { .sq.dot:hover::before { transform: scale(1.3); } .sq.cap:hover { background: rgba(58, 44, 24, .12); } }
.sq.dot:active::before { transform: scale(1.45); }
.sq.check::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle, rgba(209, 69, 59, .95) 0, rgba(209, 69, 59, .55) 38%, rgba(209, 69, 59, 0) 72%);
}
.sq .co { position: absolute; font-size: clamp(7px, 2cqw, 11px); font-weight: 700; line-height: 1; pointer-events: none; color: var(--board-line); opacity: .75; }
.sq .co.f { right: 5%; top: 4%; }
.sq .co.r { left: 5%; bottom: 4%; }

/* ---------- pieces ---------- */
.pc {
  position: absolute; width: 11.111%; height: 11.111%;
  display: grid; place-items: center; z-index: 1;
  transition: left .2s cubic-bezier(.3, .1, .3, 1), top .2s cubic-bezier(.3, .1, .3, 1), transform .2s, opacity .2s;
}
.pc svg { width: 92%; height: 92%; overflow: visible; }
.pc.lift { z-index: 2; }
.pc.gone { opacity: 0; transform: scale(.6); }
.pc.pop { animation: pop .35s cubic-bezier(.2, .9, .3, 1.3); }
@keyframes pop { 0% { transform: scale(.7); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
/* A piece points at the player it is aimed against: your opponent's tiles face you. */
.pc.flip svg { transform: rotate(180deg); }
.tile { fill: var(--tile); stroke: var(--tile-line); stroke-width: 1.6; stroke-linejoin: round; }
.pc.flip .tile { fill: #eedcb2; }
.glyph { fill: var(--tile-ink); font: 700 19px/1 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; text-anchor: middle; }
.glyph.p { fill: var(--promoted); }
.glyph.small { font-size: 15px; }
.pieces .pc svg { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .22)); }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(42, 35, 24, .36);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  animation: fade .2s ease-out;
}
.overlay.soft { background: rgba(239, 231, 216, .55); align-items: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet, .card {
  background: var(--card); color: var(--ink);
  width: 100%; max-width: 440px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  overflow: auto; overscroll-behavior: contain;
  border-radius: 24px; padding: 8px 20px 20px;
  box-shadow: 0 20px 50px rgba(42, 35, 24, .22);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .overlay { align-items: center; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.row {
  display: block; width: 100%; text-align: left; min-height: 50px; padding: 0 4px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; font-weight: 600; cursor: pointer;
}
.group { padding: 12px 0 4px; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--bg); }
.seg button {
  flex: 1 1 0; min-height: 44px; border: 0; border-radius: 12px; background: transparent;
  font-weight: 600; cursor: pointer; color: var(--muted); transition: background .15s, color .15s;
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(42, 35, 24, .16); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.menu-sheet .row:first-of-type { border-top: 1px solid var(--line); }
.menu-sheet #menu-help { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet .btn.wide { margin-top: 16px; }

.promo-card { max-width: 340px; text-align: center; padding: 18px 16px 8px; }
.promo-title { font-weight: 700; font-size: 18px; }
.promo-sub { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }
.promo-row { display: flex; justify-content: center; gap: 12px; }
.promo-btn {
  width: 72px; height: 72px; border: 0; border-radius: 16px; background: var(--bg); cursor: pointer;
  display: grid; place-items: center; padding: 0; transition: transform .12s, background .15s;
}
.promo-btn svg { width: 54px; height: 54px; }
.promo-btn.main { background: #f7d49a; box-shadow: 0 0 0 2px var(--gold); }
.promo-btn:active { transform: scale(.95); }

.over-card { max-width: 340px; text-align: center; padding: 24px 22px 14px; }
.over-mark { display: flex; justify-content: center; gap: 6px; margin-bottom: 6px; }
.over-mark svg { width: 58px; height: 58px; }
.over-title { font-size: 28px; font-weight: 800; }
.over-sub { color: var(--muted); margin: 4px 0 20px; }
.link { display: block; margin: 8px auto 0; min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }

.help-sheet { max-width: 560px; }
.help-body { padding-bottom: 6px; }
.help-body h3 { font-size: 16px; margin: 18px 0 4px; }
.help-body p, .help-body li { font-size: 15px; margin: 4px 0; }
.help-body ul { padding-left: 20px; }
.fine { font-size: 13px; color: var(--muted); margin-top: 14px; }

/* ---------- small and landscape screens ---------- */
@media (max-width: 380px) {
  .app { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .btn { padding: 0 14px; }
  .back { font-size: 13px; }
  .hchip { min-width: 36px; min-height: 34px; font-size: 15px; padding: 2px 6px 2px 5px; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 520px) {
  .bar { min-height: 50px; }
  .game { gap: 5px; padding-bottom: 6px; }
  .hand { min-height: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* Online play (online.js): no New game while a friend is playing; a presence line under the turn. */
body.is-online #btn-new { display: none; }
.top { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.net { color: var(--muted); }
/* The online rows take the divider above How to play (one line, not two). */
.menu-sheet #menu-online, .menu-sheet #menu-leave { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet #menu-online ~ #menu-help { margin-top: 0; border-top: 0; }
#over-leave { margin-top: 8px; }
