/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --surface2: #242424;
    --border: #333;
    --text: #e8e8e8;
    --text-dim: #888;
    --accent: #6ba3f7;
    --accent-dim: #3d6a9e;
    --green: #7ecf8e;
    --orange: #e8a85c;
    --red: #e87070;
    --font-cn: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
    --font-en: "Inter", -apple-system, sans-serif;
    --font-mono: "JetBrains Mono", "Fira Code", monospace;
}

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

/* === Layout === */
#app {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* === Header === */
.header {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.header h1 {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.header .meta {
    color: var(--text-dim);
    font-size: 0.9rem;
}

/* === File Picker === */
.file-picker {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 2rem;
}
.file-picker select {
    flex: 1;
    padding: 0.6rem 1rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
}
.file-picker select:focus {
    outline: none;
    border-color: var(--accent);
}
.file-picker .btn {
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 500;
}
.file-picker .btn:hover { background: var(--accent-dim); }
.file-picker .btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* === Progress Bar === */
.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--surface2);
    border-radius: 2px;
    margin-bottom: 1.5rem;
    overflow: hidden;
}
.progress-bar .fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* === Sentence Card === */
.sentence-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    transition: border-color 0.2s;
}
.sentence-card:hover { border-color: var(--accent-dim); }
.sentence-card.active { border-color: var(--accent); }
.sentence-card .sent-id {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-family: var(--font-mono);
    margin-bottom: 0.5rem;
}

/* === Cantonese Text === */
.zh-text {
    font-family: var(--font-cn);
    font-size: 1.5rem;
    line-height: 2;
    margin-bottom: 0.5rem;
    cursor: pointer;
}
.zh-text .token {
    display: inline;
    padding: 2px 1px;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.15s;
}
.zh-text .token:hover {
    background: var(--accent-dim);
}
.zh-text .token.selected {
    background: var(--accent);
    color: #fff;
}

/* === English Text === */
.en-text {
    font-size: 1rem;
    color: var(--text-dim);
    display: none;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
}
.sentence-card.show-en .en-text { display: block; }

/* === Grammar Panel === */
.grammar-panel {
    display: none;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
}
.sentence-card.show-grammar .grammar-panel { display: block; }
.grammar-panel .section-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.25rem;
}
.grammar-panel .item {
    padding: 0.2rem 0;
    color: var(--text-dim);
}
.grammar-panel .notes {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--surface2);
    border-radius: 4px;
    color: var(--text-dim);
}

/* === Word Popup === */
.word-popup {
    display: none;
    position: fixed;
    z-index: 1000;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    min-width: 260px;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.word-popup.visible { display: block; }
.word-popup .word-zh {
    font-family: var(--font-cn);
    font-size: 1.8rem;
    font-weight: 600;
}
.word-popup .word-jyutping {
    font-family: var(--font-mono);
    color: var(--green);
    font-size: 1rem;
    margin-top: 0.25rem;
}
.word-popup .word-pos {
    font-size: 0.85rem;
    color: var(--orange);
    margin-top: 0.25rem;
}
.word-popup .word-def {
    font-size: 0.95rem;
    margin-top: 0.5rem;
}
.word-popup .word-usage {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

/* === Search Bar === */
.search-bar {
    margin-bottom: 1.5rem;
}
.search-bar input {
    width: 100%;
    padding: 0.6rem 1rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
}
.search-bar input:focus {
    outline: none;
    border-color: var(--accent);
}
.search-bar input::placeholder { color: var(--text-dim); }

/* === Navigation === */
.nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}
.nav-bar .btn {
    padding: 0.5rem 1rem;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}
.nav-bar .btn:hover { border-color: var(--accent); }
.nav-bar .btn:disabled { opacity: 0.3; cursor: not-allowed; }
.nav-bar .nav-info {
    font-size: 0.85rem;
    color: var(--text-dim);
    font-family: var(--font-mono);
}

/* === Loading === */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-dim);
}
.loading .spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-dim);
}
.empty-state h2 { margin-bottom: 1rem; color: var(--text); }
