/* ===========================================================
   Montgomery Practice Studio — piano theme
   Deep charcoal + ivory keys + warm gold. Refined, not kiddish.
   Mobile / iPad first.
   =========================================================== */

:root {
  --bg: #14131a;
  --bg-2: #1c1b25;
  --panel: #20202c;
  --panel-2: #272735;
  --ivory: #f4efe6;
  --ivory-dim: #cfc9bd;
  --muted: #8b8798;
  --line: #322f3d;
  --gold: #c9a24b;
  --gold-soft: #e3c477;
  --green: #4caf6d;
  --yellow: #e0b341;
  --red: #d8553f;
  --grey: #6b6878;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --tap: 44px;
  --maxw: 760px;
  font-size: 17px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ivory);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}
body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(201,162,75,.10), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; letter-spacing: .2px; }
.hidden { display: none !important; }
.accent { color: var(--gold-soft); }

/* ===================== Passphrase Gate ===================== */
.gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(16,15,21,.80), rgba(16,15,21,.93)),
    url("/piano-practice/images/gate-piano.jpg") center/cover no-repeat,
    #100f15;
  z-index: 50;
}
.gate-card {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 34px 26px 30px;
  text-align: center;
  box-shadow: var(--shadow);
}
.gate-keys {
  height: 26px; margin: 0 auto 20px; max-width: 220px;
  border-radius: 4px;
  background:
    repeating-linear-gradient(90deg, #f4efe6 0 13px, #14131a 13px 15px);
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.25), 0 3px 8px rgba(0,0,0,.4);
}
.gate-card h1 { font-size: 1.7rem; margin: 0 0 6px; line-height: 1.15; }
.gate-sub { color: var(--muted); margin: 0 0 22px; font-size: .95rem; }
.gate input {
  width: 100%; height: 52px; padding: 0 16px;
  background: var(--bg); color: var(--ivory);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: 1.05rem; text-align: center; margin-bottom: 14px;
}
.gate input:focus { outline: none; border-color: var(--gold); }
.gate button {
  width: 100%; height: 52px; border: none; border-radius: 12px;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: #2a2310; font-weight: 700; font-size: 1.05rem; cursor: pointer;
}
.gate-error { color: var(--red); min-height: 20px; margin: 12px 0 0; font-size: .9rem; }

/* ===================== App shell ===================== */
.app { max-width: var(--maxw); margin: 0 auto; padding: 0 16px 60px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 0 12px;
  background: linear-gradient(180deg, var(--bg) 70%, rgba(20,19,26,0));
  backdrop-filter: blur(4px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-size: 1.7rem; color: var(--gold-soft);
  width: 44px; height: 44px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 700; letter-spacing: 2px; font-size: .82rem; color: var(--ivory); }
.brand-sub { color: var(--muted); font-size: .72rem; letter-spacing: 2px; text-transform: uppercase; }

.child-pills { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.child-pill {
  flex: none; min-height: var(--tap); padding: 8px 18px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ivory-dim);
  font-size: .98rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.child-pill.active {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: #2a2310; border-color: transparent;
}

.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ===================== Instrument tabs ===================== */
.instrument-row { display: flex; align-items: center; gap: 8px; margin: 6px 0 4px; }
.instrument-tabs { display: flex; gap: 6px; overflow-x: auto; flex: 1; }
.inst-tab {
  flex: none; min-height: 40px; padding: 6px 16px;
  border: none; border-bottom: 2px solid transparent;
  background: transparent; color: var(--muted);
  font-size: 1rem; font-weight: 600; text-transform: capitalize; cursor: pointer;
}
.inst-tab.active { color: var(--gold-soft); border-bottom-color: var(--gold); }
.icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--ivory-dim); font-size: 1.2rem; cursor: pointer;
}

/* ===================== List ===================== */
.list-toolbar { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 6px; }
.list-toolbar h2 { font-size: 1.15rem; margin: 0; color: var(--ivory); }
.primary-btn {
  min-height: var(--tap); padding: 9px 16px; border: none; border-radius: 12px;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: #2a2310; font-weight: 700; font-size: .95rem; cursor: pointer;
}
.ghost-btn {
  min-height: var(--tap); padding: 9px 16px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--ivory-dim); font-weight: 600; font-size: .95rem; cursor: pointer;
}
.danger-btn {
  min-height: var(--tap); padding: 9px 16px; border: 1px solid rgba(216,85,63,.5); border-radius: 12px;
  background: rgba(216,85,63,.12); color: #f0a594; font-weight: 600; font-size: .95rem; cursor: pointer;
}

.section-label {
  display: flex; align-items: center; gap: 10px;
  margin: 22px 0 8px; color: var(--gold-soft);
  font-size: .78rem; letter-spacing: 2px; text-transform: uppercase; font-weight: 700;
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Song row */
.song-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 14px; margin-bottom: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer;
  transition: transform .08s ease, border-color .15s ease;
}
.song-row:active { transform: scale(.99); }
.song-row.priority { border-color: rgba(201,162,75,.45); }
.song-main { flex: 1; min-width: 0; }
.song-title { font-size: 1.05rem; font-weight: 600; color: var(--ivory); margin-bottom: 6px; word-break: break-word; }
.plays { display: flex; flex-wrap: wrap; gap: 5px 12px; }
.play { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .82rem; }
.never { color: var(--muted); font-size: .85rem; font-style: italic; }
.chev { color: var(--muted); font-size: 1.3rem; flex: none; }

/* Dots */
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; display: inline-block; box-shadow: 0 0 0 2px rgba(0,0,0,.25) inset; }
.dot-sm { width: 9px; height: 9px; }
.dot-md { width: 17px; height: 17px; }
.dot-lg { width: 26px; height: 26px; box-shadow: 0 0 0 3px rgba(0,0,0,.25) inset, 0 0 14px rgba(0,0,0,.35); }

/* Two labeled indicators (Score + Freshness) */
.indicators { display: flex; gap: 12px; flex: none; }
.ind { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 36px; }
.ind-lbl { font-size: .58rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.ind-legend { margin: 4px 0 14px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.leg-defs { display: flex; flex-wrap: wrap; gap: 2px 20px; color: var(--muted); font-size: .76rem; }
.leg-defs b { color: var(--gold-soft); font-weight: 700; }
.leg-key { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line); color: var(--muted); font-size: .74rem; }
.leg-key span { display: inline-flex; align-items: center; gap: 6px; }
.dot-key { width: 10px; height: 10px; box-shadow: none; }
.dot-green { background: var(--green); }
.dot-yellow { background: var(--yellow); }
.dot-red { background: var(--red); }
.dot-grey { background: var(--grey); }

.empty-state { color: var(--muted); text-align: center; padding: 48px 20px; line-height: 1.6; }
.updated-note { color: var(--muted); font-size: .75rem; text-align: center; margin-top: 18px; }

/* ===================== Detail view ===================== */
.back-btn { background: none; border: none; color: var(--gold-soft); font-size: 1rem; padding: 14px 0; cursor: pointer; }
.detail-header { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.detail-title-wrap { min-width: 0; }
.detail-header h2 { margin: 0; font-size: 1.45rem; word-break: break-word; }
.detail-meta { color: var(--muted); font-size: .85rem; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }
.history-heading { font-size: .95rem; color: var(--gold-soft); letter-spacing: 1px; text-transform: uppercase; margin: 0 0 12px; }

.log-entry {
  display: flex; gap: 12px; padding: 14px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; margin-bottom: 10px;
}
.log-entry .dot { margin-top: 4px; }
.log-body { flex: 1; min-width: 0; }
.log-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.log-when { font-weight: 600; color: var(--ivory); font-size: .98rem; }
.log-score { color: var(--ivory-dim); font-size: .85rem; font-weight: 600; }
.log-rel { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.log-notes { color: var(--ivory-dim); font-size: .92rem; margin-top: 8px; white-space: pre-wrap; line-height: 1.45; }
.log-edit { background: none; border: none; color: var(--muted); font-size: .8rem; cursor: pointer; padding: 6px 0 0; }

/* ===================== Modals ===================== */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(8,7,11,.6); padding: 0;
}
.modal-card {
  width: 100%; max-width: var(--maxw);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 22px 22px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow); animation: slideUp .2s ease;
  max-height: 92vh; overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-card h3 { margin: 0 0 4px; font-size: 1.25rem; }
.modal-song { color: var(--gold-soft); margin: 0 0 14px; font-size: .95rem; }
.field-label { display: block; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: 1px; margin: 16px 0 8px; }
.modal-card input[type=text], .modal-card input[type=datetime-local], .modal-card textarea {
  width: 100%; background: var(--bg); color: var(--ivory);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  font-size: 1rem; font-family: inherit;
}
.modal-card input:focus, .modal-card textarea:focus { outline: none; border-color: var(--gold); }
.modal-buttons { display: flex; gap: 10px; margin-top: 22px; }
.modal-buttons button { flex: 1; }
.confirm-text { color: var(--ivory-dim); line-height: 1.5; }
.log-delete { width: 100%; margin-top: 14px; background: none; border: none; color: #d8553f; font-size: .9rem; cursor: pointer; padding: 10px; }

/* Score picker 1-10 */
.score-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.score-btn {
  min-height: var(--tap); border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--ivory-dim);
  font-size: 1.05rem; font-weight: 700; cursor: pointer;
}
.score-btn.sel { background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: #2a2310; border-color: transparent; }

/* Segmented control */
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg-btn { flex: 1; min-height: 40px; border: none; border-radius: 9px; background: transparent; color: var(--ivory-dim); font-weight: 600; cursor: pointer; }
.seg-btn.active { background: var(--panel-2); color: var(--gold-soft); }

/* Instrument manager rows */
.inst-manage-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.inst-manage-row:last-child { border-bottom: none; }
.inst-name { text-transform: capitalize; font-weight: 600; }
.toggle-btn { min-height: 38px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--ivory-dim); font-weight: 600; cursor: pointer; }
.toggle-btn.on { background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: #2a2310; border-color: transparent; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 80;
  background: var(--panel-2); color: var(--ivory); border: 1px solid var(--line);
  padding: 12px 18px; border-radius: 999px; box-shadow: var(--shadow);
  font-size: .9rem; max-width: 90%;
}

/* ===================== Song counts ===================== */
.list-heading-wrap { min-width: 0; }
.song-counts { color: var(--muted); font-size: .8rem; margin-top: 3px; }
.song-counts .cnt-num { color: var(--ivory-dim); font-weight: 700; }
.song-counts .sep { opacity: .5; margin: 0 7px; }

/* ===================== Stats button in topbar ===================== */
.stats-btn {
  margin-left: auto; flex: none;
  min-height: 40px; padding: 7px 14px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line); color: var(--gold-soft);
  font-weight: 600; font-size: .85rem; cursor: pointer; white-space: nowrap;
}

/* ===================== Song timer ===================== */
.timer-row { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.timer-btn { flex: none; }
.timer-btn.running { background: linear-gradient(180deg, #e88a6f, var(--red)); color: #2a0f0a; }
.timer-display {
  font-variant-numeric: tabular-nums; font-size: 1.5rem; font-weight: 700;
  color: var(--ivory); font-family: ui-monospace, Menlo, monospace; letter-spacing: 1px;
}
.timer-display.running { color: var(--gold-soft); }
.log-dur { color: var(--gold-soft); font-size: .82rem; font-weight: 600; }

/* Checkbox row (log modal) */
.checkbox-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; cursor: pointer; color: var(--ivory-dim); font-size: 1rem; }
.checkbox-row input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--gold); flex: none; }

/* Metronome chip in history */
.metro-chip { display: inline-block; margin-top: 8px; padding: 2px 9px; border-radius: 999px; background: rgba(201,162,75,.14); border: 1px solid rgba(201,162,75,.4); color: var(--gold-soft); font-size: .72rem; font-weight: 600; }

/* ===================== Stats / goal ===================== */
.goal-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 8px 0 18px; }
.goal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.goal-today { font-size: 1.15rem; font-weight: 700; color: var(--ivory); }
.link-btn { background: none; border: none; color: var(--gold-soft); font-size: .85rem; cursor: pointer; padding: 6px 0; flex: none; }
.progress { height: 14px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--gold), var(--gold-soft)); transition: width .4s ease; }
.progress-fill.met { background: linear-gradient(90deg, #3c9a5b, var(--green)); }
.goal-sub { color: var(--muted); font-size: .85rem; margin-top: 10px; }

.range-seg { margin: 4px 0 18px; }
.chart { width: 100%; overflow: hidden; }
.chart svg { width: 100%; height: auto; display: block; }
.bar-rect { fill: var(--gold); }
.bar-rect.met { fill: var(--green); }
.bar-rect.today { fill: var(--gold-soft); }
.bar-label { fill: var(--muted); font-size: 11px; }
.bar-val { fill: var(--ivory-dim); font-size: 10px; }
.target-line { stroke: var(--red); stroke-width: 2; opacity: .9; }
.avg-line { stroke: var(--ivory-dim); stroke-width: 1.4; stroke-dasharray: 4 3; opacity: .8; }
.avg-label { fill: var(--ivory-dim); font-size: 9px; }
.chart-note { color: var(--muted); font-size: .78rem; text-align: center; margin-top: 8px; line-height: 1.7; }
.chart-note b { color: var(--ivory-dim); font-weight: 700; }
.lg-goal { color: var(--red); font-weight: 700; }
.lg-avg { color: var(--ivory-dim); letter-spacing: -1px; }

/* hours/minutes input row */
.hm-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.hm-row input { width: 70px; text-align: center; }
.hm-row span { color: var(--muted); font-size: .95rem; margin-right: 6px; }
.modal-card input[type=number], .modal-card input[type=date] {
  width: 100%; background: var(--bg); color: var(--ivory);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  font-size: 1rem; font-family: inherit; margin-bottom: 4px;
}

/* ===================== Larger screens (iPad landscape / desktop) ===================== */
@media (min-width: 720px) {
  :root { font-size: 18px; }
  .modal { align-items: center; padding: 24px; }
  .modal-card { border-radius: 22px; }
  .song-row { padding: 16px 18px; }
}
