/* Gan Thang · กันทาง — navy + gold, matching the lengamegan.com front page */
:root {
  --bg: #0f1420; --panel: #171e2e; --line: #2a3550; --ink: #eef1f7; --muted: #9aa6bf;
  --gold: #f0d48a; --gold-ink: #1a1408; --teal: #5fd3c4; --teal-ink: #08201d; --warn: #ff8a7a;
  --sq: #1d2639; --groove: #121826;
  font-family: "Segoe UI", "Leelawadee UI", "Noto Sans Thai", "Sukhumvit Set", Tahoma, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 760px; margin: 0 auto;
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 44px; flex: none; }
h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.th-name { color: var(--gold); }
.tools { display: flex; gap: 6px; }

button { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  min-height: 40px; padding: 0 14px; cursor: pointer; transition: border-color .15s, background .15s; }
button:hover:not(:disabled) { border-color: #3d4c72; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); font-weight: 700; }
button.icon { width: 40px; padding: 0; display: inline-grid; place-items: center; font-weight: 700; }
button.icon svg { width: 20px; height: 20px; }
button.chip { padding: 0 11px; font-size: 14px; }
button[aria-pressed="true"]:not(.icon) { border-color: var(--gold); color: var(--gold); }
button.link { background: none; border: none; color: var(--gold); padding: 0 4px; text-decoration: underline; text-underline-offset: 3px; }

.status { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: none; }
.side { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; min-height: 50px;
  display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center;
  transition: border-color .2s, box-shadow .2s; }
.side.g { color: var(--gold); } .side.t { color: var(--teal); }
.side.active { border-color: currentColor; box-shadow: inset 0 0 0 1px currentColor; }
.side .pm { grid-row: 1 / 3; width: 22px; height: 22px; }
.side .who { color: var(--ink); font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side .n { grid-row: 1 / 3; grid-column: 3; font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.side .pips { display: flex; gap: 2px; }
.pip { width: 5px; height: 11px; border-radius: 2px; background: currentColor; }
.pip.used { opacity: .16; }

.turn { margin: 6px 0 2px; min-height: 22px; text-align: center; font-size: 15px; color: var(--muted); flex: none; }
.turn.g { color: var(--gold); } .turn.t { color: var(--teal); }
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#board { width: var(--bs, 300px); height: var(--bs, 300px); display: block; touch-action: none; user-select: none; -webkit-user-select: none; }

.controls { flex: none; }
.controls .row { display: flex; gap: 8px; align-items: center; height: 50px; }
.mode { flex: 1; text-align: center; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wallrow .why { flex: 1; font-size: 14px; color: var(--muted); }
.wallrow .why.bad { color: var(--warn); }
.wallrow button { width: 52px; padding: 0; font-size: 18px; }

/* board drawing */
.bg { fill: var(--groove); }
.sq { fill: var(--sq); }
.tint.g { fill: var(--gold); opacity: .13; } .tint.t { fill: var(--teal); opacity: .13; }
.last { fill: none; stroke-width: 2.5; opacity: .55; }
.last.g { stroke: var(--gold); } .last.t { stroke: var(--teal); }
.from { fill: currentColor; opacity: .08; }
.dot { opacity: .8; pointer-events: none; }
.dot.g { fill: var(--gold); } .dot.t { fill: var(--teal); }
.cursor { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-dasharray: 5 4; }
.routedot { fill: none; stroke-width: 2; opacity: .6; }
.routedot.g { stroke: var(--gold); } .routedot.t { stroke: var(--teal); }
.wall { rx: 3; }
.wall.g { fill: var(--gold); } .wall.t { fill: var(--teal); }
.wall.fresh { filter: drop-shadow(0 0 4px rgba(255, 255, 255, .45)); }
.ghost { opacity: .55; }
.ghost.held { opacity: .85; }
.ghost.bad { fill: var(--warn) !important; opacity: .8; }
.pawn { transition: transform .22s ease-out; }
.pawn .body.g { fill: var(--gold); } .pawn .body.t { fill: var(--teal); }
.pawn .mark.g { fill: var(--gold-ink); } .pawn .mark.t { fill: var(--teal-ink); }
.pawn.winner .body { animation: glow 1.1s ease-in-out infinite alternate; }
@keyframes glow { from { filter: drop-shadow(0 0 0 transparent); } to { filter: drop-shadow(0 0 7px currentColor); } }
.pawn.winner.g { color: var(--gold); } .pawn.winner.t { color: var(--teal); }
.thinking .pawn.t-turn { animation: breathe 1s ease-in-out infinite alternate; }
@keyframes breathe { from { opacity: 1; } to { opacity: .55; } }

/* sheets */
.sheet, .banner { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto; background: rgba(7, 10, 17, .74); }
.banner { background: rgba(7, 10, 17, .45); align-items: flex-end; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; width: 100%; max-width: 420px;
  margin: auto; box-shadow: 0 18px 50px rgba(0, 0, 0, .45); }
.card.small { max-width: 360px; text-align: center; }
.card h2 { margin: 0 0 4px; font-size: 22px; }
.card .tag { margin: 0 0 14px; color: var(--muted); }
fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 12px; padding: 10px 12px 12px; display: grid; gap: 10px; }
legend { padding: 0 6px; color: var(--gold); font-weight: 600; }
.seg { display: flex; gap: 6px; align-items: center; }
.seg button { flex: 1; }
.seg.small .lbl { color: var(--muted); font-size: 14px; margin-right: 4px; white-space: nowrap; }
.seg.small button { min-height: 36px; font-size: 14px; }
button.wide { width: 100%; min-height: 48px; }
fieldset .primary { min-height: 48px; }
.resume { background: rgba(240, 212, 138, .08); border: 1px solid rgba(240, 212, 138, .35); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.resume p { margin: 0 0 8px; }
.resume button { width: 100%; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
a.home { color: var(--muted); font-size: 13px; text-decoration: none; }
a.home:hover { color: var(--gold); }
.pair { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.pair button { flex: 1; }
.rules ol { padding-left: 20px; margin: 12px 0 0; line-height: 1.5; }
.rules li { margin-bottom: 6px; }
.diagrams { display: flex; gap: 10px; justify-content: space-between; }
.diagrams figure { margin: 0; flex: 1; text-align: center; font-size: 13px; color: var(--muted); }
.diagrams svg { width: 100%; max-width: 110px; display: block; margin: 0 auto 4px; }

@media (min-width: 700px) { h1 { font-size: 21px; } .turn { font-size: 16px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
@media (max-width: 380px) { h1 { font-size: 17px; } .tools { gap: 4px; } button.chip { padding: 0 8px; } button.icon { width: 36px; } }
@media (max-height: 560px) { .top { height: 38px; } .side { min-height: 42px; padding: 3px 8px; } .controls .row { height: 44px; } .turn { margin: 3px 0 1px; } }
.card.start { position: relative; }
.card.start h2 { padding-right: 104px; }
.sheet-tools { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; }

/* narrow phones: keep "Computer · Teal" whole in the side chip */
@media (max-width: 420px) {
  .side { padding: 6px 8px; column-gap: 6px; }
  .side .who { font-size: 12.5px; }
}
