/* Pixelify Sans — SIL Open Font License, see fonts/OFL.txt */
@font-face {
  font-family: "Pixelify Sans";
  src: url("fonts/PixelifySans.ttf") format("truetype");
  font-weight: 400 700;
  font-display: block;
}

:root {
  --page: #151838;
  --frame: #2B2F72;
  --topbar: #21255E;
  --btn: #5B4FD8;
  --btn-hover: #6A5FE6;
  --btn-edge: #3A3296;
  --accent: #FFB347;
  --text: #FFFFFF;
  --topbar-h: 64px;
  --font: "Pixelify Sans", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  /* Keep pixel-font edges crisp where the browser allows it. */
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  font-smooth: never;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
}

[hidden] { display: none !important; }

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--frame);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

html, body, #app, .topbar, .card, .btn { transition: background-color 0.2s; }

/* ---------- top bar ---------- */
.topbar {
  position: relative;
  height: var(--topbar-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--topbar);
}

.score {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 30px;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}

.best-icon { margin-left: 14px; }
.best-icon.record { animation: crown-hop 0.5s ease-in-out; }
@keyframes crown-hop {
  0% { transform: translateY(0) rotate(0); }
  40% { transform: translateY(-7px) rotate(-12deg); }
  70% { transform: translateY(-2px) rotate(4deg); }
  100% { transform: translateY(0) rotate(0); }
}
.top-best { transition: color 0.2s; }
/* Beating the high score: the crown's number goes gold and climbs with the score. */
.top-best.new { color: #FFD34D; }

.controls { display: flex; gap: 6px; }

/* Stopwatch, centred in the top bar. Toggle with T. */
.timer {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 26px;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn:focus-visible { outline: 3px solid var(--accent); }
.icon-btn svg { width: 28px; height: 28px; }
.icon-btn .when-on { display: none; }
.icon-btn.on .when-on { display: block; }
.icon-btn.on .when-off { display: none; }

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: square;
  stroke-linejoin: miter;
}
svg .fill { fill: currentColor; stroke: none; }

/* ---------- board ---------- */
.frame { padding: var(--frame-pad, 32px); }

.board-wrap { position: relative; }

#board { display: block; }

/* Crash shake: a few small, quickly settling jolts along the hit direction
   (--sx, --sy), plus a hair of sideways wobble. */
.board-wrap.shake { animation: crash-shake 0.32s 0.08s ease-out; }
@keyframes crash-shake {
  0% { transform: translate(0, 0); }
  18% { transform: translate(calc(var(--sx) * 4px + var(--sy) * 1px), calc(var(--sy) * 4px + var(--sx) * 1px)); }
  40% { transform: translate(calc(var(--sx) * -3px), calc(var(--sy) * -3px)); }
  62% { transform: translate(calc(var(--sx) * 2px - var(--sy) * 1px), calc(var(--sy) * 2px - var(--sx) * 1px)); }
  82% { transform: translate(calc(var(--sx) * -1px), calc(var(--sy) * -1px)); }
  100% { transform: translate(0, 0); }
}

.pill {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--topbar) 90%, transparent);
  font-size: 18px;
  font-weight: bold;
  white-space: nowrap;
  pointer-events: none;
}
.pill.center { bottom: 50%; transform: translate(-50%, 50%); font-size: 24px; }
.pill.win {
  color: #FFD34D;
  font-size: 30px;
  padding: 12px 26px;
  letter-spacing: 0.03em;
  animation: win-pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
@keyframes win-pop {
  from { transform: translate(-50%, 50%) scale(0.4); opacity: 0; }
  to { transform: translate(-50%, 50%) scale(1); opacity: 1; }
}

/* ---------- menus ---------- */
.overlay {
  position: fixed; /* use the whole window so tall menus (Settings) always fit */
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  background: color-mix(in srgb, var(--page) 60%, transparent);
  overflow: auto;
  padding: 16px;
}

.panel {
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: var(--topbar);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

#scene { display: block; width: 100%; }

.stats {
  position: absolute;
  top: 18px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 34px;
  font-weight: bold;
  text-shadow: 0 3px 0 rgba(27, 18, 56, 0.45);
  font-variant-numeric: tabular-nums;
}

.btn {
  position: relative;
  height: 58px;
  border: none;
  border-radius: 12px;
  background: var(--btn);
  box-shadow: 0 5px 0 var(--btn-edge);
  color: var(--text);
  font: bold 24px var(--font);
  cursor: pointer;
  margin-bottom: 5px;
}
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--btn-edge); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.btn svg {
  position: absolute;
  left: 22px;
  top: 50%;
  width: 30px;
  height: 30px;
  transform: translateY(-50%);
}
.btn svg .teeth { stroke-width: 3; }

.panel.wide { width: min(460px, 100%); }

.settings-card { padding: 10px 0; }

.setting { position: relative; }
.setting + .setting { margin-top: 2px; }

.track {
  position: relative;
  display: flex;
  gap: 10px;
  padding: 7px calc(50% - 30px);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  cursor: grab;
  user-select: none;
  outline: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 22%, #000 78%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 22%, #000 78%, transparent);
}
.track::-webkit-scrollbar { display: none; }
.track.dragging { cursor: grabbing; scroll-snap-type: none; }
/* Keyboard focus on a row: a soft ring around its chosen (centred) icon. */
.track:focus-visible .tile[aria-selected="true"] { outline: 3px solid rgba(255, 255, 255, 0.55); outline-offset: 3px; }

.tile {
  flex: none;
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  scroll-snap-align: center;
  transition: transform 0.08s linear, opacity 0.08s linear;
}
.tile svg { width: 30px; height: 30px; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; pointer-events: none; }
.tile canvas { display: block; pointer-events: none; }
.tile .theme-glyph { margin-bottom: 12px; } /* sit above the strip of board squares */

.btn.icon-only svg { position: static; transform: none; width: 32px; height: 32px; stroke-width: 3; }

/* "?" = random each round */
.tile.surprise {
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.25);
}
.tile .q {
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

/* Settings footer: shuffle + done */
.settings-actions { display: flex; gap: 12px; }
.settings-actions .btn { flex: 1; }
.settings-actions .btn.shuffle { flex: 0 0 68px; }

/* Chat connection button: speech bubble with a status dot */
.chat-btn { position: relative; }
.chat-btn .dot {
  position: absolute;
  right: 7px;
  bottom: 8px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #8C95A8;
  box-shadow: 0 0 0 2px var(--topbar);
}
.chat-btn[data-status="on"] .dot { background: #5BE06A; }
.chat-btn[data-status="connecting"] .dot { background: #FFD34D; }
/* Chat commands turned off (C): struck through, dot greyed out. */
.chat-btn .slash { display: none; }
.chat-btn.paused .slash { display: inline; }
.chat-btn.paused .dot { background: #8C95A8; }

/* Chat toasts: who did what, bottom-left of the board */
.toasts {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
}
.toast {
  padding: 6px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--topbar) 92%, transparent);
  font-size: 16px;
  max-width: 420px;
  animation: toast-in 0.25s ease-out both;
  transition: opacity 0.5s, transform 0.5s;
}
.toast b { color: var(--accent); }
.toast.out { opacity: 0; transform: translateY(6px); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Stream settings panel ---------- */
.stream-card {
  padding: 18px 20px 20px;
  text-align: left;
  /* Settings text needs to be read, not just glanced at: a clean UI font here
     (the pixel font stays for the title). */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.35;
}
.stream-card h2 { font-family: var(--font); -webkit-font-smoothing: none; }
.stream-card h2 { margin: 0 0 12px; font-size: 26px; }
.stream-card h3 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
}
.stream-card section + section { margin-top: 18px; }

.channel-row { display: flex; gap: 8px; }
.stream-card input[type="text"],
.stream-card input[type="number"] {
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
.stream-card input:focus-visible { outline: none; border-color: var(--accent); }
.channel-row input { flex: 1; }

.mini-btn {
  font: 700 15px var(--font);
  color: var(--text);
  background: var(--btn);
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--btn-edge);
}
.mini-btn:hover { background: var(--btn-hover); }
.mini-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.stream-card .mini-btn { font-family: inherit; font-weight: 600; }
.mini-btn.subtle { margin-top: 10px; background: rgba(255, 255, 255, 0.08); box-shadow: none; }

.status-line { margin: 8px 2px 0; font-size: 14px; opacity: 0.85; }
.status-line::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 50%;
  background: #8C95A8;
}
.status-line[data-status="on"]::before { background: #5BE06A; }
.status-line[data-status="connecting"]::before { background: #FFD34D; }

.cmd-head, .cmd-row {
  display: grid;
  grid-template-columns: 52px 1fr 104px;
  align-items: center;
  gap: 10px;
}
.cmd-head { font-size: 12px; opacity: 0.6; padding: 0 4px 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.cmd-head span:last-child { text-align: right; }
.cmd-rows { display: flex; flex-direction: column; gap: 6px; }
.cmd-row { padding: 6px 4px; border-radius: 8px; background: rgba(255, 255, 255, 0.05); }
.cmd-row.off .cmd-name { opacity: 0.45; }
.cmd-name b { font-size: 16px; font-weight: 650; }
.cmd-name .usage { font-size: 14px; opacity: 0.6; }
.cmd-group {
  margin: 10px 4px 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.55;
}
.cmd-group:first-child { margin-top: 0; }
.per-minute {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 15px;
}
.per-minute input { width: 60px; text-align: right; }
.per-minute .hint { flex-basis: 100%; font-size: 13px; opacity: 0.6; }
.cooldown { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.cooldown input { width: 66px; text-align: right; }
.cooldown span { opacity: 0.7; }

/* Pixel on/off switch */
.switch { position: relative; width: 44px; height: 24px; justify-self: center; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.15);
  pointer-events: none;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--text);
  transition: transform 0.12s;
}
.switch input:checked + span { background: #3FAE49; }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
