/* ==========================================================================
   Kalaallit meeqqanut erinarsuutaat — "warm songbook" theme
   Palette variables default to the "songbook-light" theme here; alternate
   themes re-point them in themes.css via [data-theme="…"]. Behaviour is in
   site.js; this file only styles the hooks it relies on.
   ========================================================================== */

:root {
  color-scheme: light;

  --font-serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino,
    "Book Antiqua", Georgia, serif;
  --font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* songbook-light palette (default) */
  --bg: #f3ead6;
  --bg-2: #efe4cd;
  --paper: #fffdf6;
  --ink: #2c2620;
  --ink-soft: #4c4238;
  --muted: #8a7c69;
  --line: #e6dabf;
  --line-strong: #d8c8a6;
  --accent: #2f7355;
  --accent-ink: #ffffff;
  --accent-soft: #e4efe6;
  --gold: #a3781d;
  --active: #fbe7bd;
  --active-bar: #d8a53f;
  --cat-meeqqanut: #2f7355;
  --cat-general: #3a6ea3;
  --cat-groovy: #8a4b7d;
  --shadow-sm: 0 1px 2px rgba(70, 52, 26, 0.08);
  --shadow: 0 1px 2px rgba(70, 52, 26, 0.06), 0 14px 30px -18px rgba(70, 52, 26, 0.35);

  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(1200px 500px at 100% -10%, var(--accent-soft), transparent 60%),
    linear-gradient(var(--bg), var(--bg-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.site-main {
  width: min(1060px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 64px;
}
.site-main.is-song { width: min(760px, calc(100% - 40px)); }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration: underline; }

h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.15;
  color: var(--ink);
  margin: 0;
}
.muted { color: var(--muted); }

/* -------- Header -------- */
.topline {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding-bottom: 20px;
  margin-bottom: 26px;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.topline::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 96px;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}
.is-index .topline h1 { font-size: clamp(2rem, 4.5vw, 2.9rem); letter-spacing: -0.01em; }
.topline h1 { font-size: clamp(1.7rem, 3.5vw, 2.3rem); }
.topline > div:first-child > .muted { margin-top: 6px; max-width: 52ch; }

.crumbs {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0 0 8px;
  color: var(--muted);
}
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

.toolbar { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.icon-btn {
  font-family: var(--font-sans);
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s, transform 0.05s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.icon-btn:active { transform: translateY(1px); }

/* -------- Search + category chips -------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-bottom: 26px;
}
.search-input {
  flex: 1 1 260px;
  min-width: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 12px 18px 12px 42px;
  box-shadow: var(--shadow-sm);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%238a7c69' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='6'/%3E%3Cpath d='M13 13l4 4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 15px center;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-family: var(--font-sans);
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 8px 15px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.active[data-cat="general"] { background: var(--cat-general); border-color: var(--cat-general); }
.chip.active[data-cat="groovy"] { background: var(--cat-groovy); border-color: var(--cat-groovy); }

/* -------- Song cards -------- */
.song-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}
.song-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  position: relative;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.song-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.12s ease;
}
.song-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: var(--line-strong);
  text-decoration: none;
}
.song-card:hover::before { opacity: 1; }
.song-card h2 { font-size: 1.2rem; font-weight: 600; }
.song-card-da {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--muted);
  font-size: 0.98rem;
}
.card-cats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.card-cat {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  background: transparent;
}
.card-cat[data-cat="meeqqanut"] { color: var(--cat-meeqqanut); border-color: var(--cat-meeqqanut); }
.card-cat[data-cat="general"] { color: var(--cat-general); border-color: var(--cat-general); }
.card-cat[data-cat="groovy"] { color: var(--cat-groovy); border-color: var(--cat-groovy); }

.credits {
  display: grid;
  gap: 3px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}
.credits div { display: flex; flex-wrap: wrap; gap: 4px; }
.credits dt { font-weight: 600; }
.credits dt::after { content: ":"; }
.credits dd { margin: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  margin-top: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--active);
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 600;
}
.badge::before { content: "\1F3B5"; }

.empty-msg { color: var(--muted); padding: 40px 0; text-align: center; font-style: italic; }

#footer-version {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

/* -------- Song page -------- */
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 26px 10px;
  box-shadow: var(--shadow-sm);
  margin-top: 4px;
}
.is-song .topline > div:first-child > .muted { font-family: var(--font-serif); font-style: italic; }

.video-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.video-btn {
  font-family: var(--font-sans);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink-soft);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.video-btn:hover { border-color: var(--accent); }
.video-btn.active { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }

.video-embed {
  margin: 0 0 18px;
  aspect-ratio: 16 / 9;
  width: 100%;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: #0d0d0f;
  border: 1px solid var(--line);
}
.video-embed iframe { display: block; width: 100%; height: 100%; border: 0; }
#sync-status { font-size: 0.85rem; margin: 0 0 14px; }

/* -------- Lyrics: shared -------- */
.lyrics { border-top: 1px solid var(--line); }
.line-label {
  display: block;
  margin-bottom: 5px;
  font-family: var(--font-sans);
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.line-note {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}
.chords {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--gold);
  letter-spacing: 0.02em;
}

/* Single-column (labelled) lyrics */
.lyrics.single .line { display: block; }
.lyrics.single .cell {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  white-space: pre-wrap;
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--ink);
}
.lyrics.single .line.active .cell {
  background: var(--active);
  box-shadow: inset 3px 0 0 var(--active-bar);
}

/* Parallel lyrics as verse blocks (Kalaallisut | Danish) */
.lyrics.parallel { display: flex; flex-direction: column; }
.verse {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 34px;
  padding: 16px 2px;
  border-bottom: 1px solid var(--line);
}
.verse-col { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.verse-kl .line { padding: 2px 8px; border-radius: 3px; }
.verse-kl .line.active {
  background: var(--active);
  box-shadow: inset 3px 0 0 var(--active-bar);
}
.kl-text { font-family: var(--font-serif); font-size: 1.08rem; color: var(--ink); white-space: pre-wrap; }
.verse-kl .chords { display: block; margin-bottom: 1px; white-space: pre-wrap; }
.da-line { color: var(--muted); font-size: 0.97rem; padding: 2px 0; white-space: pre-wrap; }

/* Reader-selected view modes (set on <html> as data-lyrics-view) */
html[data-lyrics-view="stacked"] .verse { grid-template-columns: 1fr; gap: 8px; }
html[data-lyrics-view="stacked"] .verse-da { padding-left: 8px; border-left: 2px solid var(--line-strong); }
html[data-lyrics-view="kl"] .verse { grid-template-columns: 1fr; }
html[data-lyrics-view="kl"] .verse-da { display: none; }
html[data-lyrics-view="da"] .verse { grid-template-columns: 1fr; }
html[data-lyrics-view="da"] .verse-kl { display: none; }
html[data-lyrics-view="da"] .da-line { font-family: var(--font-serif); font-size: 1.08rem; color: var(--ink); }

/* Clickable Kalaallisut words */
.kal-word { cursor: pointer; border-radius: 3px; transition: background 0.1s, box-shadow 0.1s; }
.kal-word:hover { background: var(--active); box-shadow: 0 0 0 2px var(--active); color: var(--ink); }

/* -------- Word lookup popup -------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 20, 12, 0.5);
  backdrop-filter: blur(2px);
  z-index: 50;
}
.word-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  width: min(380px, calc(100% - 32px));
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 24px 60px -12px rgba(20, 12, 4, 0.5);
}
.word-modal h3 { font-size: 1.4rem; margin: 0 0 14px; }
.word-modal .analyzer-btn {
  display: block;
  margin-bottom: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  text-align: center;
  font-size: 0.94rem;
  font-weight: 500;
}
.word-modal .analyzer-btn:hover { text-decoration: none; filter: brightness(1.05); }
.word-modal .row { display: flex; gap: 8px; margin-top: 14px; }
.word-modal button {
  flex: 1;
  font-family: var(--font-sans);
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.9rem;
}
.word-modal button:hover { border-color: var(--accent); color: var(--accent); }

/* -------- Settings popover -------- */
.settings-panel {
  position: fixed;
  top: 74px;
  right: 24px;
  z-index: 60;
  width: min(300px, calc(100% - 32px));
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.settings-row { display: flex; flex-direction: column; gap: 6px; }
.settings-row label {
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.settings-select {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}
.settings-hint { margin: 0; font-size: 0.78rem; color: var(--muted); }
.settings-hint a { color: var(--accent); }
.settings-save {
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 9px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
.settings-save:hover { filter: brightness(1.05); }

/* -------- Responsive -------- */
@media (max-width: 700px) {
  body { font-size: 16px; }
  .topline { flex-direction: column; }
  /* Side-by-side can't fit; stack unless the reader chose a single language. */
  html:not([data-lyrics-view="kl"]):not([data-lyrics-view="da"]) .verse {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  html:not([data-lyrics-view="kl"]):not([data-lyrics-view="da"]) .verse-da {
    padding-left: 8px;
    border-left: 2px solid var(--line-strong);
  }
  .panel { padding: 18px 18px 6px; }
  .settings-panel { right: 12px; left: 12px; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
