/* ============================================================
   DEMOCAT / $DEMOCAT - design tokens
   Reference: approved deep-fried jpeg webcam-demo avatar + banner.
   Palette: oversaturated deep-fried red/orange/yellow, lifted straight
   from the compression-artifact glow of the approved art.
   Type: Archivo Black (crude bold meme-caption display) +
         Inter (chat-bubble / body, matches the messenger UI in the banner) +
         Roboto Mono (CA / readouts, monospace = "this is data").
   Spacing scale: 4 / 8 / 12 / 16 / 24 / 32 / 48 px.
   Radius: 4px sharp chrome, 16px soft chat bubbles (mixed, matches
           the mixed hard-window / soft-bubble look of the banner).
   Motion idiom: one "slam" keyframe (scale 1.3->1 + flash), reused for
   the paw stamp, the wrong-window popup and the scoreboard tick.
   ============================================================ */
:root {
  --void: #17040a;
  --window-chrome: #241016;
  --red: #ff3b1f;
  --red-dark: #b3200c;
  --orange: #ff8a1f;
  --yellow: #ffd400;
  --ink: #1a0500;
  --cream: #fff3d6;
  --cream-dim: #f0dcb0;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  --radius-sharp: 4px;
  --radius-bubble: 16px;

  --font-display: 'Archivo Black', 'Arial Black', sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'Roboto Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background:
    radial-gradient(120% 100% at 20% 0%, #4a0f08 0%, var(--void) 55%),
    var(--void);
  color: var(--cream);
  font-family: var(--font-body);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ---------- deep-fry grain overlay ---------- */
.grain-defs { position: absolute; width: 0; height: 0; }

.grain-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  pointer-events: none;
  filter: url(#deepfry);
  opacity: 0.16;
  mix-blend-mode: overlay;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  flex: 0 0 auto;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-width: 0;
}

.wordmark {
  font-family: var(--font-display);
  font-size: clamp(18px, 3.2vw, 28px);
  letter-spacing: 0.5px;
  color: var(--yellow);
  text-shadow: 2px 2px 0 var(--red-dark);
  white-space: nowrap;
}

.ticker-pill {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(10px, 2vw, 13px);
  background: var(--red);
  color: var(--cream);
  padding: 3px 8px;
  border-radius: var(--radius-sharp);
  border: 2px solid var(--ink);
  white-space: nowrap;
}

.topbar__right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: 0 0 auto;
}

.session-readout {
  font-family: var(--font-mono);
  font-size: clamp(9px, 1.8vw, 12px);
  color: var(--cream-dim);
  border: 1px solid rgba(255,243,214,0.25);
  padding: 3px 8px;
  border-radius: var(--radius-sharp);
  white-space: nowrap;
}

.x-link { display: flex; line-height: 0; }
.x-link svg { display: block; }

/* ---------- call window (the whole scene, one screen) ---------- */
.callwindow {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 var(--sp-4) var(--sp-4);
  border-radius: var(--radius-sharp);
  border: 2px solid #000;
  background: var(--window-chrome);
  box-shadow: 0 12px 0 rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.callwindow__titlebar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: #0d0508;
  border-bottom: 2px solid #000;
}

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot--r { background: #ff5f57; }
.dot--y { background: #febc2e; }
.dot--g { background: #28c840; }

.callwindow__title {
  font-family: var(--font-mono);
  font-size: 11px;
  color: rgba(255,243,214,0.55);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: 0;
}

.callwindow__rec {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--red);
  flex: 0 0 auto;
  animation: rec-blink 1.4s steps(1) infinite;
}
@keyframes rec-blink { 50% { opacity: 0.25; } }

.callwindow__body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 2px;
  background: #000;
}

/* ---------- screenshare (the game) ---------- */
.screenshare {
  flex: 1 1 68%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--window-chrome);
  padding: var(--sp-3);
  gap: var(--sp-2);
  min-height: 0;
}

.screenshare__frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: var(--radius-sharp);
  overflow: hidden;
  border: 2px solid #000;
  background: #000;
}

.screenshare__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 40%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* clickable BUY button, positioned over the drawn button in the art */
.buy-btn {
  position: absolute;
  left: 6%;
  top: 68%;
  width: 62%;
  height: 20%;
  background: transparent;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.buy-btn:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

.paw-stamp {
  position: absolute;
  left: 6%;
  top: 68%;
  width: 62%;
  height: 20%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
}
.paw-stamp.is-slamming {
  animation: slam 0.35s ease-out;
}
.paw-stamp svg { filter: drop-shadow(0 0 6px rgba(255,59,31,0.9)); }

@keyframes slam {
  0%   { opacity: 0; transform: scale(2.4) rotate(-8deg); }
  40%  { opacity: 1; transform: scale(0.85) rotate(2deg); }
  60%  { opacity: 1; transform: scale(1.15) rotate(-2deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

.result-toast {
  position: absolute;
  left: 50%;
  bottom: 4%;
  top: auto;
  transform: translateX(-50%) scale(0.8);
  background: var(--ink);
  color: var(--yellow);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(11px, 1.6vw, 14px);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sharp);
  border: 2px solid var(--yellow);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-toast.is-shown {
  animation: toast-in 2.1s ease-out forwards;
}
@keyframes toast-in {
  0%   { opacity: 0; transform: translateX(-50%) scale(0.8); }
  12%  { opacity: 1; transform: translateX(-50%) scale(1.05); }
  20%  { opacity: 1; transform: translateX(-50%) scale(1); }
  85%  { opacity: 1; }
  100% { opacity: 0; }
}

.wrongwindow {
  position: absolute;
  right: 4%;
  top: 6%;
  width: min(52%, 320px);
  background: #ece7de;
  color: var(--ink);
  border-radius: var(--radius-sharp);
  border: 2px solid #000;
  box-shadow: 0 8px 0 rgba(0,0,0,0.4);
  overflow: hidden;
  opacity: 0;
  transform: scale(0.6) rotate(-6deg);
  pointer-events: none;
  z-index: 5;
}
.wrongwindow.is-open {
  animation: slam 0.4s ease-out forwards;
}
.wrongwindow__bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  background: #d8d2c4;
  border-bottom: 1px solid #000;
}
.wrongwindow__bar .dot { width: 7px; height: 7px; }
.wrongwindow__title {
  font-family: var(--font-mono);
  font-size: 9px;
  color: #555;
  margin-left: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wrongwindow__body {
  font-family: var(--font-display);
  font-size: clamp(11px, 2vw, 15px);
  padding: var(--sp-3);
  line-height: 1.3;
  color: var(--red-dark);
}

.race-status {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: clamp(10px, 1.8vw, 13px);
  color: var(--cream-dim);
  text-align: center;
  padding: var(--sp-1) 0;
}

/* ---------- roster / chat sidebar ---------- */
.roster {
  flex: 0 0 30%;
  max-width: 260px;
  min-width: 180px;
  background: var(--window-chrome);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-height: 0;
  overflow: hidden;
}

.roster__tile {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-sharp);
  padding: 6px 8px;
  flex: 0 0 auto;
}
.roster__tile--cat { background: rgba(255,59,31,0.14); border: 1px solid rgba(255,59,31,0.4); }
.roster__tile--you { background: rgba(255,212,0,0.1); border: 1px solid rgba(255,212,0,0.35); }

.roster__avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 11px;
  color: #fff;
  flex: 0 0 auto;
}
.roster__avatar--cat { background: var(--red); }

.roster__name {
  font-size: 11px;
  color: var(--cream-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chatlog {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

.chat-bubble {
  background: var(--cream);
  color: var(--ink);
  font-size: 11px;
  line-height: 1.35;
  padding: 6px 10px;
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  max-width: 100%;
}

.chat-bubble--ca {
  cursor: pointer;
  border: 2px dashed var(--red);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  flex: 0 0 auto;
}
.ca-code {
  font-family: var(--font-mono);
  font-size: 9.5px;
  word-break: break-all;
  font-weight: 700;
  color: var(--red-dark);
}
.ca-copy-hint {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  background: var(--red);
  padding: 1px 6px;
  border-radius: 8px;
}

/* ---------- footer ---------- */
.callwindow__footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: #0d0508;
  border-top: 2px solid #000;
  flex-wrap: wrap;
}

.scoreboard {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  font-family: var(--font-mono);
  font-weight: 700;
}
.scoreboard__label { font-size: 11px; letter-spacing: 1px; color: var(--cream-dim); }
.scoreboard__num {
  font-size: clamp(20px, 3vw, 28px);
  color: var(--red);
  font-family: var(--font-display);
}
.scoreboard__num--you { color: var(--cream); }
.scoreboard__vs { color: var(--cream-dim); }
.scoreboard__num.is-ticking { animation: slam 0.3s ease-out; }

.real-buy-btn {
  font-family: var(--font-display);
  font-size: clamp(11px, 1.8vw, 14px);
  color: var(--ink);
  background: var(--yellow);
  border: 2px solid #000;
  padding: 10px 16px;
  border-radius: var(--radius-sharp);
  text-decoration: none;
  box-shadow: 0 4px 0 var(--red-dark);
  white-space: nowrap;
  transition: transform 150ms ease;
}
.real-buy-btn:hover { transform: translateY(-2px); }
.real-buy-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--red-dark); }

.noscript-fallback { display: contents; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .callwindow__body { flex-direction: column; }
  .roster {
    flex: 0 0 auto;
    max-width: none;
    flex-direction: row;
    flex-wrap: wrap;
    max-height: 34%;
  }
  .roster__tile { flex: 1 1 45%; }
  .chatlog { flex: 1 1 100%; order: 3; margin-top: 4px; }
  /* narrow viewports don't have room for the whole chat log: the CA bubble
     is required chrome (the CA lives here per lane spec), everything else
     is ambient flavor, so it is the one guaranteed to stay visible */
  .chat-bubble:not(.chat-bubble--ca) { display: none; }
}

@media (max-width: 480px) {
  .topbar { padding: var(--sp-2) var(--sp-3); }
  .callwindow { margin: 0 var(--sp-2) var(--sp-2); }
  .roster { max-height: 34%; padding: var(--sp-2); gap: 6px; }
  .roster__tile { padding: 4px 6px; }
  .roster__name { font-size: 10px; }
  .chat-bubble { font-size: 10px; padding: 5px 8px; }
  .callwindow__footer { padding: var(--sp-2) var(--sp-3); }
  .wrongwindow { width: min(70%, 260px); top: 4%; }
}

/* on short screens, the "watching this call" roster tiles are flavor;
   the CA bubble is required chrome and always wins the vertical space */
@media (max-height: 760px) {
  .roster { max-height: 30%; }
  .roster__tile:not(.roster__tile--cat) { display: none; }
}

@media (max-height: 620px) {
  .roster__tile { display: none; }
  .roster { max-height: 40%; }
}
