:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
  --space-4: 1rem; --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem; --space-10: 2.5rem; --space-12: 3rem; --space-16: 4rem;

  --font-display: 'Clash Display', 'Satoshi', sans-serif;
  --font-body: 'Satoshi', -apple-system, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg: oklch(0.16 0.012 260);
  --surface: oklch(0.21 0.014 260);
  --surface-2: oklch(0.25 0.016 260);
  --border: oklch(0.32 0.018 260);
  --text: oklch(0.94 0.005 90);
  --text-2: oklch(0.72 0.012 260);
  --accent: oklch(0.65 0.19 35);
  --accent-strong: oklch(0.7 0.2 35);
  --accent-ink: oklch(0.99 0.01 35);
  --chip-on-bg: oklch(0.32 0.09 35);
  --shadow: 0 8px 28px oklch(0 0 0 / 0.45);
}
[data-theme="light"] {
  --bg: oklch(0.97 0.004 90);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.95 0.006 90);
  --border: oklch(0.88 0.008 90);
  --text: oklch(0.22 0.015 260);
  --text-2: oklch(0.48 0.015 260);
  --accent: oklch(0.58 0.19 35);
  --accent-strong: oklch(0.52 0.19 35);
  --accent-ink: oklch(0.99 0.01 35);
  --chip-on-bg: oklch(0.93 0.05 35);
  --shadow: 0 6px 20px oklch(0.2 0.02 260 / 0.12);
}

* { box-sizing: border-box; margin: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
input { font: inherit; }

/* ---------- Access gate ---------- */
.gate[hidden] { display: none; }
.gate { min-height: 100dvh; display: grid; place-items: center; padding: var(--space-5); }
.gate-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--space-10) var(--space-8);
  max-width: 420px; width: 100%; text-align: center;
  display: flex; flex-direction: column; gap: var(--space-4); align-items: center;
}
.gate-logo { width: 56px; height: 56px; }
.gate-title { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; line-height: 1.1; }
.gate-sub { font-size: var(--text-sm); color: var(--text-2); }
.gate-form { display: flex; gap: var(--space-2); width: 100%; }
.gate-form input {
  flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: var(--space-3); color: var(--text);
  font-size: var(--text-base); text-align: center; letter-spacing: 0.12em; outline: none;
}
.gate-form input:focus { border-color: var(--accent); }
.gate-btn {
  background: var(--accent); color: var(--accent-ink); border: none;
  border-radius: var(--radius-sm); padding: var(--space-3) var(--space-5);
  font-weight: 700; font-size: var(--text-sm); transition: background 0.15s;
}
.gate-btn:hover { background: var(--accent-strong); }
.gate-btn:disabled { opacity: 0.6; cursor: wait; }
.gate-error { font-size: var(--text-xs); color: var(--accent); font-weight: 500; }
.gate-error[hidden] { display: none; }
#appShell[hidden] { display: none; }
.lock-btn {
  background: none; border: none; color: var(--text-2); font-size: var(--text-xs);
  text-decoration: underline; padding: 0; cursor: pointer;
}
.lock-btn:hover { color: var(--accent); }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in oklch, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  padding: var(--space-3) var(--space-5);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
}
.brand { display: flex; align-items: center; gap: var(--space-3); text-decoration: none; color: var(--text); }
.logo { width: 38px; height: 38px; flex-shrink: 0; }
.brand-text {
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg);
  line-height: 1.05; display: flex; flex-direction: column;
}
.brand-text em {
  font-family: var(--font-body); font-style: normal; font-weight: 500;
  font-size: var(--text-xs); color: var(--text-2); letter-spacing: 0.04em;
}
.header-actions { display: flex; align-items: center; gap: var(--space-3); }
.drill-count-badge {
  font-size: var(--text-xs); font-weight: 700; color: var(--accent);
  border: 1px solid color-mix(in oklch, var(--accent) 45%, transparent);
  padding: var(--space-1) var(--space-3); border-radius: 999px; white-space: nowrap;
}
.theme-toggle {
  background: none; border: 1px solid var(--border); border-radius: 50%;
  width: 38px; height: 38px; display: grid; place-items: center; color: var(--text);
  transition: border-color 0.15s;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }

/* ---------- Controls ---------- */
main { max-width: 1200px; margin: 0 auto; padding: var(--space-6) var(--space-5) var(--space-16); }
.finder-controls[hidden] { display: none; }
.finder-controls {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-4);
}
.search-row { display: flex; gap: var(--space-3); }
.search-box {
  flex: 1; display: flex; align-items: center; gap: var(--space-2);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0 var(--space-3);
  transition: border-color 0.15s;
}
.search-box:focus-within { border-color: var(--accent); }
.search-box svg { width: 18px; height: 18px; color: var(--text-2); flex-shrink: 0; }
.search-box input {
  flex: 1; background: none; border: none; outline: none; color: var(--text);
  padding: var(--space-3) 0; font-size: var(--text-sm); min-width: 0;
}
.clear-btn {
  background: none; border: 1px solid var(--border); color: var(--text-2);
  border-radius: var(--radius-sm); padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm); font-weight: 500; transition: all 0.15s;
}
.clear-btn:hover { border-color: var(--accent); color: var(--accent); }

.filter-group { display: flex; align-items: baseline; gap: var(--space-3); }
.filter-label {
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-2); min-width: 72px; flex-shrink: 0;
}
.filter-row-2 { display: flex; gap: var(--space-8); flex-wrap: wrap; }
.filter-row-2 .filter-group { flex: 1; min-width: 260px; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  border-radius: 999px; padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs); font-weight: 500; transition: all 0.12s; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.on {
  background: var(--chip-on-bg); border-color: var(--accent);
  color: var(--text); font-weight: 700;
}
.chip .n { opacity: 0.55; font-weight: 400; margin-left: 2px; }

.more-filters summary {
  font-size: var(--text-xs); font-weight: 700; color: var(--text-2);
  cursor: pointer; text-transform: uppercase; letter-spacing: 0.08em;
  list-style: none; display: inline-flex; align-items: center; gap: var(--space-1);
}
.more-filters summary::before { content: '+'; color: var(--accent); font-size: var(--text-sm); }
.more-filters[open] summary::before { content: '–'; }
.more-filters[open] summary { margin-bottom: var(--space-3); }
.more-filters .filter-group { margin-bottom: var(--space-3); }

/* ---------- Results ---------- */
.results-bar { display: flex; flex-direction: column; gap: var(--space-1); margin: var(--space-5) 0 var(--space-4); }
#resultCount { font-size: var(--text-sm); color: var(--text-2); font-weight: 500; }
#resultCount strong { color: var(--text); }
.hand-note { font-size: var(--text-xs); color: var(--accent); }

.results-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: var(--space-4);
}
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; text-align: left;
  padding: 0; color: var(--text); transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); }
.card-thumb { position: relative; aspect-ratio: 16/9; background: var(--surface-2); overflow: hidden; }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-thumb .no-video {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--text-2); font-size: var(--text-xs); font-weight: 500;
}
.card-thumb .play {
  position: absolute; right: var(--space-2); bottom: var(--space-2);
  background: oklch(0 0 0 / 0.65); color: white; border-radius: 999px;
  font-size: var(--text-xs); font-weight: 700; padding: 2px 10px;
  display: flex; align-items: center; gap: 4px;
}
.card-body { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); flex: 1; }
.card-badges { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.badge {
  font-size: var(--text-xs); font-weight: 700; padding: 1px 8px;
  border-radius: 4px; letter-spacing: 0.02em;
}
.badge.cat { background: var(--chip-on-bg); color: var(--text); }
.badge.lvl { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.card-title { font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg); line-height: 1.15; }
.card-fixes { font-size: var(--text-sm); color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-fixes strong { color: var(--accent); font-weight: 700; }
.card-meta { margin-top: auto; padding-top: var(--space-2); display: flex; gap: var(--space-3); font-size: var(--text-xs); color: var(--text-2); font-weight: 500; }

.empty-state[hidden] { display: none; }
.empty-state { text-align: center; padding: var(--space-16) var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); align-items: center; }
.empty-title { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 600; }
.empty-state p { color: var(--text-2); }

/* ---------- Modal ---------- */
.modal-backdrop[hidden] { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: oklch(0 0 0 / 0.6); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: var(--space-4);
  overflow-y: auto;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-width: 780px; width: 100%; max-height: 92vh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-head { position: relative; }
.modal-video { aspect-ratio: 16/9; background: black; }
.modal-video iframe { width: 100%; height: 100%; border: 0; display: block; }
.modal-close {
  position: absolute; top: var(--space-3); right: var(--space-3); z-index: 5;
  background: oklch(0 0 0 / 0.6); color: white; border: none; border-radius: 50%;
  width: 36px; height: 36px; font-size: 1.1rem; line-height: 1;
}
.yt-fallback {
  display: block; text-align: center; font-size: var(--text-xs); color: var(--text-2);
  text-decoration: none; padding: var(--space-2) var(--space-4);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.yt-fallback strong { color: var(--accent); }
.yt-fallback:hover strong { text-decoration: underline; }
.modal-content { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); }
.modal-title-row { display: flex; flex-direction: column; gap: var(--space-2); }
.modal-title { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; line-height: 1.1; }
.modal-badges { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.modal-purpose { color: var(--text-2); font-size: var(--text-sm); }

.m-section h3 {
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--accent); margin-bottom: var(--space-2);
}
.m-section p, .m-section li { font-size: var(--text-sm); color: var(--text); }
.m-section ol, .m-section ul { padding-left: 1.2rem; display: flex; flex-direction: column; gap: var(--space-1); }
.cue-box {
  background: var(--chip-on-bg); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4);
  font-weight: 700; font-size: var(--text-base); font-family: var(--font-display);
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); }
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }

.next-drill {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-4); display: flex; gap: var(--space-4); align-items: center;
  cursor: pointer; transition: border-color 0.15s; text-align: left; width: 100%;
}
.next-drill:hover { border-color: var(--accent); }
.next-drill img { width: 110px; aspect-ratio: 16/9; object-fit: cover; border-radius: var(--radius-sm); flex-shrink: 0; }
.next-drill .nd-label { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.next-drill .nd-name { font-family: var(--font-display); font-weight: 600; font-size: var(--text-base); }
.next-drill .nd-why { font-size: var(--text-xs); color: var(--text-2); }
.next-drill .nd-arrow { margin-left: auto; color: var(--accent); font-size: var(--text-lg); flex-shrink: 0; }

.equip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.equip-row .chip { cursor: default; }

.site-footer { border-top: 1px solid var(--border); padding: var(--space-6) var(--space-5); text-align: center; }
.site-footer p { font-size: var(--text-xs); color: var(--text-2); }

/* ---------- Session builder ---------- */
.build-btn {
  background: none; border: 1px solid var(--accent); color: var(--accent);
  border-radius: 999px; padding: var(--space-1) var(--space-4);
  font-size: var(--text-sm); font-weight: 700; transition: all 0.15s; white-space: nowrap;
}
.build-btn:hover, .build-btn.on { background: var(--accent); color: var(--accent-ink); }
.build-bar[hidden] { display: none; }
.build-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  background: var(--surface); border-top: 2px solid var(--accent);
  box-shadow: 0 -8px 28px oklch(0 0 0 / 0.3);
  padding: var(--space-3) var(--space-5);
  padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
}
.build-bar-row {
  max-width: 1200px; margin: 0 auto; display: flex; align-items: center;
  gap: var(--space-3); flex-wrap: wrap;
}
.build-count { font-family: var(--font-display); font-weight: 700; font-size: var(--text-base); margin-right: auto; }
.build-bar .gate-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.build-panel[hidden] { display: none; }
.build-panel {
  max-width: 1200px; margin: 0 auto var(--space-3);
  display: flex; flex-direction: column; gap: var(--space-3);
  max-height: 45vh; overflow-y: auto;
}
.build-packs { display: flex; align-items: baseline; gap: var(--space-3); }
.build-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.build-list li {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3); font-size: var(--text-sm); font-weight: 500;
}
.build-list .bl-empty { color: var(--text-2); border-style: dashed; justify-content: center; }
.bl-actions { display: flex; gap: var(--space-1); }
.bl-actions button {
  background: none; border: 1px solid var(--border); color: var(--text-2);
  border-radius: 6px; width: 28px; height: 28px; line-height: 1;
}
.bl-actions button:hover { border-color: var(--accent); color: var(--accent); }
.build-fields { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.build-fields input {
  flex: 1; min-width: 200px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3);
  color: var(--text); font-size: var(--text-sm); outline: none;
}
.build-fields input:focus { border-color: var(--accent); }
.build-output[hidden] { display: none; }
.build-output { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.build-output input {
  flex: 1; min-width: 220px; background: var(--surface-2); border: 1px solid var(--accent);
  border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3);
  color: var(--text); font-size: var(--text-xs); outline: none;
}
.card.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.sel-mark {
  position: absolute; top: var(--space-2); left: var(--space-2); z-index: 3;
  background: var(--accent); color: var(--accent-ink); font-size: var(--text-xs);
  font-weight: 700; padding: 2px 10px; border-radius: 999px;
}
.seq-badge {
  position: absolute; top: var(--space-2); left: var(--space-2); z-index: 3;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-base);
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
}
body:has(.build-bar:not([hidden])) main { padding-bottom: 140px; }

/* ---------- Session banner ---------- */
.session-banner[hidden] { display: none; }
.session-banner {
  background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius);
  margin-bottom: var(--space-5); overflow: hidden; position: relative;
}
.session-banner::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--accent);
}
.sb-inner { padding: var(--space-6) var(--space-8); display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-start; }
.sb-label {
  font-size: var(--text-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--accent);
}
.sb-title { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 700; line-height: 1.1; }
.sb-note { font-size: var(--text-base); font-weight: 500; }
.sb-hint { font-size: var(--text-sm); color: var(--text-2); }
.sb-inner .clear-btn { margin-top: var(--space-2); }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .finder-controls { padding: var(--space-4); }
  .filter-group { flex-direction: column; gap: var(--space-2); }
  .filter-label { min-width: 0; }
  .filter-row-2 { flex-direction: column; gap: var(--space-4); }
  .filter-row-2 .filter-group { min-width: 0; }
  .drill-count-badge { display: none; }
  .modal-content { padding: var(--space-4); }
  .build-btn { font-size: var(--text-xs); padding: var(--space-1) var(--space-3); }
  .sb-inner { padding: var(--space-4); }
  .build-bar-row .clear-btn, .build-bar-row .gate-btn { padding: var(--space-2) var(--space-3); font-size: var(--text-xs); }
}
