/* ==========================================================================
   Ballroom Index — design system
   Plain CSS, no build step. Edit directly.
   ========================================================================== */

/* ---- Design tokens -------------------------------------------------- */
:root {
  /* neutrals (light) */
  --bg: #faf9f7;
  --bg-elevated: #ffffff;
  --bg-sunken: #f1efeb;
  --border: #e3ded5;
  --text: #26221c;
  --text-muted: #6b6459;
  --text-faint: #948c7e;
  --link: #6d4aa8;
  --link-hover: #52357f;
  --shadow: 0 1px 2px rgba(38, 34, 28, .06), 0 4px 16px rgba(38, 34, 28, .06);
  --shadow-lift: 0 8px 24px rgba(38, 34, 28, .12);

  /* dance accents */
  --waltz: #3b6ea5;
  --waltz-bg: #eaf1f8;
  --tango: #b23a48;
  --tango-bg: #f9eaec;
  --foxtrot: #b8791f;
  --foxtrot-bg: #f8f0e0;
  --quickstep: #218a63;
  --quickstep-bg: #e6f4ee;
  --viennese: #7c5cbf;
  --viennese-bg: #f1ecfa;

  /* level badges (medal tones) */
  --lvl-prebronze: #8a8074;
  --lvl-prebronze-bg: #eeece7;
  --lvl-bronze: #9a5a2e;
  --lvl-bronze-bg: #f3e5d8;
  --lvl-silver: #6b7280;
  --lvl-silver-bg: #eceef1;
  --lvl-gold: #a3821a;
  --lvl-gold-bg: #f8f0d3;
  --lvl-additional: #2f7a6b;
  --lvl-additional-bg: #e4f1ee;
  --lvl-former: #948c7e;
  --lvl-former-bg: #eeece7;

  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 18px;
  --font-body: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --header-h: 64px;
  --max-w: 1120px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1815;
    --bg-elevated: #23201b;
    --bg-sunken: #15130f;
    --border: #38332b;
    --text: #ece7dd;
    --text-muted: #b3ab9c;
    --text-faint: #837b6c;
    --link: #b79bec;
    --link-hover: #d4bffb;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 20px rgba(0, 0, 0, .35);
    --shadow-lift: 0 10px 30px rgba(0, 0, 0, .45);

    --waltz: #7fa9d8;
    --waltz-bg: #1e2c3b;
    --tango: #e08a92;
    --tango-bg: #3a2226;
    --foxtrot: #e0ab5c;
    --foxtrot-bg: #362a17;
    --quickstep: #6bcaa4;
    --quickstep-bg: #17302a;
    --viennese: #b79bec;
    --viennese-bg: #2c2440;

    --lvl-prebronze: #b7ac9a; --lvl-prebronze-bg: #2a271f;
    --lvl-bronze: #d6935e; --lvl-bronze-bg: #33241a;
    --lvl-silver: #b9c0cc; --lvl-silver-bg: #262a30;
    --lvl-gold: #e4c355; --lvl-gold-bg: #362e13;
    --lvl-additional: #6fcbb8; --lvl-additional-bg: #16302a;
    --lvl-former: #837b6c; --lvl-former-bg: #262319;
  }
}

:root[data-theme="dark"] {
  --bg: #1a1815;
  --bg-elevated: #23201b;
  --bg-sunken: #15130f;
  --border: #38332b;
  --text: #ece7dd;
  --text-muted: #b3ab9c;
  --text-faint: #837b6c;
  --link: #b79bec;
  --link-hover: #d4bffb;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 20px rgba(0, 0, 0, .35);
  --shadow-lift: 0 10px 30px rgba(0, 0, 0, .45);

  --waltz: #7fa9d8; --waltz-bg: #1e2c3b;
  --tango: #e08a92; --tango-bg: #3a2226;
  --foxtrot: #e0ab5c; --foxtrot-bg: #362a17;
  --quickstep: #6bcaa4; --quickstep-bg: #17302a;
  --viennese: #b79bec; --viennese-bg: #2c2440;

  --lvl-prebronze: #b7ac9a; --lvl-prebronze-bg: #2a271f;
  --lvl-bronze: #d6935e; --lvl-bronze-bg: #33241a;
  --lvl-silver: #b9c0cc; --lvl-silver-bg: #262a30;
  --lvl-gold: #e4c355; --lvl-gold-bg: #362e13;
  --lvl-additional: #6fcbb8; --lvl-additional-bg: #16302a;
  --lvl-former: #837b6c; --lvl-former-bg: #262319;
}

/* ---- Reset ------------------------------------------------------------ */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; line-height: 1.25; margin: 0 0 .5em; color: var(--text); }
h1 { font-size: clamp(1.7rem, 1.3rem + 1.6vw, 2.5rem); }
h2 { font-size: clamp(1.35rem, 1.15rem + .8vw, 1.7rem); }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1em; }
ul, ol { margin: 0 0 1em; padding-left: 1.3em; }
table { border-collapse: collapse; width: 100%; }
button { font: inherit; }

.container { max-width: var(--max-w); margin: 0 auto; padding: 0 20px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

/* ---- Header / nav ------------------------------------------------------ */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  transition: box-shadow .2s ease;
}
.site-header.is-scrolled { box-shadow: var(--shadow); }
.header-inner {
  display: flex; align-items: center; gap: 20px;
  height: var(--header-h);
}
.brand {
  font-family: var(--font-display); font-weight: 700; font-size: 1.25rem;
  color: var(--text); white-space: nowrap; flex-shrink: 0;
}
.brand:hover { color: var(--text); text-decoration: none; }
.brand .brand-accent { color: var(--viennese); }

.main-nav { display: flex; gap: 4px; margin-left: 8px; flex: 1; min-width: 0; }
.main-nav a {
  padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 600; font-size: .95rem;
  white-space: nowrap;
}
.main-nav a:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.main-nav a.active { color: var(--text); background: var(--bg-sunken); }
.main-nav a[data-dance="waltz"].active { color: var(--waltz); background: var(--waltz-bg); }
.main-nav a[data-dance="tango"].active { color: var(--tango); background: var(--tango-bg); }
.main-nav a[data-dance="foxtrot"].active { color: var(--foxtrot); background: var(--foxtrot-bg); }
.main-nav a[data-dance="quickstep"].active { color: var(--quickstep); background: var(--quickstep-bg); }
.main-nav a[data-dance="viennese"].active { color: var(--viennese); background: var(--viennese-bg); }

.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.nav-toggle { display: none; }

/* Search */
.search-toggle { display: none; }
.search-wrap { position: relative; }
.search-box {
  width: 220px; padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-sunken);
  color: var(--text); font-size: .9rem;
}
.search-box:focus { outline: 2px solid var(--link); outline-offset: 1px; }
.search-results {
  position: absolute; top: calc(100% + 8px); right: 0; width: 320px; max-width: 80vw;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lift); max-height: 60vh; overflow-y: auto; padding: 6px;
  display: none; z-index: 60;
}
.search-results.is-open { display: block; }
.search-results a {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text);
}
.search-results a:hover { background: var(--bg-sunken); text-decoration: none; }
.search-results .res-dance { font-size: .75rem; color: var(--text-faint); text-transform: capitalize; }
.search-empty { padding: 10px; color: var(--text-faint); font-size: .9rem; }

/* ---- Layout -------------------------------------------------------- */
.page-hero {
  padding: 28px 0;
  border-bottom: 1px solid var(--border);
}
.page-hero.accent-waltz { background: var(--waltz-bg); }
.page-hero.accent-tango { background: var(--tango-bg); }
.page-hero.accent-foxtrot { background: var(--foxtrot-bg); }
.page-hero.accent-quickstep { background: var(--quickstep-bg); }
.page-hero.accent-viennese { background: var(--viennese-bg); }

.breadcrumbs { font-size: .85rem; color: var(--text-faint); margin-bottom: 8px; }
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs .sep { margin: 0 6px; }

.page-hero h1 { margin-bottom: 4px; }
.page-hero .subtitle { color: var(--text-muted); font-size: 1.05rem; margin: 0; }

main { padding: 32px 0 64px; }

.site-footer {
  border-top: 1px solid var(--border); padding: 28px 0; margin-top: 40px;
  color: var(--text-faint); font-size: .88rem;
}
.site-footer a { color: var(--text-muted); }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }

/* ---- Badges / chips -------------------------------------------------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 700; letter-spacing: .01em;
}
.badge-prebronze { color: var(--lvl-prebronze); background: var(--lvl-prebronze-bg); }
.badge-bronze { color: var(--lvl-bronze); background: var(--lvl-bronze-bg); }
.badge-silver { color: var(--lvl-silver); background: var(--lvl-silver-bg); }
.badge-gold { color: var(--lvl-gold); background: var(--lvl-gold-bg); }
.badge-additional { color: var(--lvl-additional); background: var(--lvl-additional-bg); }
.badge-former { color: var(--lvl-former); background: var(--lvl-former-bg); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 12px; margin: 2px 4px 2px 0; border-radius: 999px;
  background: var(--bg-sunken); color: var(--text); font-size: .88rem;
  border: 1px solid var(--border);
}
.chip:hover { background: var(--border); text-decoration: none; }

.chip-row {
  display: flex; flex-wrap: wrap; align-items: center;
  margin: 0 0 20px;
}
.chip-row-label { color: var(--text-muted); font-size: .88rem; margin: 2px 8px 2px 0; }
.chip-current {
  background: transparent; border-style: dashed; color: var(--text-faint); cursor: default;
}

/* ---- Cards / grids --------------------------------------------------- */
.card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.grid-figures { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.figure-card {
  display: block; padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-elevated);
  color: var(--text); transition: transform .12s ease, box-shadow .12s ease;
}
.figure-card:hover { box-shadow: var(--shadow-lift); transform: translateY(-2px); text-decoration: none; }
.figure-card .fc-name { font-weight: 700; display: block; margin-bottom: 6px; }
.figure-card .fc-meta { font-size: .82rem; color: var(--text-faint); }

.level-section { margin-bottom: 28px; }
.level-heading {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.level-heading h2 { margin: 0; }

/* ---- Syllabus quick-nav (sidebar / collapsible) ----------------------- */
.syllabus-nav {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px;
}
.syllabus-nav summary {
  cursor: pointer; padding: 12px 16px; font-weight: 700; list-style: none;
  display: flex; align-items: center; justify-content: space-between;
}
.syllabus-nav summary::-webkit-details-marker { display: none; }
.syllabus-nav summary::after { content: "▾"; color: var(--text-faint); transition: transform .15s ease; }
.syllabus-nav[open] summary::after { transform: rotate(180deg); }
.syllabus-nav-body { padding: 4px 16px 16px; }
.syllabus-nav-filter {
  width: 100%; padding: 8px 12px; margin-bottom: 10px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-sunken); color: var(--text);
}
.syllabus-nav-group { margin-bottom: 10px; }
.syllabus-nav-group h4 { margin: 0 0 4px; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); }
.syllabus-nav-group ul { list-style: none; padding: 0; margin: 0; }
.syllabus-nav-group li { padding: 3px 0; }
.syllabus-nav-group a.current { color: var(--text); font-weight: 700; }
.syllabus-nav-group li.no-match { display: none; }

/* ---- Figure page content ---------------------------------------------- */
.figure-header-grid {
  display: grid; grid-template-columns: minmax(0,1fr) minmax(0,2fr); gap: 24px;
  margin-bottom: 28px;
}
.figure-variants { display: flex; flex-direction: column; gap: 16px; }
.variant-block {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  background: var(--bg-elevated);
}
.variant-block .v-title { font-weight: 700; font-size: 1.05rem; margin-bottom: 6px; }
.variant-block dl { margin: 0; font-size: .92rem; color: var(--text-muted); }
.variant-block dl div { display: flex; gap: 6px; margin-bottom: 2px; }
.variant-block dt { font-weight: 600; color: var(--text-faint); min-width: 60px; }

.content-block { margin-bottom: 20px; }
.content-block h3 { margin-bottom: 8px; }

.video-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px;
  margin-bottom: 24px;
}
.video-item h4 { margin-bottom: 8px; font-size: 1rem; }
.video-notes { font-size: .93rem; color: var(--text-muted); }

.video-facade {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  border-radius: var(--radius); overflow: hidden; background: #000 center/cover no-repeat;
  cursor: pointer; border: none; display: block;
}
.video-facade::after {
  content: ""; position: absolute; inset: 0;
  background: rgba(0,0,0,.15);
}
.video-facade .play-btn {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 60px; height: 60px; border-radius: 50%;
  background: rgba(20,18,15,.75); display: flex; align-items: center; justify-content: center;
  z-index: 1;
}
.video-facade .play-btn svg { width: 22px; height: 22px; fill: #fff; margin-left: 3px; }
.video-facade:hover .play-btn { background: var(--link); }
.video-embed-wrap { position: relative; width: 100%; aspect-ratio: 16/9; border-radius: var(--radius); overflow: hidden; }
.video-embed-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---- Tabs (Natural Spin Turn cluster) ---------------------------------- */
.tab-nav { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; flex-wrap: wrap; }
.tab-nav a {
  padding: 10px 16px; font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-nav a:hover { color: var(--text); text-decoration: none; }
.tab-nav a.active { color: var(--link); border-bottom-color: var(--link); }

/* ---- Book / library cards ---------------------------------------------- */
.book-card { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; }
.book-card .book-title { font-weight: 700; font-size: 1.02rem; grid-column: 1 / -1; }
.book-card .book-meta { color: var(--text-faint); font-size: .85rem; grid-column: 1 / -1; margin-bottom: 4px; }
.book-card .book-note { grid-column: 1 / -1; color: var(--text-muted); font-size: .93rem; }

/* ---- Misc content typography (migrated prose) --------------------------- */
.prose { max-width: 76ch; }
.prose h2, .prose h3 { margin-top: 1.4em; }
.prose table { margin: 1em 0; }
.prose table td, .prose table th { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }

/* Old table-based multi-column layouts, flattened at migration time into
   plain row/col divs - lay them out side by side (wraps to stacked on
   narrow screens automatically via flex-wrap). */
.prose .row {
  display: flex; flex-wrap: wrap; gap: 16px;
  align-items: flex-start; margin: 0 0 16px;
}
/* Nested rows (e.g. a page-half split containing several stacked
   image+caption pairs) shouldn't add trailing space after the last one -
   the outer row's own margin already separates it from what follows - but
   consecutive nested rows still need a gap between each other. */
.prose .row .row { margin-bottom: 0; }
.prose .row .row + .row { margin-top: 16px; }
.prose .col { flex: 1 1 140px; min-width: 0; }
/* Outer-level splits (e.g. left/right page halves) should stack fully on
   narrow screens; nested image+caption pairs should stay compact and
   side-by-side even there - so give them different minimum widths. */
.prose > .row > .col:not(.col-media) { flex-basis: 260px; }
.prose .row .row > .col:not(.col-media) { flex-basis: 100px; }
.prose .col-media { flex: 0 0 auto; width: auto; max-width: 160px; }
.prose .col-media img { margin: 0 auto; }
.related-figures { margin-top: 8px; }

/* ---- Back to top -------------------------------------------------------- */
.back-to-top {
  position: fixed; right: 20px; bottom: 20px; z-index: 40;
  opacity: 0; pointer-events: none; transform: translateY(10px);
  transition: opacity .15s ease, transform .15s ease;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-elevated); border: 1px solid var(--border);
  box-shadow: var(--shadow-lift); color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.back-to-top.is-visible { opacity: 1; pointer-events: auto; transform: translateY(0); }

/* ---- Responsive ---------------------------------------------------------- */
@media (max-width: 860px) {
  .figure-header-grid { grid-template-columns: 1fr; }
}

@media (max-width: 920px) {
  .main-nav {
    display: none;
    position: absolute; top: var(--header-h); left: 0; right: 0;
    background: var(--bg-elevated); border-bottom: 1px solid var(--border);
    flex-direction: column; padding: 10px; box-shadow: var(--shadow);
  }
  .main-nav.is-open { display: flex; }
  .main-nav a { padding: 12px 14px; }
  .nav-toggle { display: inline-flex; }
  .search-wrap .search-box { width: 140px; }
  .header-inner { gap: 10px; }
}

@media (max-width: 560px) {
  .search-toggle { display: inline-flex; }
  .search-wrap {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0;
    padding: 10px 16px; background: var(--bg-elevated);
    border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .search-wrap.is-open { display: block; }
  .search-wrap .search-box { width: 100%; }
  .search-results { left: 16px; right: 16px; width: auto; max-width: none; }
}
