[hidden] { display: none !important; }
:root {
  --bg: #f4f1ea; --fg: #1d1b16; --muted: #6b665c; --card: #fff; --line: #d8d2c4;
  --c0: #d9394a; --c1: #2a9d5c; --c2: #e0a800; --c3: #3461d1; --back: #e8730c;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
/* dark: follows the system unless the player picked a theme (html[data-theme]) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #17161a; --fg: #ece9e2; --muted: #9b968c; --card: #222127; --line: #3a3842; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #17161a; --fg: #ece9e2; --muted: #9b968c; --card: #222127; --line: #3a3842; color-scheme: dark; }
* { box-sizing: border-box; }
/* Everything is sized in rem, and rem follows the screen: smaller or shorter phones get a
   proportionally zoomed-out UI, big desktops a slightly larger one. svh (not dvh) so text
   doesn't jump when the mobile browser toolbar shows or hides. */
html { font-size: clamp(13px, min(3.7vw, 1.95svh), 17px); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); }
#app { max-width: 65rem; margin: 0 auto; padding: 1rem; }
h1 { margin: 0 0 0.25rem; font-size: 1.8rem; }
h2 { font-size: 1rem; margin: 1.125rem 0 0.375rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sub { color: var(--muted); margin: 0.25rem 0 0.75rem; }
.err { color: var(--c0); min-height: 1.2em; }
#game-err { position: fixed; top: max(0.5rem, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 5;
  min-height: 0; margin: 0; padding: 0.375rem 0.75rem; border-radius: 0.625rem; background: var(--card); border: 1px solid var(--line); pointer-events: none; }
#game-err:empty { display: none; }
#app:has(> .panel:not([hidden])) { min-height: 100dvh; display: grid; place-items: center; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 1.125rem; padding: 1.75rem; width: min(100%, 27.5rem);
  box-shadow: 0 0.625rem 2.5rem #0000000d; }
@media (max-width: 520px) {
  #app:has(> .panel:not([hidden])) { padding: 0; place-items: stretch; }
  .panel { border: 0; border-radius: 0; box-shadow: none; padding: max(1.75rem, env(safe-area-inset-top)) 1.25rem max(1.25rem, env(safe-area-inset-bottom));
    display: flex; flex-direction: column; justify-content: center; }
}
/* home: brand lockup, chips, then the two ways in */
.brand { text-align: center; margin-bottom: 0.875rem; }
.brand .logo { display: block; width: 6rem; height: 6rem; margin: 0 auto 0.75rem; border-radius: 1.375rem; box-shadow: 0 0.375rem 1.25rem #00000014; }
.brand h1 { font-size: 2.3rem; letter-spacing: -.02em; margin: 0; }
.tagline { margin: 0.25rem 0 0; color: var(--muted); font-size: 1.05rem; }
.chips { list-style: none; padding: 0; margin: 0 0 1.125rem; display: flex; flex-wrap: wrap; justify-content: center; gap: 0.375rem; }
.chips li { font-size: .8rem; padding: 0.25rem 0.625rem; border-radius: 62.44rem; border: 1px solid var(--line); color: var(--muted); }
.homefoot { display: flex; justify-content: center; align-items: center; gap: 0.5rem; margin-top: 1.125rem; flex-wrap: wrap; }
.homefoot button.ghost { min-height: 2.25rem; }
/* segmented control (theme, charges) */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 0.625rem; background: var(--bg); border: 1px solid var(--line); }
.seg button { min-height: 2rem !important; padding: 0.25rem 0.75rem; border-radius: 0.5rem; background: transparent; color: var(--muted); font-weight: 500; }
.seg button[aria-checked="true"], .seg button[aria-pressed="true"] { background: var(--card); color: var(--fg); font-weight: 700; box-shadow: 0 1px 3px #0002; }
.seg.small { margin-top: 0.5rem; }
/* rule cards */
#rules { display: flex; flex-direction: column; gap: 0.5rem; }
.rule { padding: 0.75rem 0.875rem; border-radius: 0.75rem; border: 1.5px solid var(--line); cursor: pointer; }
.rule.on { border-color: var(--fg); box-shadow: inset 0 0 0 1px var(--fg); }
.rule p { margin: 3px 0 0; color: var(--muted); font-size: .88rem; }
.rhead { display: flex; align-items: center; gap: 0.5rem; }
.tag { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 0.4375rem; border-radius: 62.44rem;
  background: var(--fg); color: var(--bg); }
.tag.warn { background: var(--back); color: #fff; }
details.more { display: flex; flex-direction: column; gap: 0.5rem; }
details.more > summary { cursor: pointer; color: var(--muted); padding: 0.375rem 2px; font-size: .9rem; }
details.more[open] > .rule { margin-top: 0.5rem; }
#lobby-leave { margin-top: 0.375rem; }
button.danger { color: var(--c0); border-color: var(--c0); }
dialog .wide { margin: 0.25rem 0; min-height: 2.75rem; }
dialog .closebtn { margin-top: 0.875rem; }
.panel input, .panel select, .panel button { min-height: 3rem; }
button.big { width: 100%; min-height: 3.25rem; font-size: 1.05rem; border-radius: 0.75rem; margin: 0.375rem 0; }
button.wide { width: 100%; }
.or { display: flex; align-items: center; gap: 0.625rem; color: var(--muted); font-size: .85rem; margin: 0.875rem 0 0.25rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.eyebrow { margin: 0; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.code { font-size: 2.4rem; letter-spacing: .18em; margin: 0 0 0.25rem; }
.center { text-align: center; }
.row { display: flex; gap: 0.5rem; margin: 0.625rem 0; }
/* inputs and selects default to a fixed intrinsic width; let them (and the panels) shrink so
   nothing is wider than a narrow or font-scaled phone (installed apps don't zoom out to fit) */
input, select, .panel { min-width: 0; }
label { display: block; margin: 0.75rem 0; }
input, select, button { font: inherit; padding: 0.5625rem 0.75rem; border-radius: 0.5rem; border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
input { flex: 1; min-width: 0; }
label input { width: 100%; margin-top: 0.25rem; }
#code { text-transform: uppercase; letter-spacing: .2em; }
#join { min-width: 6rem; }
button { background: var(--fg); color: var(--bg); border: 0; cursor: pointer; font-weight: 600; }
button:disabled { opacity: .35; cursor: default; }
button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); font-weight: 400; padding: 0.25rem 0.625rem; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
select { width: 100%; }
#seats { list-style: none; padding: 0; margin: 0; }
#seats li { display: flex; gap: 0.625rem; align-items: center; min-height: 3.25rem; padding: 0.375rem 0; border-bottom: 1px solid var(--line); }
#seats li:last-child { border-bottom: 0; }
#seats .av { width: 2.125rem; height: 2.125rem; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--fg); color: var(--bg); font-weight: 700; }
#seats li.empty .av { background: transparent; border: 1.5px dashed var(--line); }
#seats .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#seats select, #seats button { min-height: 2.5rem; }
.dot { width: .8em; height: .8em; border-radius: 50%; display: inline-block; flex: none; }
.off { opacity: .45; }

/* game: fills the whole screen. --board is the largest square that leaves room for the
   cards (2 x 54), status bar and thumb controls; everything else is as wide as the board. */
html, body { height: 100%; }
body { overscroll-behavior: none; }
#app:has(> #game:not([hidden])) { padding: 0; max-width: none; }
#game { --board: min(100vw - 1rem, 37.5rem, 100dvh - 22.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  width: calc(var(--board) + 1rem); min-width: min(100vw, 18.75rem); height: 100dvh; margin: 0 auto;
  display: flex; flex-direction: column; gap: 0.375rem;
  padding: max(0.5rem, env(safe-area-inset-top)) 0.5rem max(0.625rem, env(safe-area-inset-bottom)); }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 0.375rem; }
.side { display: contents; }
.sidehead, .keys, .dir kbd { display: none; }
.card { display: flex; align-items: center; gap: 0.5rem; height: 3.375rem; padding: 0 0.5rem; min-width: 0;
  border-radius: 0.75rem; background: var(--card); border: 1.5px solid var(--line); transition: border-color .2s; }
.card.right { flex-direction: row-reverse; text-align: right; }
.card.empty { visibility: hidden; }
.card.turn { border-color: var(--fg); }
.card.bot .avatar::after { content: "🤖"; position: absolute; right: -.375rem; bottom: -.375rem; font-size: .75rem; }
.card.bot:not(.right) .avatar::after { right: auto; left: -.375rem; }   /* badge on the outer side */
.card.me .name::after { content: " · you"; font-weight: 400; color: var(--muted); font-size: .8rem; }
.card .info { min-width: 0; flex: 1; }
.card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .stats { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .off { opacity: .45; }
.avatar { position: relative; width: 2.25rem; height: 2.25rem; flex: none; border-radius: 50%;
  background: var(--pc); color: #fff; display: grid; place-items: center; font-weight: 700; }
.ring { position: absolute; inset: -.3125rem; width: 2.875rem; height: 2.875rem; transform: rotate(-90deg); pointer-events: none; }
.ring circle { fill: none; stroke: var(--fg); stroke-width: 3; stroke-dasharray: 138.2; stroke-linecap: round; }
/* thumb controls: [Back] [die] [Forward] */
.controls { display: grid; grid-template-columns: 1fr auto 1fr; gap: 0.625rem; }
.dir { min-height: 4rem; border-radius: 0.875rem; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 1.02rem; touch-action: manipulation; }
.dir.bw { background: transparent; color: var(--back); border: 2px dashed var(--back); }
.dir.cap { box-shadow: 0 0 0 3px var(--c0); }
.dir .sub2 { font-size: .72rem; font-weight: 400; opacity: .8; }
.dir .sub2:empty { display: none; }
.dir:disabled { opacity: .25; }
.die { width: 4rem; height: 4rem; padding: 0.25rem; border-radius: 0.875rem; background: var(--bg);
  border: 1.5px solid var(--line); touch-action: manipulation; }
.die svg { width: 100%; height: 100%; display: block; }
.die svg rect { fill: var(--card); stroke: var(--fg); stroke-width: 2; }
.die svg circle { fill: var(--fg); }
.die svg text { fill: var(--muted); font-size: 20px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.die:enabled svg text { fill: var(--fg); }
.die:enabled { border-color: var(--fg); animation: nudge 1.1s infinite; }
.die:disabled { opacity: 1; cursor: default; }
.die:not(.mine):disabled svg { opacity: .55; }
.die.rolling svg { animation: shake .45s; }
@keyframes nudge { 50% { transform: scale(1.08); } }
@keyframes shake { 25% { transform: rotate(-18deg); } 50% { transform: rotate(14deg); } 75% { transform: rotate(-8deg); } }
.boardwrap { position: relative; width: var(--board); height: var(--board); flex: none; }
#board { width: 100%; height: 100%; display: block; background: var(--card); border-radius: 0.75rem; border: 1px solid var(--line); touch-action: manipulation; }
/* results: dimmed board with a centred card */
#over { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; padding: 0.75rem;
  border-radius: 0.75rem; background: color-mix(in srgb, var(--bg) 55%, transparent); backdrop-filter: blur(3px); }
#over[hidden] { display: none; }
#over .sheet { width: min(100%, 20rem); background: var(--card); border: 1px solid var(--line); border-radius: 1.125rem;
  padding: 1.125rem 1.125rem 0.875rem; text-align: center; box-shadow: 0 0.75rem 2.5rem #0003; }
#over .trophy { font-size: 2.2rem; line-height: 1; }
#over .big { font-size: 1.35rem; font-weight: 800; margin: 0.375rem 0 0.625rem; }
#over .rank { list-style: none; margin: 0 0 0.75rem; padding: 0; text-align: left; font-size: .88rem; }
#over .rank li { display: grid; grid-template-columns: 0.625rem 1fr auto; gap: 0.5rem; align-items: center; padding: 0.3125rem 2px;
  border-bottom: 1px solid var(--line); }
#over .rank li:first-child { font-weight: 700; }
#over .rank li:last-child { border-bottom: 0; }
#over .rank .dot { width: 0.625rem; height: 0.625rem; border-radius: 50%; }
#over .rank .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#over .rank .h { color: var(--muted); }
#over .row { margin: 0; }
#over .row button { flex: 1; min-height: 2.75rem; }
#over .sub { margin: 0; }
.bar { display: flex; align-items: center; gap: 0.5rem; }
#game > .cards:first-child { margin-top: auto; }   /* spare height goes on top: everything sits in thumb reach */
#status { flex: 1; min-width: 0; font-weight: 600; text-align: center; margin: 0; padding-left: 3rem; /* balances the menu button */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.icon { width: 2.5rem; height: 2.5rem; padding: 0; font-size: 1.3rem; line-height: 1; flex: none; }
dialog { border: 1px solid var(--line); border-radius: 0.875rem; background: var(--card); color: var(--fg);
  width: min(92vw, 26.25rem); max-height: 85dvh; padding: 1rem 1.25rem; }
dialog::backdrop { background: #0006; }
dialog h2:first-child { margin-top: 0; }
label.check { display: flex; align-items: center; gap: 0.625rem; margin: 0.625rem 0; }
label.check input { flex: none; width: 1.25rem; height: 1.25rem; margin: 0; accent-color: var(--fg); }
/* hand-history window: compact rows, newest on top; fills spare height on phones,
   sits beside the board on wide screens */
.moves { flex: 1 1 auto; min-height: 5.25rem; max-height: 8rem;   /* >= 3 rows, up to ~5 when there is room */ overflow: auto; border-radius: 0.75rem; background: var(--card);
  border: 1px solid var(--line); font-size: .8rem; color: var(--muted);
  mask-image: linear-gradient(#000 85%, transparent); }
.moves:has(#log:empty) { visibility: hidden; }
.nolog .moves { display: none; }              /* phones: history is opt-in (Settings) */
#log { list-style: none; margin: 0; padding: 0.25rem 0.625rem; }
#log li { display: grid; grid-template-columns: 0.5rem minmax(0, 7em) 1.125rem 1fr; gap: 0.5rem; align-items: center;
  padding: 3px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
#log li:last-child { border-bottom: 0; }
#log li:first-child { color: var(--fg); }
#log .dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; }
#log .who { overflow: hidden; text-overflow: ellipsis; }
#log .roll { width: 1.125rem; height: 1.125rem; line-height: 1rem; text-align: center; font-size: .72rem; border: 1px solid currentColor; border-radius: 0.25rem; }
#log .roll:empty { border: 0; }
#log .act { overflow: hidden; text-overflow: ellipsis; }
#log li.bw .act { color: var(--back); }
#log li.cap .act { color: var(--c0); }
#log li.dim { opacity: .6; }
#log li.win { font-weight: 700; }
/* wide screens: a "table" layout. Board as tall as the screen allows; on the right a sidebar
   with the room, the hand history and the action buttons in the bottom-right corner. */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  #game { --board: min(100dvh - 2 * 3.375rem - 0.75rem - 2rem, 100vw - 2rem - 21.25rem - 1.5rem, 53.75rem);
    display: grid; grid-template-columns: var(--board) 21.25rem; grid-template-rows: auto var(--board) auto;
    column-gap: 1.5rem; row-gap: 0.375rem; width: auto; align-content: center; justify-content: center; padding: 1rem; }
  #game > .cards.top { grid-area: 1 / 1; margin-top: 0; }
  .boardwrap { grid-area: 2 / 1; }
  #game > .cards.bottom { grid-area: 3 / 1; }
  .side { grid-area: 1 / 2 / 4 / 3; display: flex; flex-direction: column; gap: 0.625rem; min-height: 0; }
  .sidehead { display: flex; flex-direction: column; gap: 2px; padding: 0.25rem 2px; }
  #side-room { font-weight: 700; font-size: 1.1rem; letter-spacing: .04em; }
  #side-rules { color: var(--muted); font-size: .85rem; }
  .side .moves { flex: 1 1 auto; max-height: none; mask-image: none; font-size: .85rem; }
  .side .moves:has(#log:empty) { visibility: visible; }
  .nolog .side .moves { display: block; }
  #menu .phone-only { display: none; }
  #log li { padding: 0.3125rem 0; }
  .dir { min-height: 4.75rem; position: relative; }
  .die { width: 4.75rem; height: 4.75rem; }
  .keys { display: block; margin: 0; text-align: center; color: var(--muted); font-size: .78rem; }
  .dir kbd { display: block; position: absolute; top: 0.375rem; right: 0.5rem; }
}
@media (hover: none) { .keys, .dir kbd { display: none !important; } }
kbd { font: .7rem ui-monospace, monospace; border: 1px solid currentColor; border-radius: 0.25rem; padding: 0 0.25rem; opacity: .6; }
/* turn timer drain bar above the controls */
.tbar { height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.tbar i { display: block; height: 100%; background: var(--muted); transform-origin: left; transform: scaleX(0); }
.tbar.mine i { background: var(--fg); }
/* result banner over the board */
#toast { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); opacity: 0; pointer-events: none;
  padding: 0.625rem 1.125rem; border-radius: 0.875rem; background: var(--card); border: 1.5px solid var(--fg);
  font-weight: 700; font-size: 1.15rem; white-space: nowrap; box-shadow: 0 0.375rem 1.5rem #0004; z-index: 3; }
#toast.cap { border-color: var(--c0); color: var(--c0); }
label.inline { display: flex; align-items: center; gap: 0.625rem; }
label.inline select { width: auto; flex: 1; }

/* board */
.cell { stroke: var(--line); stroke-width: 1; fill: var(--card); }
.safe-mark { fill: var(--muted); opacity: .5; font-size: 22px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.tok circle.body { stroke: #0006; stroke-width: 2; }
.tok { pointer-events: none; }
.tok.movable { pointer-events: auto; }
.tok.movable circle.body { stroke: var(--fg); stroke-width: 3.5; animation: pulse 1s infinite alternate; cursor: pointer; }
.tok.selected circle.body { stroke: var(--back); stroke-width: 4; animation: none; }
.tok:focus { outline: none; }
.tok:focus-visible circle.hit { stroke: var(--fg); stroke-width: 2; stroke-dasharray: 4 3; }
@media (prefers-reduced-motion: reduce) { .tok.movable circle.body, .die:enabled { animation: none; } }
@keyframes pulse { to { stroke-width: 1.5; } }
.target { cursor: pointer; }
.target circle { fill: none; stroke-width: 2; }
.tok circle.hit { fill: transparent; stroke: none; }
.target { opacity: .75; }
.target.fw circle { stroke: var(--fg); }
.target.bw circle { stroke: var(--back); stroke-dasharray: 5 3; }
.target.capture circle { stroke: var(--c0); fill: #d9394a33; }
.target text { font-size: 15px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; fill: var(--fg); }
.target.bw text { fill: var(--back); }
.boom { fill: none; stroke: var(--c0); stroke-width: 4; animation: boom .7s ease-out forwards; pointer-events: none; }
@keyframes boom { from { r: 6; opacity: 1; } to { r: 40; opacity: 0; } }
@media (hover: none) { .kbd { display: none; } }

/* "?" rules help */
.qmark { display: inline-grid; place-items: center; width: 1.4rem; height: 1.4rem; min-height: 0 !important; padding: 0;
  border-radius: 50%; border: 1.5px solid currentColor; background: transparent; color: var(--muted); font-size: .8rem;
  font-weight: 700; line-height: 1; vertical-align: middle; }
h2.withq { display: flex; align-items: center; gap: .5rem; }
h2.withq .qmark { width: 1.6rem; height: 1.6rem; font-size: .85rem; text-transform: none; }
.homefoot .ghost .qmark { width: 1.1rem; height: 1.1rem; font-size: .7rem; margin-right: .2rem; }
#rules-list { list-style: none; margin: 0; padding: 0; }
#rules-list li { padding: .5rem 0; border-bottom: 1px solid var(--line); }
#rules-list li:last-child { border-bottom: 0; }
#rules-list li.grp { padding: .9rem 0 .2rem; border-bottom: 0; color: var(--muted); font-size: .75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; }
#rules-list li.current b { text-decoration: underline; text-underline-offset: 3px; }
#rules-list .tag { margin-left: .5rem; vertical-align: middle; }
#rules-list p { margin: .15rem 0 0; color: var(--muted); font-size: .88rem; }
#rh-title:focus { outline: none; }
