/* =========================================================================
   Marbles and Dice -- design tokens
   Palette: deep indigo table + warm gold accent. Player marble colors
   (yellow/green/orange/blue) are semantic identity, not the UI accent.
   ========================================================================= */

:root {
  --ground: #f3f1fb;
  --surface: #ffffff;
  --surface-2: #ffffff;
  --ink: #1b1e33;
  --ink-soft: #5a5e78;
  --accent: #b8842a;
  --accent-bright: #d59f3c;
  --accent-ink: #241a06;
  --line: rgba(27, 30, 51, 0.12);
  --line-strong: rgba(27, 30, 51, 0.22);
  --shadow: 0 16px 40px -16px rgba(27, 30, 66, 0.28);
  --shadow-lg: 0 30px 70px -20px rgba(27, 30, 66, 0.35);
  --radius-card: 18px;
  --radius-control: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #171b2e;
    --surface: #1f2440;
    --surface-2: #262c4d;
    --ink: #f4f2ea;
    --ink-soft: #a6abc9;
    --accent: #e8b74a;
    --accent-bright: #f4cc70;
    --accent-ink: #241a06;
    --line: rgba(244, 242, 234, 0.12);
    --line-strong: rgba(244, 242, 234, 0.22);
    --shadow: 0 16px 40px -16px rgba(4, 6, 16, 0.55);
    --shadow-lg: 0 30px 70px -20px rgba(4, 6, 16, 0.65);
  }
}

:root[data-theme="dark"] {
  --ground: #171b2e;
  --surface: #1f2440;
  --surface-2: #262c4d;
  --ink: #f4f2ea;
  --ink-soft: #a6abc9;
  --accent: #e8b74a;
  --accent-bright: #f4cc70;
  --accent-ink: #241a06;
  --line: rgba(244, 242, 234, 0.12);
  --line-strong: rgba(244, 242, 234, 0.22);
  --shadow: 0 16px 40px -16px rgba(4, 6, 16, 0.55);
  --shadow-lg: 0 30px 70px -20px rgba(4, 6, 16, 0.65);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  /* Keep the page clear of the notch, the Dynamic Island and the home
     indicator. The insets are only non-zero because the viewport meta asks
     for viewport-fit=cover; everywhere else they resolve to 0. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--ground);
  color: var(--ink);
  font-family: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
}

h1, h2, h3 { font-family: "Unbounded", ui-sans-serif, system-ui, sans-serif; font-weight: 700; margin: 0; text-wrap: balance; }

.hidden { display: none !important; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ------------------------------ Header ------------------------------ */

.app-header {
  position: relative;
  text-align: center;
  padding: 2.2rem 3.5rem 0.6rem;
}
.title-row {
  display: inline-flex;
  align-items: baseline;
  gap: 0.7rem;
  flex-wrap: wrap;
  justify-content: center;
}
.app-header h1 {
  font-size: clamp(1.9rem, 5vw, 2.7rem);
  letter-spacing: 0.01em;
  color: var(--ink);
}
.logo-marbles {
  display: inline-flex;
  gap: 5px;
  transform: translateY(-2px);
}
.logo-marbles span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  box-shadow: inset -2px -2px 3px rgba(0, 0, 0, 0.35), inset 1px 1px 2px rgba(255, 255, 255, 0.55);
}
.tagline {
  margin: 0.6rem 0 0;
  color: var(--ink-soft);
  font-size: 1rem;
}

.theme-toggle {
  position: absolute;
  top: 1.6rem;
  right: 1.2rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.theme-toggle:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.theme-toggle:active { transform: translateY(0); }

main {
  max-width: 1560px;
  margin: 0 auto;
  padding: 1.2rem 1.2rem 3rem;
}

/* ------------------------------ Title screen ------------------------------ */

.title-screen {
  max-width: 480px;
  margin: 2.2rem auto;
  padding: 2.2rem 2rem 2.4rem;
  text-align: center;
  animation: screen-in 0.5s ease-out;
}

.title-track {
  position: relative;
  height: 44px;
  border-radius: 999px;
  background: var(--ground);
  border: 1px solid var(--line);
  overflow: hidden;
  margin-bottom: 1.6rem;
}
.title-track::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 10%;
  right: 10%;
  height: 2px;
  transform: translateY(-50%);
  background: repeating-linear-gradient(90deg, var(--line-strong) 0 8px, transparent 8px 16px);
}
.title-marble {
  position: absolute;
  top: 50%;
  left: 8%;
  width: 22px;
  height: 22px;
  margin-top: -11px;
  margin-left: -11px;
  border-radius: 50%;
  box-shadow: inset -3px -4px 6px rgba(0, 0, 0, 0.4), inset 3px 3px 4px rgba(255, 255, 255, 0.55);
  animation: title-race 1.8s ease-in-out infinite alternate;
}
.title-marble-0 { background: #f0b90b; animation-delay: 0s; }
.title-marble-1 { background: #2f9e44; animation-delay: -0.45s; }
.title-marble-2 { background: #e8720c; animation-delay: -0.9s; }
.title-marble-3 { background: #2266d1; animation-delay: -1.35s; }

@keyframes title-race {
  from { left: 8%; }
  to { left: 92%; }
}

.title-sub {
  margin: 0 0 1.4rem;
  color: var(--ink-soft);
  font-size: 1.02rem;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------ Setup screen ------------------------------ */

.setup-panel {
  max-width: 600px;
  margin: 1.2rem auto;
  padding: 1.9rem 2rem 2.1rem;
  animation: screen-in 0.45s ease-out;
}
.setup-panel h2 {
  font-size: 1.35rem;
  color: var(--ink);
  margin-bottom: 1.3rem;
}

.field-group { margin: 1.3rem 0; }
.field-group > label {
  display: block;
  font-weight: 700;
  font-size: 0.76rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 0.6rem;
}

.count-buttons {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.count-buttons button {
  flex: 1;
  padding: 0.55rem 0;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-family: "Hanken Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.count-buttons button:hover { color: var(--ink); }
.count-buttons button.active {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.35);
}

.player-rows { display: flex; flex-direction: column; gap: 0.55rem; margin: 1rem 0; }
.player-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-control);
  background: var(--ground);
  border: 1px solid var(--line);
}
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex: none;
  box-shadow: inset -3px -4px 6px rgba(0, 0, 0, 0.35), inset 3px 3px 4px rgba(255, 255, 255, 0.5);
}
.name-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
}
.type-select {
  flex: 0 0 auto;
  width: 112px;
  padding: 0.5rem 0.4rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.85rem;
}

.team-row { display: flex; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 500;
  font-size: 0.92rem;
  cursor: pointer;
  color: var(--ink);
}
.checkbox-label input[type="checkbox"] {
  appearance: none;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  flex: none;
  cursor: pointer;
  transition: background 0.18s ease;
}
.checkbox-label input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.18s ease;
}
.checkbox-label input[type="checkbox"]:checked { background: var(--accent); }
.checkbox-label input[type="checkbox"]:checked::after { transform: translateX(16px); }

.primary-btn {
  padding: 0.8rem 1.2rem;
  border-radius: var(--radius-control);
  border: none;
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  color: var(--accent-ink);
  font-family: "Hanken Grotesk", sans-serif;
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 10px 24px -10px rgba(232, 183, 74, 0.55);
  transition: transform 0.08s ease, filter 0.15s ease, box-shadow 0.15s ease;
}
.primary-btn:hover:not(:disabled) { filter: brightness(1.05); }
.primary-btn:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 4px 14px -8px rgba(232, 183, 74, 0.5); }
.primary-btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

.secondary-btn {
  padding: 0.65rem 1rem;
  border-radius: var(--radius-control);
  border: 1.5px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.secondary-btn:hover:not(:disabled) { background: var(--ground); border-color: var(--ink-soft); }
.secondary-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.mode-desc { margin: 0.6rem 0 0; font-size: 0.85rem; color: var(--ink-soft); }
.setup-secondary-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.setup-secondary-row .secondary-btn, .setup-secondary-row .primary-btn { width: auto; flex: 1; }

/* Title screen: the tutorial sits under Play, with a one-line nudge for
   first-time visitors that goes away once they've played or finished it. */
.title-tutorial-btn { margin-top: 0.7rem; }
.title-nudge { margin: 0.8rem 0 0; font-size: 0.88rem; color: var(--ink-soft); }

/* ------------------------------ House rules ------------------------------ */

.house-rules {
  margin: 1.3rem 0;
  padding: 0.9rem 1.1rem;
  border-radius: var(--radius-control);
  border: 1px solid var(--line);
  background: var(--ground);
  color: var(--ink-soft);
}
.house-rules summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.76rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.house-rules-count {
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
}
.house-rules .mode-desc { margin: 0.7rem 0 0.4rem; }
.house-rules .checkbox-label { margin-top: 0.7rem; align-items: flex-start; line-height: 1.35; }
.house-rules .checkbox-label input[type="checkbox"] { margin-top: 1px; }

/* ------------------------------ Resume card ------------------------------ */

.resume-card {
  margin: 0 0 1.4rem;
  padding: 1.1rem 1.2rem 1.2rem;
  border-radius: var(--radius-card);
  border: 1px solid var(--line-strong);
  background: linear-gradient(135deg, rgba(34, 102, 209, 0.16), rgba(34, 102, 209, 0.03));
}
.resume-badge { background: #2266d1; color: #fff; }
.resume-card .daily-summary { margin-bottom: 0.9rem; }
.resume-card .setup-secondary-row .primary-btn, .resume-card .setup-secondary-row .secondary-btn { margin: 0; }

.rules { margin-top: 1.5rem; color: var(--ink-soft); }
.rules summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--ink);
  font-size: 0.95rem;
}
.rules ul { padding-left: 1.2rem; line-height: 1.6; font-size: 0.92rem; }
.rules strong { color: var(--ink); }

/* ------------------------------ Info cards & tags ------------------------------ */

.daily-card {
  margin-top: 1.4rem;
  padding: 1.1rem 1.2rem 1.2rem;
  border-radius: var(--radius-card);
  border: 1px solid var(--line-strong);
  background: linear-gradient(135deg, rgba(213, 159, 60, 0.18), rgba(213, 159, 60, 0.04));
}
.daily-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.daily-badge, .daily-tag {
  font-family: "Unbounded", sans-serif;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent-bright);
  border-radius: 999px;
  white-space: nowrap;
}
.daily-badge { font-size: 0.7rem; padding: 0.3rem 0.65rem; }
.daily-tag { flex: none; font-size: 0.58rem; padding: 0.22rem 0.5rem; }
.rules-tag { background: var(--ink-soft); color: var(--surface); cursor: help; }
.daily-date { font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); }
.daily-summary { margin: 0 0 0.55rem; font-size: 0.9rem; line-height: 1.5; color: var(--ink-soft); }
.daily-card .secondary-btn { margin: 0; }
.modal .secondary-btn + .primary-btn { margin-top: 0.6rem; }

/* ------------------------------ Online lobby ------------------------------ */

.title-online-btn { margin-top: 0.6rem; }
.online-card { background: linear-gradient(135deg, rgba(34, 102, 209, 0.2), rgba(34, 102, 209, 0.04)); }
.online-badge { background: #2266d1; color: #fff; }
.online-tag { background: #2266d1; color: #fff; }

.online-status {
  margin: 0 0 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--ink-soft);
}
.online-status::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.online-status-online { color: #2f9e44; }
.online-status-connecting { color: var(--accent); }
.online-status-offline { color: #d7263d; }
.online-error {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-control);
  background: rgba(215, 38, 61, 0.12);
  border: 1px solid rgba(215, 38, 61, 0.4);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
}

#online-name {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-control);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
}
.join-row { display: flex; gap: 0.6rem; align-items: stretch; }
.join-row input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-control);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: "Unbounded", sans-serif;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
}
.join-row .secondary-btn { width: auto; margin: 0; flex: none; padding-inline: 1.4rem; }

.room-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius-card);
  border: 1px solid var(--line-strong);
  background: linear-gradient(135deg, rgba(34, 102, 209, 0.2), rgba(34, 102, 209, 0.04));
}
.room-code-block { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.room-code {
  font-family: "Unbounded", sans-serif;
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--ink);
}
.room-head .secondary-btn { width: auto; margin: 0; flex: none; }

.online-seats { display: grid; gap: 0.5rem; margin-bottom: 1.2rem; }
.seat-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-control);
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.seat-row.seat-open { border-style: dashed; background: transparent; }
.seat-name { font-weight: 600; color: var(--ink); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-row.seat-open .seat-name { font-weight: 500; color: var(--ink-soft); }
.seat-tag {
  flex: none;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: var(--line);
  color: var(--ink-soft);
}
.seat-tag.you { background: var(--accent-bright); color: var(--accent-ink); }
.seat-tag.offline { background: rgba(215, 38, 61, 0.18); color: #d7263d; }
.seat-action {
  flex: none;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.seat-action:hover:not(:disabled) { color: var(--ink); border-color: var(--ink-soft); }
.seat-action:disabled { opacity: 0.45; cursor: default; }

#online-host-controls:has(button:disabled) { opacity: 0.75; }
#online-wait-note { margin-bottom: 1rem; }
/* A seat whose player has dropped: the computer is covering for them. */
.status-chip.seat-offline { opacity: 0.55; }
.status-chip.seat-offline .status-name { text-decoration: line-through; }

/* ------------------------------ Game screen ------------------------------ */

.game-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.2rem;
  align-items: start;
}

.board-wrap {
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: min(100%, 95vh);
  margin: 0 auto;
  filter: drop-shadow(0 28px 50px rgba(10, 8, 30, 0.35));
}
#board { width: 100%; height: 100%; display: block; }

.board-face { fill: url(#board-wood-grad); }
.board-rim { fill: none; stroke: url(#rim-bevel); stroke-width: 15; }
.board-rim-inner { fill: none; stroke: rgba(0, 0, 0, 0.3); stroke-width: 4; }

.hole {
  fill: url(#hole-grad);
  stroke: var(--hole-stroke, #2c2010);
  stroke-width: 2;
}
/* A player's home holes are painted their own color, like the finishing slots
   on a wooden board, so the lane you're racing into reads at a glance even
   while it's empty. Set through a variable rather than an inline fill so the
   legal-target highlight further down this file still wins over it. */
.home-hole {
  fill: var(--home-fill, url(#hole-grad));
  stroke-width: 2.5;
}
.shortcut-hole { stroke-width: 3.5; }
.start-hole { stroke-width: 4; }
/* Dashed ring round a start hole: a marble parked here can't be bumped. */
.safe-ring {
  fill: none;
  stroke-width: 2;
  stroke-dasharray: 2 5;
  opacity: 0.8;
  pointer-events: none;
}
.center-hole { fill: url(#hole-grad); stroke: var(--accent); stroke-width: 4; }
.pen-hole { opacity: 0.65; }

.shortcut-line, .home-line {
  stroke: #8a5a2b;
  stroke-width: 2.5;
  stroke-dasharray: 3 6;
  opacity: 0.5;
}
.home-line { stroke-dasharray: none; opacity: 0.35; stroke-width: 14; }

.arm-label-bg { fill: rgba(20, 14, 6, 0.6); }
.arm-label {
  font-family: "Unbounded", sans-serif;
  font-size: 30px;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.5);
  stroke-width: 2px;
}

.marble-shadow { pointer-events: none; fill: rgba(20, 12, 4, 0.4); }
.marble-glint { pointer-events: none; fill: rgba(255, 255, 255, 0.8); }

/* The unit carries the position, so every move slides. */
.marble-unit { transition: transform 0.38s cubic-bezier(0.34, 1.12, 0.64, 1); }
/* While a marble is hopping, script drives the transform frame by frame --
   the transition would smear the arcs back into one long slide. */
.marble-unit.hopping { transition: none; }
.marble-spin { transform-box: fill-box; transform-origin: center; }
/* Knocked off the board: script flies the unit along its arc, so what is
   left here is the tumble on the way and the squash where it lands. Two full
   turns rather than one -- it is being thrown, not nudged. */
.marble-unit.bumped .marble-spin { animation: bump-tumble 0.64s ease-out; }
@keyframes bump-tumble {
  0% { transform: scale(1) rotate(0deg); }
  30% { transform: scale(1.35) rotate(220deg); }
  100% { transform: scale(1) rotate(720deg); }
}
.marble-unit.knock-land .marble-spin { animation: knock-land 240ms cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes knock-land {
  0% { transform: scale(1.2, 0.76); }
  55% { transform: scale(0.92, 1.09); }
  100% { transform: scale(1, 1); }
}
/* The trail the thrown marble leaves, so the eye has a line to follow. */
.fx-ghost {
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
  animation: fx-ghost 380ms ease-out forwards;
}
@keyframes fx-ghost {
  from { opacity: 0.34; transform: scale(1); }
  to { opacity: 0; transform: scale(0.5); }
}

.marble {
  stroke: rgba(0, 0, 0, 0.4);
  stroke-width: 1.5;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25));
}
.marble.movable { cursor: pointer; }
.marble.home-safe { stroke: var(--accent); stroke-width: 2.5; }

.marble-glow {
  fill: rgba(232, 183, 74, 0.4);
  stroke: var(--accent-bright);
  stroke-width: 2;
  cursor: pointer;
  animation: glow-pulse 1.1s ease-in-out infinite;
}
.marble-unit:not(.is-movable) .marble-glow { display: none; }
/* A destination the player can bump: the hole's own highlight is hidden
   under the marble sitting on it, so the marble gets lit instead -- in red,
   the bump color the danger badge already uses. */
#marble-layer .marble-unit.capture-target .marble-glow {
  display: block;
  fill: rgba(231, 76, 60, 0.35);
  stroke: #e74c3c;
}
@keyframes glow-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* Sitting on a shortcut hole: the dive to the center is available. */
.dive-ring {
  fill: none;
  stroke: var(--accent-bright);
  stroke-width: 2.5;
  stroke-dasharray: 5 7;
  pointer-events: none;
  display: none;
  animation: dive-spin 3.4s linear infinite;
}
.marble-unit.is-dive-ready .dive-ring { display: block; }
@keyframes dive-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.legal-target {
  fill: rgba(255, 255, 255, 0.25);
  stroke: var(--accent-bright);
  stroke-width: 4;
  cursor: pointer;
  animation: glow 0.9s ease-in-out infinite;
}
@keyframes glow {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* Danger, strike-ready, and almost-home badges -- small status dots offset
   from the marble so they can coexist without turning into a bullseye of
   concentric rings. Shown only for the current player's own marbles (see
   ui.js): this is decision support for whoever's about to act, not board-wide
   noise. */
.danger-badge, .strike-badge, .almost-home-badge {
  display: none;
  pointer-events: none;
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 1.5;
  transform-box: fill-box;
  transform-origin: center;
}
.marble-unit.danger .danger-badge { display: block; fill: #e5484d; animation: badge-pulse 1s ease-in-out infinite; }
.marble-unit.can-strike .strike-badge { display: block; fill: #2dd4bf; }
.marble-unit.almost-home .almost-home-badge { display: block; fill: var(--accent-bright); }
@keyframes badge-pulse {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* Board shake on a bump -- a quick, small rattle, not a seasick wobble. */
.board-wrap.shake { animation: board-shake 0.4s ease-in-out; }
@keyframes board-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-0.4deg); }
  40% { transform: translateX(5px) rotate(0.3deg); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

/* Floating callouts -- "BUMP! +1 ROLL", "SHORTCUT!", "CENTER SHOT!" -- spawned
   at a board position and left to drift up and fade on their own. */
.fx-text {
  font-family: "Unbounded", sans-serif;
  font-weight: 800;
  font-size: 26px;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 3px;
  animation: fx-float 1s ease-out forwards;
}
.fx-text.fx-bump { fill: #ff6b6b; }
.fx-text.fx-shortcut { fill: var(--accent-bright); }
@keyframes fx-float {
  0% { transform: translateY(0); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translateY(-46px); opacity: 0; }
}

/* The winning-move replay banner: unlike the callouts above it doesn't fade
   itself out on a timer -- ui.js removes it explicitly once the slow-motion
   replay lands, so it has to stay lit for however long that takes. */
.fx-text.fx-replay-banner {
  font-size: 30px;
  fill: var(--accent-bright);
  animation: fx-replay-in 350ms ease-out forwards;
}
@keyframes fx-replay-in {
  0% { transform: translateY(14px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

/* Diving into the center: the camera punches in toward the hole and settles.
   The board's viewBox is centered on the center hole, so a plain scale is
   already a push-in on exactly the right point. */
/* 620ms here is CENTER_DIVE_MS in ui.js, which removes the class afterwards.
   view-box puts the origin at the middle of the 1000x1000 viewBox, which is
   exactly the center hole, so a plain scale is already a push-in on it. */
#board-camera {
  transform-box: view-box;
  transform-origin: center;
}
/* The follow camera. Origin at the viewBox's top-left so ui.js can frame a
   region with a plain scale-then-translate; the transform itself is set
   inline, and clearing it eases back out to the whole board. */
#board-pan {
  transform-box: view-box;
  transform-origin: 0 0;
  transition: transform 240ms ease-out;
}
#board-pan.no-ease { transition: none; }
/* Used when somebody is waiting to act. They cannot reach a hole for at least
   the length of the die spin (175ms), so this has room to finish first and
   nothing ever has to be cut. */
#board-pan.quick-release { transition-duration: 140ms; }
#board-camera.center-dive { animation: center-dive 620ms cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes center-dive {
  0% { transform: scale(1); }
  30% { transform: scale(1.18); }
  55% { transform: scale(1.13); }
  100% { transform: scale(1); }
}

/* Shockwave out of the hole: a bloom, then rings. Scaled rather than grown by
   radius so it animates on the compositor, with a non-scaling stroke so the
   rings stay hairline-crisp instead of fattening as they expand. */
.fx-flash, .fx-ring {
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
}
.fx-flash {
  fill: var(--accent-bright);
  animation: fx-flash 520ms ease-out forwards;
}
@keyframes fx-flash {
  0% { transform: scale(0.55); opacity: 0.9; }
  60% { transform: scale(2.4); opacity: 0.3; }
  100% { transform: scale(3.2); opacity: 0; }
}
.fx-ring {
  fill: none;
  stroke: var(--accent-bright);
  stroke-width: 5;
  vector-effect: non-scaling-stroke;
  animation: fx-ring 700ms ease-out forwards;
}
@keyframes fx-ring {
  0% { transform: scale(1); opacity: 0.85; }
  100% { transform: scale(7); opacity: 0; }
}

/* Chips flung out of a collision, in the bumped marble's own color. Each one
   carries its own direction as --dx/--dy so a single keyframe covers the lot. */
.fx-shard {
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
  animation: fx-shard 520ms cubic-bezier(0.15, 0.7, 0.35, 1) forwards;
}
@keyframes fx-shard {
  0% { transform: translate(0, 0) scale(1.1); opacity: 0.95; }
  100% { transform: translate(var(--dx, 0), var(--dy, 0)) scale(0.25); opacity: 0; }
}

/* The moment you're choosing where to shoot out of the center: legal targets
   get a bolder, differently-colored ring so the choice reads as an event. */
.legal-target.center-shot {
  fill: rgba(93, 224, 230, 0.28);
  stroke: #2dd4bf;
  animation: glow 0.6s ease-in-out infinite;
}
.center-hole.pulse { animation: center-pulse 0.7s ease-out; }
@keyframes center-pulse {
  0% { stroke-width: 4; filter: drop-shadow(0 0 0 rgba(232, 183, 74, 0.9)); }
  60% { stroke-width: 9; }
  100% { stroke-width: 4; filter: drop-shadow(0 0 0 rgba(232, 183, 74, 0)); }
}

@media (prefers-reduced-motion: reduce) {
  .marble-glow, .legal-target, .dive-ring { animation: none; opacity: 0.8; }
  .marble-unit { transition: none; }
  .marble-unit.bumped .marble-spin { animation: none; }
  .marble-unit.knock-land .marble-spin { animation: none; }
  .fx-ghost { animation: none; opacity: 0; }
  .danger-badge { animation: none; }
  .board-wrap.shake, #board-camera.center-dive { animation: none; }
  #board-pan { transition: none; }
  .fx-text { animation: none; opacity: 1; }
  .fx-flash, .fx-ring, .fx-shard { animation: none; opacity: 0; }
  .center-hole.pulse { animation: none; }
}

/* ------------------------------ Sidebar modules ------------------------------ */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  position: sticky;
  top: 1rem;
}
.sidebar .panel { padding: 1rem 1.1rem; }

.turn-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  border-left: 5px solid var(--turn-color, var(--accent));
  transition: border-color 0.3s ease;
}
.turn-indicator { flex: 1; min-width: 0; }
.move-counter {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.turn-banner::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--turn-color, var(--accent));
  flex: none;
  transition: background 0.3s ease;
}
.turn-indicator {
  font-family: "Unbounded", sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
}

.dice-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}
.die { width: 58px; height: 58px; flex: none; }
.die svg rect { fill: var(--ground); stroke: var(--line-strong); stroke-width: 4; }
.die svg circle { fill: var(--turn-color, var(--accent)); }

.hint {
  margin: 0.7rem 0 0;
  min-height: 2.4em;
  color: var(--ink-soft);
  font-size: 0.93rem;
  line-height: 1.4;
}

/* ------------------------------ Tutorial coach ------------------------------ */

.coach-card {
  border-left: 5px solid var(--accent);
  background: linear-gradient(135deg, rgba(213, 159, 60, 0.16), var(--surface) 70%);
}
.coach-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.45rem;
}
.coach-step {
  font-family: "Unbounded", sans-serif;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}
.coach-skip {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.2rem 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.coach-skip:hover { color: var(--ink); }
.coach-title { font-size: 1.02rem; margin-bottom: 0.4rem; }
.coach-text { margin: 0; font-size: 0.92rem; line-height: 1.5; color: var(--ink); }
.coach-card .primary-btn { margin-top: 0.9rem; }

/* Whatever the tutorial wants clicked next pulses gently. */
.coach-target { animation: coach-pulse 1.3s ease-in-out infinite; }
@keyframes coach-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232, 183, 74, 0.55), 0 10px 24px -10px rgba(232, 183, 74, 0.55); }
  50% { box-shadow: 0 0 0 9px rgba(232, 183, 74, 0), 0 10px 24px -10px rgba(232, 183, 74, 0.55); }
}
@media (prefers-reduced-motion: reduce) {
  .coach-target { animation: none; box-shadow: 0 0 0 4px rgba(232, 183, 74, 0.45); }
}

.player-status {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.status-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.status-chip.current {
  background: var(--ground);
  border-color: var(--line);
  font-weight: 700;
}
.status-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dots { display: flex; gap: 4px; flex: none; }
.status-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}
.status-dots .dot.filled { background: var(--accent); }
.status-count {
  flex: none;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  font-size: 0.8rem;
  width: 2.4em;
  text-align: right;
}

.log-title {
  margin: 0 0 0.5rem;
  font-family: "Unbounded", sans-serif;
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.log {
  max-height: 160px;
  overflow-y: auto;
  font-size: 0.85rem;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.log-entry {
  padding-left: 0.6rem;
  border-left: 2px solid var(--line);
}
.log-entry:first-child {
  color: var(--ink);
  font-weight: 600;
  border-left-color: var(--accent);
}

/* ------------------------------ Modals ------------------------------ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 24, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  z-index: 10;
}
.modal {
  background: var(--surface);
  border-radius: 20px;
  padding: 2.2rem;
  max-width: 420px;
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-x: hidden;
  overflow-y: auto;
  text-align: center;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  position: relative;
}
@media (max-width: 480px) {
  .modal { padding: 1.5rem 1.3rem; }
}
.modal h2 { margin-top: 0; font-size: 1.5rem; }
.fireworks-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
#win-modal .modal::before {
  content: "";
  position: absolute;
  inset: -40%;
  background: radial-gradient(circle, rgba(232, 183, 74, 0.35), transparent 60%);
  animation: win-glow 2.4s ease-in-out infinite;
  pointer-events: none;
}
@keyframes win-glow {
  0%, 100% { opacity: 0.5; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.05); }
}
.modal > * { position: relative; z-index: 1; }
/* A loss gets the quiet version: no glow, no fireworks, muted title. */
.modal-overlay.loss .modal::before { display: none; }
.modal-overlay.loss h2 { color: var(--ink-soft); }
.win-prompt { margin: 0 0 1rem; color: var(--ink-soft); font-size: 0.92rem; }
.modal .primary-btn + .secondary-btn { margin-top: 0.6rem; }

.leaderboard-card { max-width: 480px; text-align: left; }
.leaderboard-card h2 { text-align: center; }
.leaderboard-note {
  margin: 0 0 1.1rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
}
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.leaderboard-table th, .leaderboard-table td {
  padding: 0.5rem 0.55rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.leaderboard-table th {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}
.leaderboard-scroll { overflow-x: auto; }
.lb-streak { color: var(--accent); font-weight: 700; white-space: nowrap; }
.lb-rank { color: var(--ink-soft); width: 1.6em; }
.lb-num { text-align: right; }
.leaderboard-empty {
  color: var(--ink-soft);
  text-align: center;
  padding: 1rem 0;
}
/* Your name: the one field that decides which row on the board is yours. */
.you-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.5rem;
}
.you-row label {
  font-weight: 700;
  font-size: 0.76rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
}
.you-row input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
}
.you-note { margin: 0 0 1.1rem; font-size: 0.82rem; color: var(--ink-soft); }
.leaderboard-table tr.lb-you td {
  background: rgba(213, 159, 60, 0.16);
  font-weight: 700;
  color: var(--ink);
}

/* Backup & restore -- the escape hatch from "it only lives in this browser". */
.backup-row { display: flex; gap: 0.6rem; margin-top: 1.2rem; }
.backup-row .secondary-btn { width: auto; flex: 1; }
.backup-note { margin: 0.55rem 0 0; font-size: 0.8rem; line-height: 1.45; color: var(--ink-soft); }
.restore-panel { margin-top: 0.7rem; }
.restore-panel textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-control);
  border: 1px solid var(--line);
  background: var(--ground);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  resize: vertical;
}
.restore-panel .secondary-btn { margin-top: 0.5rem; }

.leaderboard-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.3rem;
}
.leaderboard-actions .primary-btn, .leaderboard-actions .secondary-btn { width: auto; flex: 1; }

/* ------------------------------ Results & achievements ------------------------------ */

#win-modal .results-modal { max-width: 480px; text-align: left; }
#win-modal .results-modal h2, #win-message, #win-prompt { text-align: center; }

.win-achievements { margin: 0 0 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.achievement-toast {
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-control);
  background: linear-gradient(135deg, rgba(213, 159, 60, 0.22), rgba(213, 159, 60, 0.06));
  border: 1px solid var(--line-strong);
  font-size: 0.9rem;
  text-align: center;
}

.win-results { margin: 0 0 1.1rem; }
.results-scroll { overflow-x: auto; }
.results-table { font-size: 0.85rem; }
.superlatives {
  list-style: none;
  margin: 0.8rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.86rem;
  color: var(--ink-soft);
}
.superlatives strong { color: var(--ink); }

.achievements-body { display: flex; flex-direction: column; gap: 0.6rem; }
.achievement-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-control);
  background: var(--ground);
  border: 1px solid var(--line);
}
.achievement-row.locked { opacity: 0.5; }
.achievement-icon { font-size: 1.4rem; flex: none; width: 1.6em; text-align: center; }
.achievement-text { flex: 1; min-width: 0; }
.achievement-name { font-weight: 700; }
.achievement-desc { font-size: 0.85rem; color: var(--ink-soft); }
.achievement-date { font-size: 0.75rem; color: var(--ink-soft); white-space: nowrap; }

/* ------------------------------ Career stats ------------------------------ */

.career-stats:not(:empty) {
  margin-top: 1.1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}
.career-stats h3 {
  margin: 0 0 0.5rem;
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.career-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.75rem;
  padding: 0.45rem 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
}
.career-row:last-child { border-bottom: none; }
.career-row strong { color: var(--ink); flex-basis: 100%; }
.career-row span { white-space: nowrap; font-variant-numeric: tabular-nums; }

.settings-card { max-width: 420px; text-align: left; }
.settings-card h2 { text-align: center; margin-bottom: 1.2rem; }
.settings-card .field-group:first-of-type { margin-top: 0; }
.settings-card #theme-buttons button { font-size: 0.9rem; }
.settings-card .primary-btn { margin-top: 0.6rem; }

.volume-row { display: flex; align-items: center; gap: 0.7rem; }
.volume-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}
.volume-value {
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  width: 3.2em;
  text-align: right;
  font-size: 0.9rem;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--ground);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease;
}
.icon-btn:hover { border-color: var(--line-strong); }

@media (max-width: 860px) {
  .game-screen { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .app-header { padding: 2rem 3.6rem 0.5rem; }
  /* Headroom above the board. On a phone the board is the first thing under
     the browser's own toolbar, and on iOS that toolbar collapses as you
     scroll -- without this the board rides up under the status bar and the
     Dynamic Island. */
  .board-wrap { margin-top: 2rem; }
}
