/* Violin Swaras — shared styles for index.html and admin.html.
   Design goal: legible from arm's length on a music stand, so notation
   uses a large monospace font and the whole layout favors high contrast
   over decoration. */

:root {
  --ink: #1a1a2e;
  --paper: #fdfaf3;
  --paper-raised: #ffffff;
  --accent: #8b3a3a;
  --accent-soft: #f3e3e3;
  --line: #ddd4c0;
  --muted: #6b6558;
  --gold: #b8862e;
  --success: #2f7a4f;
  --font-ui: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-notation: "Courier New", "Consolas", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
}

a { color: var(--accent); }

/* ---------- Top nav ---------- */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--paper-raised);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}
.topnav .brand {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
}

/* ---------- Hamburger menu (four lines, per spec) ---------- */
.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  width: 36px;
  height: 34px;
  padding: 8px 7px;
  border-radius: 8px;
}
.hamburger-btn span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
  transition: transform 0.15s, opacity 0.15s;
}
.hamburger-btn.open span:nth-child(1) { transform: translateY(5px) rotate(45deg); }
.hamburger-btn.open span:nth-child(2) { opacity: 0; }
.hamburger-btn.open span:nth-child(3) { opacity: 0; }
.hamburger-btn.open span:nth-child(4) { transform: translateY(-5px) rotate(-45deg); }

.nav-menu {
  position: absolute;
  top: calc(100% + 12px);
  left: 0;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 230px;
  z-index: 30;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}
.nav-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
/* Top-level group ("Carnatic" / "Hindustani") — clicking it opens its
   own sub-items without closing the menu it lives in (each button
   stops click propagation in JS so the outside-click-closes listener
   never sees the event). .nav-group is the positioning anchor for its
   .nav-submenu — see below for where that submenu actually appears,
   which differs between the ☰ menu (flyout to the side) and the
   main-page row (dropdown below). */
.nav-group { position: relative; }
.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
}
.nav-group-toggle:hover { background: var(--accent-soft); }
.nav-group-toggle.active { color: var(--accent); }
.nav-chevron { font-size: 0.8rem; color: var(--muted); transition: transform 0.15s; }
.nav-chevron.open { transform: rotate(90deg); }

.nav-submenu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  padding: 8px;
  min-width: 220px;
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}
.nav-submenu.open { opacity: 1; visibility: visible; pointer-events: auto; }
/* ☰ menu: submenu flies out to the side of the group button it belongs
   to, and the ☰ dropdown itself stays open the whole time. */
.nav-menu .nav-submenu {
  position: absolute;
  top: 0;
  left: 100%;
  margin-left: 8px;
  transform: translateX(-6px);
}
.nav-menu .nav-submenu.open { transform: translateX(0); }
/* Main-page row: a normal dropdown appears below the group button. */
.main-menu-row .nav-submenu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  transform: translateY(-6px);
}
.main-menu-row .nav-submenu.open { transform: translateY(0); }

.nav-subitem {
  text-align: left;
  border: none;
  background: none;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  width: 100%;
  white-space: nowrap;
}
.nav-subitem:hover { background: var(--accent-soft); }
.nav-subitem.active { background: var(--accent); color: #fff; }

/* Narrow screens have no room for a side flyout — fall back to a plain
   accordion that expands in place, below the group button. */
@media (max-width: 600px) {
  .nav-menu .nav-submenu,
  .main-menu-row .nav-submenu {
    position: static;
    box-shadow: none;
    border: none;
    margin: 0 0 0 10px;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
    transition: max-height 0.2s ease;
  }
  .nav-menu .nav-submenu.open,
  .main-menu-row .nav-submenu.open {
    max-height: 260px;
  }
}

/* ---------- Main-page menu row (Carnatic / Hindustani / Metronome / Tuner) ---------- */
.main-menu-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 18px 0;
}
.main-menu-row .nav-group-toggle {
  width: auto;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.main-tool-btn {
  font-weight: 600;
  border-radius: 8px;
}
.main-tool-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- Metronome / Tuner panels — closeable, shown on demand ---------- */
.tool-panel {
  position: relative;
  margin: 0 0 16px;
}
.tool-panel-close {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  font-size: 0.85rem;
  line-height: 1;
  background: var(--paper-raised);
  z-index: 5;
}

/* ---------- Landing view — nothing exercise-related yet ---------- */
.landing-hint {
  margin: 20px 0;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
}
.topnav .streak {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  background: var(--accent-soft);
  padding: 6px 14px;
  border-radius: 999px;
}
.topnav nav a {
  margin-left: 16px;
  text-decoration: none;
  font-weight: 500;
  color: var(--ink);
}

/* Sign-in control in the top bar — a plain small text-style link/button,
   not a full-size call-to-action; the default button styling made it
   look oversized next to the compact streak pill on both mobile and
   desktop. */
#authArea button {
  font-size: 0.82rem;
  padding: 5px 12px;
  border-radius: 6px;
}
#authArea span {
  font-size: 0.85rem;
  margin-right: 6px;
}

/* ---------- Ad placeholders ---------- */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-linear-gradient(45deg, #eee, #eee 10px, #f7f7f7 10px, #f7f7f7 20px);
  border: 1px dashed #b8b8b8;
  color: #888;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin: 16px auto;
}
.ad-leaderboard { width: 728px; max-width: 100%; height: 90px; }
.ad-sidebar { width: 300px; max-width: 100%; height: 250px; flex-shrink: 0; }
.ad-infeed { width: 100%; max-width: 728px; height: 100px; }

/* ---------- Layout ---------- */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

.practice-area {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  margin-top: 20px;
}
.practice-main { flex: 1; min-width: 0; }

/* ---------- Carousel / exercise card ---------- */
.carousel-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  min-height: 320px;
}
.carousel-card .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.pill {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.pill.gold { background: #f6ecd6; color: var(--gold); }
.carousel-card h2 {
  margin: 0 0 6px;
  font-size: 1.8rem;
}
.carousel-card .arohana {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 18px;
}
.notation {
  font-family: var(--font-notation);
  font-size: 1.15rem;
  line-height: 1.5;
  white-space: pre-wrap;
  background: #fbf6ea;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 18px;
}
.lyrics {
  margin-top: 16px;
  font-style: italic;
  color: var(--muted);
  white-space: pre-wrap;
  /* Same size/leading as .notation — the swara row and its own syllable
     row are one unit (e.g. a Geetham's Pallavi), and having one rendered
     noticeably bigger than the other made them read as unrelated instead
     of a matched pair. */
  font-size: 1.15rem;
  line-height: 1.5;
}

button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  padding: 10px 18px;
  transition: background 0.15s;
  color: var(--ink);
}
button:hover:not(:disabled) { background: var(--accent-soft); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.primary:hover:not(:disabled) { background: #6f2d2d; }
button.primary.completed {
  background: var(--success);
  border-color: var(--success);
}

/* ---------- Tutorial / video gallery ---------- */
.tutorial-showcase {
  margin-top: 30px;
}
.video-embed {
  position: relative;
  padding-top: 56.25%;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}
.video-embed iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.video-embed.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aaa;
  font-size: 0.9rem;
}

/* ---------- Section tabs (Sarali / Jantai / Sthayi & Dhattu / Alankaram) ---------- */
.section-tabs {
  margin-top: -6px;
  padding-left: 4px;
  border-left: 3px solid var(--accent-soft);
}
.section-tabs button { font-size: 0.88rem; padding: 6px 14px; }

/* ---------- Exercise list — 3 columns, filled top-to-bottom per column ---------- */
.exercise-columns {
  display: flex;
  gap: 28px;
  margin: 4px 0 8px;
  /* A bounded, internally-scrolling box instead of letting the page grow
     as tall as the longest category's list — so viewing/finding an
     exercise never requires scrolling the whole page down past a
     hundred-item list first, on mobile or desktop. Short lists just
     shrink to fit; only a genuinely long one gets its own scrollbar. */
  max-height: 48vh;
  overflow-y: auto;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-raised);
}
.exercise-column {
  flex: 1;
  min-width: 0;
  list-style: none;
  margin: 0;
  padding: 0;
}
.exercise-list-empty { color: var(--muted); }
.exercise-column li { border-bottom: 1px solid var(--line); }
.exercise-column li:first-child { border-top: 1px solid var(--line); }
.exercise-link {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 4px;
  border: none;
  background: none;
  font-size: 1.1rem;
  color: var(--ink);
  cursor: pointer;
}
/* Plain text link, not a boxed button — an underline on hover is enough
   to say "clickable" without every item looking like a stacked pile of
   overlapping card borders. */
.exercise-link:hover { color: var(--accent); text-decoration: underline; }
.exercise-link.expanded { color: var(--accent); font-weight: 600; }

/* Renders full width, directly above the link list — "on top of the
   links" rather than squeezed beside/within them — as its own
   prominent card. */
.exercise-detail {
  position: relative;
  padding: 22px 24px 26px;
  margin-bottom: 20px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 12px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.06);
  animation: slideDown 0.15s ease-out;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.exercise-detail-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}
.exercise-detail-layout .exercise-detail-main { flex: 1; min-width: 0; }

.detail-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  font-size: 0.9rem;
  line-height: 1;
}

/* ---------- Prev/Next paging within the open exercise ---------- */
.detail-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 34px 14px 0;
}
.detail-nav h2 {
  margin: 0;
  font-size: 1.4rem;
  flex: 1;
  min-width: 0;
}
.detail-nav .nav-btn { font-size: 0.85rem; padding: 7px 14px; white-space: nowrap; }

@media (max-width: 780px) {
  .exercise-columns { flex-direction: column; gap: 0; max-height: 42vh; }
  .exercise-detail { padding: 20px 16px 22px; }
  .exercise-detail-layout { flex-direction: column; }
  .detail-nav { flex-wrap: wrap; margin-right: 30px; }
  .detail-nav h2 { order: -1; width: 100%; font-size: 1.15rem; }
}

.widget-title { font-weight: 700; font-size: 0.9rem; color: var(--ink); margin-right: 2px; }

/* ---------- Metronome — one sleek row ---------- */
.metronome {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  margin: 16px 0;
  flex-wrap: wrap;
}
.metronome button { padding: 6px 14px; font-size: 0.88rem; border-radius: 999px; }
.metronome input[type="range"] { width: 120px; }
.metronome input[type="number"] {
  width: 46px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.85rem;
}
.beat-dots { display: flex; gap: 4px; flex-wrap: wrap; }
.beat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--line);
  transition: background 0.05s, transform 0.05s;
}
.beat-dot.on { background: var(--accent); transform: scale(1.2); }
.beat-dot.on.accent { background: var(--gold); transform: scale(1.4); }

/* ---------- Tanpura tuner ---------- */
.tanpura {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 16px;
  margin: 10px 0 16px;
  flex-wrap: wrap;
}
.tanpura-label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.tanpura-string {
  padding: 6px 12px;
  font-size: 0.85rem;
  border-radius: 999px;
}
.tanpura-string.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.tanpura-stop { font-size: 0.8rem; padding: 6px 12px; border-radius: 999px; color: var(--muted); }

/* ---------- Violin reference audio ---------- */
.violin-audio { margin-top: 16px; }
.violin-audio p { font-weight: 600; margin-bottom: 6px; }
.violin-audio audio { width: 100%; }

/* ---------- Category filter ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0;
}
.filters button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- Book collections ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
  margin: 4px 0 20px;
}
.book-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.book-card img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--accent-soft);
}
.book-card .book-card-body { padding: 12px 14px 16px; flex: 1; display: flex; flex-direction: column; }
.book-card h3 { margin: 0 0 6px; font-size: 1rem; }
.book-card p { margin: 0 0 12px; font-size: 0.85rem; color: var(--muted); flex: 1; }
.book-card .buy-link {
  display: inline-block;
  text-align: center;
  background: var(--gold);
  color: #fff;
  padding: 8px 0;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
}
.book-grid-empty { color: var(--muted); grid-column: 1 / -1; }

/* ---------- Admin dashboard ---------- */
.admin-login {
  max-width: 380px;
  margin: 80px auto;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  text-align: center;
}
.admin-login input {
  width: 100%;
  padding: 10px;
  margin: 8px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
}
.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 24px 0 16px;
}
.exercise-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper-raised);
}
.exercise-table th, .exercise-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.exercise-table th { background: var(--accent-soft); }
.exercise-table tr:hover { background: #faf6ec; }
.exercise-table .actions button { padding: 5px 10px; font-size: 0.82rem; margin-right: 4px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--paper-raised);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { margin-top: 0; }
.form-row { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-weight: 600; font-size: 0.88rem; }
.form-row input, .form-row select, .form-row textarea {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
}
.form-row textarea { font-family: var(--font-notation); min-height: 90px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.error-text { color: #b03030; font-size: 0.85rem; margin-top: 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 780px) {
  .topnav { flex-wrap: wrap; gap: 8px; }

  /* Single column already collapses via .exercise-columns' own mobile
     rule; notation/lyrics get a further size bump here since a phone
     screen no longer needs to fit 3 columns' worth of content side by
     side, so there's no reason to keep desktop's more conservative size. */
  .notation, .lyrics { font-size: 1.2rem; line-height: 1.55; }
  .exercise-link { font-size: 1.15rem; padding: 14px 4px; }
}
