/* Clatter: a toy box. Light: a birch board on warm paper, ink buttons. Dark: a slate board under a lamp, yellow
   buttons. Players are blue (ring), orange (cross), green (triangle) and pink (square); in Teams, Team A is blue and
   sky blue, Team B orange and red. Every piece also carries its shape, so colour is never the only clue. */
@font-face { font-family: "Jost"; font-style: normal; font-weight: 300 800; font-display: swap; src: url(/fonts/jost-latin-wght-normal.woff2) format("woff2"); }

:root {
  --bg: #F2EEE6;
  --bg2: #E8E2D6;
  --card: #FFFDF8;
  --ink: #22212B;
  --muted: #67646F;
  --line: #DCD3C3;
  --accent: #22212B;
  --on-accent: #FFFFFF;
  --hi: #E4A11B;
  --good: #2E7D4F;
  --bad: #B23A48;
  --board: #E3D6BA;
  --board-edge: #C7B48F;
  --hole: #CDBE9C;
  --ice: rgba(120, 190, 240, .32);
  --glow: rgba(240, 170, 40, .28);
  --fog: rgba(200, 204, 214, .9);
  --p0: #2F6FD6; --p1: #E8902A; --p2: #169C79; --p3: #C4519A;
  --t0: #2F6FD6; --t1: #E8902A; --t2: #62B8EC; --t3: #C9461F;
  --backdrop: rgba(20, 20, 30, .45);
  --font: "Jost", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --lb-panel: var(--card); --lb-panel2: var(--bg2); --lb-text: var(--ink); --lb-muted: var(--muted); --lb-line: var(--line);
  --lb-accent: var(--accent); --lb-ink: var(--on-accent); --lb-bad: var(--bad); --lb-font: var(--font);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #12131C;
  --bg2: #1B1D2A;
  --card: #1A1C28;
  --ink: #F1F0F6;
  --muted: #A3A3B8;
  --line: #2E3142;
  --accent: #F4D35E;
  --on-accent: #1B1A10;
  --hi: #F4D35E;
  --good: #6FD39A;
  --bad: #FF8A98;
  --board: #262A3A;
  --board-edge: #3B4157;
  --hole: #151722;
  --ice: rgba(110, 180, 240, .25);
  --glow: rgba(255, 210, 74, .2);
  --fog: rgba(105, 110, 130, .92);
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { touch-action: manipulation; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); 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);
  background-image: radial-gradient(circle at 20% 20%, rgba(0, 0, 0, .035) 0 2px, transparent 2.5px); background-size: 28px 28px; }
:root[data-theme="dark"] body { background-image: radial-gradient(120% 70% at 50% 0%, #1D2032, #12131C 70%); background-attachment: fixed; }
a { color: inherit; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--hi); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------ page frame */
.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: .95rem; white-space: nowrap; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; 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(--bg2); } }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 0 8px; gap: 10px; }
h1 { font-weight: 800; font-size: 2rem; margin: 0; line-height: 1; letter-spacing: .01em; display: flex; align-items: center; gap: 10px; }
.h-mark { display: grid; grid-template-columns: repeat(2, 11px); gap: 2px; width: 24px; }
.h-mark i { width: 11px; height: 11px; border-radius: 50%; display: block; }
.h-mark i:nth-child(1) { background: var(--p0); grid-column: 1; grid-row: 2; }
.h-mark i:nth-child(2) { background: var(--p1); grid-column: 2; grid-row: 2; }
.h-mark i:nth-child(3) { background: var(--p2); grid-column: 2; grid-row: 1; }
.sub { margin: 0; color: var(--muted); font-size: .95rem; white-space: nowrap; }
body.playing .title-row { padding-bottom: 4px; }
body.playing h1 { font-size: 1.5rem; }

/* ------------------------------------------------------------ the lobby and settings */
.intro { margin: 0 0 4px; color: var(--muted); }
.panel { margin: 14px auto 0; max-width: 600px; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; }
.p-h { margin: 0 0 8px; font-size: 1.1rem; }
.set { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.set-l { font-size: .85rem; color: var(--muted); min-width: 78px; }
.cards-l { display: block; margin: 12px 0 6px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; background: var(--bg2); border-radius: 999px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 0 12px; min-height: 34px; cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.seg button:disabled { cursor: default; }
.seg button:disabled:not(.on) { opacity: .5; }
.cardset { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 6px; }
.cs-b { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: transparent; border-radius: 12px; min-height: 40px; padding: 4px 10px; cursor: pointer;
  font-size: .9rem; font-weight: 600; color: var(--muted); text-decoration: line-through; text-align: left; }
.cs-b.on { color: var(--ink); text-decoration: none; background: var(--bg2); border-color: transparent; }
.cs-b:disabled { cursor: default; }
.cs-b .ic { width: 18px; height: 18px; flex: none; }
.fine { margin: 6px 0 0; color: var(--muted); font-size: .85rem; }
.ic { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 0 16px; min-height: 40px; font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; }
.btn.go, .go { border: 0; background: var(--accent); color: var(--on-accent); font-weight: 700; border-radius: 999px; min-height: 44px; padding: 0 24px; cursor: pointer; }
@media (hover: hover) { .btn:hover { border-color: var(--hi); } }

/* ------------------------------------------------------------ the game */
.game { margin-top: 2px; }
.seats { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; }
.chip { display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 999px; background: var(--card); border: 2px solid var(--line); min-height: 36px; max-width: 100%; }
.chip .nm { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 9em; }
.chip .tag { color: var(--muted); font-weight: 500; }
.chip .bd { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: .78rem; white-space: nowrap; }
.chip .team { font-weight: 800; color: var(--ink); background: var(--bg2); border-radius: 6px; padding: 0 5px; }
.chip .badge { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--bg2); color: var(--ink); }
.chip .badge .ic { width: 14px; height: 14px; }
.chip.turn { border-color: var(--ink); box-shadow: 0 0 0 3px var(--glow); }
.chip.won { border-color: var(--hi); box-shadow: 0 0 0 3px var(--glow); }
.chip.me .nm { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px; }
@media (prefers-reduced-motion: no-preference) { .chip.turn { animation: turnpulse 1.4s ease-in-out infinite; } }
@keyframes turnpulse { 50% { box-shadow: 0 0 0 6px var(--glow); } }
.dir { font-weight: 800; color: var(--muted); padding: 0 4px; }
.shp { width: 26px; height: 26px; flex: none; }
.shp .disc { stroke: rgba(0, 0, 0, .25); stroke-width: 1; }
.shp .glyph { fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.f0 .disc { fill: var(--p0); } .f1 .disc { fill: var(--p1); } .f2 .disc { fill: var(--p2); } .f3 .disc { fill: var(--p3); }
.t0 .disc { fill: var(--t0); } .t1 .disc { fill: var(--t1); } .t2 .disc { fill: var(--t2); } .t3 .disc { fill: var(--t3); }

.turnbar { position: relative; margin: 8px 0 6px; padding: 6px 12px 8px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); border-left-width: 6px; overflow: hidden; }
.turnbar.p0 { border-left-color: var(--p0); } .turnbar.p1 { border-left-color: var(--p1); } .turnbar.p2 { border-left-color: var(--p2); } .turnbar.p3 { border-left-color: var(--p3); }
.seats.teams ~ .turnbar.p2 { border-left-color: var(--t2); } .seats.teams ~ .turnbar.p3 { border-left-color: var(--t3); }
.turnbar.mine { background: color-mix(in srgb, var(--hi) 14%, var(--card)); }
.turnbar.done { border-left-color: var(--hi); }
.turn-t { margin: 0; font-weight: 700; font-size: 1rem; min-height: 1.45em; }
.turn-r { margin: 0; color: var(--muted); font-size: .8rem; }
.turn-r:empty { display: none; }
.timer { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--bg2); }
.timer i { display: block; height: 100%; background: var(--hi); transform-origin: left; }

.stage { position: relative; display: flex; justify-content: center; touch-action: none; -webkit-user-select: none; user-select: none; }
.cv { display: block; border-radius: 14px; cursor: pointer; touch-action: none; }
.cv:focus-visible { outline: 3px solid var(--hi); outline-offset: 3px; }
.flash { position: absolute; left: 50%; top: 2px; transform: translate(-50%, 0) scale(.9); display: grid; grid-template-columns: auto auto; column-gap: 8px; align-items: center;
  background: var(--card); color: var(--ink); border: 2px solid var(--ink); border-radius: 14px; padding: 5px 14px 5px 10px; box-shadow: 0 6px 18px rgba(0, 0, 0, .22); pointer-events: none; z-index: 2;
  opacity: 0; animation: flashin .25s ease-out forwards; }
.flash.out { transition: opacity .35s, transform .35s; opacity: 0 !important; transform: translate(-50%, -30%) scale(.9); animation: none; }
.flash b { font-size: 1.05rem; line-height: 1.1; }
.flash span { font-size: .78rem; color: var(--muted); grid-column: 2; line-height: 1.1; }
.flash .ic.big { width: 26px; height: 26px; grid-row: 1 / 3; }
.flash.p0 { border-color: var(--p0); } .flash.p1 { border-color: var(--p1); } .flash.p2 { border-color: var(--p2); } .flash.p3 { border-color: var(--p3); }
@keyframes flashin { from { opacity: 0; transform: translate(-50%, -40%) scale(.7) rotate(-4deg); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; opacity: 1; transform: translate(-50%, 0); } }

.aim { margin: 8px 0 0; padding: 8px 10px; border-radius: 14px; background: color-mix(in srgb, var(--hi) 16%, var(--card)); border: 1px solid var(--hi); }
.aim-t { margin: 0 0 6px; font-weight: 600; font-size: .92rem; }
.aim-b { display: flex; flex-wrap: wrap; gap: 6px; }
.aim-b .btn { min-height: 40px; }
.hand { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 8px 0 0; }
.card { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 6px; align-items: center; text-align: left; padding: 6px 8px; min-height: 52px;
  border-radius: 12px; border: 2px solid var(--line); background: var(--card); cursor: pointer; }
.card .ic { grid-row: 1 / 3; width: 22px; height: 22px; }
.card b { font-size: .95rem; line-height: 1.1; }
.card span { font-size: .72rem; color: var(--muted); line-height: 1.15; }
.card:disabled { opacity: .55; cursor: default; }
.card.sel { border-color: var(--hi); background: color-mix(in srgb, var(--hi) 16%, var(--card)); }
@media (hover: hover) { .card:not(:disabled):hover { border-color: var(--hi); transform: translateY(-1px); } }
.nocards { grid-column: 1 / -1; text-align: center; margin: 4px 0; }
.over { text-align: center; }
.kicker { margin: 0; color: var(--muted); font-size: .9rem; letter-spacing: .04em; }
.big { margin: 2px 0 4px; font-size: 2rem; font-weight: 800; letter-spacing: -.01em; }
.res-line { margin: 2px 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.g-foot { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin: 10px 0 0; }
.log { list-style: none; margin: 0; padding: 0; font-size: .82rem; color: var(--muted); min-width: 0; }
.log li { overflow: hidden; text-overflow: ellipsis; }
.log li:first-child { color: var(--ink); }

@media (max-width: 420px) {
  .wrap { padding: 0 12px; }
  .chip { padding-right: 8px; min-height: 32px; gap: 4px; }
  .chip .nm { font-size: .82rem; max-width: 6.5em; }
  .shp { width: 22px; height: 22px; }
  .card { grid-template-columns: 1fr; padding: 5px 6px; min-height: 48px; }
  .card .ic { grid-row: auto; width: 18px; height: 18px; }
  .card span { display: none; }
  .turn-t { font-size: .92rem; }
  .set-l { min-width: 0; width: 100%; }
}

/* ------------------------------------------------------------ dialogs, toast, footer */
dialog.dlg { border: 1px solid var(--line); border-radius: 20px; background: var(--card); color: var(--ink); max-width: min(460px, calc(100vw - 24px)); width: 100%; padding: 24px 22px;
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: auto; }
dialog.dlg::backdrop { background: var(--backdrop); }
dialog.dlg h2 { margin: 0 0 10px; font-size: 1.35rem; }
dialog.dlg h3 { margin: 14px 0 4px; font-size: 1.02rem; }
dialog.dlg p { margin: 6px 0; }
dialog.dlg form:first-child { position: sticky; top: 0; height: 0; z-index: 3; }
.x { position: absolute; top: -14px; right: -12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--bg2); font-size: 1.5rem; cursor: pointer; line-height: 1; }
dialog.dlg .go { display: block; margin: 14px auto 0; }
.cardlist { list-style: none; margin: 4px 0; padding: 0; display: grid; gap: 5px; font-size: .92rem; }
.cardlist li { display: grid; grid-template-columns: 20px 1fr; column-gap: 8px; }
.cardlist .ic { width: 18px; height: 18px; margin-top: 2px; grid-row: 1 / 3; }
.cardlist b { display: inline; }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 50; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.ad-inline { margin: 18px 0; }
.foot { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; padding: 18px 0 30px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); margin-top: 10px; }
.foot a { color: var(--muted); }
