@import url('fonts.css');

/* Design tokens — taken from the AI Buzzword Board design canvas. */
:root {
  --gold: #d4af37;
  --gold-frame: #c9a227;
  --red: #e2664f;
  --green: #4cb782;
  --green-ink: #04281a;
  --ink: #0b2440;
  --panel: rgba(4, 18, 40, .55);
  --panel-solid: #07213f;
  --hair: rgba(255, 255, 255, .14);
  --stage: radial-gradient(circle at 26% 8%, rgba(255,255,255,.14), transparent 46%),
           repeating-radial-gradient(circle at 82% 118%, rgba(255,255,255,.055) 0 2px, transparent 2px 92px),
           repeating-radial-gradient(circle at 12% -20%, rgba(255,255,255,.05) 0 2px, transparent 2px 120px),
           linear-gradient(180deg, #08356b 0%, #1272c4 58%, #2ba0e8 100%);
  --tile-back: radial-gradient(circle at 50% 47%, rgba(255,255,255,.22) 0 13%, rgba(255,255,255,.07) 13% 19%, transparent 20%),
               linear-gradient(180deg, #3fc3b1, #199484);

  /* board scales to the viewport but never past the mock's 62x84 tile */
  --tile-w: min(62px, calc((80vw - 230px) / 14));
  --tile-h: calc(var(--tile-w) * 1.3548);
  --tile-font: calc(var(--tile-w) * .742);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: Barlow, system-ui, -apple-system, sans-serif;
  background: #08356b;
  color: #fff;
  overflow: hidden;
}

button { font-family: inherit; border: 0; background: none; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .4; }

.stage { height: 100vh; display: flex; flex-direction: column; background: var(--stage); overflow: hidden; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px; background: var(--panel); border-bottom: 1px solid var(--hair); flex: none;
}
.brand { display: flex; align-items: baseline; gap: 14px; }
.brand-mark { font-family: Anton, sans-serif; font-size: 21px; letter-spacing: .14em; color: var(--gold); }
.brand-sub { font: 600 12px/1 Barlow; letter-spacing: .18em; color: rgba(255,255,255,.55); }

.speedbox { display: flex; align-items: center; gap: 10px; }
.speedbox-label { font: 600 11px/1 Barlow; letter-spacing: .16em; color: rgba(255,255,255,.5); margin-right: 4px; }
.speeds { display: flex; gap: 5px; background: rgba(0,0,0,.25); padding: 4px; border-radius: 8px; }
.speeds button { font: 700 13px/1 Barlow; padding: 8px 12px; border-radius: 6px; color: rgba(255,255,255,.55); }
.speeds button:hover { color: #fff; background: rgba(255,255,255,.1); }
.speeds button[aria-pressed="true"] { background: var(--gold); color: var(--ink); }

.pill { font: 700 12px/1 Barlow; letter-spacing: .2em; padding: 9px 16px; border-radius: 6px; }
.pill-red { background: var(--red); color: #fff; }
.pill-green { background: var(--green); color: var(--green-ink); }
.pill-plain { background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.3); color: #fff; }

/* ---------------------------------------------------------------- layout */
.main { flex: 1; display: flex; min-height: 0; }
.boardside { width: 80%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 26px 30px; min-width: 0; }
.rail { width: 20%; background: var(--panel); border-left: 1px solid var(--hair); display: flex; flex-direction: column; min-width: 0; }

/* ---------------------------------------------------------------- board */
.flipwrap { perspective: 2600px; width: 100%; flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
.flipper {
  position: relative; transform-style: preserve-3d;
  transition: transform .62s cubic-bezier(.4, .1, .2, 1);
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
}
.flipped .flipper { transform: rotateY(180deg); }
.face { backface-visibility: hidden; display: flex; align-items: center; justify-content: center; }
.face-front { position: relative; }
.face-back { position: absolute; inset: 0; transform: rotateY(180deg); }

.board {
  --tile-w: min(62px, calc((80vw - 230px) / 14), calc((100vh - 360px) / var(--rows, 4) / 1.3548));
  --tile-h: calc(var(--tile-w) * 1.3548);
  --tile-font: calc(var(--tile-w) * .742);
  padding: 16px; border: 5px solid var(--gold-frame); border-radius: 14px; background: #000;
  box-shadow: 0 0 0 2px rgba(0,0,0,.5), 0 24px 50px rgba(0,0,0,.45);
  transition: border-color .25s, box-shadow .25s;
}
.board.is-frozen { border-color: var(--red); box-shadow: 0 0 0 6px rgba(226,102,79,.22), 0 24px 50px rgba(0,0,0,.45); }
.board-grid { display: flex; flex-direction: column; gap: 5px; background: #000; padding: 5px; box-shadow: inset 0 0 0 2px rgba(120,230,255,.5); }
.board-row { display: flex; gap: 5px; justify-content: center; }
.board-foot {
  margin: 14px -16px -16px; background: var(--panel-solid); border-top: 1px solid rgba(255,255,255,.12);
  padding: 13px 0; text-align: center; font: 700 18px/1 Barlow; letter-spacing: .42em; color: #fff;
}

.tile { width: var(--tile-w); height: var(--tile-h); flex: none; }
/* green: nothing goes here (a space, or off the end of the line) */
.tile-blank { background: var(--tile-back); box-shadow: inset 0 0 0 1px rgba(255,255,255,.16); }
/* white: a letter belongs here and hasn't been turned over yet */
.tile-hidden { background: #fff; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.tile-face {
  background: #fff; display: flex; align-items: center; justify-content: center;
  font-family: 'Archivo Black', sans-serif; font-size: var(--tile-font); color: #0a0a0a; line-height: 1;
}
/* only the letters that just turned over animate — letters already on the
   board must sit still when the board re-renders for some other reason */
.tile-face.is-new { animation: tileflip .3s ease-out; }
@keyframes tileflip { from { transform: rotateY(90deg); } to { transform: rotateY(0); } }

/* ---------------------------------------------------------- definition side */
.defpanel {
  width: 100%; height: 100%; border: 6px solid var(--gold-frame); border-radius: 16px;
  background: linear-gradient(180deg, #07213f, #04101f); box-shadow: 0 24px 50px rgba(0,0,0,.4);
  padding: 44px 52px; display: flex; flex-direction: column; justify-content: center; position: relative;
}
.defpanel-tag { position: absolute; top: 16px; left: 22px; font: 700 11px/1 Barlow; letter-spacing: .22em; color: rgba(28,189,170,.9); }
.defpanel-hint { position: absolute; top: 14px; right: 20px; font: 600 11px/1 Barlow; letter-spacing: .14em; color: rgba(255,255,255,.35); }
.def-title { font-family: Anton, sans-serif; font-size: clamp(34px, 4.2vw, 66px); line-height: 1; letter-spacing: .02em; color: #fff; }
.def-rule { width: 92px; height: 5px; background: var(--gold); margin: 22px 0 24px; }
.def-body { font: 400 clamp(18px, 2vw, 29px)/1.45 Barlow; color: rgba(255,255,255,.92); max-width: 940px; text-wrap: pretty; }
.def-meta { display: flex; gap: 38px; margin-top: 32px; }
.def-meta h4 { font: 700 11px/1 Barlow; letter-spacing: .18em; color: rgba(255,255,255,.45); }
.def-meta p { font: 500 clamp(14px, 1.35vw, 19px)/1.4 Barlow; color: rgba(255,255,255,.8); max-width: 420px; margin-top: 8px; }

/* ---------------------------------------------------------------- controls */
.controls { display: flex; align-items: center; gap: 14px; margin-top: 26px; width: 100%; flex: none; }
.spacer { flex: 1; }
.btn { font: 700 14px/1 Barlow; letter-spacing: .1em; padding: 15px 24px; border-radius: 9px; background: rgba(4,18,40,.5); color: #fff; border: 1px solid rgba(255,255,255,.28); transition: background .15s, transform .08s; }
.btn:hover:not(:disabled) { background: rgba(4,18,40,.8); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-gold { background: var(--gold); color: var(--ink); border-color: transparent; }
.btn-gold:hover:not(:disabled) { background: #e5c454; }
.btn-green { background: var(--green); color: var(--green-ink); border-color: transparent; }
.btn-green:hover:not(:disabled) { background: #63cd98; }
.btn-danger { background: rgba(226,102,79,.28); color: #ffd2c7; border-color: rgba(255,150,125,.6); }
.btn-danger:hover:not(:disabled) { background: rgba(226,102,79,.5); }
.btn-lg { font-size: 15px; padding: 17px 34px; }

.timerbox { display: flex; align-items: center; gap: 12px; background: rgba(4,18,40,.5); border: 1px solid rgba(212,175,55,.4); border-radius: 10px; padding: 12px 18px; }
.timerring { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--gold); border-right-color: rgba(212,175,55,.2); animation: spin 1.1s linear infinite; }
.timerring.is-paused { animation: none; border-right-color: var(--gold); opacity: .45; }
@keyframes spin { to { transform: rotate(360deg); } }
.timerbox h4 { font: 700 11px/1 Barlow; letter-spacing: .16em; color: rgba(255,255,255,.55); }
.timerbox .t { font-family: Anton, sans-serif; font-size: 22px; color: var(--gold); line-height: 1.1; }

.buzzcard { margin-top: 24px; width: 100%; display: flex; align-items: center; gap: 16px; background: rgba(4,18,40,.55); border: 1px solid rgba(226,102,79,.65); border-radius: 12px; padding: 16px 20px; flex: none; }
.buzzcard .av { width: 46px; height: 46px; border-radius: 50%; background: var(--red); color: #fff; font: 700 16px/46px Barlow; text-align: center; flex: none; }
.buzzcard h4 { font: 700 11px/1 Barlow; letter-spacing: .18em; color: rgba(255,255,255,.55); }
.buzzcard .who { font-family: Anton, sans-serif; font-size: 30px; line-height: 1.15; color: #fff; }

/* ---------------------------------------------------------------- rail */
.rail-head { padding: 18px 18px 12px; border-bottom: 1px solid rgba(255,255,255,.12); display: flex; align-items: baseline; justify-content: space-between; }
.rail-head h3 { font: 700 12px/1 Barlow; letter-spacing: .2em; color: var(--gold); }
.rail-head span { font: 600 11px/1 Barlow; color: rgba(255,255,255,.5); }
.rail-list { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 10px 12px; display: flex; flex-direction: column; gap: 7px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent; }
.rail-list::-webkit-scrollbar { width: 6px; }
.rail-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.25); border-radius: 3px; }
.rail-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.12); background: rgba(0,0,0,.3); flex: none; }
.rail-foot h4 { font: 700 10px/1 Barlow; letter-spacing: .18em; color: rgba(255,255,255,.45); margin-bottom: 8px; }
.rail-foot .url { font: 700 15px/1.2 Barlow; color: #fff; letter-spacing: .04em; word-break: break-all; }
.rail-foot .note { font: 600 12px/1.4 Barlow; color: rgba(255,255,255,.55); }

.prow { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); text-align: left; width: 100%; flex: none; }
.prow .av { width: 26px; height: 26px; border-radius: 50%; background: rgba(212,175,55,.22); color: var(--gold); font: 700 11px/26px Barlow; text-align: center; flex: none; }
.prow .nm { flex: 1; min-width: 0; font: 600 14px/1.2 Barlow; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .sc { font-family: Anton, sans-serif; font-size: 17px; color: var(--gold); }
.prow .tag { font: 700 10px/1 Barlow; letter-spacing: .1em; color: #ffe2d9; }
.prow.is-buzzed { background: var(--red); border: 1.5px solid #ff9d86; }
.prow.is-buzzed .av { background: #fff; color: var(--red); }
.prow.is-buzzed .nm { font-weight: 700; }
.prow.is-buzzed .sc { color: #fff; }
.prow.is-winner { background: var(--green); border: 1.5px solid #9ff0c6; }
.prow.is-winner .av { background: var(--green-ink); color: #9ff0c6; }
.prow.is-winner .nm, .prow.is-winner .sc, .prow.is-winner .tag { color: var(--green-ink); font-weight: 700; }
.prow.is-clickable { cursor: pointer; }
.prow.is-clickable:hover { background: rgba(255,255,255,.2); border-color: var(--gold); }
.prow.is-offline .av, .prow.is-offline .nm { opacity: .45; }

/* compact rows once the room gets big (>12) so 20 players still fit */
.rail-list.is-compact .prow { padding: 6px 9px; gap: 8px; }
.rail-list.is-compact .prow .av { width: 22px; height: 22px; font-size: 10px; line-height: 22px; }
.rail-list.is-compact .prow .nm { font-size: 13px; }
.rail-list.is-compact .prow .sc { font-size: 15px; }
.rail-list.is-compact { gap: 5px; }

.rail-empty { font: 500 13px/1.5 Barlow; color: rgba(255,255,255,.45); padding: 14px 4px; text-align: center; }

/* ---------------------------------------------------------------- lobby */
.lobby { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px; gap: 0; min-height: 0; }
.chips { display: flex; align-items: stretch; margin: 30px 0 0; background: rgba(4,18,40,.55); border: 1px solid rgba(255,255,255,.18); border-radius: 12px; overflow: hidden; box-shadow: 0 14px 34px rgba(0,0,0,.3); }
.chip { font: 700 17px/1 Barlow; letter-spacing: .14em; padding: 17px 22px; color: #fff; display: flex; align-items: center; }
.chip + .chip { border-left: 1px solid rgba(255,255,255,.18); }
.chip-code { font-family: Anton, sans-serif; font-size: 26px; letter-spacing: .18em; color: var(--gold); background: rgba(0,0,0,.28); }
.joinbar { width: min(620px, 70%); margin-top: 42px; }
.joinbar-top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 9px; }
.joinbar-top h4 { font: 700 11px/1 Barlow; letter-spacing: .18em; color: rgba(255,255,255,.6); }
.joinbar-top span { font: 700 11px/1 Barlow; letter-spacing: .18em; color: rgba(255,255,255,.6); }
.bar { height: 8px; border-radius: 4px; background: rgba(0,0,0,.28); overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #3fc3b1, var(--gold)); transition: width .4s ease; }
.namepills { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 18px; max-height: 76px; overflow: hidden; width: min(860px, 92%); }
.namepill { font: 600 13px/1 Barlow; padding: 8px 13px; border-radius: 999px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); color: #fff; animation: pillin .35s ease-out; }
@keyframes pillin { from { opacity: 0; transform: translateY(6px) scale(.9); } to { opacity: 1; transform: none; } }
.namepill-more { background: transparent; border-style: dashed; color: rgba(255,255,255,.6); }
.joinline { font: 500 16px/1.5 Barlow; color: rgba(255,255,255,.8); margin-top: 20px; text-align: center; }
.joinline b { color: var(--gold); font-weight: 700; }
.lobby-foot { font: 700 12px/1 Barlow; letter-spacing: .22em; color: rgba(255,255,255,.4); padding: 20px; text-align: center; flex: none; }

/* ---------------------------------------------------------------- results */
.results { width: min(1000px, 92%); }
.results h2 { font-family: Anton, sans-serif; font-size: 54px; letter-spacing: .04em; text-align: center; margin-bottom: 8px; }
.results .sub { font: 600 13px/1 Barlow; letter-spacing: .2em; color: rgba(255,255,255,.55); text-align: center; margin-bottom: 28px; }
.rrow { display: flex; align-items: center; gap: 16px; padding: 13px 20px; border-radius: 10px; background: rgba(4,18,40,.5); border: 1px solid var(--hair); margin-bottom: 8px; }
.rrow .rank { font-family: Anton, sans-serif; font-size: 24px; color: rgba(255,255,255,.4); width: 44px; }
.rrow .nm { flex: 1; font: 600 21px/1 Barlow; }
.rrow .sc { font-family: Anton, sans-serif; font-size: 27px; color: var(--gold); }
.rrow.top { background: rgba(212,175,55,.16); border-color: var(--gold); }
.rrow.top .rank, .rrow.top .nm { color: var(--gold); }

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

/* lobby board: compact 2x10, sized to the sample loading screen */
.board.is-lobby { --tile-w: min(58px, calc((100vw - 700px) / 10)); box-shadow: 0 0 0 2px rgba(0,0,0,.5), 0 18px 40px rgba(0,0,0,.4); }
.board.is-lobby .board-grid { box-shadow: inset 0 0 0 2px rgba(120,230,255,.35); }

/* nothing in the lobby column may be squeezed by flex */
.lobby > * { flex: none; }
.namepills { max-height: none; }

/* puzzle side: board hugs its content so the controls sit right beneath it (mock 2a/2b).
   definition side: the panel fills the area (mock 2c). */
.boardside.is-puzzle .flipwrap { flex: 0 1 auto; }
.boardside.is-puzzle .flipper { height: auto; }
.boardside.is-puzzle .face-back { display: none; }
.boardside.is-def .face-front { pointer-events: none; }

/* final leaderboard: one column for a small room, two once it gets big */
.lobby { overflow-y: auto; justify-content: safe center; }
.results.is-wide { width: min(1180px, 96%); }
.rrows { display: grid; grid-template-columns: 1fr; gap: 8px; }
.rrows.is-2 { grid-template-columns: repeat(2, 1fr); column-gap: 22px; }
.rrows.is-3 { grid-template-columns: repeat(3, 1fr); column-gap: 18px; gap: 6px; }
.rrows.is-2 .rrow, .rrows.is-3 .rrow { padding: 9px 16px; margin: 0; gap: 12px; }
.rrows.is-2 .rrow .rank, .rrows.is-3 .rrow .rank { font-size: 19px; width: 34px; }
.rrows.is-2 .rrow .nm, .rrows.is-3 .rrow .nm { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rrows.is-2 .rrow .sc, .rrows.is-3 .rrow .sc { font-size: 22px; }
.rrows.is-3 .rrow { padding: 7px 13px; gap: 9px; }
.rrows.is-3 .rrow .rank { font-size: 17px; width: 28px; }
.rrows.is-3 .rrow .nm { font-size: 15.5px; }
.rrows.is-3 .rrow .sc { font-size: 19px; }
.rrows .rrow { margin: 0; }
.results.is-wide h2 { font-size: 44px; }
.results.is-wide .sub { margin-bottom: 20px; }

/* shutdown */
.closedcard { width: min(680px, 92%); text-align: center; background: rgba(4,18,40,.55); border: 1px solid var(--hair); border-radius: 16px; padding: 52px 48px; }
.closedmark { width: 74px; height: 74px; margin: 0 auto 22px; border-radius: 50%; background: rgba(76,183,130,.2); color: var(--green); font: 400 38px/74px Anton, sans-serif; }
.closedcard h2 { font-family: Anton, sans-serif; font-size: 40px; letter-spacing: .04em; margin-bottom: 14px; }
.closedcard p { font: 400 17px/1.6 Barlow; color: rgba(255,255,255,.8); margin-top: 10px; }
.closedcard p.dim { font-size: 14.5px; color: rgba(255,255,255,.5); }
.closedcard p.warn { font-size: 15px; color: #ffd2c7; background: rgba(226,102,79,.2); border: 1px solid rgba(255,150,125,.5); border-radius: 9px; padding: 14px 18px; margin-top: 18px; }
.closedcard code { font: 600 14px ui-monospace, Menlo, monospace; background: rgba(0,0,0,.35); padding: 2px 7px; border-radius: 5px; color: var(--gold); }
.closedcard.is-bad .closedmark { background: rgba(226,102,79,.22); color: var(--red); }

/* long copy on the back of the board steps down so the card never overflows */
.defpanel.is-long .def-body { font-size: clamp(16px, 1.55vw, 23px); }
.defpanel.is-long .def-meta p { font-size: clamp(13px, 1.15vw, 17px); }
.defpanel.is-long .def-title { font-size: clamp(30px, 3.4vw, 54px); }
.defpanel.is-long .def-meta { margin-top: 22px; }
