:root {
    --primary: #4A90D9;
    --primary-dark: #357ABD;
    --success: #4CAF50;
    --warning: #FF9800;
    --error: #F44336;
    --bg: #F5F7FA;
    --surface: #FFFFFF;
    --text: #2C3E50;
    --text-secondary: #7F8C8D;
    --border: #E0E6ED;
    --radius: 12px;
    --nav-height: 60px;
    --header-height: 56px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
}

.hidden { display: none !important; }
.screen { min-height: 100vh; min-height: 100dvh; }
.screen.active { display: flex; }

/* Login */
.login-container {
    margin: auto;
    padding: 2rem;
    text-align: center;
    width: 100%;
    max-width: 320px;
}
.login-container h1 {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 0.25rem;
}
.login-container p { color: var(--text-secondary); margin-bottom: 2rem; }
.login-container input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}
.login-container input:focus { border-color: var(--primary); }
.login-container button {
    width: 100%;
    padding: 14px;
    margin-top: 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.login-container button:active { background: var(--primary-dark); }
.error { color: var(--error); font-size: 0.875rem; margin-top: 0.5rem; }

/* Header */
#app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    z-index: 100;
}
#app-header h2 { font-size: 1.125rem; }

/* Main content */
#main-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}
#page-content {
    flex: 1;
    overflow-y: auto;
    padding: calc(var(--header-height) + 0.75rem) 1rem calc(var(--nav-height) + 0.75rem);
}
.page { display: none; }
.page.active { display: block; }

/* Bottom nav */
#bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--nav-height);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.65rem;
    cursor: pointer;
    transition: color 0.2s;
    gap: 2px;
}
.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 1.25rem; }

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* Practice page */
.prompt-card {
    background: var(--primary);
    color: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    text-align: center;
}
.prompt-card .prompt-korean {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 0.5rem;
}
.prompt-card .prompt-english {
    font-size: 0.85rem;
    opacity: 0.85;
}
.target-items {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.target-chip {
    background: #E3F2FD;
    color: var(--primary-dark);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
}

/* Record button */
.record-area { text-align: center; padding: 1rem 0; }
.record-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 4px solid var(--primary);
    background: white;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    transition: all 0.2s;
    position: relative;
}
.record-btn.recording {
    border-color: var(--error);
    background: var(--error);
    animation: pulse 1.5s infinite;
}
.record-btn.recording::after {
    content: '';
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 4px;
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
.record-label {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Feedback */
.feedback-section { margin-top: 1rem; }
.score-badge {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 1rem;
}
.score-high { background: #E8F5E9; color: #2E7D32; }
.score-mid { background: #FFF3E0; color: #E65100; }
.score-low { background: #FFEBEE; color: #C62828; }

.feedback-item {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}
.feedback-item:last-child { border-bottom: none; }
.feedback-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 6px;
    flex-shrink: 0;
}
.status-correct { background: var(--success); }
.status-incorrect { background: var(--error); }
.status-missing { background: var(--warning); }
.status-wrong_form { background: var(--warning); }
.feedback-text { flex: 1; }
.feedback-point { font-weight: 600; font-size: 0.9rem; }
.feedback-explanation { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }

.correction-box {
    background: #F1F8E9;
    border-radius: var(--radius);
    padding: 1rem;
    margin-top: 0.75rem;
}
.correction-box h4 { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.25rem; }
.correction-box p { font-size: 0.95rem; line-height: 1.5; }

.transcript-box {
    background: #FFF8E1;
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

/* Items page */
.search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.search-bar input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    outline: none;
}
.search-bar input:focus { border-color: var(--primary); }
.search-bar select {
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: white;
    font-size: 0.9rem;
}

.item-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.item-korean { font-size: 1.1rem; font-weight: 600; }
.item-english { font-size: 0.85rem; color: var(--text-secondary); margin-top: 2px; }
.item-meta {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.35rem;
}
.badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: #ECEFF1;
    color: var(--text-secondary);
}
.badge-level { background: #E3F2FD; color: var(--primary-dark); }
.badge-type { background: #F3E5F5; color: #7B1FA2; }

.mastery-ring {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* Stats page */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.stat-card {
    text-align: center;
    padding: 1rem;
}
.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
}
.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.mastery-bar {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    height: 28px;
    margin: 0.75rem 0;
}
.mastery-bar > div { transition: width 0.5s; }
.bar-mastered { background: var(--success); }
.bar-learning { background: var(--warning); }
.bar-struggling { background: var(--error); }
.bar-unseen { background: #E0E6ED; }

.mastery-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.8rem;
}
.legend-item { display: flex; align-items: center; gap: 0.35rem; }
.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Settings page */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-label { font-size: 0.9rem; }
.setting-row select, .setting-row input {
    padding: 8px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    background: white;
}

/* Review page */
.review-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.overdue-tag {
    font-size: 0.75rem;
    color: var(--error);
    font-weight: 600;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn:active { opacity: 0.8; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-block { width: 100%; }

/* Loading */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 0.75rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Formality selector */
.formality-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.formality-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: white;
    font-size: 0.8rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}
.formality-btn.active {
    border-color: var(--primary);
    background: #E3F2FD;
    color: var(--primary-dark);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { font-size: 0.9rem; }

/* Add item form */
.add-form {
    margin-bottom: 1rem;
}
.add-form input, .add-form select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    outline: none;
}
.add-form input:focus { border-color: var(--primary); }
.form-row {
    display: flex;
    gap: 0.5rem;
}
.form-row > * { flex: 1; }

/* API key section */
.api-key-status {
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    margin-bottom: 0.75rem;
}
.key-active { background: #E8F5E9; color: #2E7D32; }
.key-missing { background: #FFF3E0; color: #E65100; }
.api-key-input-row {
    display: flex;
    gap: 0.5rem;
}
.api-key-input-row input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: monospace;
    outline: none;
}
.api-key-input-row input:focus { border-color: var(--primary); }
.api-key-input-row .btn { padding: 10px 14px; font-size: 1rem; }
.api-key-msg {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
}
.msg-success { background: #E8F5E9; color: #2E7D32; }
.msg-error { background: #FFEBEE; color: #C62828; }
.msg-info { background: #E3F2FD; color: var(--primary-dark); }
