:root {
  --bg: #0b0e14;
  --panel: #131824;
  --panel-2: #1a2130;
  --border: #242c3d;
  --text: #e7ebf3;
  --muted: #8b95a8;
  --accent: #ff4d8d;
  --accent-2: #7c6cff;
  --ok: #3ddc97;
  --warn: #ffb545;
  --danger: #ff6b6b;
  --radius: 12px;
  --header-h: 56px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
a { color: var(--accent-2); }
h2, h3 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .01em; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); min-height: 1em; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- header */
.topbar {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 22px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 17px; letter-spacing: -.01em; }
.tagline { color: var(--muted); font-size: 11.5px; }
.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border);
  font-size: 12.5px; white-space: nowrap;
}
.pill.version { font-weight: 600; }
.pill.countdown { font-variant-numeric: tabular-nums; color: var(--ok); }
.pill.countdown.busy { color: var(--warn); }
.pill.conn { padding: 4px 8px; color: var(--danger); }
.pill.conn.on { color: var(--ok); }
.me { display: flex; align-items: center; gap: 10px; }
.nick-btn {
  background: var(--panel-2); border: 1px dashed var(--border); border-radius: 8px;
  padding: 5px 10px; font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nick-btn:hover { border-color: var(--accent-2); }
.stars { font-weight: 700; }

/* ---------------------------------------------------------------- layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
  height: calc(100vh - var(--header-h));
  min-height: 560px;
}
.stage-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; overflow: auto; }
.chat-col {
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  min-height: 0;
}

/* ---------------------------------------------------------------- stage */
.stage {
  position: relative;
  width: 100%;
  max-width: 960px;
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
  flex: 0 0 auto;
}
.game-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }
.game-frame.pending { opacity: 0; pointer-events: none; }
.stage-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(11, 14, 20, .85); color: var(--muted); z-index: 2;
}
.strip {
  width: 100%; max-width: 960px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.score-box { font-size: 15px; }
.score-box strong { font-size: 18px; }
.desc { flex: 1 1 200px; font-size: 13px; }
.strip-actions { display: flex; gap: 8px; }

button.ghost {
  background: transparent; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; color: var(--text);
}
button.ghost:hover { border-color: var(--accent-2); background: var(--panel-2); }

/* ---------------------------------------------------------------- leaderboard */
.leaderboard {
  width: 100%; max-width: 960px; margin: 0 auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.leaderboard h2 { margin-bottom: 8px; }
.leaderboard ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; }
.leaderboard li {
  display: grid; grid-template-columns: 32px 1fr auto; gap: 8px; align-items: center;
  padding: 5px 8px; border-radius: 8px; font-variant-numeric: tabular-nums;
}
.leaderboard li.me { background: rgba(124, 108, 255, .15); outline: 1px solid rgba(124, 108, 255, .35); }
.leaderboard li .rank { color: var(--muted); font-weight: 700; }
.leaderboard li .nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard li .score { font-weight: 700; }
.leaderboard .empty { color: var(--muted); padding: 6px 8px; }

/* ---------------------------------------------------------------- trends */
.trends {
  width: 100%; max-width: 960px; margin: 0 auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.trends h2 { display: flex; align-items: baseline; gap: 8px; }
.trend-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; margin-top: 10px; }
.trend-card {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; min-width: 0;
}
.trend-img {
  width: 96px; height: 96px; flex: 0 0 96px; border-radius: 10px; object-fit: contain;
  background: radial-gradient(circle at 50% 40%, rgba(124, 108, 255, .25), rgba(255, 255, 255, .03));
}
.trend-placeholder { display: flex; align-items: center; justify-content: center; font-size: 40px; }
.trend-body { min-width: 0; }
.trend-body h3 { font-size: 15px; margin-bottom: 2px; }
.trend-blurb { margin: 0 0 4px; font-size: 13.5px; }
button.ghost.small { padding: 4px 8px; font-size: 12px; }
.trend-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px 0; }
.trend-chips:empty { display: none; }
.chip {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; color: var(--text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); }

.trend-card h3 a { color: inherit; text-decoration: none; }
.trend-card h3 a:hover { text-decoration: underline; }
.dict-link { margin-left: 6px; white-space: nowrap; }

/* ---------------------------------------------------------------- dictionary pages */
.topbar .nav a { color: var(--text); text-decoration: none; margin-left: 16px; font-weight: 600; font-size: 14px; }
.topbar .nav a.active { color: var(--accent); }
.page { max-width: 960px; margin: 0 auto; padding: 20px 16px 40px; }
.page h1 { font-size: 28px; margin: 0 0 8px; letter-spacing: -.01em; }
.page h2 { font-size: 17px; margin: 24px 0 8px; }
.page .lead { font-size: 16px; }
.crumbs { margin-bottom: 12px; }
.crumbs a { color: var(--muted); }
.dict-search { display: flex; gap: 8px; margin: 14px 0 18px; flex-wrap: wrap; }
.dict-search input, .dict-search select {
  padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font: inherit;
}
.dict-search input { flex: 1 1 220px; min-width: 0; }
.dict-search button { padding: 9px 14px; border-radius: 8px; border: 0; background: var(--accent); color: #fff; font-weight: 700; }
.dict-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.kind-badge {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px; vertical-align: middle; margin-left: 6px;
  background: rgba(124, 108, 255, .18); color: var(--accent-2); font-weight: 600;
}
.pill.live { background: rgba(61, 220, 151, .15); color: var(--ok); border-color: rgba(61, 220, 151, .4); margin-left: 6px; font-size: 11px; padding: 2px 8px; }
.entry-hero { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 8px; }
.entry-img {
  width: 200px; height: 200px; flex: 0 0 200px; border-radius: 16px; object-fit: contain; font-size: 72px;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(124, 108, 255, .25), rgba(255, 255, 255, .03));
}
.entry-head { flex: 1 1 320px; min-width: 0; }
.entry-text p { font-size: 15.5px; line-height: 1.65; }
.btn { display: inline-block; background: var(--accent); color: #fff; border-radius: 8px; padding: 9px 14px; font-weight: 700; text-decoration: none; }
.btn:hover { filter: brightness(1.08); }
.sources { list-style: none; padding: 0; margin: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.sources a {
  display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); text-decoration: none; font-weight: 600; font-size: 13.5px;
}
.sources a:hover { border-color: var(--accent-2); }
.tags a { color: var(--muted); text-decoration: none; margin-right: 8px; }
.tags a:hover { color: var(--accent-2); }

/* ---------------------------------------------------------------- chat */
.chat-head { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-log { flex: 1 1 auto; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.msg { font-size: 14px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg .nick { font-weight: 700; color: var(--accent-2); margin-right: 6px; }
.msg.mine .nick { color: var(--accent); }
.msg .star-count { font-size: 11px; color: var(--warn); margin-right: 6px; }
.msg.system { color: var(--muted); font-style: italic; background: var(--panel-2); border-left: 3px solid var(--accent-2); padding: 6px 8px; border-radius: 6px; }
.chat-frozen {
  margin: 10px 12px; padding: 14px; border-radius: 10px;
  background: linear-gradient(135deg, rgba(124, 108, 255, .18), rgba(255, 77, 141, .12));
  border: 1px solid rgba(124, 108, 255, .4); text-align: center;
}
.chat-frozen p { margin: 8px 0 0; }
.chat-frozen ul { text-align: left; margin: 10px 0 0; padding-left: 18px; color: var(--muted); }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.chat-form input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font: inherit;
}
.chat-form input:focus { outline: none; border-color: var(--accent-2); }
.chat-form input:disabled { opacity: .5; }
.chat-form button {
  padding: 10px 14px; border-radius: 8px; border: 0; background: var(--accent); color: #fff; font-weight: 700;
}
.chat-form button:disabled { opacity: .5; cursor: not-allowed; }
.chat-notice { margin: 0 12px 10px; padding: 8px 10px; border-radius: 8px; font-size: 13px; background: rgba(255, 107, 107, .12); color: var(--danger); border: 1px solid rgba(255, 107, 107, .35); }
.chat-notice.ok { background: rgba(61, 220, 151, .12); color: var(--ok); border-color: rgba(61, 220, 151, .35); }
.turnstile { padding: 0 12px 12px; display: flex; justify-content: center; }

/* ---------------------------------------------------------------- toast & dialogs */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--accent-2); border-radius: 12px;
  padding: 12px 16px; max-width: min(560px, calc(100vw - 32px)); z-index: 50;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5); animation: toast-in .25s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; width: min(520px, calc(100vw - 32px)); max-height: 85vh;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h3 { font-size: 17px; margin-bottom: 6px; }
dialog input {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font: inherit; margin-top: 8px;
}
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
dialog button[type="submit"] { background: var(--accent); border: 0; color: #fff; border-radius: 8px; padding: 8px 14px; font-weight: 700; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.version-list { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; max-height: 65vh; }
.ver { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.ver.live { border-color: var(--ok); }
.ver header { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ver ul { margin: 6px 0; padding-left: 18px; }
.ver .pill { background: rgba(61, 220, 151, .15); color: var(--ok); border-color: rgba(61, 220, 151, .4); }

/* ---------------------------------------------------------------- spinner */
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .15); border-top-color: var(--accent);
  animation: spin .9s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .stage-col { overflow: visible; }
  .chat-col { height: 60vh; min-height: 380px; }
  .tagline { display: none; }
}
@media (max-width: 600px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .status { gap: 4px; }
  .pill { font-size: 11px; padding: 3px 8px; }
  .layout { padding: 10px; gap: 10px; }
  .leaderboard ol { grid-template-columns: 1fr; }
}
