/* Cairn, a high moor in flat morning light. Fixed light palette (same in light and dark OS modes). */
:root {
  color-scheme: light;
  --mist-0: #eef2ea;
  --mist-1: #dfe6dc;
  --mist-2: #cbd6c6;
  --ink: #23302c;
  --muted: #5d6e66;
  --panel: #f8faf6;
  --panel-2: #eaefe5;
  --line: #c3cebd;
  --heath: #b6c3b0;          /* board frame */
  --cell: #d7dfd1;
  --cell-2: #cdd7c7;
  --slate: #3d6e8f;
  --slate-dark: #1f4258;
  --slate-light: #a8cde3;
  --amber: #cf8320;
  --amber-dark: #7d4a08;
  --amber-light: #f3ce93;
  --pick: #fff6e2;           /* legal-target ring: bright, never a player colour */
  --pick-edge: #2f3d36;
  --warn: #b0392b;
  --good: #2f7d5c;
  --cellsize: 64px;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #cf8320;
  --tut-accent-ink: #2a1a08;
  --tut-bubble: #fbf7ee;
  --tut-ink: #23302c;
  --tut-muted: #5d6e66;
  --tut-dim: rgba(26, 38, 32, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: linear-gradient(180deg, var(--mist-0) 0%, var(--mist-1) 55%, var(--mist-2) 100%) fixed;
  color: var(--ink);
  font: 15px/1.4 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; }

.ridge {
  position: fixed; left: 0; right: 0; bottom: 0; width: 100%; height: 18vh; max-height: 140px;
  pointer-events: none; z-index: 0;
}

/* ---------- top bar ---------- */
.app {
  position: relative; z-index: 1;
  max-width: 1040px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.topbar { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; min-height: 52px; }
.back {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  color: var(--muted); text-decoration: none; font-size: 24px; border-radius: 22px;
}
.back:hover, .back:focus-visible { color: var(--slate); background: rgba(35, 48, 44, .07); }
.title {
  margin: 0; font-size: 21px; letter-spacing: .09em; font-weight: 800;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.logo { width: 26px; height: 26px; }
.iconbtn {
  width: 44px; height: 44px; border: 0; border-radius: 22px; background: transparent;
  font-size: 22px; line-height: 1; color: var(--ink); cursor: pointer; justify-self: end;
}
.iconbtn:hover, .iconbtn[aria-expanded="true"] { background: rgba(35, 48, 44, .09); }
.iconbtn:focus-visible, .back:focus-visible { outline: 3px solid var(--slate); outline-offset: 2px; }
.menu {
  position: absolute; z-index: 15; top: calc(env(safe-area-inset-top) + 50px); right: max(10px, env(safe-area-inset-right));
  min-width: 210px; padding: 6px; border-radius: 16px; background: var(--panel);
  box-shadow: 0 14px 34px rgba(30, 44, 36, .22), 0 0 0 1px var(--line);
  display: flex; flex-direction: column;
}
.menu button {
  min-height: 48px; padding: 0 14px; border: 0; border-radius: 10px; background: transparent;
  text-align: left; font-weight: 600; cursor: pointer; color: var(--ink);
}
.menu button:hover, .menu button:focus-visible { background: rgba(35, 48, 44, .07); outline: none; }
.menu button:disabled { opacity: .4; cursor: default; background: transparent; }
.menu #menu-online, .menu #menu-leave { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }

.btn {
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 2px solid var(--ink); background: var(--ink); color: var(--panel);
  font-weight: 700; cursor: pointer; transition: transform .12s, background .15s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn.small { min-height: 40px; padding: 0 10px; font-size: 13px; border-radius: 9px; }
.btn.ghost { background: transparent; color: var(--ink); border-color: rgba(35, 48, 44, .35); }
.btn.primary { background: var(--slate); border-color: var(--slate-dark); color: #fff; }
.btn:disabled { opacity: .35; cursor: default; transform: none; }
.btn:focus-visible, .cell:focus-visible, .choice button:focus-visible { outline: 3px solid var(--slate); outline-offset: 2px; }

/* ---------- layout (portrait first) ---------- */
.game { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pcard {
  position: relative;
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 6px 8px; border-radius: 12px; background: var(--panel);
  border: 2px solid transparent; transition: border-color .2s, box-shadow .2s;
}
.pcard.turn.p0 { border-color: var(--slate); box-shadow: 0 0 0 3px rgba(61, 110, 143, .16); }
.pcard.turn.p1 { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(207, 131, 32, .16); }
.pinfo { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.2; }
.pname { font-size: 15px; }
.prole { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.ptoken { flex: none; width: 24px; height: 16px; border-radius: 4px; }
.ptoken.p0 { background: linear-gradient(160deg, var(--slate-light), var(--slate) 55%, var(--slate-dark)); box-shadow: 0 0 0 2px var(--slate-dark); }
.ptoken.p1 { border-radius: 9px; background: linear-gradient(160deg, var(--amber-light), var(--amber) 55%, var(--amber-dark)); box-shadow: 0 0 0 2px var(--amber-dark); }
.pstones {
  flex: none; min-width: 34px; height: 30px; padding: 0 7px; border-radius: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  font-size: 14px; font-weight: 800; background: var(--panel-2); color: var(--ink);
}
.pstones::before {
  content: ""; width: 11px; height: 8px; border-radius: 2px; background: var(--muted); opacity: .85;
}
.p0 .pstones::before { background: var(--slate); }
.p1 .pstones::before { background: var(--amber); border-radius: 5px; }
.pstones.out { color: var(--warn); }

.turn-row { display: flex; align-items: stretch; gap: 8px; flex-wrap: wrap; }
.status {
  flex: 1 1 200px; min-height: 48px; padding: 5px 12px; border-radius: 12px; background: var(--panel);
  border-left: 5px solid var(--muted); display: flex; flex-direction: column; justify-content: center;
}
.status.p0 { border-left-color: var(--slate); }
.status.p1 { border-left-color: var(--amber); }
.status.warn { background: #fdf0ed; }
.status-main { font-weight: 800; font-size: 16px; }
.status-sub { font-size: 13px; color: var(--muted); }
.status.thinking .status-main::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.net {
  flex: 0 1 auto; align-self: center; padding: 6px 10px; border-radius: 10px;
  background: var(--panel-2); font-size: 12.5px; color: var(--muted);
}

/* ---------- board ---------- */
.board-col { display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 0; }
.board-wrap {
  position: relative;
  width: min(100%, 520px, calc(100vh - 260px));
  width: min(100%, 520px, calc(100dvh - 260px));
  min-width: min(100%, 290px);
  aspect-ratio: 1 / 1;
  padding: 7px; border-radius: 16px;
  background: linear-gradient(160deg, #c2ccbb, #a9b7a3);
  box-shadow: 0 10px 24px rgba(40, 56, 44, .22), inset 0 0 0 2px #9fae99;
}
.board {
  position: relative; width: 100%; height: 100%;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); grid-template-rows: repeat(5, minmax(0, 1fr)); gap: 4px;
}
.cell {
  position: relative; padding: 0; margin: 0; border: 0; border-radius: 9px; cursor: default;
  background: linear-gradient(150deg, var(--cell), var(--cell-2));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .45), inset 0 -2px 0 rgba(60, 76, 62, .1);
  overflow: hidden; min-width: 0; min-height: 0;
}
.cell .art { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cell.tap { cursor: pointer; }

/* who holds the cell */
.cell.held-0 { box-shadow: inset 0 0 0 2.5px var(--slate), inset 0 -2px 0 rgba(60, 76, 62, .1); }
.cell.held-1 { box-shadow: inset 0 0 0 2.5px var(--amber), inset 0 -2px 0 rgba(60, 76, 62, .1); }

/* stack height, small and quiet */
.cell .h {
  position: absolute; left: 3px; top: 2px; z-index: 4;
  min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px;
  font-size: 10.5px; line-height: 15px; font-weight: 800; text-align: center;
  background: rgba(255, 255, 255, .8); color: var(--ink);
}
.cell.ready .h { background: var(--warn); color: #fff; }

/* one stone short of a cairn */
.cell.ready::before {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  border-radius: 9px; box-shadow: inset 0 0 0 2px rgba(176, 57, 43, .55);
}
.cell .danger {
  position: absolute; right: 0; top: 0; width: 0; height: 0; z-index: 5;
  border-top: 16px solid var(--warn); border-left: 16px solid transparent; pointer-events: none;
}

/* selected stack */
.cell.sel { cursor: pointer; }
.cell.sel::after {
  content: ""; position: absolute; inset: 0; z-index: 5; pointer-events: none; border-radius: 9px;
  box-shadow: inset 0 0 0 3px var(--pick-edge), inset 0 0 0 6px var(--pick);
}

/* legal targets */
.cell.target { cursor: pointer; }
.cell.target::after {
  content: ""; position: absolute; left: 50%; top: 50%; z-index: 5; pointer-events: none;
  width: 58%; height: 58%; transform: translate(-50%, -50%); border-radius: 50%;
  border: 3px dashed var(--pick); background: rgba(255, 246, 226, .3);
  box-shadow: 0 0 0 2px rgba(47, 61, 54, .55), inset 0 0 0 2px rgba(47, 61, 54, .4);
  animation: pulse 1.6s ease-in-out infinite;
}
.cell.target .n {
  position: absolute; left: 50%; top: 50%; z-index: 6; transform: translate(-50%, -50%);
  font-size: 15px; font-weight: 900; color: var(--pick-edge); pointer-events: none;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .9);
}
.cell.target.aimed::after { animation: none; border-style: solid; background: rgba(255, 246, 226, .55); }
.cell .star {
  position: absolute; right: 3px; top: 0; z-index: 6; color: #b8860b; font-size: 15px; line-height: 1.1;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff; pointer-events: none;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* ghost preview of the stones a carry would leave behind */
.cell .ghost { opacity: .55; }
.cell.path::before {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none; border-radius: 9px;
  background: rgba(255, 246, 226, .3); box-shadow: inset 0 0 0 2px rgba(47, 61, 54, .3);
}
.cell.last::after {
  content: ""; position: absolute; inset: 6%; z-index: 2; pointer-events: none; border-radius: 8px;
  border: 2.5px solid var(--lastc, var(--ink)); opacity: .85; animation: fadeRing 2.2s ease-out 1;
}
@keyframes fadeRing { 0% { transform: scale(1.2); opacity: 0; } 30% { opacity: 1; } 100% { transform: scale(1); } }

/* ---------- action bar ---------- */
.actions {
  width: min(100%, 520px); min-height: 46px;
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px;
}
.actions .hint-text { font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: 12px; background: rgba(26, 38, 32, .5); overflow-y: auto;
}
.sheet {
  width: min(100%, 520px); max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px;
  box-shadow: 0 20px 50px rgba(26, 38, 32, .35);
}
.sheet h2 { margin: 0 0 6px; font-size: 22px; }
.howwin {
  display: flex; gap: 10px; align-items: center; margin: 6px 0 12px; padding: 10px;
  border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line);
}
.howwin p { margin: 0; font-size: 13.5px; }
.howwin-art { width: 104px; flex: none; }
.choice { border: 0; padding: 0; margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.choice legend { font-weight: 700; font-size: 13px; margin-bottom: 5px; padding: 0; }
.choice .hint { font-weight: 400; color: var(--muted); }
.choice button {
  flex: 1 1 auto; min-height: 44px; padding: 0 12px; border-radius: 10px; cursor: pointer;
  border: 2px solid var(--line); background: var(--panel-2); color: var(--ink); font-weight: 600;
}
.choice button[aria-checked="true"] { border-color: var(--slate); background: #e2eef5; color: var(--slate-dark); }
.choice.disabled { opacity: .45; pointer-events: none; }
.fine { font-size: 12.5px; color: var(--muted); margin: 4px 0 8px; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 12px; }

.over-sheet { text-align: center; }
.over-mark { width: 64px; height: 64px; margin: 0 auto 8px; }
.over-way { font-size: 16px; font-weight: 700; margin: 4px 0; color: var(--slate-dark); }

.help-sheet, .info-panel { width: min(100%, 640px); padding: 0; display: flex; flex-direction: column; }
.help-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px 8px; border-bottom: 1px solid var(--line); }
.help-head h2 { margin: 0; font-size: 20px; }
.help-body { padding: 4px 18px 18px; overflow-y: auto; }
.help-body h3 { margin: 16px 0 6px; font-size: 16px; color: var(--slate-dark); }
.help-body p, .help-body li { font-size: 14px; }
.help-body ul, .help-body ol { padding-left: 20px; margin: 6px 0; }
.goal-box { padding: 10px 12px; border-radius: 10px; background: #eef4e9; border: 1px solid var(--line); }
.t-slate { color: var(--slate-dark); }
.t-amber { color: var(--amber-dark); }
.counts { display: grid; gap: 6px; font-size: 14px; }
.counts .row { display: flex; align-items: center; gap: 8px; }
.counts .swatch { width: 18px; height: 12px; border-radius: 3px; flex: none; }
.counts .swatch.p0 { background: var(--slate); }
.counts .swatch.p1 { background: var(--amber); border-radius: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.lg { display: inline-block; width: 14px; height: 14px; flex: none; }
.lg-target { border: 3px dashed var(--pick-edge); border-radius: 50%; }
.lg-ready { border-radius: 3px; box-shadow: inset 0 0 0 2px var(--warn); }
.lg-danger { border-top: 14px solid var(--warn); border-left: 14px solid transparent; width: 0; height: 0; }
.log { list-style: none; margin: 0; padding: 8px 10px; border-radius: 12px; background: var(--panel-2); font-size: 13px; }
.log li { padding: 3px 0; border-bottom: 1px solid rgba(35, 48, 44, .08); display: flex; gap: 7px; align-items: baseline; }
.log li:last-child { border-bottom: 0; }
.log .dot { flex: none; width: 10px; height: 7px; border-radius: 2px; display: inline-block; }
.log .dot.p0 { background: var(--slate); }
.log .dot.p1 { background: var(--amber); border-radius: 4px; }
.log li.sys { color: var(--muted); font-style: italic; }
.rates { border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.rates td, .rates th { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: left; }

/* ---------- wider screens ---------- */
@media (min-width: 820px) {
  .game { max-width: 620px; margin: 0 auto; }
  .board-wrap { width: min(100%, 560px, calc(100vh - 240px)); width: min(100%, 560px, calc(100dvh - 240px)); }
}
@media (max-width: 380px) {
  .title { font-size: 18px; }
  .logo { display: none; }
  .pstones { min-width: 30px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- online play (the shared kit, in Cairn's palette) ---------- */
.pdot {
  position: absolute; left: 26px; top: 50%; margin-top: 3px; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--panel); background: #9aa79f; transition: background .3s;
}
.pdot.on { background: #4fa877; }
.pdot.off { background: #9aa79f; }
body.is-online #menu-new, body.is-online #btn-undo, body.is-online #menu-tutorial { display: none; }
.sheet-actions.online-over { justify-content: center; }
.sheet-actions.online-over .btn { flex: 1 1 0; }
.sheet-actions.online-over #over-rematch { order: -1; flex-basis: 100%; }
#online.bp-online {
  --on-accent: var(--slate); --on-accent-ink: #ffffff; --on-panel: var(--panel); --on-ink: var(--ink);
  --on-muted: var(--muted); --on-line: var(--line); background: rgba(26, 38, 32, .5);
}
#online .online-sheet { border: 1px solid var(--line); }
#online .btn { background: var(--panel-2); }
#online .btn.primary { background: var(--slate); color: #fff; }
#online .btn.ghost { background: transparent; box-shadow: inset 0 0 0 2px rgba(35, 48, 44, .35); }
#online .online-url { background: #fff; color: var(--ink); border: 2px solid var(--line); text-align: center; }
#online .online-url:focus { border-color: var(--slate); }
#online .online-friend, #online .on-sw { background: var(--panel-2); color: var(--ink); border: 1px solid var(--line); }
#online .online-friend .dot { background: rgba(35, 48, 44, .2); }
#online .online-friend.on .dot { background: #4fa877; box-shadow: 0 0 0 3px rgba(79, 168, 119, .18); }
#online .online-friend .fstate { color: var(--muted); }
#online .online-friend .fact { color: var(--slate-dark); }
#online .online-friend.sent .fact { color: var(--good); }
#online .online-friend.no .fact { color: var(--warn); }
#online .online-signin a { color: var(--slate-dark); }
#online .on-sw-track { background: rgba(35, 48, 44, .18); }
#online .on-sw[aria-checked="true"] .on-sw-track { background: #4fa877; }
body .bp-online-endbar { background: var(--panel); color: var(--ink); box-shadow: 0 10px 30px rgba(26, 38, 32, .3), 0 0 0 1px var(--line); }
body .bp-online-endbar .bp-endbar-btn { background: var(--panel-2); color: var(--ink); }
body .bp-online-endbar .bp-endbar-btn.primary { background: var(--slate); color: #fff; }
body:has(.bp-online-endbar:not([hidden])) .app { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
