:root {
  --bg: #15181d;
  --panel: #1e2229;
  --panel-2: #272c35;
  --line: #333a45;
  --text: #e9e6df;
  --muted: #9aa1ad;
  --accent: #e0a94a;
  --accent-ink: #1b1508;
  --danger: #d9634f;
  --ok: #6fbf73;
  --s0: #cf3a30;
  --s1: #2f74c8;
  --s2: #2f9d4e;
  --s3: #ecb51f;
  --radius: 12px;
}
/* Light: when the device asks for it, unless the player chose dark; or when the player chose
   light (scheme.js sets data-scheme on <html>). The light colours are therefore written twice:
   keep the two blocks the same. */
@media (prefers-color-scheme: light) {
  :root:not([data-scheme="dark"]) {
    --bg: #f4f1ea;
    --panel: #ffffff;
    --panel-2: #f0ece3;
    --line: #dcd6c8;
    --text: #23262b;
    --muted: #6a707b;
    --accent: #b9781a;
    --accent-ink: #ffffff;
  }
}
:root[data-scheme="light"] {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --panel-2: #f0ece3;
  --line: #dcd6c8;
  --text: #23262b;
  --muted: #6a707b;
  --accent: #b9781a;
  --accent-ink: #ffffff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; max-width: 1120px; margin: 0 auto;
}
.brand { color: var(--text); text-decoration: none; font-weight: 700; font-size: 20px; letter-spacing: .02em; }
.brand { display: inline-flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.brand-mark rect { fill: var(--accent); }
.brand-mark circle { fill: var(--accent-ink); }
.brand-mark path { stroke: var(--accent-ink); stroke-width: 1.6; stroke-linecap: round; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, .chip input:focus-visible + span, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger.armed { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.big { width: 100%; font-size: 18px; padding: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Home screen */
.home { max-width: 560px; margin: 0 auto; padding: 8px 16px 40px; }
.home h1 { font-size: 30px; margin: 12px 0 4px; }
.lead { color: var(--muted); margin: 0 0 20px; }
fieldset { border: 0; padding: 0; margin: 0 0 22px; }
legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip > span {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 76px; min-height: 48px; padding: 6px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600;
}
.chip > span small { font-weight: 400; color: var(--muted); font-size: 12px; }
.chip input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }
.custom { display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.custom label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); flex: 1; min-width: 140px; }
.linkrow input, .joinrow input {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font: inherit; min-height: 44px; min-width: 0;
}
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }
.switch small { color: var(--muted); }

/* Home screen: back to the game against the computer */
.resume { width: 100%; margin: 0 0 20px; border-color: var(--accent); }
/* Joining with a short code */
.join {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin: 0 0 22px;
}
.join label { display: block; font-weight: 700; margin-bottom: 8px; }
.joinrow { display: flex; gap: 8px; }
.joinrow input { flex: 1; text-transform: uppercase; letter-spacing: .12em; font-weight: 600; }
.joinrow input::placeholder { color: var(--muted); opacity: .6; font-weight: 400; }
.join-error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }

/* Home screen: the rules */
.rules { margin-top: 26px; color: var(--muted); }
.rules summary { cursor: pointer; font-weight: 700; color: var(--text); }
.rules ul { margin: 10px 0 0; padding-left: 20px; }
.rules li { margin-bottom: 6px; }

/* Game */
.game { max-width: 1120px; margin: 0 auto; padding: 0 12px 24px; }
.invite {
  background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 auto 14px; max-width: 720px;
}
.invite h2 { margin: 0 0 2px; font-size: 20px; }
.invite p { margin: 0 0 10px; color: var(--muted); }
.linkrow { display: flex; gap: 8px; flex-wrap: wrap; }
.linkrow input { flex: 1 1 220px; }
.invite-more {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line);
}
.qr { flex: none; width: 148px; height: 148px; border-radius: 8px; overflow: hidden; background: #fff; }
.qr svg { display: block; width: 100%; height: 100%; }
.invite-alt { flex: 1 1 220px; }
.invite-alt p:last-child { margin-bottom: 0; }
.coderow { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.code {
  font: 700 26px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .12em; color: var(--text); user-select: all; white-space: nowrap;
}
.invite .start { margin-top: 10px; width: 100%; border-color: var(--accent); }
.warn { color: var(--accent) !important; font-size: 14px; margin: 10px 0 0 !important; }

/* The game screen. Narrow: status, table, my tiles, players, one under the other. Wide: the
   table and my tiles on the left, the rest in a column on the right. */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; max-width: 720px; margin: 0 auto; }
.tablecol { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.table { height: clamp(230px, min(100vw - 40px, 100dvh - 330px), 560px); }
.side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
@media (min-width: 900px) {
  .layout { max-width: none; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto 1fr; gap: 12px 20px; align-items: start; }
  .tablecol { grid-column: 1; grid-row: 1 / span 2; }
  .layout > .turn { grid-column: 2; grid-row: 1; }
  .side { grid-column: 2; grid-row: 2; }
  .table { height: clamp(300px, min((100vw - 400px) * .64, 100dvh - 230px), 600px); }
}

/* The table: green baize in a walnut frame. The line of tiles is one SVG drawn by app.js
   (layout.js says where each tile lies); it is scaled so that the whole line always fits. */
.table-frame {
  padding: 10px; border-radius: 18px;
  background: linear-gradient(135deg, #7a5230, #4a2f1a 45%, #6b4628 70%, #3b2413);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, .25), inset 0 -2px 3px rgba(0, 0, 0, .5),
    0 10px 24px rgba(0, 0, 0, .35), 0 2px 4px rgba(0, 0, 0, .3);
}
.table {
  position: relative; border-radius: 10px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 40%, #2f7d55, #1f5c3d 70%, #184a31);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35), inset 0 2px 10px rgba(0, 0, 0, .5);
}
.table svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.table-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  text-align: center; color: rgba(255, 255, 255, .7); font-weight: 600;
}

/* A tile: ivory with dark pips. The same drawing on the table, in the hand and in the lists. */
.tile rect { fill: #f6f0df; stroke: #b9ad8f; stroke-width: .03; }
.tile line { stroke: #8d8266; stroke-width: .05; stroke-linecap: round; }
.tile circle { fill: #24211c; }
.table .tile { filter: drop-shadow(0 .05px .06px rgba(0, 0, 0, .55)); }
.table .tile.last rect { stroke: var(--accent); stroke-width: .08; }
.table .tile.last { animation: tile-in .28s ease-out; }
.table .tile.last.seen { animation: none; }
@keyframes tile-in { from { opacity: 0; } to { opacity: 1; } }
/* where the picked tile can go: tap one of the two ends */
.slot { cursor: pointer; }
.slot rect { fill: rgba(255, 255, 255, .16); stroke: #fff; stroke-width: .07; stroke-dasharray: .22 .14; animation: ghost .9s ease-in-out infinite alternate; }
.slot:hover rect, .slot:focus-visible rect { fill: rgba(255, 255, 255, .38); }
.slot:focus-visible { outline: none; }
@keyframes ghost { from { fill-opacity: .5; } to { fill-opacity: 1; } }

/* My tiles */
.hand {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-height: 96px; align-content: flex-start;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px;
}
.hand:empty { display: none; }
.hand-tile {
  appearance: none; border: 0; background: none; padding: 0; margin: 0; flex: none; cursor: default;
  width: clamp(34px, 10.5vw, 44px); aspect-ratio: 1 / 2; border-radius: 7px; transition: transform .12s, opacity .12s;
}
.hand-tile svg { display: block; width: 100%; height: 100%; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .4)); }
.hand.choosing .hand-tile:not(.can) { opacity: .42; }
.hand-tile.can { cursor: pointer; }
.hand-tile.can:hover { transform: translateY(-4px); }
.hand-tile.can .tile rect { stroke: var(--accent); stroke-width: .07; }
.hand-tile.picked { transform: translateY(-9px); }
.hand-tile.picked .tile rect { stroke-width: .12; }
.hand-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Status and the boneyard (the face-down tiles a player draws from) */
.turn {
  display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; min-height: 74px;
}
.boneyard {
  appearance: none; flex: none; position: relative; width: 40px; height: 64px; padding: 0; border-radius: 8px; cursor: pointer;
  background: linear-gradient(145deg, #3a3f49, #23272e); border: 2px solid #59606c; color: #fff;
  font: 700 18px/1 system-ui, sans-serif; box-shadow: 3px 3px 0 #1a1d22, 0 6px 10px rgba(0, 0, 0, .28);
}
.boneyard:disabled { cursor: default; opacity: .8; }
.boneyard.ready { border-color: var(--accent); animation: boneyard-ready 1.1s ease-out infinite; }
.boneyard:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@keyframes boneyard-ready {
  from { box-shadow: 3px 3px 0 #1a1d22, 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent); }
  to { box-shadow: 3px 3px 0 #1a1d22, 0 0 0 12px transparent; }
}
.s0 { --c: var(--s0); } .s1 { --c: var(--s1); } .s2 { --c: var(--s2); } .s3 { --c: var(--s3); }
.status[data-seat="0"] { --c: var(--s0); } .status[data-seat="1"] { --c: var(--s1); }
.status[data-seat="2"] { --c: var(--s2); } .status[data-seat="3"] { --c: var(--s3); }
.status { font-weight: 600; font-size: 17px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.status-note { font-weight: 400; font-size: 14px; color: var(--muted); }

.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.player {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; min-height: 42px;
}
.player.turn { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.player.winner { border-color: var(--ok); box-shadow: inset 0 0 0 1px var(--ok); }
.player .dot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--c); }
.player .name { font-weight: 600; }
.player.absent .name { color: var(--muted); }
.player .tag { font-size: 13px; color: var(--muted); }
.player .tag.you { color: var(--accent); }
.player { flex-wrap: wrap; }
.player .nums { margin-left: auto; display: inline-flex; align-items: center; gap: 12px; font-variant-numeric: tabular-nums; }
.player .left { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-weight: 600; }
.player .left::before { content: ""; width: 9px; height: 16px; border-radius: 2.5px; background: var(--muted); }
.player .score { font-weight: 700; min-width: 2ch; text-align: right; }
/* the tiles a player was left with, turned over when the round ends */
.player .reveal { flex: 1 0 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding-top: 2px; }
.player .reveal svg { width: 34px; height: 17px; display: block; }
.player .reveal .sum { margin-left: 6px; font-size: 13px; color: var(--muted); }
.match { margin: 0; color: var(--muted); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  .hand-tile { transition: none; }
  .boneyard.ready, .slot rect, .table .tile.last { animation: none; }
}

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50;
  max-width: calc(100vw - 32px); text-align: center; box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}

.foot { margin-top: 28px; text-align: center; font-size: 14px; }
.foot a { color: var(--muted); }
.foot a:hover { color: var(--text); }

/* Header: language switch (flags only) next to "New game" */
.top-actions { display: flex; align-items: center; gap: 10px; }
.langs { display: inline-flex; align-items: center; gap: 6px; }
.flag {
  appearance: none; border: 0; background: none; padding: 6px 2px; margin: 0; cursor: pointer; line-height: 0;
  opacity: .45; transition: opacity .15s;
}
.flag svg { display: block; width: 26px; height: 17px; border-radius: 3px; box-shadow: 0 0 0 1px var(--line); }
.flag:hover { opacity: .8; }
.flag[aria-pressed=true] { opacity: 1; cursor: default; }
.flag[aria-pressed=true] svg { box-shadow: 0 0 0 1px var(--bg), 0 0 0 3px var(--accent); }
.flag:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Foot of the home screen: "Language" opens the list of every language */
.foot { color: var(--muted); }
.foot-link {
  appearance: none; border: 0; background: none; padding: 0; margin: 0; font: inherit; color: var(--muted);
  text-decoration: underline; cursor: pointer;
}
.foot-link:hover { color: var(--text); }
.foot-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.lang-all { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.lang-all[hidden] { display: none; }
.flag.named {
  display: inline-flex; align-items: center; gap: 8px; opacity: 1; line-height: 1.2; font: inherit; font-size: 14px;
  color: var(--text); padding: 7px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
}
.flag.named svg { width: 22px; height: 14px; box-shadow: 0 0 0 1px var(--line); }
.flag.named:hover { border-color: var(--muted); }
.flag.named[aria-pressed=true] { border-color: var(--accent); font-weight: 600; }

/* Header: voice chat — the microphone and, while voice is on, a button to leave */
.voice { display: inline-flex; align-items: center; gap: 6px; }
.btn.icon { padding: 6px; min-width: 36px; }
.btn.icon svg, .voice-mark svg {
  display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
#voice-mic.on { border-color: var(--accent); color: var(--accent); }
#voice-mic.on.linked { background: var(--ok); border-color: var(--ok); color: #10210f; }
#voice-mic.on.muted { background: transparent; border-color: var(--danger); color: var(--danger); }
#voice-mic.calling { border-color: var(--ok); color: var(--ok); animation: voice-call 1.6s ease-out infinite; }
@keyframes voice-call {
  from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
  to { box-shadow: 0 0 0 9px transparent; }
}
@media (prefers-reduced-motion: reduce) { #voice-mic.calling { animation: none; } }
.voice-mark { flex: none; color: var(--muted); line-height: 0; }
.voice-mark svg { width: 14px; height: 14px; }
.voice-mark.linked { color: var(--ok); }
/* The other players are played by <audio> elements that have to be in the page */
.voice-audio { position: absolute; width: 0; height: 0; overflow: hidden; }
/* Narrow phones: in a game the header keeps the tile only, so the buttons fit */
@media (max-width: 560px) {
  body.in-game .brand [data-i18n] { display: none; }
  body.in-game .top-actions { gap: 8px; }
}

/* The Playhall bar: the portal's name, its categories, the flags and light/dark. On the start
   screen only; during a game the game's own header is all there is. While it shows, the flags
   are in it, so the ones in the game's header step aside. */
.hall {
  display: flex; align-items: center; gap: 14px;
  max-width: 1120px; margin: 0 auto; padding: 10px 16px 9px;
  border-bottom: 1px solid var(--line); font-size: 14px;
}
body:has(#home[hidden]) .hall { display: none; }
body:has(#home:not([hidden])) .top [data-lang-switch] { display: none; }
.hall-brand { font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; flex: none; }
.hall-tabs { display: flex; gap: 2px; flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.hall-tabs::-webkit-scrollbar { display: none; }
.hall-tabs a {
  color: var(--muted); text-decoration: none; padding: 5px 9px; border-radius: 7px;
  white-space: nowrap; border: 1px solid transparent;
}
.hall-tabs a:hover { color: var(--text); }
.hall-tabs a[aria-current] { color: var(--text); background: var(--panel); border-color: var(--line); font-weight: 600; }
.hall-tools { display: flex; align-items: center; gap: 10px; flex: none; }
.hall .scheme {
  width: 30px; height: 30px; flex: none; padding: 0; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.hall .scheme:hover { color: var(--text); border-color: var(--muted); }
.hall .scheme svg { display: block; }
.hall .scheme:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
