/* FitNote Karaoke Studio — design system
   Deep navy / peacock surfaces, gold accent, warm coral used sparingly.
   Fluid shell (max 1440px), responsive: desktop ≥1024, tablet 721–1023,
   phone ≤720 (bottom tab bar), song rows ≤640. */

:root {
  --bg: #050f24;
  --bg-2: #081a3d;
  --panel: #0b2148;
  --panel-2: #0e2a5c;
  --panel-3: #081733;
  --line: rgba(148, 178, 255, 0.16);
  --line-gold: rgba(240, 193, 75, 0.35);
  --text: #f6f2e7;
  --muted: #a7b4d4;
  --gold: #f0c14b;
  --gold-2: #ffd97a;
  --gold-ink: #241a02;
  --coral: #ff8a66;
  --danger: #ff6b6b;
  --radius: 16px;
  --header-h: 69px;
  --gutter: clamp(14px, 3vw, 32px);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 550px at 88% -10%, rgba(240, 193, 75, 0.10), transparent 60%),
    radial-gradient(900px 520px at -12% 4%, rgba(64, 140, 255, 0.13), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 42%, #040b1c);
  background-color: var(--bg);
  min-height: 100vh;
  overflow-x: clip;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9em; }
::selection { background: var(--gold); color: var(--gold-ink); }

button {
  background: #122c5e;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  min-height: 42px;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
button:hover:not(:disabled) { background: #173a7d; border-color: var(--line-gold); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary {
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  border-color: #d9a92f;
  color: var(--gold-ink);
  font-weight: 650;
}
button.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ffe08d, #f5cb5e); border-color: var(--gold); }

input, select {
  background: #0a1c3f;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  min-height: 44px;
  font: inherit;
  font-size: 0.95rem;
}
input:focus, select:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px rgba(240, 193, 75, 0.22); }
input[type="range"] { padding: 0; min-height: 28px; accent-color: var(--gold); vertical-align: middle; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--gold); }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ------------------------------------------------------------- header */
.topbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 12px;
  min-height: var(--header-h);
  padding: 12px var(--gutter);
  background: rgba(7, 20, 45, 0.94);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}
@media (min-width: 721px) {
  .topbar { background: rgba(7, 20, 45, 0.85); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 40px; height: 40px; border-radius: 10px; display: block; flex: none; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
.brand-text { min-width: 0; }
.brand-text h1, .topbar h1 {
  margin: 0;
  font-size: 1.22rem;
  line-height: 1.12;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tagline { color: var(--muted); font-size: 0.8rem; font-style: italic; white-space: nowrap; }
@media (max-width: 1100px) { .tagline { display: none; } }

.tabs {
  display: flex;
  gap: 4px;
  margin-left: auto;
  padding: 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 9px 15px;
  min-height: 44px;
  font-weight: 550;
  white-space: nowrap;
}
.tab:hover:not(:disabled) { background: rgba(255, 255, 255, 0.07); border-color: transparent; }
.tab.active {
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: var(--gold-ink);
  font-weight: 650;
}
.tab-icon { font-size: 1.02rem; line-height: 1; }
.tab[data-tab="record"] .tab-icon { color: var(--coral); }
.tab.active .tab-icon { color: inherit; }
#install-btn { flex: none; font-weight: 600; }
@media (max-width: 1100px) {
  .tab { padding: 9px 10px; }
  .brand-text h1, .topbar h1 { font-size: 1.08rem; }
  #install-btn { padding: 9px 10px; font-size: 0.88rem; }
}

/* ------------------------------------------------------------- shell */
#app { max-width: 1440px; margin: 0 auto; padding-inline: var(--gutter); }
.view { padding: 18px 0 28px; }

/* ------------------------------------------------------------- now playing */
.now-playing {
  margin-top: 16px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line-gold);
  border-radius: 18px;
  padding: clamp(12px, 2vw, 20px);
  box-shadow: var(--shadow);
}
.np-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: flex-start; }
.np-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--gold); font-weight: 700; }
.np-title { font-size: clamp(1.05rem, 2.2vw, 1.35rem); font-weight: 650; line-height: 1.25; margin-top: 2px; }
.np-meta { color: var(--muted); font-size: 0.9em; margin-top: 2px; }
.np-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.np-actions button { min-height: 44px; }
.player-wrap { position: relative; margin-top: 12px; aspect-ratio: 16 / 9; background: #000; border-radius: 12px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06); }
#player-holder { position: absolute; inset: 0; }
.player-wrap iframe { width: 100%; height: 100%; border: 0; display: block; }
.player-error { position: absolute; inset: 0; background: rgba(5, 10, 22, 0.95); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 20px; z-index: 2; }

/* ------------------------------------------------------------- library */
.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(12px, 2vw, 18px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.25);
}
@media (min-width: 721px) {
  .controls {
    position: sticky;
    top: calc(var(--header-h) + 10px);
    z-index: 10;
    background: rgba(11, 33, 72, 0.88);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }
}
#search { width: 100%; font-size: 1.02rem; min-height: 52px; padding: 12px 16px; border-radius: 12px; }
.filter-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.filter-row select { width: 100%; min-width: 0; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border-radius: 999px; padding: 8px 14px; min-height: 40px; }
.chip.active { background: linear-gradient(180deg, var(--gold-2), var(--gold)); border-color: #d9a92f; color: var(--gold-ink); font-weight: 650; }
#result-count { padding-inline: 2px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.song-card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
@media (hover: hover) {
  .song-card:hover { transform: translateY(-3px); border-color: var(--line-gold); box-shadow: 0 14px 28px rgba(0, 0, 0, 0.38); }
}
.song-card.playing { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset, 0 10px 24px rgba(0, 0, 0, 0.35); }
.song-card img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; background: #000; flex: none; }
.song-card .body { padding: 11px 13px 12px; display: flex; flex-direction: column; flex: 1; min-width: 0; }
.song-card .t {
  font-weight: 600; font-size: 0.96rem; line-height: 1.32;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.song-card .m { color: var(--muted); font-size: 0.82rem; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-card .foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: auto; padding-top: 8px; }
.song-card .foot .m { margin-top: 0; }
.heart {
  background: none; border: none; font-size: 1.3rem; line-height: 1;
  min-width: 44px; min-height: 44px; padding: 6px;
  display: grid; place-items: center;
  color: var(--muted); border-radius: 999px;
}
.heart:hover:not(:disabled) { background: rgba(255, 255, 255, 0.06); border-color: transparent; }
.heart.on { color: var(--coral); }
.badge { background: rgba(240, 193, 75, 0.14); color: var(--gold-2); border: 1px solid rgba(240, 193, 75, 0.25); border-radius: 999px; padding: 2px 9px; font-size: 0.72rem; text-transform: capitalize; white-space: nowrap; }

/* ------------------------------------------------------------- cards / record */
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(16px, 2.4vw, 22px);
  margin-bottom: 16px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
}
.card h2 { margin-top: 0; font-size: 1.08rem; letter-spacing: 0.01em; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 10px 0; }
.row label:has(input[type="range"]) { display: flex; align-items: center; gap: 10px; flex: 1 1 240px; }
.row label:has(input[type="range"]) input[type="range"] { flex: 1; min-width: 120px; }

/* selectable pills (mic input choice + monitor) */
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 9px 15px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer; font-size: 0.94rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.pill:hover { border-color: var(--line-gold); }
.pill:has(input:checked) { background: rgba(240, 193, 75, 0.14); border-color: var(--gold); }
.pill:focus-within { outline: 2px solid var(--gold); outline-offset: 2px; }
.pill input[type="radio"] {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px; margin: 0; flex: none;
  border-radius: 50%; border: 2px solid var(--muted); background: transparent;
}
.pill input[type="radio"]:checked { border-color: var(--gold); background: var(--gold); box-shadow: inset 0 0 0 3px var(--panel-3); }
.pill input[type="checkbox"] { width: 17px; height: 17px; margin: 0; flex: none; }

.vu { flex: 1; min-width: 120px; height: 14px; background: #050d1f; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.vu > div { height: 100%; width: 0%; background: linear-gradient(90deg, #22c55e 60%, #eab308 80%, #ef4444); transition: width 60ms linear; }
.clip { color: var(--danger); font-weight: 700; font-size: 0.8rem; }
.lyrics { background: #060f26; border: 1px solid var(--line); border-radius: 12px; padding: 16px; text-align: center; margin: 12px 0; }
.lyric-cur { font-size: clamp(1.15rem, 2.6vw, 1.4rem); font-weight: 600; line-height: 1.5; }
.lyric-next { font-size: 1rem; margin-top: 4px; }

#capture-panel { background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-top: 12px; }
#capture-panel .row input { flex: 1 1 180px; }
#sing-result, #studio-result { margin-top: 12px; }
#sing-result audio, #studio-result audio { width: 100%; display: block; margin: 10px 0; }

@media (min-width: 1024px) {
  #view-record { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
  #view-record .card { margin-bottom: 0; }
  #view-record .card-studio { grid-column: 1 / -1; }
}

/* ------------------------------------------------------------- takes */
.take {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(14px, 2.2vw, 20px);
  margin-bottom: 14px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
}
.take h3 { margin: 0 0 4px; font-size: 1.06rem; line-height: 1.3; }
.take audio { width: 100%; margin: 10px 0; display: block; }
.take .editor { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.take .editor label {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.9rem;
}
.take .editor label input[type="range"] { width: 110px; }
.take .editor .t-offset { width: 84px; min-height: 38px; }
.take .downloads { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.take .downloads button { min-height: 40px; }

/* ------------------------------------------------------------- about / footer */
.about h2 { margin-top: 28px; font-size: 1.25rem; }
.about p, .about ul { line-height: 1.65; max-width: 70ch; }
.about ul { line-height: 1.75; }
.popular { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 34px; max-width: none; }
.popular li { padding: 5px 0; border-bottom: 1px solid rgba(148, 178, 255, 0.08); }
.popular a { color: #d9c98f; text-decoration: none; }
.popular a:hover { color: var(--gold-2); text-decoration: underline; }
.site-footer {
  padding: 20px var(--gutter) 34px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9em;
  max-width: 1440px;
  margin: 0 auto;
}
.site-footer strong { color: var(--text); }

/* ------------------------------------------------------------- overlays */
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  max-width: min(92vw, 560px); text-align: center;
  background: #122c5e; border: 1px solid var(--line-gold); color: var(--text);
  padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 60;
}
#scroll-sentinel { height: 4px; }
.ios-hint {
  position: fixed; left: 12px; right: 12px; bottom: 14px;
  background: var(--bg-2); border: 1px solid var(--line-gold); border-radius: 12px;
  padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
  z-index: 60;
}
.ios-hint button { flex: none; min-height: 40px; }

/* ------------------------------------------------------------- tablet */
@media (max-width: 1023px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
  .filter-row { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .filter-row select { grid-column: span 2; }
  .filter-row select:nth-child(4), .filter-row select:nth-child(5) { grid-column: span 3; }
  .popular { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ------------------------------------------------------------- phone */
@media (max-width: 720px) {
  body { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
  input, select { font-size: 16px; } /* prevents iOS focus zoom */
  input[type="range"] { min-height: 36px; }

  .topbar { padding: 10px 12px; min-height: 56px; gap: 10px; }
  .brand-logo { width: 32px; height: 32px; border-radius: 8px; }
  .brand-text h1, .topbar h1 { font-size: 1.02rem; }
  .tagline { display: none; }
  #install-btn { margin-left: auto; min-height: 40px; }

  /* tab nav becomes a fixed bottom tab bar */
  .tabs {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    margin: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: rgba(7, 20, 45, 0.97);
    border: none;
    border-top: 1px solid var(--line);
    border-radius: 0;
  }
  .tab {
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    min-height: 54px;
    padding: 6px 2px;
    font-size: 0.72rem;
    font-weight: 550;
    border-radius: 12px;
    color: var(--muted);
  }
  .tab-icon { font-size: 1.2rem; }
  .tab.active { background: rgba(240, 193, 75, 0.14); color: var(--gold); }

  .view { padding: 14px 0 22px; }
  .now-playing { margin-top: 12px; }

  /* now-playing actions: tidy grid, Record prominent and full-width */
  .np-actions { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; width: 100%; }
  .np-actions #np-record { grid-column: 1 / -1; order: -3; }
  .np-actions #np-prev { grid-column: span 2; order: -2; }
  .np-actions #np-next { grid-column: span 2; order: -2; }
  .np-actions #np-close { grid-column: span 2; order: -2; }
  .np-actions #np-copy { grid-column: 1 / -1; order: -1; }
  .np-head > div:first-child { width: 100%; }

  .chips { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }

  .filter-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-row select { grid-column: auto; }
  .filter-row select:nth-child(4) { grid-column: auto; }
  .filter-row #f-sort { grid-column: 1 / -1; }

  .toast { bottom: calc(82px + env(safe-area-inset-bottom)); }
  .ios-hint { bottom: calc(76px + env(safe-area-inset-bottom)); }

  .take .editor label { flex: 1 1 150px; }
  .take .editor label input[type="range"] { flex: 1; width: auto; min-width: 80px; }
  .take .downloads button { flex: 1 1 auto; }
}

/* song cards become horizontal list rows for fast scanning */
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; gap: 10px; }
  .song-card { flex-direction: row; align-items: stretch; }
  .song-card img { width: 128px; height: 100%; aspect-ratio: auto; }
  .song-card .body { padding: 9px 6px 9px 12px; }
  .song-card .t { font-size: 0.93rem; }
  .popular { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
