:root {
    --primary: #8B7CF6;
    --primary-dark: #755DE1;
    --accent: #68C7B8;
    --bg: #F8F6FF;
    --card-bg: rgba(255, 255, 255, 0.92);
    --text: #334155;
    --text-muted: #7A8194;
    --border: #E9E4FF;
    --danger: #FF7A7A;
    --radius: 18px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, #fdfbff 0%, #f6f2ff 45%, #eefbf8 100%);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at top left, rgba(139, 124, 246, 0.14), transparent 30%),
                radial-gradient(circle at bottom right, rgba(104, 199, 184, 0.16), transparent 30%);
    pointer-events: none;
    z-index: -1;
}

/* Improve readability on glass-like theme */
html { scroll-behavior: smooth; }


a { text-decoration: none; color: inherit; }

/* ---------- Auth ---------- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f7ebff 0%, #eaf7ff 50%, #eafbf7 100%);
    padding: 20px;
}
.auth-card {
    /* iPhone glass-ish */
    background: rgba(255, 255, 255, 0.60);
    padding: 40px;
    border-radius: 24px;
    width: 380px;
    box-shadow: 0 20px 60px rgba(116, 98, 220, 0.16);
    border: 1px solid rgba(255,255,255,0.65);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}
.brand { font-size: 24px; margin: 0; text-align: center; font-weight: 800; }
.brand span { color: var(--primary); }
.subtitle { text-align: center; color: var(--text-muted); margin-top: 6px; }

/* Glass tabs (login/register) */
.tabs {
    display: flex;
    margin: 24px 0 16px;
    border-radius: 16px;
    padding: 4px;
    border: 1px solid rgba(233, 228, 255, 0.9);
    background: rgba(255,255,255,0.35);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}
.tab {
    flex: 1;
    text-align: center;
    padding: 10px;
    color: var(--text-muted);
    font-weight: 700;
    border-radius: 12px;
    border: 1px solid transparent;
    background: transparent;
}
.tab.active {
    color: #fff;
    border-color: rgba(255,255,255,0.45);
    background: linear-gradient(135deg, rgba(139,124,246,0.95) 0%, rgba(104,199,184,0.95) 100%);
    box-shadow: 0 10px 24px rgba(139, 124, 246, 0.18);
}
.tab:hover { color: var(--primary); }

.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-size: 13px; font-weight: 600; margin-top: 8px; }

.auth-form input, .auth-form select {
    padding: 12px; border: 1px solid var(--border); border-radius: 12px; font-size: 14px; background: #fcfbff;
}
.auth-form button {
    margin-top: 20px; padding: 13px; background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    color: #fff; border: none; border-radius: 12px; font-weight: 700; font-size: 15px; cursor: pointer;
    box-shadow: 0 10px 24px rgba(139, 124, 246, 0.22);
}
.auth-form button:hover { transform: translateY(-1px); background: linear-gradient(135deg, var(--primary-dark) 0%, #5bb9a7 100%); }
.alert-error { background: #fff1f0; color: var(--danger); padding: 10px 14px; border-radius: 12px; font-size: 13px; margin-bottom: 10px; }

/* ---------- Navbar ---------- */
.navbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 32px; background: rgba(255,255,255,0.84); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10; backdrop-filter: blur(10px);
    box-shadow: 0 8px 20px rgba(117, 93, 225, 0.06);
}
.nav-brand { font-weight: 800; font-size: 18px; }
.nav-brand span { color: var(--primary); }
.nav-links { display: flex; align-items: center; gap: 24px; font-size: 14px; }
.nav-links a { color: var(--text-muted); font-weight: 600; transition: color .2s ease; }
.nav-links a:hover { color: var(--primary); }
.nav-user { color: var(--text); font-weight: 700; }
.nav-logout { color: var(--danger) !important; }

/* ---------- Layout ---------- */
.container { max-width: 980px; margin: 0 auto; padding: 32px 20px 80px; }
.section-title { margin: 32px 0 16px; font-size: 18px; font-weight: 700; }
.back-link { display: inline-block; margin-bottom: 16px; color: var(--text-muted); font-weight: 600; font-size: 14px; }
.subtitle-page { color: var(--text-muted); }

/* ---------- Stats ---------- */
.stats-row { display: flex; gap: 16px; flex-wrap: wrap; }
.stat-card {
    flex: 1; min-width: 140px; background: var(--card-bg); border-radius: var(--radius);
    padding: 18px 20px; display: flex; align-items: center; gap: 14px; box-shadow: 0 10px 24px rgba(139, 124, 246, 0.08);
    border: 1px solid rgba(233, 228, 255, 0.9);
}
.stat-icon { font-size: 28px; }
.stat-card strong { font-size: 20px; display: block; }
.stat-card p { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }

/* ---------- Category grid ---------- */
.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: 16px; }
.category-card {
    background: var(--card-bg); padding: 20px; border-radius: var(--radius);
    box-shadow: 0 10px 24px rgba(139, 124, 246, 0.08); position: relative; transition: transform .2s ease, box-shadow .2s ease;
    border: 1px solid rgba(233, 228, 255, 0.9);
}
.category-card:hover { transform: translateY(-4px); box-shadow: 0 16px 32px rgba(139, 124, 246, 0.12); }
.category-icon { font-size: 32px; }
.category-card h3 { margin: 10px 0 4px; font-size: 16px; }
.category-card p { color: var(--text-muted); font-size: 13px; margin: 0 0 30px; }
.badge { font-size: 11px; padding: 3px 10px; border-radius: 20px; font-weight: 700; position: absolute; bottom: 16px; left: 20px; }
.badge-beginner { background: #EAFBF7; color: #4BA78B; }
.badge-intermediate { background: #FFF7E8; color: #C98A00; }
.badge-advanced { background: #FFF0EF; color: var(--danger); }
.dialog-count { position: absolute; bottom: 18px; right: 20px; font-size: 12px; color: var(--text-muted); }

/* ---------- Page header ---------- */
.page-header { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.category-icon-lg { font-size: 42px; }
.page-header h1 { margin: 0; font-size: 22px; }
.page-header p { margin: 4px 0 0; color: var(--text-muted); }

/* ---------- Dialog list ---------- */
.dialog-list { display: flex; flex-direction: column; gap: 12px; }
.dialog-item {
    background: var(--card-bg); padding: 16px 20px; border-radius: var(--radius);
    display: flex; justify-content: space-between; align-items: center;
    box-shadow: 0 10px 24px rgba(139, 124, 246, 0.06); border: 1px solid rgba(233, 228, 255, 0.9);
}
.dialog-item-info h3 { margin: 0 0 4px; font-size: 15px; }
.dialog-item-info p { margin: 0; color: var(--text-muted); font-size: 13px; }
.dialog-meta { font-size: 12px; color: var(--text-muted); }
.status-done { color: var(--accent); font-weight: 600; font-size: 13px; }
.status-progress { color: #E8A400; font-weight: 600; font-size: 13px; }
.status-new { color: var(--primary); font-weight: 600; font-size: 13px; }

/* ---------- Player ---------- */
.player-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.player-header h1 { margin: 0; font-size: 20px; }
.player-controls-top { display: flex; gap: 16px; align-items: center; font-size: 13px; }
.player-controls-top select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: #fcfbff; }
.toggle-loop { display: flex; align-items: center; gap: 6px; }

.transcript { display: flex; flex-direction: column; gap: 10px; margin-bottom: 90px; }
.line {
    background: var(--card-bg); border-radius: var(--radius); padding: 16px 20px;
    display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
    box-shadow: 0 10px 24px rgba(139, 124, 246, 0.06); border: 2px solid transparent; transition: border-color .2s ease, transform .2s ease;
}
.line:hover { transform: translateY(-1px); }
.line-active { border-color: var(--primary); }
.speaker-badge {
    display: inline-block; background: #f3eeff; color: var(--primary); font-weight: 700;
    font-size: 11px; padding: 2px 10px; border-radius: 20px; margin-bottom: 8px;
}
.line-text { margin: 0; font-size: 16px; line-height: 1.7; }
.line-translation { margin: 6px 0 0; color: var(--text-muted); font-size: 13px; font-style: italic; }
.word { cursor: pointer; border-radius: 4px; padding: 0 2px; }
.word:hover { background: #f0eaff; }
.word-active { background: var(--primary); color: #fff; }
.line-actions { display: flex; flex-direction: column; align-items: center; gap: 8px; flex-shrink: 0; }
.btn-play-line, .btn-record-line {
    width: 40px; height: 40px; border-radius: 50%; border: none; background: #f6f2ff;
    font-size: 16px; cursor: pointer; transition: background .2s ease, transform .2s ease;
}
.btn-play-line:hover { background: #efe7ff; transform: scale(1.04); }
.btn-record-line.recording { background: var(--danger); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.6;} }
.user-audio-playback { width: 180px; height: 32px; }

.player-bottom-bar {
    position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255,255,255,0.94);
    border-top: 1px solid var(--border); padding: 14px 20px; display: flex; align-items: center;
    justify-content: center; gap: 16px; box-shadow: 0 -8px 24px rgba(117, 93, 225, 0.08); z-index: 5; backdrop-filter: blur(8px);
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%); color: #fff; border: none; padding: 12px 24px;
    border-radius: 12px; font-weight: 700; cursor: pointer; font-size: 14px; box-shadow: 0 10px 24px rgba(139, 124, 246, 0.2);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-secondary {
    background: #f7f3ff; color: var(--text); border: none; padding: 12px 20px;
    border-radius: 12px; font-weight: 600; cursor: pointer; font-size: 14px;
}
#progressIndicator { font-size: 13px; color: var(--text-muted); font-weight: 600; }
.vocab-hint { text-align: center; color: var(--text-muted); font-size: 13px; margin-top: 14px; }

/* ---------- Modal ---------- */
.modal {
    position: fixed; inset: 0; background: rgba(18, 24, 40, 0.35); display: flex;
    align-items: center; justify-content: center; z-index: 50;
}
.modal-box { background: #fff; padding: 24px; border-radius: var(--radius); width: 320px; box-shadow: 0 20px 40px rgba(51, 65, 85, 0.16); }
.modal-box h3 { margin: 0 0 12px; }
.vocab-word-display { font-size: 18px; font-weight: 700; color: var(--primary); margin: 0 0 12px; }
.modal-box textarea {
    width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--border); font-family: inherit; resize: vertical; background: #fcfbff;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- Vocab page ---------- */
.vocab-list { display: flex; flex-direction: column; gap: 10px; }
.vocab-card {
    background: var(--card-bg); padding: 16px 20px; border-radius: var(--radius);
    display: flex; justify-content: space-between; align-items: center; box-shadow: 0 10px 24px rgba(139, 124, 246, 0.06); border: 1px solid rgba(233, 228, 255, 0.9);
}
.vocab-card h3 { margin: 0 0 4px; color: var(--primary); }
.vocab-card p { margin: 0; color: var(--text); font-size: 14px; }
.vocab-source { font-size: 12px; color: var(--text-muted); }
.btn-delete { background: none; border: none; font-size: 16px; cursor: pointer; opacity: .5; }
.btn-delete:hover { opacity: 1; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* ---------- Progress page / week chart ---------- */
.week-chart { display: flex; gap: 10px; align-items: flex-end; height: 140px; background: var(--card-bg); border-radius: var(--radius); padding: 16px; box-shadow: 0 10px 24px rgba(139, 124, 246, 0.06); border: 1px solid rgba(233, 228, 255, 0.9); }
.week-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.week-bar { width: 60%; background: linear-gradient(180deg, var(--accent) 0%, var(--primary) 100%); border-radius: 6px 6px 0 0; min-height: 4px; }
.week-bar-wrap span { margin-top: 6px; font-size: 11px; color: var(--text-muted); }

@media (max-width: 640px) {
    .navbar { padding: 12px 16px; }
    .nav-links { gap: 12px; font-size: 12px; }
    .line { flex-direction: column; }
    .line-actions { flex-direction: row; align-self: flex-end; }
}

/* ---------- Tambah Materi ---------- */
.step-card { background: var(--card-bg); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; box-shadow: 0 10px 24px rgba(139, 124, 246, 0.06); border: 1px solid rgba(233, 228, 255, 0.9); }
.step-card h2 { margin: 0 0 16px; font-size: 17px; }
.prompt-form { display: flex; flex-direction: column; gap: 14px; }
.prompt-form label { font-size: 13px; font-weight: 600; display: flex; flex-direction: column; gap: 6px; }
.prompt-form input, .prompt-form select {
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; font-weight: 400; background: #fcfbff;
}
.prompt-form-row { display: grid; grid-template-columns: 1fr 1fr 100px; gap: 14px; }
#promptResultWrap { margin-top: 20px; }
.prompt-label { font-size: 13px; font-weight: 600; display: block; margin-bottom: 8px; }
#promptOutput, #aiResultInput {
    width: 100%; padding: 14px; border: 1px solid var(--border); border-radius: 10px;
    font-family: 'Courier New', monospace; font-size: 12.5px; line-height: 1.6; resize: vertical; margin-bottom: 12px; background: #fcfbff;
}
.copy-status { margin-left: 10px; color: var(--accent); font-weight: 600; font-size: 13px; }
.hint-text { color: var(--text-muted); font-size: 13px; margin-bottom: 14px; }
.preview-box { background: linear-gradient(135deg, #faf8ff 0%, #f3fcf9 100%); border-radius: 12px; padding: 16px 18px; margin: 16px 0; border: 1px solid var(--border); }
.preview-box h3 { margin: 0 0 4px; font-size: 16px; }
.preview-sub { margin: 0 0 12px; color: var(--text-muted); font-size: 13px; }
.preview-line { font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.preview-more { color: var(--text-muted); font-style: italic; }
.alert-success { background: #EAFBF7; color: #2C7A63; padding: 12px 16px; border-radius: 12px; font-size: 13px; margin-top: 14px; }
#importStatus:empty { display: none; }
