:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #222536;
    --surface3: #2a2e45;
    --accent: #6c63ff;
    --accent2: #a78bfa;
    --accent3: #38bdf8;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --text: #e2e8f0;
    --text2: #94a3b8;
    --text3: #64748b;
    --border: #2d3154;
    --card-front: #1e2235;
    --card-back: #1a2a1e;
    --font-display: 'Segoe UI', system-ui, sans-serif;
    --radius: 16px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-display);
    min-height: 100vh;
}

/* NAV */
nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 24px;
    height: 60px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-logo {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--accent2);
    letter-spacing: -0.5px;
    margin-right: 16px;
}
.nav-logo span { color: var(--accent3); }

.nav-btn {
    background: none;
    border: none;
    color: var(--text2);
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }
.nav-spacer { flex: 1; }

/* PAGES */
.page { display: none; padding: 32px 24px; max-width: 1100px; margin: 0 auto; }
.page.active { display: block; }

/* HEADINGS */
h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 20px; color: var(--text); }
h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; color: var(--text2); }

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    transition: all 0.2s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #5a52e0; transform: translateY(-1px); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--surface2); color: var(--text); }
.btn-ghost:hover { background: var(--surface3); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 8px; }

/* CARDS GRID */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

/* FLIP CARD */
.flip-card { perspective: 1000px; height: 220px; cursor: pointer; }
.flip-card-inner {
    position: relative; width: 100%; height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(.4, .2, .2, 1);
}
.flip-card.flipped .flip-card-inner { transform: rotateY(180deg); }
.flip-card-front, .flip-card-back {
    position: absolute; width: 100%; height: 100%;
    backface-visibility: hidden;
    border-radius: var(--radius);
    padding: 20px;
    display: flex; flex-direction: column; justify-content: space-between;
    border: 1px solid var(--border);
}
.flip-card-front { background: var(--card-front); }
.flip-card-back { background: var(--card-back); transform: rotateY(180deg); }
.card-word { font-size: 1.6rem; font-weight: 800; color: var(--accent2); }
.card-alts { font-size: 0.82rem; color: var(--text3); margin-top: 4px; font-style: italic; }
.card-list { font-size: 0.9rem; color: var(--text2); }
.card-meaning { font-size: 1.2rem; font-weight: 700; color: var(--success); }
.card-example {
    font-size: 0.8rem; color: var(--text3);
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px; padding: 8px 10px;
    font-style: italic; border-left: 3px solid var(--accent);
}
.card-example b { color: var(--accent2); }
.card-tag {
    font-size: 0.72rem; background: var(--accent); color: #fff;
    padding: 2px 8px; border-radius: 20px; display: inline-block; opacity: 0.7;
}
.card-hint { font-size: 0.72rem; color: var(--text3); text-align: right; }

/* STUDY AREA */
.study-area { max-width: 560px; margin: 0 auto; text-align: center; }
.study-progress { margin-bottom: 24px; }
.progress-bar-bg { background: var(--surface2); border-radius: 99px; height: 8px; margin-top: 8px; }
.progress-bar-fill {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    height: 8px; border-radius: 99px; transition: width 0.4s;
}
.study-big-card {
    background: var(--card-front);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 40px 32px;
    min-height: 280px;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    cursor: pointer; transition: box-shadow 0.2s;
    perspective: 1000px; position: relative;
}
.study-big-card:hover { box-shadow: 0 0 0 2px var(--accent); }
.study-big-word { font-size: 2.4rem; font-weight: 900; color: var(--accent2); margin-bottom: 8px; }
.study-big-alts { font-size: 0.9rem; color: var(--text3); margin-bottom: 16px; font-style: italic; }
.study-big-meaning { font-size: 1.4rem; font-weight: 700; color: var(--success); }
.study-big-example {
    font-size: 0.88rem; color: var(--text2);
    background: rgba(255, 255, 255, 0.04);
    border-radius: 10px; padding: 12px 16px; margin-top: 16px;
    font-style: italic; border-left: 3px solid var(--accent); text-align: left; width: 100%;
}
.study-big-example b { color: var(--accent2); }
.study-actions { display: flex; gap: 12px; margin-top: 20px; justify-content: center; flex-wrap: wrap; }
.btn-knew { background: var(--success); color: #fff; }
.btn-knew:hover { background: #16a34a; }
.btn-forgot { background: var(--danger); color: #fff; }
.btn-forgot:hover { background: #dc2626; }
.srs-indicator {
    position: absolute; top: 12px; right: 14px;
    font-size: 0.75rem; color: var(--text3);
    background: var(--surface2); border-radius: 8px; padding: 3px 8px;
}

/* SETS */
.sets-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; align-items: center; }
.set-pill {
    padding: 8px 16px; border-radius: 99px;
    border: 1px solid var(--border); background: var(--surface2);
    color: var(--text2); cursor: pointer; font-size: 0.85rem; font-weight: 600;
    transition: all 0.2s;
}
.set-pill:hover, .set-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.set-pill.delete-mode::after { content: ' \2715'; color: var(--danger); }

/* PACK SELECTOR */
.pack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.pack-card {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 12px; padding: 16px; cursor: pointer; text-align: center;
    transition: all 0.2s;
}
.pack-card:hover, .pack-card.active { border-color: var(--accent); background: rgba(108, 99, 255, 0.1); }
.pack-card .pack-num { font-size: 1.8rem; font-weight: 900; color: var(--accent2); }
.pack-card .pack-label { font-size: 0.78rem; color: var(--text3); margin-top: 4px; }
.pack-card .pack-progress { font-size: 0.72rem; color: var(--success); margin-top: 4px; }

/* INPUT FORM */
.form-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px; margin-bottom: 24px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.82rem; color: var(--text3); font-weight: 600; }
.form-group input, .form-group select, .form-group textarea {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 10px; padding: 10px 14px; color: var(--text);
    font-size: 0.9rem; outline: none; transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); }
.form-group textarea { resize: vertical; min-height: 72px; }
.form-full { grid-column: 1 / -1; }

/* WORD LIST TABLE */
.word-table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th {
    background: var(--surface2); color: var(--text3);
    font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.06em; padding: 12px 16px; text-align: left;
}
td { padding: 11px 16px; font-size: 0.88rem; border-top: 1px solid var(--border); color: var(--text2); vertical-align: middle; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 0.72rem; font-weight: 700; }
.badge-purple { background: rgba(108, 99, 255, 0.2); color: var(--accent2); }
.badge-blue { background: rgba(56, 189, 248, 0.2); color: var(--accent3); }
.badge-green { background: rgba(34, 197, 94, 0.2); color: var(--success); }
.badge-red { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

/* TABS */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab-btn {
    padding: 10px 18px; border: none; background: none; color: var(--text3);
    cursor: pointer; font-size: 0.88rem; font-weight: 600;
    border-bottom: 2px solid transparent; transition: all 0.2s; margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent2); border-bottom-color: var(--accent2); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* STATS */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px;
    display: flex; flex-direction: column; gap: 4px;
}
.stat-num { font-size: 2rem; font-weight: 900; color: var(--accent2); }
.stat-label { font-size: 0.82rem; color: var(--text3); }

/* UPLOAD AREA */
.upload-drop {
    border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 48px; text-align: center; cursor: pointer; transition: all 0.2s;
}
.upload-drop:hover, .upload-drop.drag { border-color: var(--accent); background: rgba(108, 99, 255, 0.05); }
.upload-icon { font-size: 2.5rem; margin-bottom: 12px; }
.upload-text { font-size: 0.95rem; color: var(--text2); }
.upload-hint { font-size: 0.8rem; color: var(--text3); margin-top: 6px; }

/* TOAST */
#toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px 20px; font-size: 0.88rem;
    color: var(--text); box-shadow: var(--shadow);
    transform: translateY(80px); opacity: 0; transition: all 0.3s;
    z-index: 999; max-width: 320px;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { border-left: 4px solid var(--success); }
#toast.error { border-left: 4px solid var(--danger); }
#toast.info { border-left: 4px solid var(--accent); }

/* MODAL */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.7); z-index: 200;
    align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 20px; padding: 28px; width: 90%; max-width: 480px;
    box-shadow: var(--shadow);
}
.modal h3 { font-size: 1.1rem; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* SRS NEXT */
.srs-badge {
    display: inline-block; padding: 3px 10px; border-radius: 99px;
    font-size: 0.75rem; font-weight: 700;
    background: rgba(108, 99, 255, 0.15); color: var(--accent2);
}
.srs-badge.overdue { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.srs-badge.today { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.srs-badge.future { background: rgba(34, 197, 94, 0.15); color: var(--success); }

/* DIVIDER */
.divider { height: 1px; background: var(--border); margin: 24px 0; }

/* INLINE INPUT */
.inline-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.input-inline {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 10px; padding: 8px 14px; color: var(--text);
    font-size: 0.9rem; outline: none; flex: 1; min-width: 120px;
    transition: border-color 0.2s;
}
.input-inline:focus { border-color: var(--accent); }

/* EMPTY STATE */
.empty { text-align: center; padding: 60px 24px; color: var(--text3); }
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty p { font-size: 1rem; }

/* FLIP HINT */
.flip-hint { position: absolute; bottom: 10px; right: 12px; font-size: 0.7rem; color: var(--text3); }

/* AUTH */
#auth-overlay {
    position: fixed; inset: 0; background: var(--bg);
    z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-box {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 24px; padding: 36px 32px; width: 100%; max-width: 420px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.5);
    animation: authIn 0.4s cubic-bezier(.4,0,.2,1);
}
@keyframes authIn { from { opacity:0; transform: translateY(24px); } to { opacity:1; transform: translateY(0); } }
.auth-logo { text-align: center; font-size: 2rem; font-weight: 900; color: var(--accent2); margin-bottom: 6px; letter-spacing: -1px; }
.auth-logo span { color: var(--accent3); }
.auth-subtitle { text-align: center; color: var(--text3); font-size: 0.85rem; margin-bottom: 28px; }
.auth-tabs { display: flex; border-radius: 12px; background: var(--surface2); padding: 4px; margin-bottom: 24px; }
.auth-tab {
    flex: 1; padding: 10px; border: none; background: none;
    color: var(--text3); font-size: 0.88rem; font-weight: 700;
    cursor: pointer; border-radius: 10px; transition: all 0.2s;
}
.auth-tab.active { background: var(--accent); color: #fff; }
.auth-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.auth-field label { font-size: 0.8rem; color: var(--text3); font-weight: 600; }
.auth-field input {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px 16px; color: var(--text);
    font-size: 0.95rem; outline: none; transition: border-color 0.2s; width: 100%;
}
.auth-field input:focus { border-color: var(--accent); }
.auth-btn {
    width: 100%; padding: 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff; border: none; border-radius: 12px;
    font-size: 1rem; font-weight: 800; cursor: pointer;
    transition: all 0.2s; margin-top: 8px;
}
.auth-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.auth-btn:disabled { opacity: 0.6; transform: none; cursor: wait; }
.auth-error {
    background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.3);
    border-radius: 10px; padding: 10px 14px; font-size: 0.84rem;
    color: var(--danger); margin-bottom: 14px; display: none;
}
.nav-user { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.nav-username {
    font-size: 0.78rem; font-weight: 700; color: var(--accent3);
    background: rgba(56,189,248,0.1); padding: 4px 10px; border-radius: 20px; white-space: nowrap;
}

/* =============================================
   RESPONSIVE
============================================= */
img, video, iframe { max-width: 100%; }
* { -webkit-tap-highlight-color: transparent; }

@media (max-width: 768px) {
    nav { padding: 0 12px; height: 54px; gap: 2px; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    nav::-webkit-scrollbar { display: none; }
    .nav-logo { font-size: 1.1rem; margin-right: 8px; flex-shrink: 0; }
    .nav-btn { padding: 6px 10px; font-size: 0.78rem; white-space: nowrap; flex-shrink: 0; }
    .page { padding: 16px 12px 80px; }
    h2 { font-size: 1.2rem; margin-bottom: 14px; }
    .cards-grid { grid-template-columns: 1fr; gap: 12px; }
    .flip-card { height: 200px; }
    .card-word { font-size: 1.3rem; }
    .card-meaning { font-size: 1rem; }
    .card-example { font-size: 0.75rem; }
    #page-cards > div:first-child { flex-wrap: wrap; gap: 8px; }
    #page-cards .input-inline { min-width: 0; flex: 1 1 120px; }
    .study-area { max-width: 100%; }
    .study-big-card { padding: 24px 16px; min-height: 220px; border-radius: 16px; }
    .study-big-word { font-size: 1.8rem; }
    .study-big-meaning { font-size: 1.1rem; }
    .study-big-example { font-size: 0.82rem; padding: 10px 12px; }
    .study-actions { gap: 8px; }
    .study-actions .btn { padding: 12px 20px; font-size: 0.9rem; flex: 1; justify-content: center; }
    .tabs { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 1px; }
    .tabs::-webkit-scrollbar { display: none; }
    .tab-btn { white-space: nowrap; padding: 10px 14px; font-size: 0.82rem; }
    .pack-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
    .pack-card { padding: 12px; }
    .pack-card .pack-num { font-size: 1.4rem; }
    .form-grid { grid-template-columns: 1fr; }
    .form-card { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-num { font-size: 1.6rem; }
    .upload-drop { padding: 28px 16px; }
    .word-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    td, th { padding: 9px 10px; font-size: 0.8rem; }
    .sets-row { gap: 8px; }
    .set-pill { padding: 6px 12px; font-size: 0.8rem; }
    .inline-row { gap: 8px; }
    .input-inline { font-size: 0.85rem; padding: 8px 10px; }
    .modal { width: 95%; padding: 20px 16px; border-radius: 16px; }
    .modal-actions { flex-wrap: wrap; gap: 8px; }
    .modal-actions .btn { flex: 1; justify-content: center; }
    #toast { bottom: 12px; right: 12px; left: 12px; max-width: none; font-size: 0.85rem; }
    .srs-indicator { font-size: 0.68rem; padding: 2px 6px; }
    .btn { font-size: 0.85rem; padding: 9px 16px; }
    .btn-sm { font-size: 0.75rem; padding: 6px 10px; }
    .auth-box { padding: 28px 20px; border-radius: 20px; }
    .auth-logo { font-size: 1.6rem; }
}

@media (max-width: 400px) {
    .study-big-word { font-size: 1.5rem; }
    .card-word { font-size: 1.2rem; }
    .pack-grid { grid-template-columns: repeat(2, 1fr); }
    nav { gap: 0; }
    .nav-btn { padding: 5px 7px; font-size: 0.72rem; }
}
