/* AF-träning — shares the site design tokens from /theme.css (linked before this
   file) and the Wavelets/BPM/Keyboard component style. Covers the mode-chooser
   landing and the individual mode pages. Swedish UI (audience: AF Musikklasser
   applicants in Stockholm). */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation; /* no double-tap-to-zoom on fast taps */
}

.app {
  min-height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* Header — small, uppercase, dim, spaced, like the rest of the family. */
.topbar {
  padding: env(safe-area-inset-top, 16px) 16px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}
.topbar h1 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.topbar .spacer { flex: 1; }
/* Language switch (flags), injected into the topbar by i18n.js */
.lang-switch { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.lang-switch .lang-flag {
  appearance: none; border: 1px solid transparent; background: transparent;
  padding: 2px; border-radius: 4px; cursor: pointer; line-height: 0; opacity: 0.45;
}
.lang-switch .lang-flag img { display: block; border-radius: 2px; }
.lang-switch .lang-flag.active { opacity: 1; border-color: var(--border); }
.lang-switch .lang-flag:active { background: var(--surface-active); }

/* Help bar (bottom of the landing page) + About overlay — matches wavelets/keyboard. */
.help-bar { display: flex; justify-content: center; padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 20px); flex: 0 0 auto; }
.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 1.2rem; font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--surface-active); color: var(--text); border-color: var(--accent-dim); }
/* Octave toggle (start page): smaller circle, bigger clef glyph. */
.octave-toggle { width: 34px; height: 34px; font-size: 1.8rem; color: var(--accent); padding-bottom: 3px; }

/* Start-note picker + labels (prepared-song / Valfri sång pages). Must live here,
   not in a page <style> block — the site CSP blocks inline styles. */
.picker { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 999px; padding: 4px 6px; }
.picker .pbtn { appearance: none; border: none; background: transparent; color: var(--accent); font-size: 1.1rem; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; }
.picker .pbtn:active { background: var(--surface-active); }
.picker .pval { min-width: 3ch; text-align: center; font-weight: 700; font-size: 1.1rem; color: var(--text); font-variant-numeric: tabular-nums; }
.plabel { color: var(--text-dim); font-size: 0.9rem; align-self: center; }
.row[hidden] { display: none; }           /* .row sets display:flex, which outranks the UA [hidden] rule */
.row.prep-column { flex-direction: column; } /* Valfri sång: song picker on its own row above the controls */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 24px; z-index: 10;
}
.overlay[hidden] { display: none; }
.about-panel {
  position: relative;
  background: var(--bg-panel);
  border-radius: 20px;
  padding: 28px 24px;
  max-width: 480px; max-height: 80vh;
  overflow-y: auto;
}
.about-panel h2 { margin: 0 0 16px; font-size: 1.25rem; color: var(--text); }
.about-panel h3 { margin: 20px 0 6px; font-size: 0.95rem; color: var(--accent); }
.about-panel h3:first-of-type { margin-top: 0; }
.about-panel p { margin: 0 0 8px; font-size: 0.92rem; line-height: 1.55; color: var(--text-dim); }
.about-panel p.exercise { margin: 0 0 10px; }
.about-panel strong { color: var(--text); font-weight: 600; }
.about-panel a { color: var(--accent); }
.about-close {
  position: absolute;
  top: 12px; right: 12px;
  appearance: none; border: none; background: transparent;
  color: var(--text-dim);
  font-size: 1.6rem; line-height: 1; cursor: pointer;
}
.about-close:active { color: var(--text); }
/* Back button (mode pages) */
.back-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 1.2rem; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none;
}
.back-btn:active { background: var(--surface-active); color: var(--text); }

.content {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 16px 16px;
  gap: 12px;
}

/* --- Mode chooser (index) --- */
.lede {
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 4px 2px 8px;
}
.lede a { color: var(--accent); }
.cards { display: flex; flex-direction: column; gap: 12px; }
.card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-panel);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.card:active { background: var(--surface-active); }
.card .emoji { font-size: 1.8rem; line-height: 1; width: 2rem; text-align: center; }
.card .body { flex: 1; min-width: 0; }
.card .title { font-size: 1.05rem; font-weight: 600; color: var(--text); }
.card .desc { font-size: 0.85rem; color: var(--text-dim); line-height: 1.4; margin-top: 2px; }
.card .chev { color: var(--text-dim); font-size: 1.2rem; }
.card.soon { opacity: 0.55; cursor: default; pointer-events: none; }
.badge {
  font-size: 0.65rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--bg); background: var(--accent-dim);
  padding: 2px 8px; border-radius: 999px; margin-left: 8px;
}

/* --- Shared controls --- */
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  align-self: center;
}
.seg button {
  appearance: none; border: none; background: transparent;
  color: var(--text-dim); font: inherit; font-size: 0.8rem; font-weight: 600;
  letter-spacing: 0.04em; padding: 8px 18px; cursor: pointer;
}
.seg button.active { background: var(--bg-panel); color: var(--accent); }

.primary-btn {
  appearance: none;
  border: 1px solid var(--accent-dim);
  background: transparent;
  color: var(--accent);
  font: inherit; font-size: 1rem; font-weight: 600;
  padding: 14px 28px; border-radius: 999px; cursor: pointer;
  align-self: center;
}
.primary-btn:active { background: var(--surface-active); color: var(--text); }
.primary-btn:disabled { opacity: 0.4; cursor: default; }
.ghost-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font: inherit; font-size: 0.85rem; font-weight: 600;
  padding: 10px 20px; border-radius: 999px; cursor: pointer;
  align-self: center;
}
.ghost-btn:active { background: var(--surface-active); color: var(--text); }

.status {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.95rem;
  min-height: 1.4em;
}
.status.go { color: var(--accent); font-weight: 600; }

/* --- Rhythm mode --- */
/* One fixed slot that holds EITHER the tap zone (session ongoing) or the result. */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.tap-zone {
  flex: 1 1 auto;
  min-height: 120px;
  border: 2px dashed var(--border);
  border-radius: 20px;
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  touch-action: none;
  user-select: none;
  padding: 20px;
}
.tap-zone[hidden] { display: none; }
.tap-zone.mic-tap { border-color: var(--accent-dim); color: var(--accent); }
.tap-zone.armed { border-color: var(--accent-dim); color: var(--accent); }
.tap-zone.live { font-size: 2.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tap-zone.flash { background: var(--surface-active); }
.row { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }
/* Reserve the controls row's height so the stage below doesn't jump when the
   play / "Kör igen" / "Kör ny" buttons appear or disappear. */
#controls { min-height: 50px; }

/* Report */
.report { display: flex; flex-direction: column; gap: 14px; }
.report[hidden] { display: none; }
.report canvas { width: 100%; height: auto; display: block; background: var(--bg-panel); border-radius: 14px; }
.contour-scroll { width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.report .contour-scroll canvas { max-width: none; }

/* Kid-friendly result header: "X av N rätt" + renhet-stars */
.verdict { text-align: center; display: flex; flex-direction: column; gap: 3px; }
.verdict .score { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.verdict .sub2 { font-size: 0.85rem; color: var(--text-dim); }
.verdict .stars { font-size: 1.15rem; letter-spacing: 3px; color: var(--accent); }
.verdict .stars .dim { color: var(--border); }
.verdict .cap { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-dim); }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px;
}
.metric .val { font-size: 1.5rem; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.metric .val.warn { color: var(--warn); }
.metric .val.bad { color: var(--danger); }
.metric .lbl { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.metric .sub { font-size: 0.8rem; color: var(--text-dim); }
.legend { display: flex; gap: 16px; justify-content: center; font-size: 0.78rem; color: var(--text-dim); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* --- Treklanger: sung-tone result rows (target -> what you sang) --- */
.tri-rows { display: flex; flex-direction: column; gap: 8px; }
.tri-row {
  display: grid;
  grid-template-columns: 2.4rem 1.1rem 1fr auto 1.4rem;
  align-items: center; gap: 10px;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px;
}
.tri-row .t-tgt { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.tri-row .t-arrow { color: var(--text-dim); }
.tri-row .t-sung { font-weight: 600; color: var(--accent); }
.tri-row .t-cents { color: var(--text-dim); font-size: 0.85rem; font-variant-numeric: tabular-nums; text-align: right; }
.tri-row .t-mark { text-align: center; font-weight: 700; color: var(--accent); }
.tri-row .t-sung.warn, .tri-row .t-cents.warn, .tri-row .t-mark.warn { color: var(--warn); }
.tri-row .t-sung.bad, .tri-row .t-cents.bad, .tri-row .t-mark.bad { color: var(--danger); }
