/* ── Base ── */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0D0D1A;
    --bg2: #1A1A2E;
    --card: rgba(255,255,255,0.04);
    --border: rgba(255,255,255,0.06);
    --text: #fff;
    --text2: rgba(255,255,255,0.7);
    --text3: rgba(255,255,255,0.4);
    --text4: rgba(255,255,255,0.15);
    --accent: #E8A838;
    --accent-grad: linear-gradient(135deg, #E8A838, #D4782F);
    --danger: #FF4757;
    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
    background: linear-gradient(160deg, var(--bg) 0%, var(--bg2) 40%, #16213E 100%);
    color: var(--text);
    font-family: 'Pretendard', 'Noto Sans KR', -apple-system, sans-serif;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

#app {
    max-width: 520px;
    margin: 0 auto;
    padding: 20px;
    padding-top: calc(20px + var(--safe-top));
    padding-bottom: calc(80px + var(--safe-bottom));
}

/* ── Animations ── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.hidden { display: none !important; }

/* ── Header ── */
.header {
    text-align: center;
    padding: 16px 0 8px;
}
.header h1 {
    font-size: 26px;
    font-weight: 900;
    background: linear-gradient(90deg, #fff, rgba(255,255,255,0.6));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}
.header p {
    color: var(--text3);
    font-size: 12px;
    margin-top: 4px;
}

/* ── Mode Selector ── */
.mode-selector {
    display: flex;
    gap: 8px;
    margin: 16px 0;
    background: var(--card);
    border-radius: var(--radius);
    padding: 6px;
}
.mode-btn {
    flex: 1;
    padding: 10px 4px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
    color: var(--text3);
    font-size: 13px;
    font-weight: 700;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: all 0.3s;
    font-family: inherit;
}
.mode-btn .mode-icon { font-size: 20px; }
.mode-btn.active {
    background: var(--accent-grad);
    color: #fff;
}

/* ── Tab Selector ── */
.tab-selector {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}
.tab-btn {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
    background: transparent;
    color: var(--text3);
    font-size: 12px;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-family: inherit;
}
.tab-btn.active {
    background: rgba(255,255,255,0.1);
    color: #fff;
    border-bottom-color: var(--accent);
}
.tab-btn.disabled {
    color: var(--text4);
    cursor: default;
}

/* ── Tab Content ── */
.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }

/* ── Live Stats ── */
.live-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}
.stat-item { text-align: center; }
.stat-value { font-size: 36px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat-value.accent { color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text3); }

.volume-ring {
    width: 40px; height: 40px;
    border-radius: 50%;
    margin: 0 auto 4px;
    background: conic-gradient(var(--accent) 0deg, rgba(255,255,255,0.08) 0deg);
    display: flex;
    align-items: center;
    justify-content: center;
}
.volume-inner {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--bg2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
}

/* ── Canvas ── */
#pitch-canvas, #compare-canvas {
    width: 100%;
    height: 200px;
    border-radius: var(--radius-sm);
    background: rgba(0,0,0,0.3);
}
#compare-canvas { height: 180px; }

/* ── Record Button ── */
.record-btn-wrap {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}
.record-btn {
    width: 72px; height: 72px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--accent-grad);
    box-shadow: 0 0 30px rgba(232,168,56,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}
.record-btn.recording {
    background: linear-gradient(135deg, #FF4757, #FF6B81);
    box-shadow: 0 0 30px rgba(255,71,87,0.4);
    transform: scale(1.1);
    animation: pulse 1.5s ease infinite;
}
.rec-circle {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: #fff;
    transition: border-radius 0.2s;
}
.record-btn.recording .rec-circle {
    border-radius: 4px;
}

.hint {
    text-align: center;
    font-size: 12px;
    color: var(--text3);
    margin-top: -8px;
}

/* ── Result Card ── */
.result-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 16px;
    border: 1px solid var(--border);
    animation: fadeIn 0.5s ease;
}
.result-header {
    display: flex;
    align-items: center;
    gap: 20px;
}
.result-body { flex: 1; }
.result-body h3 { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.result-meta { font-size: 12px; color: var(--text3); margin-bottom: 8px; }
.feedback-item {
    font-size: 13px;
    color: var(--text2);
    margin-bottom: 4px;
    line-height: 1.5;
}

/* Score circle */
.score-wrap { position: relative; width: 130px; height: 130px; flex-shrink: 0; }
.score-wrap svg { width: 130px; height: 130px; }
.score-center {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    text-align: center;
}
.score-num { font-size: 32px; font-weight: 800; }
.score-label { font-size: 11px; color: var(--text3); margin-top: -2px; }

.compare-btn {
    width: 100%;
    margin-top: 16px;
    padding: 10px;
    border: none;
    border-radius: var(--radius-xs);
    background: var(--accent-grad);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
}

/* ── Upload Sources ── */
.source-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
}
.source-btn {
    flex: 1;
    padding: 18px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    font-family: inherit;
    color: var(--text);
}
.source-btn:active { transform: scale(0.97); }
.dropbox-btn {
    border-color: rgba(0,97,255,0.2);
    background: linear-gradient(135deg, rgba(0,97,255,0.1), rgba(0,97,255,0.05));
}
.source-label { font-size: 13px; font-weight: 700; color: rgba(255,255,255,0.6); }
.source-label.blue { color: #5B9BFF; }
.source-sub { font-size: 10px; color: rgba(255,255,255,0.3); }

.status-msg {
    text-align: center;
    padding: 10px;
    font-size: 12px;
    color: var(--text3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.file-info {
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
}
.file-info span:last-child {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.audio-player {
    width: 100%;
    border-radius: var(--radius-xs);
    height: 42px;
    filter: invert(0.85) hue-rotate(180deg);
    margin-bottom: 8px;
}

.spinner {
    text-align: center;
    padding: 40px;
    color: var(--text3);
}
.spin-circle {
    width: 40px; height: 40px;
    border: 3px solid var(--accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

/* ── Compare ── */
.section-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.compare-guide {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--text2);
    line-height: 1.7;
}
.compare-guide .guide-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.compare-guide strong { color: var(--text); }
.compare-legend {
    margin-top: 16px;
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 16px;
    border: 1px solid var(--border);
    font-size: 13px;
    color: var(--text2);
    line-height: 1.6;
}
.legend-dot {
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 4px;
}
.legend-dot.red { background: #FF6B6B; }
.legend-dot.accent { background: var(--accent); }
.legend-hint { margin-top: 8px; color: var(--text3); font-size: 12px; }

/* ── Tips ── */
.tips-toggle {
    width: 100%;
    margin-top: 20px;
    padding: 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--card);
    color: var(--text3);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
}
.tips-panel {
    margin-top: 8px;
    padding: 16px;
    background: var(--card);
    border-radius: var(--radius-sm);
    animation: fadeIn 0.3s ease;
}
.tip-item {
    padding: 8px 0;
    font-size: 13px;
    color: var(--text2);
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.tip-item:last-child { border-bottom: none; }
.tip-num {
    color: var(--accent);
    margin-right: 8px;
    font-weight: 700;
}

/* ── Install Banner ── */
.install-banner {
    position: fixed;
    bottom: 0;
    left: 0; right: 0;
    background: rgba(30,30,50,0.95);
    backdrop-filter: blur(10px);
    padding: 14px 20px;
    padding-bottom: calc(14px + var(--safe-bottom));
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text2);
    z-index: 100;
    animation: fadeIn 0.3s ease;
}
.install-banner button {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: var(--accent-grad);
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
}
.install-banner button.dismiss {
    background: transparent;
    color: var(--text3);
    padding: 8px;
}

/* ── Dropbox File Browser Modal ── */
.dbx-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 500;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}
.dbx-modal.open { display: flex; }
.dbx-dialog {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 460px;
    width: 90%;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.2s ease;
}
.dbx-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.dbx-title { font-size: 14px; font-weight: 700; }
.dbx-path { font-size: 11px; color: var(--text3); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dbx-close {
    background: none; border: none; color: var(--text3); cursor: pointer;
    font-size: 16px; padding: 4px 8px; border-radius: 6px;
}
.dbx-close:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.dbx-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}
.dbx-item {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    transition: background 0.15s;
}
.dbx-item:last-child { border-bottom: none; }
.dbx-item:hover { background: rgba(255,255,255,0.06); }
.dbx-item:active { background: rgba(255,255,255,0.1); }
.dbx-folder { color: var(--text2); font-weight: 600; }
.dbx-file { color: var(--text); }
.dbx-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.dbx-loading, .dbx-empty {
    padding: 32px 16px;
    text-align: center;
    font-size: 13px;
    color: var(--text3);
}

/* ── Server Busy Message ── */
.server-busy-msg {
    text-align: center;
    padding: 24px 16px;
    font-size: 14px;
    color: #ffb347;
    background: rgba(255,179,71,0.06);
    border: 1px solid rgba(255,179,71,0.15);
    border-radius: var(--radius-sm);
    line-height: 1.6;
}

/* ── Transcript Section ── */
.transcript-section {
    margin-top: 16px;
    background: rgba(0,0,0,0.2);
    border-radius: var(--radius-sm);
    padding: 14px;
    border: 1px solid var(--border);
}
.transcript-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text2);
}
.transcript-text {
    font-size: 13px;
    color: var(--text2);
    line-height: 1.6;
}
.segment-list {
    max-height: 240px;
    overflow-y: auto;
}
.segment-item {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.segment-item:last-child { border-bottom: none; }
.segment-item:hover { background: rgba(255,255,255,0.06); }
.segment-item.warning {
    background: rgba(255,71,87,0.08);
}
.segment-item.warning:hover {
    background: rgba(255,71,87,0.14);
}
.segment-time {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 11px;
    color: var(--accent);
    flex-shrink: 0;
    font-weight: 600;
}
.segment-text {
    font-size: 13px;
    color: var(--text);
    flex: 1;
    min-width: 0;
}
.segment-meta {
    font-size: 11px;
    color: var(--text3);
    width: 100%;
    padding-left: 52px;
}

/* ── Coaching ── */
.coaching-btn {
    width: 100%;
    margin-top: 12px;
    padding: 12px;
    border: none;
    border-radius: var(--radius-xs);
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.2s;
}
.coaching-btn:hover { opacity: 0.9; }
.coaching-btn:disabled { opacity: 0.6; cursor: default; }

.coaching-panel {
    margin-top: 12px;
    background: rgba(102,126,234,0.06);
    border: 1px solid rgba(102,126,234,0.15);
    border-radius: var(--radius-sm);
    padding: 16px;
    animation: fadeIn 0.3s ease;
}
.coaching-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 10px;
    color: #a78bfa;
}
.coaching-content {
    font-size: 13px;
    color: var(--text2);
    line-height: 1.7;
}
.coaching-content h2, .coaching-content h3, .coaching-content h4 {
    font-size: 14px;
    font-weight: 700;
    margin: 12px 0 6px;
    color: var(--text);
}
.coaching-content ul {
    padding-left: 18px;
    margin: 6px 0;
}
.coaching-content li {
    margin-bottom: 4px;
}
.coaching-content strong {
    color: var(--text);
}
.coaching-loading {
    text-align: center;
    padding: 20px;
    font-size: 13px;
    color: var(--text3);
}
.coaching-error {
    padding: 12px;
    font-size: 13px;
    color: #ff6b6b;
    text-align: center;
}

/* ── Progress Bars ── */
.progress-container {
    padding: 16px;
    background: var(--card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    text-align: left;
    display: block;
    width: 100%;
}
.progress-step {
    margin-bottom: 14px;
}
.progress-step:last-child {
    margin-bottom: 0;
}
.progress-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text3);
    margin-bottom: 6px;
    transition: color 0.3s;
}
.progress-step.active .progress-label {
    color: var(--text);
}
.progress-step.done .progress-label {
    color: var(--text3);
}
.progress-pct {
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}
.progress-track {
    height: 6px;
    background: rgba(255,255,255,0.06);
    border-radius: 3px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-grad);
    border-radius: 3px;
    transition: width 0.4s ease;
}
.progress-step.done .progress-fill {
    background: rgba(255,255,255,0.15);
    transition: background 0.3s ease;
}
.progress-fill.indeterminate {
    animation: indeterminate 1.5s ease infinite;
}
@keyframes indeterminate {
    0% { opacity: 1; }
    50% { opacity: 0.35; }
    100% { opacity: 1; }
}

/* ── Mode Colors ── */
body.mode-singing {
    --accent: #7C5CFC;
    --accent-grad: linear-gradient(135deg, #7C5CFC, #5C3FD4);
}
body.mode-pronunciation {
    --accent: #2ABFBF;
    --accent-grad: linear-gradient(135deg, #2ABFBF, #1A8F8F);
}
