:root {
  --bg: #15181d;
  --panel: #1e2229;
  --panel-2: #272c35;
  --line: #333a45;
  --text: #e9e6df;
  --muted: #9aa1ad;
  --accent: #e0a94a;
  --accent-ink: #1b1508;
  --danger: #d9634f;
  --ok: #6fbf73;
  --s0: #dc5a4d;
  --s1: #4f8fe6;
  --s2: #57b368;
  --s3: #e3b23c;
  --cell: #2c323c;
  --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f1ea;
    --panel: #ffffff;
    --panel-2: #f0ece3;
    --line: #dcd6c8;
    --text: #23262b;
    --muted: #6a707b;
    --accent: #b9781a;
    --accent-ink: #ffffff;
    --cell: #e9e4d8;
  }
}
* { 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); }

.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 {
  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: 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 .start { margin-top: 10px; width: 100%; border-color: var(--accent); }
.warn { color: var(--accent) !important; font-size: 14px; margin: 10px 0 0 !important; }

.layout { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.boardcol { --size: min(100vw - 24px, 100dvh - 240px, 720px); width: max(var(--size), 272px); max-width: calc(100vw - 24px); }
.side { width: 100%; max-width: 720px; display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 900px) {
  .layout { flex-direction: row; align-items: flex-start; justify-content: center; gap: 20px; }
  .boardcol { --size: min(100vw - 380px, 100dvh - 90px, 720px); }
  .side { width: 320px; }
}

/* The board: an 11 × 11 grid; cells and pawns are placed by app.js */
.board {
  position: relative; width: 100%; aspect-ratio: 1; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
}
.cell, .pawn { position: absolute; width: calc(100% / 11); height: calc(100% / 11); }
.cell::before {
  content: ""; position: absolute; inset: 9%; border-radius: 50%;
  background: var(--cell); border: 1px solid var(--line);
}
.s0 { --c: var(--s0); } .s1 { --c: var(--s1); } .s2 { --c: var(--s2); } .s3 { --c: var(--s3); }
.cell.start::before { background: var(--c); border-color: var(--c); }
.cell.house::before { background: color-mix(in srgb, var(--c) 38%, var(--panel)); border-color: var(--c); }
.cell.base::before { background: transparent; border: 2px solid var(--c); }
.cell.idle { opacity: .3; }
.pawn {
  appearance: none; border: 0; background: none; padding: 0; margin: 0; z-index: 2; cursor: default;
  transition: left .14s linear, top .14s linear;
}
.pawn::before {
  content: ""; position: absolute; inset: 20%; border-radius: 50%; background: var(--c);
  border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, .45);
}
.pawn.can { cursor: pointer; z-index: 3; }
.pawn.can::before { animation: pawn-can 1s ease-in-out infinite alternate; }
.pawn.can:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 50%; }
@keyframes pawn-can {
  from { box-shadow: 0 0 0 0 var(--text), 0 2px 5px rgba(0, 0, 0, .45); transform: scale(1); }
  to { box-shadow: 0 0 0 3px var(--text), 0 2px 5px rgba(0, 0, 0, .45); transform: scale(1.18); }
}

/* Side panel: dice and status, the players, the actions */
.turn {
  display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.dice {
  appearance: none; flex: none; width: 64px; height: 64px; padding: 0; border-radius: 14px; cursor: pointer;
  background: #f6f1e6; border: 3px solid var(--c, var(--line)); color: #23262b;
}
.dice[data-seat="0"] { --c: var(--s0); } .dice[data-seat="1"] { --c: var(--s1); }
.dice[data-seat="2"] { --c: var(--s2); } .dice[data-seat="3"] { --c: var(--s3); }
.dice svg { display: block; width: 100%; height: 100%; fill: currentColor; }
.dice:disabled { cursor: default; opacity: .75; }
.dice.ready { border-color: var(--accent); animation: dice-ready 1.1s ease-out infinite; }
.dice:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.dice.rolling svg { animation: dice-roll .4s ease-out; }
@keyframes dice-ready {
  from { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent); }
  to { box-shadow: 0 0 0 12px transparent; }
}
@keyframes dice-roll { from { transform: rotate(-200deg) scale(.6); opacity: .2; } to { transform: none; opacity: 1; } }
.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); }
.home-count { margin-left: auto; display: inline-flex; gap: 4px; }
.home-count i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--c); }
.home-count i.in { background: var(--c); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  .pawn { transition: none; }
  .pawn.can::before, .dice.ready, .dice.rolling svg { animation: none; }
  .pawn.can::before { box-shadow: 0 0 0 3px var(--text); }
}

.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; }

/* 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 die only, so the buttons fit */
@media (max-width: 560px) {
  body.in-game .brand [data-i18n] { display: none; }
  body.in-game .top-actions { gap: 8px; }
}
