/*
 * Hex, a tall rhombus of hexagons on warm paper. Fixed palette (the page never follows the OS theme).
 *
 * The board is drawn with flat-top hexagons and the columns sheared downwards, so the rhombus is
 * taller than it is wide. A phone has height to spare and very little width, so this turns the spare
 * height into bigger hexagons: about 42 × 36 px at 11 × 11 on a 390 px screen, where the usual wide
 * layout would leave them near 22 px. Rows still run top to bottom and columns left to right.
 *
 * Geometry comes from render.js as inline custom properties: --ar (width / height of the whole
 * rhombus) on .board, and left/top/width/height percentages on each .hex.
 */
:root {
  color-scheme: light;
  --bg: #f4f0e7;
  --bg-2: #ebe4d6;
  --card: #fffdf8;
  --ink: #20232b;
  --muted: #757986;
  --line: #e3ddcf;
  --hex: #ece5d6;          /* an empty hexagon */
  --hex-2: #e3dbc9;        /* its lower edge, for a little depth */
  --gap: #f4f0e7;          /* the paper showing between hexagons */
  --p0: #d98324;           /* Amber: links top to bottom */
  --p0-dark: #96560f;
  --p0-tint: rgba(217, 131, 36, .28);
  --p1: #4557c4;           /* Indigo: links left to right */
  --p1-dark: #263275;
  --p1-tint: rgba(69, 87, 196, .26);
  --gold: #f0b429;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #f0b429;
  --tut-accent-ink: #20232b;
  --tut-bubble: #fffdf8;
  --tut-ink: #20232b;
  --tut-muted: #757986;
  --tut-dim: rgba(22, 24, 32, .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(32, 35, 43, .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.small { min-height: 40px; padding: 0 14px; font-size: 15px; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.btn:disabled, .row:disabled { opacity: .35; cursor: default; transform: none; }
.btn:focus-visible, .hex:focus-visible, .seg button:focus-visible, .row:focus-visible, .link:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
}

/* ---------- game ---------- */
.game {
  flex: 1; min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 8px; padding-bottom: 10px;
}
.top { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.turn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 18px; border-radius: 999px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line); font-weight: 650; font-size: 16px; min-height: 40px;
}
.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: '...'; } }
.net { color: var(--muted); font-size: 15px; }
.controls { display: flex; justify-content: center; align-items: center; gap: 8px; min-height: 44px; flex-wrap: wrap; }
.controls .ask { font-size: 15px; color: var(--muted); }
.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; }

/* ---------- stones as icons (turn pill, result card, help) ---------- */
.stone-icon { display: inline-block; flex: none; width: 20px; height: 20px; border-radius: 50%; position: relative; }
.stone-icon.none { background: var(--line); }
.s0 { background: var(--p0); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .16); }
.s0::after {
  content: ''; position: absolute; inset: 26%; border-radius: 50%;
  border: 2px solid var(--p0-dark);
}
.s1 { background: var(--p1); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .16); }
.s1::after {
  content: ''; position: absolute; inset: 24%; background: #dfe4ff;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

/* ---------- board ---------- */
.board-wrap { min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.board {
  position: relative;
  width: min(100%, calc((100vh - 260px) * var(--ar, .62)), 460px);
  aspect-ratio: var(--ar, .62);
}
@supports (container-type: size) {
  .board-wrap { container-type: size; }
  .board { width: min(100cqw, calc(100cqh * var(--ar, .62)), 460px); }
}
.hex {
  position: absolute; margin: 0; padding: 0; border: 0; cursor: default;
  background: linear-gradient(180deg, var(--hex) 62%, var(--hex-2) 100%);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  display: grid; place-items: center;
  transition: filter .15s;
}
/* The four edges, in the colour of the player who must reach them (corners carry both). */
.hex.e-top { background-image: linear-gradient(180deg, var(--p0-tint) 0 18%, transparent 18%), linear-gradient(180deg, var(--hex) 62%, var(--hex-2) 100%); }
.hex.e-bottom { background-image: linear-gradient(0deg, var(--p0-tint) 0 18%, transparent 18%), linear-gradient(180deg, var(--hex) 62%, var(--hex-2) 100%); }
.hex.e-left { background-image: linear-gradient(90deg, var(--p1-tint) 0 20%, transparent 20%), linear-gradient(180deg, var(--hex) 62%, var(--hex-2) 100%); }
.hex.e-right { background-image: linear-gradient(270deg, var(--p1-tint) 0 20%, transparent 20%), linear-gradient(180deg, var(--hex) 62%, var(--hex-2) 100%); }
.hex.e-top.e-left { background-image: linear-gradient(180deg, var(--p0-tint) 0 18%, transparent 18%), linear-gradient(90deg, var(--p1-tint) 0 20%, transparent 20%), linear-gradient(180deg, var(--hex) 62%, var(--hex-2) 100%); }
.hex.e-top.e-right { background-image: linear-gradient(180deg, var(--p0-tint) 0 18%, transparent 18%), linear-gradient(270deg, var(--p1-tint) 0 20%, transparent 20%), linear-gradient(180deg, var(--hex) 62%, var(--hex-2) 100%); }
.hex.e-bottom.e-left { background-image: linear-gradient(0deg, var(--p0-tint) 0 18%, transparent 18%), linear-gradient(90deg, var(--p1-tint) 0 20%, transparent 20%), linear-gradient(180deg, var(--hex) 62%, var(--hex-2) 100%); }
.hex.e-bottom.e-right { background-image: linear-gradient(0deg, var(--p0-tint) 0 18%, transparent 18%), linear-gradient(270deg, var(--p1-tint) 0 20%, transparent 20%), linear-gradient(180deg, var(--hex) 62%, var(--hex-2) 100%); }
.hex.open { cursor: pointer; }
@media (hover: hover) { .hex.open:hover { filter: brightness(1.04); } }
.hex.open:active { filter: brightness(.96); }

/* a stone sitting on a hexagon */
.stone {
  position: relative; width: 66%; height: 76%; border-radius: 50%;
  animation: place .18s ease-out;
}
.stone.p0 { background: var(--p0); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18), 0 1px 2px rgba(32, 35, 43, .3); }
.stone.p0::after { content: ''; position: absolute; inset: 26%; border-radius: 50%; border: 2px solid var(--p0-dark); }
.stone.p1 { background: var(--p1); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18), 0 1px 2px rgba(32, 35, 43, .3); }
.stone.p1::after { content: ''; position: absolute; inset: 24%; background: #dfe4ff; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
@keyframes place { from { transform: scale(.4); opacity: .4; } to { transform: none; opacity: 1; } }
.stone.ghost { opacity: .42; animation: none; }
.stone.last::before {
  content: ''; position: absolute; z-index: 2; left: 50%; top: 50%; width: 16%; height: 16%;
  transform: translate(-50%, -50%); border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(32, 35, 43, .25);
}
.stone.win { animation: light .5s ease-out both; animation-delay: calc(var(--d, 0) * 55ms); box-shadow: 0 0 0 3px var(--gold), inset 0 -2px 0 rgba(0, 0, 0, .18); }
@keyframes light { from { transform: scale(1); } 60% { transform: scale(1.22); } to { transform: scale(1.08); } }
.board.done .stone:not(.win) { opacity: .42; filter: saturate(.55); }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(32, 35, 43, .36);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  animation: fade .2s ease-out;
}
.overlay.soft { background: rgba(244, 240, 231, .5); 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(32, 35, 43, .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(32, 35, 43, .16); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.note.plain { margin-top: 6px; }
.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; }

.over-card { max-width: 340px; text-align: center; padding: 24px 22px 14px; }
.over-mark { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; }
.over-mark .stone-icon { width: 52px; height: 52px; }
.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; }
.t0 { color: var(--p0-dark); }
.t1 { color: var(--p1-dark); }

/* ---------- 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; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 560px) {
  .bar { min-height: 50px; }
  .game { gap: 4px; padding-bottom: 6px; }
  .board { width: min(100%, calc((100vh - 170px) * var(--ar, .62)), 460px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !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; }
.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; }
