/* ============================================================
   RESISTANCE — shared design system
   Tokens + primitives used by index / player / host.
   Single dark theme. Page-specific layout lives in each template.
   ============================================================ */

@font-face {
  font-family: 'Oswald';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/static/fonts/oswald-latin.woff2') format('woff2');
}

:root {
  --bg: #0b0e14;
  --panel: #131824;
  --elev: #1a2130;
  --elev2: #212a3d;
  --ink: #e8ecf4;
  --muted: #8b94a7;
  --faint: #5a6376;
  --teal: #3fd8d4;
  --teal-dim: #1e6f6d;
  --teal-glow: rgba(63, 216, 212, 0.35);
  --crimson: #e5484d;
  --crimson-dim: #7a2a2d;
  --crimson-glow: rgba(229, 72, 77, 0.35);
  --amber: #f5b953;
  --amber-dim: #8a6a2f;
  --line: rgba(255, 255, 255, 0.06);
  --line-strong: rgba(255, 255, 255, 0.12);
  --r: 14px;
  --r-sm: 9px;
  --r-lg: 20px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.35);
  --display: 'Oswald', 'Arial Narrow', Impact, system-ui, sans-serif;
  --body: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
::selection { background: var(--teal-dim); color: #fff; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--elev2) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--elev2); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Typography ---------- */
.display { font-family: var(--display); text-transform: uppercase; letter-spacing: 0.06em; }
h1, h2, h3 { font-family: var(--display); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.t-muted { color: var(--muted); }
.t-teal { color: var(--teal); }
.t-crimson { color: var(--crimson); }
.t-amber { color: var(--amber); }
.t-center { text-align: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 22px;
  border-radius: var(--r);
  font-family: var(--display);
  font-size: 17px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--elev);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease,
    box-shadow 0.15s ease, opacity 0.15s ease, filter 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  text-decoration: none;
}
.btn:hover { background: var(--elev2); border-color: rgba(255, 255, 255, 0.2); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.btn:disabled, .btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  filter: saturate(0.5);
  pointer-events: auto;
}
.btn-teal {
  background: linear-gradient(180deg, #2ba7a4, #197a78);
  border-color: rgba(63, 216, 212, 0.55);
  color: #eafffe;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.btn-teal:hover { background: linear-gradient(180deg, #33bdb9, #1d8b88); box-shadow: 0 0 22px var(--teal-glow); }
.btn-crimson {
  background: linear-gradient(180deg, #c23a3f, #8e2529);
  border-color: rgba(229, 72, 77, 0.55);
  color: #ffecec;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.btn-crimson:hover { background: linear-gradient(180deg, #d54247, #a12b30); box-shadow: 0 0 22px var(--crimson-glow); }
.btn-amber {
  background: linear-gradient(180deg, #d9a344, #a37427);
  border-color: rgba(245, 185, 83, 0.55);
  color: #fff6e3;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.btn-amber:hover { box-shadow: 0 0 22px rgba(245, 185, 83, 0.3); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-ghost:hover { color: var(--ink); border-color: var(--line-strong); background: rgba(255, 255, 255, 0.03); }
.btn-sm { min-height: 36px; padding: 6px 14px; font-size: 13px; border-radius: var(--r-sm); }
.btn-big { min-height: 62px; font-size: 21px; width: 100%; }
.btn .spin { display: none; }
.btn.loading { pointer-events: none; opacity: 0.75; }
.btn.loading .spin { display: inline-block; }
.btn.loading .btn-label { opacity: 0.6; }

.spin {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Panels / chips ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--elev);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.chip.teal { color: var(--teal); border-color: rgba(63, 216, 212, 0.35); background: rgba(63, 216, 212, 0.08); }
.chip.crimson { color: var(--crimson); border-color: rgba(229, 72, 77, 0.35); background: rgba(229, 72, 77, 0.08); }
.chip.amber { color: var(--amber); border-color: rgba(245, 185, 83, 0.35); background: rgba(245, 185, 83, 0.08); }
/* defensive: harmless today (chips are plain spans everywhere) but keeps any
   future focusable/interactive chip usage consistent with the rest of the system */
.chip:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.divider { height: 1px; background: var(--line); margin: 14px 0; }

/* ---------- Inputs ---------- */
.field {
  width: 100%;
  min-height: 50px;
  padding: 12px 16px;
  border-radius: var(--r);
  background: var(--elev);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
}
.field::placeholder { color: var(--faint); opacity: 1; }
.field:hover:not(:disabled):not(:focus) { border-color: rgba(255, 255, 255, 0.18); }
.field:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(63, 216, 212, 0.15); }
.field:disabled { opacity: 0.5; }

/* ---------- Toggle switch ---------- */
.switch { position: relative; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
.switch .knob {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: var(--elev2);
  border: 1px solid var(--line-strong);
  transition: background 0.18s ease, border-color 0.18s ease;
}
.switch .knob::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.18s ease, background 0.18s ease;
}
.switch input:checked + .knob { background: var(--teal-dim); border-color: var(--teal); }
.switch input:checked + .knob::after { transform: translateX(20px); background: var(--teal); }
.switch input:hover:not(:disabled) + .knob { border-color: rgba(255, 255, 255, 0.25); }
.switch input:focus-visible + .knob { outline: 2px solid var(--teal); outline-offset: 2px; }
.switch input:disabled + .knob { opacity: 0.45; }

/* ---------- Avatars ---------- */
.avatar {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: var(--r);
  overflow: hidden;
  background: var(--elev2);
  border: 1px solid var(--line-strong);
  flex: 0 0 auto;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease, transform 0.15s ease;
}
.avatar:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar .initials {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-weight: 600;
  font-size: 17px;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* ---------- Toasts ---------- */
#toast-container {
  position: fixed;
  top: calc(10px + var(--sat));
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(92vw, 480px);
}
.toast {
  background: rgba(20, 26, 40, 0.94);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  padding: 9px 16px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  animation: toastIn 0.22s ease;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.toast.good { border-color: rgba(63, 216, 212, 0.5); color: var(--teal); }
.toast.bad { border-color: rgba(229, 72, 77, 0.5); color: #ff9a9d; }
.toast.warn { border-color: rgba(245, 185, 83, 0.5); color: var(--amber); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- Center overlays (NotifyMgr) ---------- */
.ovl {
  position: fixed;
  inset: 0;
  z-index: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(5, 8, 13, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: ovlIn 0.25s ease;
}
.ovl.fade-out, .ovl .fade-out { animation: ovlOut 0.3s ease forwards; }
@keyframes ovlIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes ovlOut { to { opacity: 0; } }
.ovl-card {
  width: min(94vw, 440px);
  max-height: 86vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #161c2b, #101521);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow), 0 0 60px rgba(0, 0, 0, 0.5);
  padding: 26px 22px;
  text-align: center;
  animation: cardPop 0.32s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes cardPop { from { opacity: 0; transform: scale(0.88) translateY(12px); } to { opacity: 1; transform: none; } }
.ovl-kicker {
  font-family: var(--display);
  font-size: 12px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.ovl-title {
  font-family: var(--display);
  font-size: 30px;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.ovl-sub { color: var(--muted); font-size: 14px; }

/* Secondary ticker */
.ticker {
  position: fixed;
  top: calc(58px + var(--sat));
  left: 50%;
  transform: translateX(-50%);
  z-index: 650;
  background: rgba(19, 24, 36, 0.95);
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  padding: 10px 20px;
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
  max-width: 92vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ---------- Flip cards ---------- */
.flip { perspective: 900px; }
.flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.3, 1.2, 0.4, 1);
}
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--r-sm);
  overflow: hidden;
}
.flip-back { transform: rotateY(180deg); }

/* ---------- Countdown ring ---------- */
.cring { position: relative; width: 54px; height: 54px; flex: 0 0 auto; }
.cring svg { transform: rotate(-90deg); }
.cring .ring-bg { fill: none; stroke: var(--elev2); stroke-width: 4; }
.cring .ring-fg {
  fill: none;
  stroke: var(--teal);
  stroke-width: 4;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s linear, stroke 0.3s ease;
}
.cring.low .ring-fg { stroke: var(--crimson); }
.cring .cring-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-weight: 600;
  font-size: 17px;
  transition: color 0.3s ease; /* matches .ring-fg's own stroke color pace, not the 150ms UI default */
}
.cring.low .cring-num { color: var(--crimson); animation: pulseNum 1s ease infinite; }
.cring.frozen .ring-fg { stroke: var(--faint); }
.cring.frozen .cring-num { color: var(--muted); font-size: 19px; }
@keyframes pulseNum { 50% { transform: scale(1.15); } }

/* ---------- Misc anims ---------- */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
.shake { animation: shake 0.4s ease; }
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 0 rgba(63, 216, 212, 0); }
  50% { box-shadow: 0 0 18px var(--teal-glow); }
}
@keyframes floatUp {
  0% { opacity: 0; transform: translateY(6px) scale(0.7); }
  15% { opacity: 1; transform: translateY(0) scale(1.15); }
  100% { opacity: 0; transform: translateY(-46px) scale(1); }
}
.emote-float {
  position: fixed;
  z-index: 800;
  font-size: 30px;
  pointer-events: none;
  animation: floatUp 1.6s ease forwards;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

/* Reconnect indicator */
.reconnect-icon {
  position: fixed;
  top: calc(12px + var(--sat));
  right: calc(12px + var(--sar));
  z-index: 950;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(229, 72, 77, 0.12);
  border: 1px solid rgba(229, 72, 77, 0.5);
  color: #ff9a9d;
  border-radius: 99px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  /* hidden via opacity/visibility (not display) so showing/hiding can fade
     smoothly instead of popping; position:fixed means this never affects layout */
  opacity: 0;
  transform: translateY(-6px) scale(0.94);
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0.15s;
}
.reconnect-icon.active {
  opacity: 1;
  transform: none;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.15s ease, transform 0.15s ease;
  animation: pulseOp 1.2s ease infinite;
}
@keyframes pulseOp { 50% { opacity: 0.55; } }

/* Skeletons */
.skel {
  background: linear-gradient(90deg, var(--elev) 25%, var(--elev2) 50%, var(--elev) 75%);
  background-size: 200% 100%;
  animation: skel 1.2s linear infinite;
  border-radius: var(--r-sm);
}
@keyframes skel { to { background-position: -200% 0; } }

/* ---------- Shared reveal/cinematic components (player + host) ---------- */
.cine { position: fixed; inset: 0; z-index: 750; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 26px; text-align: center; background: rgba(5,8,13,0.93); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); animation: ovlIn 0.3s ease; overflow-y: auto; }
.cine.crimson { background: radial-gradient(90% 70% at 50% 40%, rgba(70,12,14,0.92), rgba(5,8,13,0.97)); }
.cine-kicker { font-family: var(--display); font-size: 12px; letter-spacing: 0.34em; color: var(--muted); text-transform: uppercase; }
.cine-title { font-family: var(--display); font-size: clamp(30px, 8vw, 44px); letter-spacing: 0.1em; text-transform: uppercase; line-height: 1.05; }
.cine-sub { color: var(--muted); font-size: 14px; max-width: 320px; }
.scanbar { width: min(70vw, 280px); height: 3px; border-radius: 3px; background: var(--elev2); overflow: hidden; position: relative; }
.scanbar::after { content: ''; position: absolute; top: 0; bottom: 0; left: -35%; width: 35%; border-radius: 3px; background: linear-gradient(90deg, transparent, var(--teal), transparent); animation: scan 1.1s linear infinite; }
@keyframes scan { to { left: 100%; } }
.spy-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.spy-row .avatar { width: 62px; height: 62px; border-radius: 14px; border: 2px solid var(--crimson); box-shadow: 0 0 22px var(--crimson-glow); animation: cardPop 0.4s cubic-bezier(0.2,1.4,0.4,1) backwards; }
.spy-row .spy-cell { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; color: #ffb3b5; max-width: 74px; }
.spy-cell .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.votegrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 10px; margin: 16px 0 6px; width: min(92vw, 430px); }
.vg-cell { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.vg-cell .nm { font-size: 11px; font-weight: 700; color: var(--muted); max-width: 76px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vg-token { width: 52px; height: 52px; }
.vg-token .flip-face { border-radius: 50%; border: 2px solid var(--line-strong); display: flex; align-items: center; justify-content: center; font-size: 21px; font-weight: 800; }
.vg-face-back { background: radial-gradient(circle at 35% 30%, #232d42, #131824); color: var(--faint); }
.vg-face-ap { background: radial-gradient(circle at 35% 30%, #35c2be, #17605e); color: #04312f; border-color: var(--teal) !important; }
.vg-face-rj { background: radial-gradient(circle at 35% 30%, #e0565b, #8e2529); color: #fff; border-color: var(--crimson) !important; }
.vg-token img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.stamp { font-family: var(--display); font-size: 34px; letter-spacing: 0.16em; text-transform: uppercase; padding: 8px 22px; border-radius: var(--r); border: 3px solid; transform: rotate(-5deg) scale(0); display: inline-block; margin-top: 12px; }
.stamp.on { animation: stampIn 0.35s cubic-bezier(0.2, 1.6, 0.3, 1) forwards; }
@keyframes stampIn { from { transform: rotate(-14deg) scale(2.2); opacity: 0; } to { transform: rotate(-5deg) scale(1); opacity: 1; } }
.stamp.ap { color: var(--teal); border-color: var(--teal); text-shadow: 0 0 20px var(--teal-glow); }
.stamp.rj { color: var(--crimson); border-color: var(--crimson); text-shadow: 0 0 20px var(--crimson-glow); }
.mr-cards { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; margin: 18px 0 8px; }
.mr-card { width: 58px; height: 80px; }
.mr-card .flip-face { border-radius: var(--r-sm); border: 1px solid var(--line-strong); display: flex; align-items: center; justify-content: center; font-size: 24px; overflow: hidden; }
.mr-back { background: linear-gradient(160deg, #1c2536, #10151f); color: var(--faint); font-size: 16px; }
.mr-s { background: linear-gradient(170deg, #1d7a77, #0d3d3b); color: #c8fffd; border-color: rgba(63,216,212,0.6) !important; }
.mr-f { background: linear-gradient(170deg, #a53337, #571619); color: #ffd9da; border-color: rgba(229,72,77,0.7) !important; }
.mr-card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
@keyframes wiggle { 0%,100% { transform: translateX(0) rotate(0); } 25% { transform: translateX(-5px) rotate(-3deg); } 75% { transform: translateX(5px) rotate(3deg); } }
.mr-cards.shuffling .mr-card { animation: wiggle 0.3s ease infinite; }
.mr-spot { font-size: 12.5px; color: var(--amber); margin-top: 6px; }
.mr-tally { font-family: var(--display); font-size: 16px; letter-spacing: 0.1em; color: var(--muted); margin-top: 4px; }
.secret-box { border: 1px dashed rgba(245,185,83,0.5); background: rgba(245,185,83,0.05); border-radius: var(--r); padding: 12px; margin-top: 12px; font-size: 14px; }
.secret-box b { color: var(--amber); }

/* Utility */
.hidden { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1 1 auto; min-width: 0; }
