@import url('https://fonts.googleapis.com/css2?family=Permanent+Marker&display=swap');

/* Interval Trainer Page */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    cursor: default;
}

input[type="text"], input[type="search"], input[type="password"],
input[type="email"], input[type="url"], input[type="number"],
input:not([type]), textarea { cursor: text; }

:root {
    --bg: #f2f2f7;
    --surface: #ffffff;
    --surface2: #f2f2f7;
    --border: #e0e0e5;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.07), 0 0 0 1px rgba(0,0,0,0.04);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.04);
    --text: #1c1c1e;
    --text-muted: #6b6b70;
    --accent: #d4622a;
    --accent-dim: rgba(212, 98, 42, 0.1);
    --green: #34c759;
    --green-dim: rgba(52, 199, 89, 0.12);
    --red: #ff3b30;
    --red-dim: rgba(255, 59, 48, 0.12);
    --radius: 12px;
    --header-h: 52px;
    --nav-h: 56px;
}

[data-theme="dark"] {
    --bg: #111113;
    --surface: #1c1c1e;
    --surface2: #252528;
    --border: #38383a;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
    --text: #f2f2f7;
    --text-muted: #98989e;
    --accent: #e0723a;
    --accent-dim: rgba(224, 114, 58, 0.15);
    --green: #30d158;
    --green-dim: rgba(48, 209, 88, 0.15);
    --red: #ff453a;
    --red-dim: rgba(255, 69, 58, 0.15);
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

body {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────── */
.sm-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    padding: 0 12px;
    z-index: 100;
    gap: 8px;
}

.sm-header-back {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--accent);
    padding: 4px 8px 4px 0;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
    display: flex;
    align-items: center;
}

.app-logo {
    width: 26px;
    height: 29px;
    flex-shrink: 0;
}

.app-name {
    font-family: 'Permanent Marker', cursive;
    font-size: 17px;
    color: var(--accent);
    white-space: nowrap;
    letter-spacing: 0.3px;
    flex-shrink: 0;
    line-height: 1;
}

.sm-header-title {
    font-size: 17px;
    font-weight: 700;
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sm-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

/* ── Instrument toggle ────────────────────────────────────── */
.sm-instrument-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 8px;
    color: var(--text-muted);
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s;
    display: flex;
    align-items: center;
}
.sm-instrument-toggle:active { opacity: 0.7; }
.sm-instrument-toggle .hidden { display: none; }

.sm-instrument-wrap { position: relative; }
.sm-instrument-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--surface);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    overflow: hidden;
    z-index: 120;
    min-width: 130px;
}
.sm-instrument-menu.hidden { display: none; }
.sm-instrument-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}
.sm-instrument-option:hover { background: var(--accent-dim); }
.sm-instrument-option:active { opacity: 0.7; }
.sm-instrument-option.active {
    color: var(--accent);
    font-weight: 600;
}
.sm-instrument-option svg { flex-shrink: 0; }

/* ── Theme toggle ────────────────────────────────────────── */
.sm-theme-toggle {
    background: none;
    border: none;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 8px;
    color: var(--text-muted);
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s;
}
.sm-theme-toggle:active { opacity: 0.7; }
.sm-theme-toggle::before { content: '\263D'; }
[data-theme="dark"] .sm-theme-toggle::before { content: '\2600'; }

[data-theme="dark"] .sm-header {
    background: var(--surface);
    border-bottom-color: var(--border);
}
[data-theme="dark"] .sm-nav {
    background: var(--surface);
    border-top-color: var(--border);
}

/* ── Main content ─────────────────────────────────────────── */
.intervals-main {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: calc(var(--header-h) + 16px) 16px calc(var(--nav-h) + 24px);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── Mode toggle (Learn / Quiz) ─────────────────────────── */
.mode-toggle {
    display: flex;
    gap: 0;
    background: var(--surface2);
    border-radius: 10px;
    padding: 3px;
    border: 1px solid var(--border);
}

.mode-btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    background: none;
    color: var(--text-muted);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s;
}

.mode-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.mode-btn:active { transform: scale(0.97); }

/* ── Learn mode ─────────────────────────────────────────── */
.view-learn {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.view-quiz {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.view-learn.hidden, .view-quiz.hidden { display: none; }

.learn-intro {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.5;
    text-align: center;
    padding: 0 8px;
}

.learn-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.learn-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 14px;
}

.learn-card:active { transform: scale(0.98); }

.learn-card.playing {
    border-color: var(--accent);
    background: var(--accent-dim);
}

.learn-card-play {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.learn-card-play svg {
    width: 16px;
    height: 16px;
    margin-left: 2px;
}

.learn-card-info {
    flex: 1;
    min-width: 0;
}

.learn-card-top {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.learn-card-short {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

.learn-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.learn-card-ref {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 3px;
}

.learn-card-character {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 2px;
}

.learn-card-notes {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    margin-top: 3px;
    min-height: 18px;
    transition: opacity 0.2s;
}

.learn-compare-hint {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    opacity: 0.7;
    font-style: italic;
    padding: 0 8px;
    transition: opacity 0.3s;
}

.learn-compare-hint.hidden {
    display: none;
}

.learn-diagram-section {
    margin-top: 4px;
    text-align: center;
}

.learn-diagram-section .fretboard-svg {
    max-width: 100%;
    width: 100%;
}

/* ── Stats bar ───────────────────────────────────────────── */
.stats-bar {
    display: flex;
    gap: 8px;
}

.stat-card {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.stat-value.streak { color: var(--accent); }
.stat-value.correct { color: var(--green); }
.stat-value.total-pct { color: var(--text); }

/* ── Level selector ──────────────────────────────────────── */
.level-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.level-btn {
    flex: 1;
    min-width: 0;
    padding: 8px 4px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    background: var(--surface);
    color: var(--text-muted);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.15s;
}

.level-btn.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
}

.level-btn:active { transform: scale(0.95); }

/* ── Direction toggle ────────────────────────────────────── */
.direction-row {
    display: flex;
    gap: 8px;
}

.dir-btn {
    flex: 1;
    padding: 8px 6px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    background: var(--surface);
    color: var(--text-muted);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.15s;
}

.dir-btn.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
}

.dir-btn:active { transform: scale(0.95); }

/* ── Play area ───────────────────────────────────────────── */
.play-area {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.play-prompt {
    font-size: 14px;
    color: var(--text-muted);
    text-align: center;
}

.play-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(212, 98, 42, 0.35);
    transition: transform 0.12s, box-shadow 0.12s;
    -webkit-tap-highlight-color: transparent;
}

.play-btn:active {
    transform: scale(0.92);
    box-shadow: 0 1px 5px rgba(212, 98, 42, 0.25);
}

.play-btn svg {
    width: 28px;
    height: 28px;
}

.play-btn.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Note display */
.note-display {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 28px;
    font-weight: 700;
    min-height: 40px;
}

.note-name {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 14px;
    min-width: 52px;
    text-align: center;
}

.note-arrow {
    color: var(--text-muted);
    font-size: 20px;
}

.note-name.hidden-note {
    color: transparent;
    background: var(--surface2);
}

/* ── Answer grid ─────────────────────────────────────────── */
.answer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
}

.answer-btn {
    padding: 14px 8px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    background: var(--surface);
    color: var(--text);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.15s;
    line-height: 1.3;
}

.answer-btn:active { transform: scale(0.96); }

.answer-btn.correct {
    background: var(--green-dim);
    border-color: var(--green);
    color: var(--green);
}

.answer-btn.wrong {
    background: var(--red-dim);
    border-color: var(--red);
    color: var(--red);
}

.answer-btn.reveal {
    background: var(--green-dim);
    border-color: var(--green);
    color: var(--green);
    opacity: 0.7;
}

.answer-btn:disabled {
    pointer-events: none;
}

/* ── Feedback strip ──────────────────────────────────────── */
.feedback-strip {
    width: 100%;
    text-align: center;
    min-height: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.feedback-result {
    font-size: 16px;
    font-weight: 700;
    opacity: 0;
    transition: opacity 0.2s;
}

.feedback-result.show { opacity: 1; }
.feedback-result.is-correct { color: var(--green); }
.feedback-result.is-wrong { color: var(--red); }

.feedback-hint {
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.2s;
}

.feedback-hint.show { opacity: 1; }

/* ── Fretboard diagram ───────────────────────────────────── */
.fretboard-section {
    width: 100%;
}

.fretboard-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
    text-align: center;
}

.fretboard-svg {
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
    display: block;
}

/* ── Toast ────────────────────────────────────────────────── */
.intervals-toast {
    position: fixed;
    bottom: calc(var(--nav-h) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--text);
    color: var(--bg);
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 200;
}

.intervals-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.hidden { display: none !important; }

/* ── Bottom Nav ──────────────────────────────────────────── */
.sm-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.sm-nav-btn {
    flex: 1;
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 0;
    color: var(--text-muted);
    font: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s;
    cursor: pointer;
    text-decoration: none;
}

.sm-nav-btn.active { color: var(--accent); }
.sm-nav-btn:active { opacity: 0.7; }

svg.sm-nav-icon {
    width: 24px;
    height: 24px;
    stroke-width: 1.5;
    transition: stroke-width 0.2s ease, transform 0.15s ease;
}

.sm-nav-btn.active svg.sm-nav-icon {
    stroke-width: 2.5;
}

.sm-nav-btn:active svg.sm-nav-icon {
    transform: scale(0.9);
}

.sm-nav-label { font-size: 10px; font-weight: 600; letter-spacing: 0.3px; text-transform: uppercase; }

/* ── Desktop tweaks ──────────────────────────────────────── */
@media (min-width: 600px) {
    .intervals-main {
        max-width: 540px;
        margin: 0 auto;
    }
    .answer-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
}
