/* infiniDomino — HUD and page styles. Cosy, warm, playful. */

:root {
  --ink: #2c1d13;
  --ink-soft: #6b5242;
  --paper: rgba(255, 249, 240, 0.86);
  --paper-strong: rgba(255, 251, 245, 0.96);
  --edge: rgba(255, 255, 255, 0.65);
  --coral: #ff7a59;
  --pink: #f2668b;
  --sun: #ffd166;
  --mint: #3fc9a8;
  --shadow: 0 6px 22px rgba(28, 12, 2, 0.32), 0 1px 3px rgba(28, 12, 2, 0.25);
  --radius: 16px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", "Varela Round", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --pad-t: max(12px, env(safe-area-inset-top));
  --pad-r: max(12px, env(safe-area-inset-right));
  --pad-b: max(12px, env(safe-area-inset-bottom));
  --pad-l: max(12px, env(safe-area-inset-left));
  color-scheme: light;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #3a281d;
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
#scene.dragging { cursor: grabbing !important; }
/* Keyboard play (Enter / Space on the highlighted centre domino). */
#scene:focus-visible { outline: 3px solid rgba(255, 122, 89, 0.7); outline-offset: -3px; }

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 42%, transparent 58%, rgba(22, 10, 3, 0.42) 100%),
    linear-gradient(to bottom, rgba(255, 214, 160, 0.06), transparent 30%);
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- HUD layout ---------- */

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  padding: var(--pad-t) var(--pad-r) var(--pad-b) var(--pad-l);
  z-index: 10;
}
#hud > * > * { pointer-events: auto; }

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.hud-bottom {
  position: absolute;
  left: var(--pad-l);
  right: var(--pad-r);
  bottom: var(--pad-b);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.card {
  background: var(--paper);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  backdrop-filter: blur(12px) saturate(1.3);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- brand + connection ---------- */

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 7px 8px;
}
.logo { width: 30px; height: 30px; flex: none; filter: drop-shadow(0 2px 2px rgba(80, 30, 10, 0.25)); }
.title {
  margin: 0 4px 0 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  white-space: nowrap;
}
.title span { color: var(--coral); }

.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px 4px 8px;
  border-radius: 999px;
  background: rgba(60, 35, 20, 0.08);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.conn .dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b9a89b;
  flex: none;
}
.conn-live .dot { background: #2fbf71; }
.conn-live .dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(47, 191, 113, 0.55);
  animation: live-pulse 2.4s ease-out infinite;
}
.conn-connecting .dot, .conn-reconnecting .dot { background: #f2a93b; animation: blink 0.9s ease-in-out infinite alternate; }
.conn-offline { background: rgba(239, 91, 75, 0.14); color: #a23324; }
.conn-offline .dot { background: #ef5b4b; }
.conn-paused .dot { background: #8a7a6e; }

@keyframes live-pulse {
  0% { transform: scale(1); opacity: 1; }
  70%, 100% { transform: scale(2.75); opacity: 0; }
}
@keyframes blink { from { opacity: 0.35; } to { opacity: 1; } }

/* ---------- stats (#hud-stats, rendered from the _hud signal) ---------- */

#hud-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 62vw;
}
#hud-stats .stat {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--paper);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  backdrop-filter: blur(12px) saturate(1.3);
  border: 1px solid var(--edge);
  box-shadow: var(--shadow);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
#hud-stats .stat b {
  color: var(--ink);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
#hud-stats .stat-online b::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 6px 1px 0;
  border-radius: 50%;
  background: #2fbf71;
  vertical-align: middle;
}
#hud-stats .stat-falling b { color: #e4572e; }
#hud-stats .stat-you {
  background: linear-gradient(135deg, #c2410c, #be185d);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}
#hud-stats .stat-you b { color: #fff; }

/* ---------- coordinates + go to ---------- */

.coords {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
}
.readout {
  min-width: 8.5em;
  font-weight: 800;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--ink);
  transition: color 0.2s;
}
.readout.hovered { color: #c4441f; }
.readout .ax {
  margin: 0 4px 0 7px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0.7;
}
.readout .ax:first-child { margin-left: 0; }

.coords input {
  width: 9.5em;
  border: 1.5px solid transparent;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.75);
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.coords input::placeholder { color: #7a6152; font-weight: 600; }
.coords input:focus { border-color: var(--coral); background: #fff; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 14px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.15s cubic-bezier(0.3, 1.6, 0.5, 1), box-shadow 0.2s, background 0.2s, filter 0.2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(0.96); }
.btn:focus-visible { outline: 3px solid rgba(255, 122, 89, 0.7); outline-offset: 2px; }
.btn svg { width: 22px; height: 22px; flex: none; }

.btn-go {
  padding: 8px 13px;
  background: var(--ink);
  color: #fff7ee;
  font-size: 14px;
}
.btn-go:hover { background: #4a3122; }

.actions { display: flex; align-items: center; gap: 8px; }

.btn-jump {
  height: 48px;
  padding: 0 18px 0 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, #c2410c 0%, #c9302c 50%, #be185d 100%);
  color: #fff;
  font-size: 15px;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 22px rgba(232, 80, 60, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  text-shadow: 0 1px 1px rgba(120, 30, 10, 0.3);
}
.btn-jump:hover { filter: brightness(1.06) saturate(1.05); box-shadow: 0 10px 26px rgba(232, 80, 60, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
.btn-jump svg { filter: drop-shadow(0 1px 1px rgba(120, 30, 10, 0.3)); }
.btn-jump.following { background: linear-gradient(135deg, #7c3aed 0%, #be185d 100%); box-shadow: 0 8px 22px rgba(150, 50, 160, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.35); }

/* ---------- follow mode pill ---------- */

.follow-pill {
  position: fixed;
  left: 50%;
  top: calc(var(--pad-t) + 64px);
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 12px;
  border-radius: 999px;
  background: rgba(44, 29, 19, 0.8);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fff3e4;
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow);
  pointer-events: none;
  z-index: 16;
  animation: pop-in 0.3s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.follow-pill[hidden] { display: none; }
.follow-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 3px rgba(255, 122, 89, 0.3);
  animation: blink 0.8s ease-in-out infinite alternate;
}

.btn-icon {
  width: 46px;
  height: 46px;
  padding: 0;
  background: var(--paper);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  backdrop-filter: blur(12px) saturate(1.3);
  border: 1px solid var(--edge);
  box-shadow: var(--shadow);
}
.btn-icon:hover { background: var(--paper-strong); }
.btn-sound .icon-off { display: none; }
.btn-sound.muted .icon-on { display: none; }
.btn-sound.muted .icon-off { display: block; }
.btn-sound.muted { color: #a5442c; }

/* ---------- toasts (server appends .toast into #toasts) ---------- */

#toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--pad-b) + var(--hud-bottom-h, 64px) + 12px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  width: min(92vw, 440px);
  pointer-events: none;
  z-index: 20;
}
#toasts > .toast:not(:nth-last-child(-n + 3)) { display: none; }
.toast {
  pointer-events: none; /* informational only: taps go through to the table / HUD */
  max-width: 100%;
  padding: 10px 16px 10px 14px;
  border-radius: 14px;
  background: var(--paper-strong);
  border: 1px solid var(--edge);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  animation: toast-in 0.42s cubic-bezier(0.2, 1.5, 0.4, 1) both, toast-out 0.35s ease-in 2.25s forwards;
}
.toast::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin: 0 8px 1px 0;
  border-radius: 3px;
  vertical-align: middle;
  background: var(--mint);
  transform: rotate(12deg);
}
.toast-warn { background: #fff0cc; color: #6d4300; }
.toast-warn::before { background: #f2a93b; }
.toast-err { background: #ffe0da; color: #8d2414; }
.toast-err::before { background: #ef5b4b; }
/* Persistent (e.g. "A new version is available"): no fade-out. */
.toast.toast-sticky { animation: toast-in 0.42s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.92); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(0.97); } }

/* ---------- first-visit hint ---------- */

.hint {
  position: fixed;
  left: 50%;
  top: calc(var(--pad-t) + 64px);
  transform: translate(-50%, -8px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(44, 29, 19, 0.78);
  color: #fff3e4;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s, transform 0.5s;
  z-index: 15;
}
.hint b { color: var(--sun); }
.hint.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; cursor: pointer; }

/* ---------- loading ---------- */

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.7s ease;
  z-index: 5;
}
.loading.show { opacity: 1; }
.loading p {
  margin: 0;
  color: #ffe9d2;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.loader { display: flex; gap: 9px; height: 40px; align-items: flex-end; }
.loader i {
  display: block;
  width: 11px;
  height: 34px;
  border-radius: 4px;
  background: var(--coral);
  transform-origin: 100% 100%;
  animation: topple 1.6s cubic-bezier(0.55, 0, 0.6, 1) infinite;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
}
.loader i:nth-child(2) { background: #ffb347; animation-delay: 0.12s; }
.loader i:nth-child(3) { background: var(--sun); animation-delay: 0.24s; }
.loader i:nth-child(4) { background: var(--mint); animation-delay: 0.36s; }
.loader i:nth-child(5) { background: #5f9df2; animation-delay: 0.48s; }
@keyframes topple {
  0%, 12% { transform: rotate(0); }
  30%, 62% { transform: rotate(58deg); }
  80%, 100% { transform: rotate(0); }
}

/* ---------- help overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--pad-t) var(--pad-r) var(--pad-b) var(--pad-l);
  background: rgba(30, 15, 6, 0.45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  z-index: 30;
  animation: fade-in 0.2s ease both;
}
.overlay[hidden] { display: none; }
.help-card {
  position: relative;
  width: min(580px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 24px 26px 20px;
  background: var(--paper-strong);
  animation: pop-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.help-card h2 { margin: 0 44px 6px 0; font-size: 22px; letter-spacing: -0.01em; }
.help-card h3 { margin: 18px 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.help-card .lede { margin: 0 0 12px; color: var(--ink-soft); font-weight: 600; }
.rules { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 9px; }
.rules li {
  position: relative;
  padding-left: 22px;
  line-height: 1.42;
  font-size: 14.5px;
}
.rules li::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 4px;
  width: 9px;
  height: 14px;
  border-radius: 3px;
  background: var(--coral);
  transform: rotate(14deg);
}
.rules li:nth-child(2)::before { background: var(--sun); }
.rules li:nth-child(3)::before { background: var(--mint); }
.rules li:nth-child(4)::before { background: #5f9df2; }
.keys { width: 100%; border-collapse: collapse; font-size: 14px; }
.keys th {
  width: 9.5em;
  padding: 6px 10px 6px 0;
  text-align: left;
  vertical-align: top;
  color: var(--ink-soft);
  font-weight: 700;
}
.keys td { padding: 6px 0; line-height: 1.7; }
.keys tr + tr { border-top: 1px solid rgba(60, 35, 20, 0.08); }
kbd {
  display: inline-block;
  min-width: 1.7em;
  margin: 0 1px;
  padding: 0 6px;
  border-radius: 7px;
  background: #fff;
  border: 1px solid rgba(60, 35, 20, 0.18);
  border-bottom-width: 3px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 800;
  line-height: 1.6;
  text-align: center;
}
code {
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(60, 35, 20, 0.08);
  font-size: 0.92em;
}
.fineprint { margin: 16px 0 0; font-size: 13px; color: var(--ink-soft); }
.help-close { position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; box-shadow: none; }

/* ---------- paused overlay (idle) ---------- */

#paused { cursor: pointer; }
.paused-card {
  padding: 22px 28px;
  text-align: center;
  background: var(--paper-strong);
  animation: pop-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.paused-card h2 { margin: 0 0 6px; font-size: 22px; }
.paused-card p { margin: 0; color: var(--ink-soft); font-weight: 600; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(12px) scale(0.96); } }

/* ---------- fatal ---------- */

.fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.fatal .card { max-width: 420px; padding: 22px 24px; background: var(--paper-strong); }
.fatal h2 { margin: 0 0 8px; }

/* ---------- small screens ---------- */

@media (max-width: 720px) {
  .hud-top { flex-direction: column; align-items: stretch; }
  #hud-stats { max-width: none; justify-content: flex-start; }
  #hud-stats .stat { padding: 4px 9px; font-size: 12px; }
  #hud-stats .stat-total { display: none; }
  .brand { align-self: flex-start; }
  .btn-jump span { display: none; }
  .btn-jump { width: 48px; padding: 0; }
  .readout { min-width: 0; font-size: 13px; }
  .coords input { width: 7.2em; }
  .hint { top: auto; bottom: calc(var(--pad-b) + 140px); white-space: normal; width: max-content; max-width: 90vw; text-align: center; }
  .follow-pill { top: auto; bottom: calc(var(--pad-b) + var(--hud-bottom-h, 64px) + 70px); font-size: 12.5px; }
}
@media (max-width: 420px) {
  .title { font-size: 17px; }
  .conn .conn-label { display: none; }
  .conn { padding: 5px; }
  .coords input { width: 6em; }
  .btn-icon { width: 42px; height: 42px; }
}
@media (pointer: coarse) {
  .btn-go { padding: 10px 14px; }
  .coords input { font-size: 16px; width: 8.3em; }
}
@media (pointer: coarse) and (max-width: 720px) {
  .coords input { width: 6.3em; }
}
@media (pointer: coarse) and (max-width: 420px) {
  .coords input { width: 5.25em; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .toast { animation: none; }
}
