:root {
    --bg: #eef1f8;
    --bg-2: #e4e9f4;
    --card: #ffffff;
    --ink: #12151c;
    --muted: #5b6475;
    --line: #d5dbe8;
    --navy: #1e3a8a;
    --navy-2: #152c6e;
    --sun: #f5c518;
    --coral: #e23d2d;
    --teal: #0f766e;
    --good: #15803d;
    --shadow: 0 16px 40px rgba(18, 21, 28, 0.08);
}

* { box-sizing: border-box; }
html {
    margin: 0;
    min-height: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
html, body { overflow-x: hidden; }
body {
    margin: 0;
    min-height: 100%;
    min-height: 100dvh;
    background:
        radial-gradient(900px 420px at 90% -10%, #dfe7ff, transparent 55%),
        radial-gradient(700px 380px at -10% 0%, #fff3c4, transparent 50%),
        var(--bg);
    color: var(--ink);
    font-family: Figtree, "Segoe UI", sans-serif;
    font-size: 1.05rem;
    line-height: 1.5;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, a, summary { touch-action: manipulation; }

a { color: var(--navy); }
a:hover { color: var(--coral); }

.frame {
    width: min(1120px, calc(100% - 1.5rem));
    margin: 0.9rem auto 2.5rem;
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.1rem;
    align-items: center;
    padding: 0.85rem 1rem;
    background: var(--navy);
    color: #f8fafc;
    border-radius: 22px;
    box-shadow: var(--shadow);
}
.brand { display: flex; gap: 0.7rem; align-items: center; text-decoration: none; color: inherit; }
.brand-mark {
    width: 2.5rem; height: 2.5rem;
    display: grid; place-items: center;
    background: var(--sun);
    color: var(--ink);
    border-radius: 12px;
    font-family: "Bricolage Grotesque", sans-serif;
    font-weight: 800;
    font-size: 1.05rem;
}
.brand-kicker {
    display: block;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.75;
    font-weight: 700;
}
.brand-name {
    display: block;
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
}

.nav { display: flex; gap: 0.35rem; flex-wrap: wrap; flex: 1 1 auto; }
.nav a {
    color: #e2e8f0;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.95rem;
    padding: 0.5rem 0.85rem;
    min-height: 2.5rem;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
}
.nav a:hover, .nav a.is-active { background: rgba(255,255,255,0.12); color: #fff; }
.nav a.is-active { background: var(--sun); color: var(--ink); }
.badge {
    display: inline-flex;
    min-width: 1.15rem;
    padding: 0 0.32rem;
    margin-left: 0.2rem;
    border-radius: 999px;
    background: var(--coral);
    color: #fff;
    font-size: 0.7rem;
    line-height: 1.25rem;
    justify-content: center;
}
.topbar-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; margin-left: auto; }

.class-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem 0.8rem;
    align-items: center;
    margin: 0.85rem 0 0;
    padding: 0.7rem 0.2rem 0.2rem;
}
.class-bar-label {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}
.class-pills { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pill {
    text-decoration: none;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.35rem 0.8rem;
    font-weight: 700;
    font-size: 0.88rem;
}
.pill:hover { border-color: var(--navy); color: var(--navy); }
.pill.is-on {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
}
.class-hint, .bar-link { font-size: 0.88rem; color: var(--muted); font-weight: 600; }
.bar-link { color: var(--navy); }

.btn {
    font-family: inherit;
    font-weight: 750;
    font-size: 0.9rem;
    border: 1px solid var(--ink);
    background: var(--card);
    color: var(--ink);
    padding: 0.55rem 0.95rem;
    min-height: 2.65rem;
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn:hover { background: var(--bg-2); color: var(--ink); }
.btn-primary { background: var(--sun); border-color: #e0b40f; color: var(--ink); }
.btn-primary:hover { background: #ffd84a; color: var(--ink); }
.btn-ghost { border-color: var(--line); background: transparent; color: var(--ink); }
.topbar .btn-ghost { border-color: transparent; background: rgba(255,255,255,0.1); color: #fff; }
.topbar .btn-ghost:hover { background: rgba(255,255,255,0.16); color: #fff; }
.topbar .btn-primary:hover { color: var(--ink); }

.main { padding: 1.3rem 0 0.5rem; }
.page-head, .hero {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1.2rem;
}
h1, h2, .headword, .mini-word {
    font-family: "Bricolage Grotesque", sans-serif;
    letter-spacing: -0.04em;
    margin: 0.1rem 0;
}
h1 { font-size: clamp(1.9rem, 4vw, 3rem); line-height: 1.02; font-weight: 800; }
h2 { font-size: 1.2rem; font-weight: 800; }
h3 {
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--navy);
    margin: 0 0 0.3rem;
    font-weight: 800;
}
.eyebrow {
    margin: 0;
    font-size: 0.75rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-weight: 800;
    color: var(--coral);
}
.lede { color: var(--muted); max-width: 40rem; margin: 0.35rem 0 0; }
.muted { color: var(--muted); }
.empty-title { font-family: "Bricolage Grotesque", sans-serif; font-size: 1.5rem; font-weight: 800; margin: 0 0 0.3rem; }

.stat-pills {
    list-style: none;
    display: flex;
    gap: 0.5rem;
    padding: 0;
    margin: 0;
    flex-wrap: wrap;
}
.stat-pills li {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 0.55rem 0.8rem;
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 700;
}
.stat-pills strong {
    display: block;
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 1.35rem;
    color: var(--ink);
}

.entry, .empty-day, .flashcard, .panel, .preview-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: var(--shadow);
}
.entry, .empty-day { padding: 1.4rem 1.5rem 1.3rem; margin: 0.4rem 0 1rem; }
.empty-day { border-style: dashed; border-color: #c9b56a; background: #fffbeb; }
.headword {
    font-size: clamp(2.6rem, 8vw, 4.8rem);
    line-height: 0.92;
    margin: 0 0 0.35rem;
    font-weight: 800;
}
.meta-line { color: var(--muted); margin: 0 0 0.85rem; font-weight: 650; }
.pron { font-variant-numeric: tabular-nums; }
.pos { font-style: italic; margin-left: 0.55rem; }
.definition { font-size: 1.2rem; margin: 0; overflow-wrap: anywhere; }
.block { margin-top: 1rem; padding-top: 0.85rem; border-top: 1px solid var(--line); }
.example { font-style: italic; margin: 0; overflow-wrap: anywhere; }
.block { margin-top: 1rem; padding-top: 0.85rem; border-top: 1px solid var(--line); }
.example { font-style: italic; margin: 0; }
.mini-word { font-size: 2rem; }

.entry-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.2rem 0 1.2rem; }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0; margin: 1rem 0 0; }
.chip {
    display: inline-block;
    padding: 0.22rem 0.7rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--chip, var(--navy)) 16%, white);
    color: var(--chip, var(--navy));
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 800;
}
.chip-class { outline: 2px solid color-mix(in srgb, var(--chip) 35%, white); }

.side-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.9rem;
    margin-top: 0.4rem;
}
.panel { padding: 1.05rem 1.15rem 1.15rem; }
.panel.highlight { background: #fff7d6; border-color: #ead57a; }
.archive, .class-today, .word-list, .group-list { list-style: none; padding: 0; margin: 0; }
.archive li + li, .class-today li + li, .word-list li, .group-list li { border-top: 1px solid var(--line); }
.archive a, .class-today a, .word-list a, .group-list a {
    display: grid;
    gap: 0.35rem 0.8rem;
    padding: 0.7rem 0;
    text-decoration: none;
    color: inherit;
}
.archive a { grid-template-columns: 4.2rem 7rem 1fr; }
.class-today a, .group-list a { grid-template-columns: 1.1rem 1fr auto; align-items: center; }
.word-list a { grid-template-columns: 8.5rem 5.5rem 1fr; }
.archive-date { color: var(--navy); font-weight: 800; font-size: 0.82rem; }
.archive-word, .word-list strong, .group-list strong { font-family: "Bricolage Grotesque", sans-serif; font-size: 1.15rem; font-weight: 800; }
.archive-def, .word-list span, .group-list span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.word-list em { color: var(--muted); font-style: italic; }
.word-list.compact li { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.word-list.compact a { grid-template-columns: 8rem 1fr; flex: 1; }
.swatch { width: 0.85rem; height: 0.85rem; border-radius: 999px; display: inline-block; }

.import-panel, .import-form, .filters, .inline-add {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: end;
    margin-top: 0.9rem;
}
.wotd-fetch {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: end;
    margin-top: 0.85rem;
}
.import-form[hidden], .preview-slot[hidden] { display: none !important; }
.wotd-fetch .btn { min-width: 12rem; }
.schedule-list { list-style: none; padding: 0; margin: 0; }
.schedule-list li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: start;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--line);
}
.schedule-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.8rem;
    margin: 0 0 0.2rem;
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--navy);
}
.schedule-word {
    font-family: "Bricolage Grotesque", sans-serif;
    font-size: 1.2rem;
    font-weight: 800;
    text-decoration: none;
}
.preview-card .headword { overflow-wrap: anywhere; }
.filters { margin: 1rem 0 1.2rem; }
.filters.tight { margin: 0; }
.grow { flex: 1; min-width: 12rem; }
.field { display: grid; gap: 0.25rem; font-size: 0.78rem; font-weight: 800; }
.field span { letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
input, select, textarea {
    font: inherit;
    font-size: 1rem;
    font-weight: 600;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 12px;
    width: 100%;
}
.stack { display: grid; gap: 0.75rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.8rem; }
.form-grid .full { grid-column: 1 / -1; }
.lookup-bar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    background: #e8eefc;
    border-radius: 16px;
}
.fieldset { border: 1px solid var(--line); padding: 0.8rem 1rem 1rem; margin: 1rem 0; border-radius: 16px; }
.fieldset legend { font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 800; padding: 0 0.3rem; }
.check-grid { display: flex; flex-wrap: wrap; gap: 0.7rem 1.1rem; }
.check { display: flex; gap: 0.4rem; align-items: center; font-weight: 700; }
.check input { width: auto; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; margin-bottom: 1.1rem; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.55rem 0.35rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.linkish { background: none; border: 0; color: var(--coral); cursor: pointer; font: inherit; font-weight: 700; padding: 0; }
.danger { margin-top: 1rem; }

.study-stage { max-width: 640px; margin: 1.3rem auto 0; }
.flashcard {
    width: 100%;
    min-height: 280px;
    border: 2px solid var(--ink);
    cursor: pointer;
    padding: 0;
    text-align: left;
    color: inherit;
    box-shadow: 8px 8px 0 var(--navy);
}
.flashcard .face {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 280px;
    padding: 1.5rem 1.7rem;
    gap: 0.55rem;
}
.flashcard .back { display: none; }
.flashcard.is-flipped .front { display: none; }
.flashcard.is-flipped .back { display: flex; }
.flashcard .kicker {
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 800;
    color: var(--navy);
}
.grade { margin-top: 1.1rem; }
.grade-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
.grade-again { border-color: var(--coral); color: var(--coral); }
.grade-hard { border-color: #b45309; color: #b45309; }
.grade-good { border-color: var(--good); color: var(--good); }
.grade-easy { background: var(--navy); color: #fff; border-color: var(--navy); }

.flashes { margin-top: 0.9rem; }
.flash { padding: 0.75rem 0.95rem; border-radius: 14px; background: #fff; border: 1px solid var(--line); }
.flash-success { border-left: 6px solid var(--good); }
.flash-error { border-left: 6px solid var(--coral); }

.colophon {
    margin-top: 1.8rem;
    padding-top: 0.8rem;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
}
.source-line { margin-top: 1rem; }
.preview-card { margin-top: 1rem; padding: 1rem 1.1rem; border-left: 6px solid var(--sun); }
.preview-card .headword { font-size: 2.1rem; }
.preview-error { color: var(--coral); margin-top: 0.8rem; font-weight: 700; }

.who {
    font-size: 0.85rem;
    font-weight: 700;
    opacity: 0.85;
    align-self: center;
}
.prompt {
    font-size: 1.05rem;
    color: var(--muted);
    font-weight: 650;
}
.grade.is-locked, .grade[hidden] { display: none !important; }
.student-list { list-style: none; padding: 0; margin: 0; }
.student-list li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--line);
}
.student-list strong { display: block; }
.issued-line { margin: 0.35rem 0; font-size: 1.05rem; }
.issued code {
    font-size: 1.1rem;
    background: #fff;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
}
.auth-body { display: grid; place-items: center; min-height: 100vh; }
.auth-wrap { width: min(560px, calc(100% - 1.5rem)); }
.auth-brand { color: var(--ink); margin-bottom: 1rem; display: flex; gap: 0.7rem; align-items: center; text-decoration: none; }
.auth-card { padding: 1.4rem 1.4rem 1.5rem; }
.auth-card h1 { font-size: 2rem; }
.auth-wide { width: min(560px, 100%); }
.setup-steps {
    list-style: none;
    display: flex;
    gap: 0.4rem;
    padding: 0;
    margin: 0.8rem 0 1.1rem;
    font-size: 0.82rem;
    font-weight: 800;
}
.setup-steps li {
    flex: 1;
    background: var(--bg-2);
    border-radius: 999px;
    padding: 0.4rem 0.55rem;
    text-align: center;
    color: var(--muted);
}
.setup-steps .is-on { background: var(--sun); color: var(--ink); }
.setup-steps .is-done { background: #dcfce7; color: var(--good); }
.check-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.check-list li {
    display: grid;
    grid-template-columns: 3.2rem 1fr;
    gap: 0.6rem;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--line);
    align-items: start;
}
.check-list strong {
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.check-list .ok strong { color: var(--good); }
.check-list .bad strong { color: var(--coral); }
.check-list .warn strong { color: #b45309; }

@media (max-width: 860px) {
    .frame { width: min(1120px, calc(100% - 1.1rem)); margin: 0.55rem auto 1.6rem; }
    .topbar { border-radius: 18px; padding: 0.75rem 0.8rem; }
    .brand { flex: 1 1 auto; min-width: 0; }
    .nav, .topbar-actions { flex: 1 1 100%; margin-left: 0; }
    .topbar-actions .btn { flex: 1 1 auto; justify-content: center; }
    .who { display: none; }
    .form-grid, .split, .archive a, .word-list a, .hero, .lookup-bar, .page-head {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }
    .page-head, .hero, .lookup-bar { align-items: stretch; }
    .stat-pills, .grade-row { grid-template-columns: 1fr 1fr; }
    .archive a { grid-template-columns: 4.2rem 1fr; }
    .archive-def { display: none; }
    .word-list a { grid-template-columns: 1fr; }
    .class-today a { grid-template-columns: 1.1rem 1fr; }
    .class-today em { grid-column: 2; }
    .flashcard { box-shadow: 5px 5px 0 var(--navy); }
    .flashcard .face { min-height: 240px; padding: 1.2rem 1.15rem; }
    .headword { font-size: clamp(2.1rem, 12vw, 3.4rem); }
    .entry, .empty-day, .panel, .auth-card { padding: 1.1rem 1rem 1.05rem; border-radius: 18px; }
    .student-list li, .schedule-list li { flex-direction: column; align-items: stretch; gap: 0.45rem; }
    .setup-steps { flex-wrap: wrap; }
    .setup-steps li { flex: 1 1 30%; }
    .wotd-fetch .btn, .import-panel .btn, .entry-actions .btn { width: 100%; justify-content: center; }
    .entry-actions form { width: 100%; }
    .entry-actions form .btn { width: 100%; }
    .grade > .muted { display: none; }
    .filters { align-items: stretch; }
    .grow { min-width: 0; }
    .class-pills { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 0.15rem; -webkit-overflow-scrolling: touch; }
    .pill { flex: 0 0 auto; }
    input, select, textarea { font-size: 16px; }
}
@media (max-width: 520px) {
    .grade-row { grid-template-columns: 1fr 1fr; gap: 0.45rem; }
    .grade-row .btn { min-height: 3rem; }
    .setup-steps li { flex: 1 1 100%; }
    .nav a { padding: 0.45rem 0.7rem; font-size: 0.88rem; }
}
