/* ==========================================================================
   Tokens
   ========================================================================== */
:root,
:root[data-theme="dark"] {
  --bg: #0a0b10;
  --bg-elev: #111319;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.065);
  --surface-3: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.075);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #eef0f7;
  --text-2: #b6bacb;
  --muted: #7d8296;
  --faint: #4a4e5e;
  --accent: #8b7dff;
  --accent-soft: rgba(139, 125, 255, 0.16);
  --accent-2: #22d3ee;
  --good: #22c55e;
  --good-soft: rgba(34, 197, 94, 0.16);
  --bad: #f43f5e;
  --bad-soft: rgba(244, 63, 94, 0.14);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.15);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 20px 50px -20px rgba(0, 0, 0, 0.6);
  --menu-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px var(--border-strong);
  --glow-1: rgba(124, 108, 255, 0.18);
  --glow-2: rgba(34, 211, 238, 0.09);
  --radius: 18px;
  --radius-sm: 12px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-elev: #ffffff;
  --surface: rgba(255, 255, 255, 0.75);
  --surface-2: rgba(15, 20, 40, 0.045);
  --surface-3: rgba(15, 20, 40, 0.08);
  --border: rgba(15, 20, 40, 0.08);
  --border-strong: rgba(15, 20, 40, 0.14);
  --text: #0f1222;
  --text-2: #3b4053;
  --muted: #6b7185;
  --faint: #b3b7c5;
  --accent: #6a58f5;
  --accent-soft: rgba(106, 88, 245, 0.12);
  --accent-2: #0891b2;
  --good: #16a34a;
  --good-soft: rgba(22, 163, 74, 0.12);
  --bad: #e11d48;
  --bad-soft: rgba(225, 29, 72, 0.1);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.12);
  --shadow: 0 1px 2px rgba(15, 20, 40, 0.04), 0 12px 32px -16px rgba(15, 20, 40, 0.18);
  --menu-shadow: 0 24px 60px -16px rgba(15, 20, 40, 0.28), 0 0 0 1px var(--border);
  --glow-1: rgba(106, 88, 245, 0.12);
  --glow-2: rgba(8, 145, 178, 0.08);
  color-scheme: light;
}

/* ==========================================================================
   Base
   ========================================================================== */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  touch-action: manipulation;
  transition: background-color 0.3s ease, color 0.3s ease;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 500px at 12% -10%, var(--glow-1), transparent 60%),
    radial-gradient(700px 420px at 95% 0%, var(--glow-2), transparent 60%);
  z-index: 0;
}

button { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
kbd {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.78em;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ==========================================================================
   App shell
   ========================================================================== */
.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  height: 100vh;
  height: 100dvh;
  max-width: 1440px;
  margin: 0 auto;
  padding: 18px 24px 14px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 8px);
  gap: 2px;
  padding: 5px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.brand-mark i { width: 8px; height: 8px; border-radius: 2px; background: var(--accent); }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(7) { background: var(--accent-2); }
.brand-mark i:nth-child(3), .brand-mark i:nth-child(9) { background: var(--good); }
.brand-mark i:nth-child(4), .brand-mark i:nth-child(8) { background: var(--warn); }
.brand-mark i:nth-child(5) { background: var(--bad); }

.controls {
  display: flex;
  gap: 8px;
  flex: 1;
  justify-content: center;
}

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

.dropdown { position: relative; }

.select-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(12px);
  cursor: pointer;
  font-weight: 600;
  font-size: 14.5px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, background 0.15s;
}
.select-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.select-btn .cubing-icon { font-size: 20px; color: var(--accent); }
.select-btn.subtle { font-family: "JetBrains Mono", monospace; font-size: 13.5px; }
.select-label .sh { display: none; }
.select-btn .chev { width: 16px; height: 16px; color: var(--muted); transition: transform 0.2s; }
.select-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn.sm { width: 34px; height: 34px; border-radius: 10px; }
.icon-btn.sm svg { width: 16px; height: 16px; }

[data-theme="dark"] .i-moon, [data-theme="light"] .i-sun { display: none; }

/* ---------- Menus ---------- */
.menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--bg-elev);
  border-radius: 16px;
  box-shadow: var(--menu-shadow);
  padding: 8px;
  animation: pop 0.16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateX(-50%) translateY(-6px) scale(0.98); } }

.event-menu {
  display: grid;
  grid-template-columns: repeat(2, minmax(210px, 1fr));
  gap: 2px;
  width: max-content;
}
.event-item, .format-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.12s;
}
.event-item:hover, .format-item:hover { background: var(--surface-2); }
.event-item.active, .format-item.active { background: var(--accent-soft); color: var(--accent); }
.event-item .cubing-icon { font-size: 20px; width: 22px; text-align: center; }
.event-item-name { flex: 1; }
.event-item-count { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.format-menu { width: 220px; }
.format-item { justify-content: space-between; }
.tag {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--text-2);
}

/* ---------- Scramble ---------- */
.scramble-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.scramble-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.scramble-meta { display: flex; align-items: center; gap: 10px; min-width: 0; }
.scramble-meta .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scramble-actions { display: flex; gap: 6px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--good-soft);
  color: var(--good);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.scramble-text {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: clamp(17px, 2vw, 24px);
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1.55;
  text-align: center;
  word-spacing: 0.25em;
  min-height: 1.55em;
  max-height: 30vh;
  overflow-y: auto;
  text-wrap: balance;
}
.scramble-text.md { font-size: clamp(15px, 1.6vw, 20px); }
.scramble-text.sm { font-size: clamp(13px, 1.3vw, 16px); word-spacing: 0.15em; }
.scramble-text.xs { font-size: clamp(12px, 1.1vw, 14px); word-spacing: 0.1em; line-height: 1.5; }
.scramble-text.minx { white-space: pre; text-wrap: nowrap; font-size: clamp(12.5px, 1.3vw, 16px); word-spacing: 0.05em; max-height: 34vh; }

.skeleton {
  display: block;
  height: 18px;
  margin: 6px auto;
  width: min(640px, 90%);
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.skeleton.short { width: min(360px, 60%); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ==========================================================================
   Layout
   ========================================================================== */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
  min-height: 0;
}

/* ---------- Stage / Timer ---------- */
.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  border-radius: var(--radius);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  cursor: pointer;
}

.stage-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.25, 1);
  will-change: transform;
}

.timer {
  font-family: "Inter", system-ui, sans-serif;
  font-weight: 600;
  font-size: clamp(76px, 13vw, 184px);
  line-height: 1;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum", "ss01";
  color: var(--text);
  transition: color 0.12s ease, transform 0.2s ease, text-shadow 0.2s ease;
}

.stage.is-hold .timer { color: var(--bad); }
.stage.is-ready .timer { color: var(--good); text-shadow: 0 0 60px rgba(34, 197, 94, 0.35); transform: scale(1.02); }
.stage.is-running .timer { transform: scale(1.04); }
.stage.is-inspect:not(.is-hold):not(.is-ready) .timer { color: var(--accent); }
.stage.is-inspect.warn:not(.is-hold):not(.is-ready) .timer { color: var(--warn); }
.stage.is-inspect.danger:not(.is-hold):not(.is-ready) .timer { color: var(--bad); }
.stage.pb .timer { animation: pbPulse 1.2s ease; }
@keyframes pbPulse {
  0% { text-shadow: 0 0 0 transparent; }
  30% { text-shadow: 0 0 50px var(--accent); color: var(--accent); }
  100% { text-shadow: 0 0 0 transparent; }
}

.inspect-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.2s;
  height: 16px;
}
.inspect-label.show { opacity: 1; }

.solve-actions {
  display: flex;
  gap: 8px;
  animation: fadeUp 0.2s ease-out;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } }

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 38px;
  padding: 0 16px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.15s;
}
.pill:hover { background: var(--surface-2); color: var(--text); }
.pill.icon { min-width: 38px; padding: 0; }
.pill.icon svg { width: 16px; height: 16px; }
.pill.icon:hover { color: var(--bad); border-color: var(--bad-soft); background: var(--bad-soft); }
.pill.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill[data-penalty="-1"].active { background: var(--bad-soft); color: var(--bad); }
.pill[data-penalty="2"].active { background: var(--warn-soft); color: var(--warn); }

.quick-stats {
  display: flex;
  gap: 28px;
  font-variant-numeric: tabular-nums;
  transition: opacity 0.25s;
}
.quick-stats > div { display: flex; align-items: baseline; gap: 8px; }
.qs-label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; }
.qs-val { font-family: "JetBrains Mono", monospace; font-size: 18px; font-weight: 500; }

.stage-hint {
  position: absolute;
  bottom: 12px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  padding: 0 16px;
  transition: opacity 0.25s;
}
.stage-hint b { color: var(--good); font-weight: 600; }

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  transition: opacity 0.25s;
}
.site-footer a {
  color: var(--text-2);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
  transition: color 0.15s, border-color 0.15s;
}
.site-footer a:hover { color: var(--accent); border-color: var(--accent); }

/* Focus mode: hide everything but the timer while inspecting / solving */
.app.focus .site-footer,
.app.focus .topbar,
.app.focus .scramble-card,
.app.focus .sidebar,
.app.focus .quick-stats,
.app.focus .stage-hint {
  opacity: 0;
  pointer-events: none;
}
.app.focus .scramble-card { transform: translateY(-6px); }
.app.focus { cursor: none; }

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: opacity 0.25s ease;
}
.sidebar-scroll {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 0;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
.sheet-handle { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  flex: none;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head h3 { margin: 2px 0 0; font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em; }
.card-head .small { text-align: right; line-height: 1.5; font-variant-numeric: tabular-nums; }

.text-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.text-btn:hover { background: var(--surface-2); color: var(--text); }
.text-btn.danger:hover { color: var(--bad); background: var(--bad-soft); }

/* Round */
.round-slots {
  display: grid;
  grid-template-columns: repeat(var(--slots, 5), minmax(0, 1fr));
  gap: 6px;
}
.slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px;
  border-radius: 10px;
  border: 1px dashed var(--border-strong);
  background: transparent;
  font-variant-numeric: tabular-nums;
  min-width: 0;
}
.slot.filled { border-style: solid; border-color: var(--border); background: var(--surface-2); cursor: pointer; }
.slot.filled:hover { border-color: var(--border-strong); }
.slot.next { border-color: var(--accent); background: var(--accent-soft); }
.slot-n { font-size: 10.5px; font-weight: 600; color: var(--muted); }
.slot-t { font-family: "JetBrains Mono", monospace; font-size: 13px; font-weight: 500; white-space: nowrap; }

.round-result {
  display: flex;
  gap: 18px;
  margin-top: 12px;
  font-size: 13px;
  font-family: "JetBrains Mono", monospace;
}
.round-result .muted { font-family: "Inter", sans-serif; font-weight: 600; font-size: 11.5px; margin-right: 4px; letter-spacing: 0.04em; }
.round-result > .muted { font-family: "Inter", sans-serif; font-size: 12.5px; font-weight: 400; letter-spacing: 0; }

.round-history { margin-top: 6px; }
.round-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 8px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: 12.5px;
}
.round-row:hover { background: var(--surface-2); }
.round-times { font-family: "JetBrains Mono", monospace; color: var(--muted); word-spacing: 0.3em; line-height: 1.5; }
.round-res { font-family: "JetBrains Mono", monospace; font-weight: 600; }

/* Stats */
.stats-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats-table th, .stats-table td { padding: 0; text-align: left; }
.stats-table thead th { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; padding-bottom: 6px; }
.stats-table tbody th { font-size: 13px; font-weight: 600; color: var(--text-2); width: 70px; }
.stats-table tbody tr + tr { border-top: 1px solid var(--border); }
.stat-cell {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 8px;
  margin: 1px 0;
  border-radius: 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  cursor: pointer;
}
.stat-cell:hover { background: var(--surface-2); }
td.best .stat-cell { color: var(--accent); font-weight: 600; }
.stat-empty { display: block; padding: 8px; color: var(--faint); font-family: "JetBrains Mono", monospace; }

/* Preview */
.preview {
  display: grid;
  place-items: center;
  min-height: 150px;
}
.preview twisty-player { width: 100%; height: 190px; }
.preview-empty { padding: 30px 0; }

/* Solves list */
.solves-head, .solve-row {
  display: grid;
  grid-template-columns: 44px 1fr 1fr 1fr;
  gap: 6px;
  align-items: center;
}
.solves-head {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 10px 6px;
}
.solves-list { list-style: none; margin: 0; padding: 0; }
.solve-row {
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.solves-list li:nth-child(odd) .solve-row { background: var(--surface); }
.solve-row:hover { background: var(--surface-2) !important; }
.solve-n { font-size: 12px; color: var(--muted); }
.solve-t { font-family: "JetBrains Mono", monospace; font-size: 14px; font-weight: 600; }
.solve-t.dnf { color: var(--bad); }
.solve-row.pb .solve-t { color: var(--accent); }
.solve-a { font-family: "JetBrains Mono", monospace; font-size: 13px; color: var(--text-2); }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 22px 12px 14px;
}
.empty-state p { margin: 12px 0 2px; font-weight: 600; }
.empty-cube { display: grid; grid-template-columns: repeat(3, 12px); gap: 3px; opacity: 0.55; }
.empty-cube i { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-3); }
.empty-cube i:nth-child(5) { background: var(--accent); }

/* ==========================================================================
   Modals
   ========================================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 10, 0.55);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.18s;
}
.modal-card {
  position: relative;
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 22px;
  box-shadow: var(--menu-shadow);
  padding: 22px;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity 0.18s, transform 0.18s;
}
.modal.open .modal-backdrop { opacity: 1; }
.modal.open .modal-card { opacity: 1; transform: none; }

.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.modal-head h2 {
  margin: 4px 0 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
#settingsTitle { font-size: 24px; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
  margin-bottom: 18px;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 9px 8px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-2);
  cursor: pointer;
}
.segmented button.active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 0 1px var(--border); }

.detail-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 8px;
}
.detail-scramble {
  font-family: "JetBrains Mono", monospace;
  font-size: 14.5px;
  line-height: 1.6;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  word-spacing: 0.2em;
  white-space: pre-line;
}
.detail-meta { margin-top: 12px; }

.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 20px; }

.btn {
  height: 40px;
  padding: 0 16px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: var(--surface-3); }
.btn.danger-ghost { background: transparent; border-color: transparent; color: var(--bad); }
.btn.danger-ghost:hover { background: var(--bad-soft); }

.stat-list { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.stat-list li {
  counter-increment: s;
  display: grid;
  grid-template-columns: 22px 88px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
  align-items: baseline;
}
.stat-list li::before { content: counter(s); color: var(--muted); font-size: 12px; }
.stat-t { font-family: "JetBrains Mono", monospace; font-weight: 600; font-size: 14px; }
.stat-s { font-family: "JetBrains Mono", monospace; color: var(--text-2); font-size: 12px; line-height: 1.5; word-spacing: 0.15em; white-space: pre-line; }

/* Settings */
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.setting-title { font-weight: 600; font-size: 14px; }
.setting-desc { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.switch { position: relative; width: 44px; height: 26px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: var(--surface-3);
  transition: background 0.2s;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s cubic-bezier(0.3, 1.4, 0.6, 1);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.select {
  height: 36px;
  padding: 0 32px 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center / 14px;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  appearance: none;
  cursor: pointer;
}
.select option { background: var(--bg-elev); color: var(--text); }

.data-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.shortcuts { margin: 18px 0 0; line-height: 2; }

/* ==========================================================================
   Toast
   ========================================================================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 200;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 11px 18px;
  border-radius: 12px;
  background: var(--bg-elev);
  box-shadow: var(--menu-shadow);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.good { color: var(--good); }
.toast.accent { color: var(--accent); }

.scrim { display: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr) 330px; }
}

@media (max-width: 900px) {
  :root { --sheet-peek: 60px; }

  .app {
    padding: max(12px, env(safe-area-inset-top)) 16px 0;
    gap: 12px;
  }

  .topbar { gap: 8px; }
  .brand-name { display: none; }
  .controls { justify-content: flex-start; min-width: 0; }
  .select-btn { height: 40px; padding: 0 12px; gap: 8px; }
  #eventDropdown { min-width: 0; flex: 0 1 auto; }
  #eventBtn { max-width: 100%; min-width: 0; }
  .actions { flex: none; }
  #eventBtn .select-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .icon-btn { width: 40px; height: 40px; }
  .select-label .lg { display: none; }
  .select-label .sh { display: inline; }

  .menu {
    position: fixed;
    top: calc(max(12px, env(safe-area-inset-top)) + 50px);
    left: 16px;
    right: 16px;
    transform: none;
    max-height: 70dvh;
    overflow-y: auto;
  }
  @keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(0.98); } }
  .event-menu { grid-template-columns: 1fr 1fr; width: auto; }
  .event-item { padding: 10px; gap: 8px; font-size: 13px; }
  .format-menu { width: auto; left: auto; min-width: 220px; }

  .scramble-card { padding: 10px 14px 14px; border-radius: 16px; }
  .scramble-head { margin-bottom: 6px; }
  .scramble-text { font-size: 17px; max-height: 24dvh; }
  .scramble-text.md { font-size: 15px; }
  .scramble-text.sm { font-size: 13px; }
  .scramble-text.xs { font-size: 11.5px; }
  .scramble-text.minx { font-size: min(13px, 2.9vw); max-height: 30dvh; }

  .layout { grid-template-columns: 1fr; }

  .stage { padding-bottom: calc(var(--sheet-peek) + env(safe-area-inset-bottom) + 28px); }
  .timer { font-size: clamp(64px, 22vw, 140px); }
  .stage { padding-bottom: calc(var(--sheet-peek) + env(safe-area-inset-bottom) + 52px); }
  .stage-hint { bottom: calc(var(--sheet-peek) + env(safe-area-inset-bottom) + 36px); font-size: 12.5px; }
  .site-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--sheet-peek) + env(safe-area-inset-bottom) + 10px);
    z-index: 2;
    font-size: 12px;
  }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    height: 86dvh;
    background: var(--bg-elev);
    border-top: 1px solid var(--border);
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -20px 50px -20px rgba(0, 0, 0, 0.45);
    transform: translateY(calc(100% - var(--sheet-peek) - env(safe-area-inset-bottom)));
    transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.25, 1), opacity 0.25s ease;
  }
  .sidebar.open { transform: translateY(0); }

  .sheet-handle {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    height: var(--sheet-peek);
    padding: 10px 20px 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    flex: none;
    font-size: 13.5px;
    font-weight: 600;
  }
  .grabber {
    position: absolute;
    top: 8px;
    left: 50%;
    width: 38px;
    height: 4px;
    margin-left: -19px;
    border-radius: 99px;
    background: var(--surface-3);
  }
  .sheet-summary { display: flex; align-items: center; gap: 10px; color: var(--text-2); }
  .sheet-summary .dot { width: 4px; height: 4px; border-radius: 50%; background: var(--faint); }
  .sheet-handle .chev { color: var(--muted); transition: transform 0.3s; }
  .sidebar.open .sheet-handle .chev { transform: rotate(180deg); }

  .sidebar-scroll {
    padding: 4px 16px calc(24px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }
  .sidebar .card { background: var(--surface-2); box-shadow: none; backdrop-filter: none; }
  [data-theme="light"] .sidebar .card { background: var(--bg); }

  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(5, 6, 10, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
  }
  .scrim.show { opacity: 1; pointer-events: auto; }

  .toast { bottom: calc(var(--sheet-peek) + env(safe-area-inset-bottom) + 16px); }

  .modal { align-items: end; padding: 0; }
  .modal-card {
    width: 100%;
    border-radius: 22px 22px 0 0;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
    max-height: 90dvh;
    transform: translateY(30px);
  }
  .setting { align-items: flex-start; }
}

@media (max-width: 420px) {
  #themeBtn { display: none; }
  .quick-stats { gap: 18px; }
  .qs-val { font-size: 16px; }
  .pill { min-width: 48px; height: 36px; padding: 0 12px; }
  .scramble-meta .small { display: none; }
  .slot-t { font-size: 11.5px; }
}

@media (max-height: 560px) and (min-width: 901px) {
  .scramble-text { max-height: 18vh; }
  .timer { font-size: clamp(60px, 10vw, 120px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
