/* ═══════════════════════════════════════════════════
   Flashcard App — Design System v2
   Concept: "Precision Lab" — the scientist's workstation.
   Cool lab-bench surfaces, brass instrument fittings,
   data read out with the clarity of a measurement gauge.
   ═══════════════════════════════════════════════════ */

/* ── Design Tokens ─────────────────────────────── */
:root {
    /* Palette — cool lab white + warm brass */
    --paper:     #F2F5F9;
    --surface:   #FFFFFF;
    --ink:       #1B1F24;
    --bg:        #F2F5F9;
    --text:      #1B1F24;
    --text-secondary: #556070;
    --primary:   #B87D3D;
    --primary-hover: #9E6A30;
    --primary-light: #FDF6EE;
    --vermilion: #B87D3D;
    --vermilion-hover: #9E6A30;
    --teal:      #287D7D;
    --teal-hover:#1E6565;
    --slate:     #556070;
    --slate-light:#8892A0;
    --border:    #E0E5EC;
    --border-light:#EDF0F5;
    --tag-bg:    #FDF6EE;
    --tag-text:  #B87D3D;
    --success:   #2D7D5F;
    --warning:   #D4842A;
    --danger:    #CF4454;

    /* Typography */
    --font-display: "Segoe UI", "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    --font-body: "Segoe UI", "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    --font-mono: "Cascadia Code", "JetBrains Mono", "Consolas", "Courier New", monospace;
    --font-reading: "Noto Serif SC", "STSong", "Songti SC", "Georgia", serif;

    /* Spacing & Shape */
    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 2px rgba(27,31,36,0.04), 0 1px 3px rgba(27,31,36,0.06);

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="dark"] {
    color-scheme: dark;
    --paper:     #171A1F;
    --surface:   #1F2228;
    --ink:       #E8ECF1;
    --bg:        #171A1F;
    --text:      #E8ECF1;
    --text-secondary: #8892A0;
    --primary:   #D4A04A;
    --primary-hover: #E0B060;
    --primary-light: #2A2218;
    --vermilion: #D4A04A;
    --vermilion-hover: #E0B060;
    --teal:      #48B0A0;
    --teal-hover:#5CC8B8;
    --slate:     #8892A0;
    --slate-light:#6B7380;
    --border:    #2A2E36;
    --border-light:#22252C;
    --tag-bg:    #2A2218;
    --tag-text:  #D4A04A;
    --success:   #3DA080;
    --warning:   #E5A040;
    --danger:    #E05550;
    --shadow: 0 1px 3px rgba(0,0,0,0.25), 0 1px 2px rgba(0,0,0,0.15);
}

/* ── Reset ──────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.6;
    background: var(--paper);
    color: var(--ink);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Subtle graph-paper texture — the lab notebook feel */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.25;
    background-image:
        radial-gradient(circle, var(--border) 1px, transparent 1px);
    background-size: 24px 24px;
}
[data-theme="dark"] body::before { opacity: 0.12; }

/* ── Type Scale ─────────────────────────────────── */
h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
}
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.9rem; }
p { margin-bottom: 0.5rem; }

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--teal-hover); }

/* ── Buttons ────────────────────────────────────── */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.4;
    transition: background 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    user-select: none;
    letter-spacing: 0.01em;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 2px 8px rgba(184,125,61,0.25);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--slate);
}
.btn-outline:hover {
    background: var(--border-light);
    color: var(--ink);
    border-color: var(--slate-light);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { opacity: 0.88; }

.btn-sm {
    padding: 5px 10px;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
}

.btn-icon {
    padding: 6px;
    border-radius: var(--radius-sm);
    width: 34px;
    height: 34px;
    justify-content: center;
    min-width: 34px;
}

/* ── Badges ─────────────────────────────────────── */
.badge {
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    font-family: var(--font-body);
}
.badge-type   { background: #FDF6EE; color: #B87D3D; }
.badge-diff   { background: #ECF7F5; color: #287D7D; }
.badge-source { background: #F5F7FA; color: #556070; }
.badge-priority { background: #FDF6EE; color: #B87D3D; border: 1px solid rgba(184,125,61,0.25); }

[data-theme="dark"] .badge-type   { background: #2A2218; color: #D4A04A; }
[data-theme="dark"] .badge-diff   { background: #1A2A28; color: #48B0A0; }
[data-theme="dark"] .badge-source { background: #22252C; color: #8892A0; }
[data-theme="dark"] .badge-priority { background: #2A2218; color: #D4A04A; border-color: rgba(212,160,74,0.25); }

/* ── Tags ───────────────────────────────────────── */
.tag {
    background: var(--tag-bg);
    color: var(--tag-text);
    padding: 2px 9px;
    border-radius: var(--radius-sm);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.01em;
}

/* ── Toast ──────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 200;
    background: var(--ink);
    color: var(--paper);
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    display: none;
    box-shadow: 0 4px 20px rgba(27,31,36,0.18);
    letter-spacing: 0.01em;
    animation: toastIn 0.25s var(--ease-out);
}
@keyframes toastIn {
    from { transform: translateY(8px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

/* ── Topbar ─────────────────────────────────────── */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow);
}
.topbar h2 {
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-display);
    letter-spacing: -0.01em;
}
.topbar .left {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ── Container ──────────────────────────────────── */
.container {
    max-width: 920px;
    margin: 0 auto;
    padding: 28px 20px;
    position: relative;
    z-index: 1;
}

/* ── Empty State ────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 72px 16px;
    color: var(--slate);
    position: relative;
    z-index: 1;
}
.empty-state .icon { font-size: 3rem; margin-bottom: 16px; opacity: 0.6; }
.empty-state h2 {
    font-family: var(--font-display);
    margin-bottom: 8px;
    color: var(--ink);
    font-weight: 600;
}

/* ── Form Elements ──────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--slate);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-family: var(--font-body);
}
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: var(--font-body);
    background: var(--paper);
    color: var(--ink);
    transition: border-color 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(184,125,61,0.1);
}
.form-group textarea { resize: vertical; min-height: 70px; }
.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23556070' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 22px;
}

/* ── Modal ──────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(27,31,36,0.45);
    z-index: 100;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
    overscroll-behavior: contain;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
    width: 92%;
    max-width: 500px;
    max-height: 82vh;
    overflow-y: auto;
    box-shadow: 0 8px 40px rgba(27,31,36,0.12);
}
.modal h2 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 650;
    margin-bottom: 22px;
    letter-spacing: -0.01em;
}

/* ── Stats Grid ─────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 14px;
    text-align: center;
    box-shadow: var(--shadow);
}
.stat-card .value {
    font-size: 1.4rem;
    font-weight: 650;
    color: var(--primary);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    letter-spacing: -0.02em;
}
.stat-card .label {
    font-size: 0.7rem;
    color: var(--slate);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

/* ── Card List ──────────────────────────────────── */
.card-list { list-style: none; }
.card-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s var(--ease-out), border-color 0.15s var(--ease-out);
}
.card-item:hover {
    box-shadow: 0 1px 4px rgba(27,31,36,0.06);
    border-color: var(--slate-light);
}
.card-item .info { flex: 1; min-width: 200px; }
.card-item .q-text {
    font-size: 0.92rem;
    margin-bottom: 6px;
    line-height: 1.65;
}
.card-item .q-meta {
    font-size: 0.72rem;
    color: var(--slate);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.card-item .actions { display: flex; gap: 6px; }

/* ── Filters ────────────────────────────────────── */
.filters { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.filters select {
    padding: 7px 32px 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-size: 0.83rem;
    font-family: var(--font-body);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23556070' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

/* ── Section Header ─────────────────────────────── */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.section-header h2 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    color: var(--ink);
}

/* ── Section Divider ────────────────────────────── */
.section-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 32px 0 24px;
}

/* ── Instrument readout (monospace stats) ────────── */
.stat-mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    color: var(--primary);
    font-weight: 600;
}

/* ── Focus / Accessibility ──────────────────────── */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ── Reduced Motion ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── Responsive: Tablet (≤768px) ────────────────── */
@media (max-width: 768px) {
    .container { padding: 20px 14px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; }
    .modal { padding: 22px 18px; }
}

/* ── Responsive: Phone (≤480px) ─────────────────── */
@media (max-width: 480px) {
    .topbar { flex-direction: column; align-items: flex-start; gap: 8px; }
    .topbar .left { width: 100%; }
    .topbar h2 { font-size: 0.9rem; }
    .btn { min-height: 44px; display: inline-flex; align-items: center; }
    .toast {
        left: 16px; right: 16px; bottom: 18px;
        text-align: center;
        border-radius: var(--radius);
    }
    .modal-overlay { align-items: flex-end; }
    .modal {
        width: 100%; max-width: none; max-height: 88vh;
        border-radius: 16px 16px 0 0;
        padding: 22px 16px;
    }
    .card-item { flex-direction: column; align-items: flex-start; gap: 10px; }
    .card-item .actions { align-self: flex-end; }
    .filters { flex-direction: column; }
    .filters select { width: 100%; font-size: 16px; min-height: 40px; }
    .container { padding: 14px 10px; }
    .section-header { flex-wrap: wrap; gap: 8px; }
}
