:root {
  --bg: #0e1118;
  --surface: #181c26;
  --surface-2: #232838;
  --fg: #f2f4f8;
  --muted: #9aa3b5;
  --accent: #4da6ff;
  --ok: #3ddc84;
  --bad: #ff6b6b;
  --radius: 1rem;
  /* Lines and veils over the background: white in the dark theme, black in the light. */
  --tint: 255 255 255;
  /* Coloured text that has to read on the page background. */
  --gold-text: #f0c040;
  --orange-text: #ffb020;
  --hot-text: #ff8a6a;
  --warn-text: #ffcf6e;
  --bad-text: #ff9a9a;
  /* "only": the page has its own colours; browsers' forced dark modes
     (Chrome's, Samsung Internet's) shouldn't repaint it. */
  color-scheme: only dark;
}
/* The light theme (Settings → Colours). Game art (felt, cards, chips)
   keeps its own colours in both. */
:root[data-theme='light'] {
  /* Warm paper: a card table under lamplight, gentler than white. */
  --bg: #d8d2c6;
  --surface: #ebe6db;
  --surface-2: #cec6b6;
  --fg: #1f1b14;
  --muted: #57503f;
  --accent: #2b7fd6;
  --ok: #1c9a55;
  --bad: #d23b3b;
  --tint: 0 0 0;
  --gold-text: #8a6200;
  --orange-text: #a35a00;
  --hot-text: #c0391b;
  --warn-text: #9a5b00;
  --bad-text: #b42828;
  color-scheme: only light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

h1,
h2 {
  margin: 0;
}

.view {
  min-height: 100dvh;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}
.view.chooser {
  padding: 0;
}
/* Wide screens: home, Settings and the games' start pages and lobbies at a
   comfortable width, centred (the dice, the chooser and game tables use the
   whole screen). */
.view.home {
  max-width: 64rem;
  margin-inline: auto;
}
.view.settings,
.view.eleusis,
.view.card-table:not(:has(.rg-cols)) {
  max-width: 42rem;
  margin-inline: auto;
}

.muted {
  color: var(--muted);
}

/* ---------- buttons & controls ---------- */

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--fg);
  cursor: pointer;
}
.icon-btn svg {
  width: 1.4rem;
  height: 1.4rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* A hidden button stays hidden (the display below would show it). */
.btn[hidden],
.btn-primary[hidden] {
  display: none;
}
.btn,
.btn-primary {
  display: block;
  width: 100%;
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border: 0;
  border-radius: 0.75rem;
  background: var(--surface-2);
  color: var(--fg);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary {
  background: var(--accent);
  color: #06121f;
}

.seg {
  display: flex;
  padding: 0.25rem;
  border-radius: 999px;
  background: var(--surface-2);
}
.seg button {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.25rem;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.seg button[aria-checked='true'] {
  background: var(--fg);
  color: var(--bg);
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.25rem 0.25rem 0.85rem;
  border-radius: 999px;
  background: var(--surface-2);
}
.stepper[hidden] {
  display: none;
}
.stepper-label {
  margin-right: 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.stepper button {
  /* About 44 px: a comfortable tap target. */
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 1.2rem;
  cursor: pointer;
}
.stepper output {
  min-width: 2.2rem;
  text-align: center;
  font-weight: 700;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
}
.toggle small {
  color: var(--muted);
}
.toggle input {
  appearance: none;
  flex: none;
  position: relative;
  width: 3rem;
  height: 1.75rem;
  margin: 0;
  border-radius: 999px;
  background: var(--surface-2);
  cursor: pointer;
  transition: background 0.2s;
}
.toggle input::after {
  content: '';
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 0.2s;
}
.toggle input:checked {
  background: var(--accent);
}
.toggle input:checked::after {
  transform: translateX(1.25rem);
}
.toggle input:disabled {
  opacity: 0.4;
}

.field {
  display: grid;
  gap: 0.4rem;
  padding: 0.75rem 0;
}
.field span {
  display: flex;
  justify-content: space-between;
}
.field output {
  font-weight: 700;
}
.field small {
  color: var(--muted);
}
.field input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}

/* ---------- bottom sheet dialog ---------- */

.sheet {
  width: min(32rem, 100%);
  max-height: 85dvh;
  margin: auto auto 0;
  padding: 1.25rem 1.25rem max(1.25rem, env(safe-area-inset-bottom));
  border: 0;
  border-radius: 1.25rem 1.25rem 0 0;
  background: var(--surface);
  color: var(--fg);
}
.sheet::backdrop {
  background: rgb(0 0 0 / 0.6);
}
.sheet h2 {
  margin-bottom: 0.5rem;
  font-size: 1.2rem;
}

/* ---------- home ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.topbar h1 {
  flex: 1;
  font-size: 1.6rem;
}

/* The Join box (any code) and the open games, above the tiles. */
.home-codes {
  margin-bottom: 1.25rem;
}
/* The old address: move this phone's data to the new one (move-home.js). */
.move-card {
  margin-bottom: 1.25rem;
  padding: 0.25rem 1.1rem 0.9rem;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
}
.move-card .btn-primary {
  margin-top: 0.25rem;
  text-align: center;
  text-decoration: none;
}
.move-later {
  display: block;
  margin: 0.9rem auto 0;
  padding: 0.3rem;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  text-align: center;
  text-decoration: underline;
  cursor: pointer;
}
.move-msg:empty,
.move-in-msg:empty {
  display: none;
}
.move-warn {
  color: var(--bad);
}
.move-in-msg .btn-primary {
  text-align: center;
  text-decoration: none;
}
.home-join {
  display: flex;
  gap: 0.5rem;
}
.home-join input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--surface-2);
  border-radius: 0.6rem;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  -webkit-user-select: text;
  user-select: text;
}
.home-join .btn {
  width: auto;
  margin: 0;
  padding: 0 1.4rem;
}
.home-join-msg:empty {
  display: none;
}
.home-join-msg {
  margin-top: 0.4rem;
}
.home-open-title {
  margin: 1rem 0 0.4rem;
  font-size: 0.95rem;
}
.home-show-all {
  margin-top: 0.5rem;
  padding: 0.4rem 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.home .rg-tables {
  display: grid;
  gap: 0.4rem;
}
.home .rg-tables div {
  display: flex;
}
.home .rg-tables div[hidden] {
  display: none;
}
.home .rg-tables a {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  min-width: 0;
  padding: 0.6rem 0.8rem;
  border-radius: 0.6rem 0 0 0.6rem;
  background: var(--surface-2);
  color: var(--fg);
  text-decoration: none;
  letter-spacing: 0.1em;
}
.home .rg-tables .sg-what {
  margin-left: 0.4rem;
  color: var(--muted);
  font-size: 0.9em;
  letter-spacing: 0;
}
.home .rg-tables small {
  flex: none;
  color: var(--muted);
  letter-spacing: 0;
}
.home .rg-tables .dc-unsave {
  padding: 0 0.8rem;
  border: 0;
  border-radius: 0 0.6rem 0.6rem 0;
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 1rem;
}
.tile {
  display: grid;
  gap: 0.35rem;
  padding: 1.25rem;
  border-radius: var(--radius);
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 22%, var(--surface)), var(--surface) 70%);
  color: var(--fg);
  text-decoration: none;
  transition: transform 0.15s;
}
.tile:active {
  transform: scale(0.97);
}
.tile[aria-disabled='true'] {
  opacity: 0.45;
  pointer-events: none;
}
.tile-icon {
  width: 2.75rem;
  height: 2.75rem;
  margin-bottom: 0.5rem;
  fill: none;
  stroke: var(--accent);
  color: var(--accent);
  stroke-width: 1.8;
}
.tile-title {
  font-size: 1.15rem;
  font-weight: 700;
}
.tile-blurb {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- settings ---------- */

.card {
  margin-bottom: 1rem;
  padding: 0.5rem 1.25rem 1.25rem;
  border-radius: var(--radius);
  background: var(--surface);
}
.card h2 {
  margin-top: 0.75rem;
  font-size: 1.1rem;
}
.checks {
  margin: 0;
  padding: 0;
  list-style: none;
}
.checks li {
  padding: 0.45rem 0;
}
.checks li span {
  display: inline-block;
  width: 1.25rem;
  font-weight: 700;
}
.checks .ok span {
  color: var(--ok);
}
.checks .no span {
  color: var(--bad);
}
.checks small {
  color: var(--muted);
}

.test-result:empty {
  display: none;
}
.test-result {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
}

.about .version {
  font-size: 1.05rem;
}
.about .update-status:empty {
  display: none;
}
.btn-update {
  min-height: 2.75rem;
  margin-left: 0.4rem;
  padding: 0.5rem 1rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #0b1020;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.topbar-version {
  margin-left: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}
.checks .info span {
  color: var(--accent);
  font-style: italic;
  font-family: Georgia, serif;
}
.storage-row .btn-update {
  display: block;
  margin: 0.45rem 0 0 1.25rem;
}
.storage-row .btn-update:disabled {
  opacity: 0.5;
}

.backup h3 {
  margin: 1.1rem 0 0.2rem;
  font-size: 1rem;
}
.backup-actions .btn {
  margin-top: 0.6rem;
  text-align: center;
}
.backup-text {
  width: 100%;
  margin-top: 0.6rem;
  padding: 0.6rem;
  border: 1px solid var(--surface-2);
  border-radius: 0.6rem;
  background: var(--bg, #0e1118);
  color: var(--fg);
  font: 0.8rem/1.3 ui-monospace, monospace;
}
.backup-status:empty {
  display: none;
}
.backup [hidden] {
  display: none;
}

/* ---------- Eleusis rule language card (tools/eleusis/rule-card.js) ---------- */

.rule-card .rule-url {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--surface-2);
  border-radius: 0.6rem;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 0.85rem;
}
.rule-card .rule-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.rule-card .rule-buttons > * {
  margin-top: 0;
  text-align: center;
  text-decoration: none;
}
.rule-card .rule-msg {
  min-height: 1.2em;
  margin: 0.5rem 0 0;
}

/* ---------- share-a-link sheet (js/lib/share-link.js) ---------- */

.share-sheet .share-url {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--surface-2);
  border-radius: 0.6rem;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
}
.share-sheet .share-msg {
  min-height: 1.2em;
  margin: 0.4rem 0;
}
.share-sheet .share-row {
  display: flex;
  gap: 0.5rem;
}
.share-sheet .share-row > * {
  flex: 1;
}
.share-sheet .share-why {
  margin: 0.6rem 0 0;
  font-size: 0.75rem;
}

/* ---------- settings: colours ---------- */

.theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
}
.theme-row .seg {
  flex: 0 1 15rem;
}
/* Five sound packs: the buttons get a line of their own. */
.theme-row:has(.sound-packs) {
  flex-wrap: wrap;
  gap: 0.5rem;
}
.theme-row .seg.sound-packs {
  flex: 1 1 100%;
}
.seg.sound-packs button {
  padding-inline: 0.1rem;
  font-size: 0.9rem;
}

/* Light theme: white panels on a light page need an edge to stand apart
   (players' seats, scores, cards of the menu…). */
:root[data-theme='light']
  :is(.card, .tc-team, .tc-seatbtn, .tc-slot, .tc-got, .tc-round, .tc-show, .tc-facebtn, .rg-paused, .rg-enemy, .rg-pl, .rg-fx-panel, .rg-group, .tile) {
  box-shadow:
    0 0 0 1px #bdb3a0,
    0 1px 3px rgba(40, 30, 10, 0.14);
}

/* The phone's "reduce motion" setting: no animated tiles or toggles. */
@media (prefers-reduced-motion: reduce) {
  .tile,
  .toggle input,
  .toggle input::after {
    transition: none;
  }
}

/* ---------- notifications (Settings) ---------- */

.notify-kinds {
  border-top: 1px solid var(--surface-2);
}
.notify-kinds[hidden] {
  display: none;
}
.notify-status {
  color: var(--warn-text);
}

/* ---------- privacy (Settings) ---------- */

.privacy ul {
  margin: 0 0 0.75rem;
  padding-left: 1.2rem;
}
.privacy li {
  margin: 0.2rem 0;
}
.privacy-confirm[hidden] {
  display: none;
}
.privacy-row {
  display: flex;
  gap: 0.5rem;
}
.privacy-row .btn {
  flex: 1;
}
.btn.danger {
  background: var(--bad);
  color: #fff;
}

/* ---------- help and the tour ---------- */

.help-text p,
.help-text ul {
  margin: 0 0 0.7rem;
}
.help-text ul {
  padding-left: 1.2rem;
}

/* The tour (js/lib/tour.js): the page dimmed but for one part, and a tip. */
dialog.tour {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
}
dialog.tour::backdrop {
  background: transparent;
}
.tour-spot {
  position: fixed;
  border-radius: 0.8rem;
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 200vmax rgb(0 0 0 / 0.62);
  pointer-events: none;
  transition:
    left 0.25s ease,
    top 0.25s ease,
    width 0.25s ease,
    height 0.25s ease;
}
.tour-tip {
  position: fixed;
  width: min(22rem, calc(100vw - 1.5rem));
  padding: 1rem 1.1rem;
  border-radius: 1rem;
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.5);
}
.tour-tip h2 {
  margin: 0.15rem 0 0.35rem;
  font-size: 1.1rem;
}
.tour-tip p {
  margin: 0 0 0.8rem;
}
.tour-n {
  color: var(--muted);
}
.tour-row {
  display: flex;
  gap: 0.5rem;
}
.tour-row > * {
  flex: 1;
}
@media (prefers-reduced-motion: reduce) {
  .tour-spot {
    transition: none;
  }
}

/* "Tap to start" (app.js): over a tool opened before anything was tapped. */
.tap-start {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  border: 0;
  background: rgb(0 0 0 / 0.55);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.tap-start:focus {
  outline: none;
}
.tap-start span {
  display: grid;
  gap: 0.4rem;
  max-width: 20rem;
  padding: 1.2rem 1.4rem;
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.5);
  text-align: center;
}
.tap-start b {
  font-size: 1.3rem;
}
.tap-start small {
  color: var(--muted);
  font-size: 0.95rem;
}

/* ---------- switching screens (js/lib/switcher.js) ---------- */

/* Where you are among the open screens, after a swipe on the top bar. */
.sw-toast {
  position: fixed;
  left: 50%;
  top: max(4.2rem, calc(env(safe-area-inset-top) + 3.6rem));
  z-index: 60;
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  max-width: calc(100vw - 2rem);
  padding: 0.55rem 0.9rem;
  border-radius: 0.9rem;
  background: var(--surface-2);
  color: var(--fg);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.35);
  font-size: 0.9rem;
  text-align: center;
  transform: translateX(-50%);
  transition: opacity 0.35s;
  pointer-events: none;
}
.sw-toast.gone {
  opacity: 0;
}
.sw-dots {
  display: flex;
  gap: 0.35rem;
}
.sw-dots i {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.5;
}
.sw-dots i.on {
  background: var(--accent);
  opacity: 1;
}
#app header {
  transition: transform 0.15s ease-out;
}

/* A timer or clock that ran out on another screen. */
.sw-alarm {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  width: min(30rem, calc(100vw - 2rem));
  border-radius: 0.9rem;
  background: var(--bad);
  color: #fff;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.4);
  transform: translateX(-50%);
}
.sw-alarm a {
  flex: 1;
  padding: 0.9rem 1rem;
  color: inherit;
  font-weight: 600;
  text-decoration: none;
}
.sw-alarm a b {
  margin-left: 0.4rem;
  text-decoration: underline;
}
.sw-alarm button {
  padding: 0.9rem 1rem;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 1.2rem;
  cursor: pointer;
}

/* ---------- the nearby sharing test (tools/nearby) ---------- */

.nb-count {
  font-size: 3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.nb-log {
  max-height: 16rem;
  overflow: auto;
  padding: 0.6rem;
  border-radius: 0.6rem;
  background: var(--bg);
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.nb-step textarea,
.nb-paste {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.6rem;
  border: 1px solid var(--surface-2);
  border-radius: 0.6rem;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 0.8rem;
}
.nb-step h2 {
  margin-top: 0.75rem;
}
.nb-ok {
  color: var(--good, #30a46c);
}
.nb-bad {
  color: var(--bad);
}

/* Your seat code under a table in "Your tables" and "Open games": tap to
   copy it (js/net/seat-chip.js). */
.rg-tables div {
  flex-wrap: wrap;
}
.seat-line {
  flex-basis: 100%;
  margin: 0.2rem 0 0.1rem;
}
.seat-line[hidden] {
  display: none;
}
.seat-chip {
  padding: 0.3rem 0.7rem;
  border: 1px dashed var(--muted);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.85rem;
  cursor: copy;
}
.seat-chip b {
  letter-spacing: 0.08em;
}
.seat-chip small {
  margin-left: 0.3rem;
  color: var(--muted);
}

/* A code as a QR code (js/lib/qr.js): black on white in any theme, so a
   camera reads it. */
.qr-box {
  width: min(70vw, 18rem);
  margin: 0.5rem auto;
  padding: 0.5rem;
  border-radius: 0.75rem;
  background: #fff;
}
.qr-box svg {
  display: block;
  width: 100%;
  height: auto;
}
.qr-code {
  margin: 0.4rem 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
}
