/* ═══════════════════════════════════════════════════════════
   Topper Cracker — MASTER STYLESHEET
   Primary: #3f779d | Fonts: Fraunces + DM Sans
═══════════════════════════════════════════════════════════ */

/* ─── TOKENS ──────────────────────────────────────────────── */
:root {
  --brand:        #3f779d;
  --brand-dim:    #2d5a7a;
  --brand-glow:   rgba(63,119,157,.18);
  --brand-light:  rgba(63,119,157,.08);

  --bg:           #f5f6f8;
  --surface:      #ffffff;
  --surface-2:    #f0f2f5;
  --border:       rgba(0,0,0,.07);

  --text:         #1a1d23;
  --text-2:       #5a6472;
  --text-3:       #9aa3b0;

  --shadow-sm:    0 2px 8px rgba(0,0,0,.06);
  --shadow-md:    0 8px 24px rgba(0,0,0,.09);
  --shadow-lg:    0 20px 50px rgba(0,0,0,.12);

  --radius-sm:    10px;
  --radius-md:    18px;
  --radius-lg:    26px;

  --transition:   .28s cubic-bezier(.4,0,.2,1);

  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'DM Sans', -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg:           #111418;
  --surface:      #1c2029;
  --surface-2:    #242933;
  --border:       rgba(255,255,255,.07);
  --text:         #e8eaf0;
  --text-2:       #8b94a6;
  --text-3:       #50596a;
  --shadow-sm:    0 2px 8px rgba(0,0,0,.3);
  --shadow-md:    0 8px 24px rgba(0,0,0,.4);
  --shadow-lg:    0 20px 50px rgba(0,0,0,.55);
}

/* ─── RESET & BASE ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;

  /* ✅ ADD THESE */
  display: flex;
  flex-direction: column;
}

/* Subtle noise texture */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 0; opacity: .6;
}

a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }

/* ─── LAYOUT HELPERS ──────────────────────────────────────── */
.container {
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 24px;
  position: relative; z-index: 1;
}

/* ─── NAVBAR ──────────────────────────────────────────────── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background var(--transition), border-color var(--transition);
}
.navbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  max-width: 1060px; margin: 0 auto;
}
.brand {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--brand);
  letter-spacing: -.3px;
}
.brand em { font-style: italic; font-weight: 300; }
.nav-actions { display: flex; align-items: center; gap: 12px; }

/* Wrapper */
.settings-wrapper {
    position: relative;
}

/* Gear Button */
.gear-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: 0.3s;
}

.gear-btn:hover {
    background: #3f779d;
    color: white;
    transform: rotate(90deg);
}

/* Dropdown Menu */
.settings-menu {
    position: absolute;
    top: 48px;
    right: 0;
    width: 180px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    display: none;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    z-index: 999;
}

/* Show menu */
.settings-menu.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {opacity: 0; transform: translateY(-10px);}
    to {opacity: 1; transform: translateY(0);}
}

/* Menu item */
.menu-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Your existing toggle style */
.theme-toggle {
    width: 40px;
    height: 22px;
    background: var(--border);
    border-radius: 999px;
    position: relative;
    cursor: pointer;
}

.theme-toggle::before {
    content: "";
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: 0.3s;
}

html[data-theme="light"] .theme-toggle::before {
    transform: translateX(18px);
}

#musicToggle {
    width: 40px;
    height: 22px;
    background: var(--border);
    border-radius: 999px;
    position: relative;
    cursor: pointer;
    border: none;
}

#musicToggle::before {
    content: "";
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: 0.3s;
}

#musicToggle.active::before {
    transform: translateX(18px);
}

#musicToggle.active {
    background: #3f779d;
}

/* ─── MUSIC DRAWER ────────────────────────────────────────── */
.music-drawer {
    position: fixed;
    bottom: -100%; /* Hidden by default */
    left: 0; right: 0;
    height: 75vh;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-radius: 30px 30px 0 0;
    box-shadow: 0 -10px 40px rgba(0,0,0,0.3);
    z-index: 10000;
    transition: bottom 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.music-drawer.active {
    bottom: 0;
}

.drawer-handle {
    width: 40px;
    height: 5px;
    background: var(--border);
    border-radius: 10px;
    margin: -5px auto 15px;
    cursor: pointer;
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.now-playing-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.music-note {
    font-size: 24px;
    background: var(--brand-glow);
    padding: 10px;
    border-radius: 12px;
}

.station-label { font-size: 10px; text-transform: uppercase; color: var(--text-3); }
#currentStationName { font-family: var(--font-display); color: var(--brand); }

/* Tabs for Radio/Spotify */
.source-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.tab-btn {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    border: 1px solid var(--border);
    color: var(--text-2);
}
.tab-btn.active {
    background: var(--brand);
    color: white;
}

/* Grid of Stations */
.station-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    overflow-y: auto;
    flex: 1;
    padding-bottom: 20px;
}

.station-card {
    background: var(--surface-2);
    padding: 15px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid transparent;
    transition: 0.2s;
    cursor: pointer;
}

.station-card:hover { border-color: var(--brand); }
.station-card.active-stat {
    background: var(--brand-light);
    border-color: var(--brand);
}

/* Controls */
.drawer-controls {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.ctrl-btn {
    font-size: 20px;
    color: var(--text);
}

.play-main {
    width: 60px;
    height: 60px;
    background: var(--brand);
    color: white !important;
    border-radius: 50%;
    display: grid;
    place-items: center;
    box-shadow: 0 4px 15px var(--brand-glow);
}

/* Admin link */
.admin-link {
  font-size: .78rem;
  font-weight: 500;
  color: var(--text-3);
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.admin-link:hover {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-light);
}

/* ─── BREADCRUMB ──────────────────────────────────────────── */
.breadcrumb-wrap {
  padding: 20px 0 0;
  margin-bottom: 4px;
}
.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: .82rem; color: var(--text-3);
  list-style: none;
}
.breadcrumb-item a { color: var(--text-3); transition: color var(--transition); }
.breadcrumb-item a:hover { color: var(--brand); }
.breadcrumb-item.active { color: var(--text-2); font-weight: 500; }
.breadcrumb-sep { font-size: .65rem; opacity: .5; }

/* ─── PAGE HEADER ─────────────────────────────────────────── */
.page-header { padding: 36px 0 28px; }
.page-header.centered { text-align: center; }

.eyebrow {
  font-size: .72rem;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--brand);
  font-weight: 600;
  margin-bottom: 10px;
}
.page-title {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 300;
  color: var(--text);
  line-height: 1.2;
}
.page-title em { font-style: italic; color: var(--brand); }
.page-sub {
  margin-top: 8px;
  font-size: .88rem;
  color: var(--text-3);
  font-weight: 300;
}

/* ─── GRID ────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  padding-bottom: 60px;
}
.card-grid.two-col { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }

/* ─── NAV CARDS ───────────────────────────────────────────── */
.nav-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 28px;
  cursor: pointer;
  position: relative; overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  animation: fadeUp .35s ease both;
}
.nav-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--brand), transparent);
  opacity: 0; transition: opacity var(--transition);
}
.nav-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--brand-glow); }
.nav-card:hover::before { opacity: 1; }

.nav-card-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  background: var(--brand-light);
  display: grid; place-items: center;
  margin-bottom: 16px; font-size: 1.2rem; color: var(--brand);
  transition: background var(--transition);
}
.nav-card:hover .nav-card-icon { background: var(--brand-glow); }
.nav-card-title { font-size: 1.05rem; font-weight: 600; color: var(--text); margin-bottom: 6px; }

.nav-card-desc {
  font-size: .83rem; color: var(--text-3); line-height: 1.5; font-weight: 300;
  max-height: 64px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.nav-card-desc::-webkit-scrollbar { width: 3px; }
.nav-card-desc::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

.nav-card-footer {
  margin-top: 20px; display: flex; align-items: center; justify-content: space-between;
}
.nav-card-badge {
  font-size: .72rem; font-weight: 600; color: var(--brand);
  background: var(--brand-light); padding: 4px 10px; border-radius: 999px;
}
.nav-card-arrow { color: var(--text-3); font-size: 1.1rem; transition: transform var(--transition), color var(--transition); }
.nav-card:hover .nav-card-arrow { transform: translateX(4px); color: var(--brand); }

/* ─── TOPIC LIST ──────────────────────────────────────────── */
.topic-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 60px; }
.topic-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 22px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  animation: fadeUp .3s ease both;
}
.topic-item:hover { transform: translateX(4px); box-shadow: var(--shadow-sm); border-color: var(--brand-glow); }
.topic-item-left { display: flex; align-items: center; gap: 14px; }
.topic-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex-shrink: 0;
  transition: transform var(--transition);
}
.topic-item:hover .topic-dot { transform: scale(1.5); }
.topic-name { font-weight: 500; font-size: .95rem; }
.topic-count { font-size: .78rem; color: var(--text-3); margin-top: 2px; }
.topic-cta {
  font-size: .78rem; font-weight: 600; color: var(--brand);
  background: var(--brand-light); padding: 6px 14px; border-radius: 999px;
  transition: background var(--transition); white-space: nowrap;
}
.topic-item:hover .topic-cta { background: var(--brand-glow); }

/* ─── FLIP CARD ───────────────────────────────────────────── */
.flip-scene {
  width: 100%; 
  max-width: 600px;
  /* CHANGE: Use min-height instead of fixed height */
  min-height: 400px; 
  perspective: 1800px; 
  cursor: pointer;
  margin: 0 auto 28px;
  position: relative;
}
.flip-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .7s cubic-bezier(.4,0,.2,1);
  transform-style: preserve-3d;
}
.flip-scene.flipped .flip-inner { transform: rotateY(180deg); }

.flip-face {
  position: absolute; 
  inset: 0;
  backface-visibility: hidden; 
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex; 
  flex-direction: column;
  align-items: center; 
  justify-content: flex-start;
  padding: 30px; /* Adjusted padding */
  overflow: hidden; /* Keeps things neat */
}
.flip-face-back { transform: rotateY(180deg); border-color: var(--brand-glow); }

.face-label {
  font-size: .68rem; letter-spacing: 2.5px; text-transform: uppercase;
  font-weight: 600; color: var(--text-3); margin-bottom: 20px; flex-shrink: 0;
}
.flip-face-back .face-label { color: var(--brand); }

.face-content {
  flex: 1; 
  overflow-y: auto; /* IMPORTANT: Enables scrolling for very long text */
  width: 100%;
  display: flex; 
  align-items: center; 
  justify-content: center;
  scrollbar-width: thin; 
  scrollbar-color: var(--brand) transparent;
}
.face-content::-webkit-scrollbar { width: 4px; }
.face-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

/* 🎯 DYNAMIC FONT SIZE */
.face-text {
  font-family: var(--font-display);
  /* Use clamp: Min 1rem, Ideal 4vw, Max 1.3rem */
  font-size: clamp(1rem, 4vw, 1.3rem); 
  font-weight: 300;
  text-align: center; 
  color: var(--text); 
  line-height: 1.55; 
  width: 100%;
  word-wrap: break-word;
}
.flip-face-back .face-text {
  font-family: var(--font-body);
  font-size: 1rem; font-weight: 400;
  color: var(--text-2); line-height: 1.65;
}

/* ─── CARD NAVIGATION ─────────────────────────────────────── */
.card-nav-wrap { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.card-nav { display: flex; align-items: center; gap: 16px; }
.card-counter { font-size: .8rem; color: var(--text-3); font-weight: 500; }
.card-counter strong { color: var(--text); }

.arrow-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: grid; place-items: center;
  font-size: 1.3rem; color: var(--text-2);
  transition: all var(--transition);
}
.arrow-btn:hover:not([disabled]) {
  background: var(--brand); color: white;
  border-color: var(--brand); box-shadow: 0 6px 20px rgba(63,119,157,.4);
  transform: scale(1.06);
}
.arrow-btn[disabled] { opacity: .3; cursor: not-allowed; }

.flip-hint {
  font-size: .75rem; color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
  animation: pulse 2.5s ease infinite;
}
.progress-wrap {
  width: 100%; max-width: 600px; height: 3px;
  background: var(--surface-2); border-radius: 999px;
  margin: 0 auto 28px; overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--brand), #6fb3d4);
  border-radius: 999px; transition: width .5s cubic-bezier(.4,0,.2,1);
}

.keyboard-hint { font-size: .72rem; color: var(--text-3); text-align: center; margin-top: 8px; }
.kbd {
  display: inline-block; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 5px;
  padding: 2px 7px; font-size: .68rem; font-weight: 600; color: var(--text-2);
}

/* ─── EMPTY / ALERT ───────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 24px; color: var(--text-3); }
.empty-state-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h3 { font-family: var(--font-display); font-weight: 300; color: var(--text-2); }

/* ─── FOOTER ──────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px; text-align: center;
  font-size: .78rem; color: var(--text-3);
  position: relative; z-index: 1;
}

/* ─── ANIMATIONS ──────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse { 0%,100%{opacity:.5} 50%{opacity:1} }

/* ─── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 600px) {
  .card-grid, .card-grid.two-col { grid-template-columns: 1fr; }
  .flip-scene { height: 320px; }
  .flip-face { padding: 24px 20px; }
  .face-text { font-size: 1.1rem; }
  .navbar-inner { padding: 14px 16px; }
}