:root {
    --red: #ba0c2f;
    --red-soft: #fbe9ec;
    --navy: #00205b;
    --bg: #f6f4f0;
    --surface: #ffffff;
    --surface-2: #f0ede7;
    --text: #1d2433;
    --muted: #697086;
    --border: #e2ded6;
    --good: #1f8a4c;
    --good-soft: #e3f4ea;
    --bad: #c2352b;
    --bad-soft: #fbe7e5;
    --warn: #b76e00;
    --warn-soft: #fff1d9;
    --blue-soft: #e6ecf8;
    --accent: var(--red);
    --shadow: 0 1px 2px rgba(20, 25, 40, .06), 0 4px 14px rgba(20, 25, 40, .05);
    --radius: 14px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --red-soft: #3a1a21;
        --bg: #14161c;
        --surface: #1d2029;
        --surface-2: #262a35;
        --text: #e9eaf0;
        --muted: #9aa0b3;
        --border: #313646;
        --good: #4cc27f;
        --good-soft: #17301f;
        --bad: #f0746a;
        --bad-soft: #3a1c1a;
        --warn: #f2b14b;
        --warn-soft: #34290f;
        --blue-soft: #1f2940;
        --accent: #f0566f;
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
a { color: inherit; }
h1 { font-size: 1.6rem; margin: .3rem 0 .4rem; line-height: 1.2; }
h2 { font-size: 1.2rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tiny { font-size: .75rem; }
.center { text-align: center; }
.right { text-align: right; }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.row { display: flex; align-items: center; gap: .5rem; }
.row.wrap { flex-wrap: wrap; margin: .5rem 0 1rem; }
.center-row { justify-content: center; flex-wrap: wrap; margin-top: 1rem; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */

.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 1rem;
    padding: .6rem max(16px, calc((100vw - 880px) / 2));
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; display: flex; align-items: center; gap: .5rem; font-size: 1.1rem; }
.flag, .login-flag {
    display: inline-block; width: 26px; height: 19px; border-radius: 3px;
    background:
        linear-gradient(90deg, transparent 7px, var(--navy) 7px 10px, transparent 10px) ,
        linear-gradient(transparent 8px, var(--navy) 8px 11px, transparent 11px),
        linear-gradient(90deg, transparent 6px, #fff 6px 11px, transparent 11px),
        linear-gradient(transparent 7px, #fff 7px 12px, transparent 12px),
        var(--red);
}
.tabs { display: flex; gap: .25rem; margin-left: auto; }
.tabs a {
    text-decoration: none; padding: .4rem .7rem; border-radius: 999px;
    color: var(--muted); font-weight: 600; font-size: .95rem;
    display: flex; align-items: center; gap: .35rem;
}
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.active { background: var(--red-soft); color: var(--accent); }

.view { max-width: 880px; margin: 0 auto; padding: 1rem 16px 3rem; position: relative; }

@media (max-width: 720px) {
    .topbar { padding: .55rem 16px; }
    .tabs {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
        background: var(--surface); border-top: 1px solid var(--border);
        justify-content: space-around; gap: 0; margin: 0;
        padding: .25rem .25rem calc(.25rem + env(safe-area-inset-bottom));
    }
    .tabs a { flex-direction: column; gap: 0; font-size: .68rem; padding: .3rem .4rem; border-radius: 10px; flex: 1; }
    .tabs a .ti { font-size: 1.25rem; line-height: 1.3; }
    .view { padding-bottom: 6rem; }
    .hide-mobile { display: none; }
    h1 { font-size: 1.4rem; }
}

/* ---------- cards / tiles ---------- */

.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow);
}
.card.link { display: block; text-decoration: none; transition: transform .1s, border-color .1s; }
.card.link:hover { border-color: var(--accent); transform: translateY(-1px); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .8rem; }
.grid .card { display: flex; flex-direction: column; gap: .35rem; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin: 1rem 0 .6rem; }
@media (max-width: 520px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .7rem .8rem; text-decoration: none; box-shadow: var(--shadow);
}
.tile.link:hover { border-color: var(--accent); }
.tile-top { display: flex; align-items: center; gap: .4rem; font-size: 1.35rem; }
.tile-top strong { font-variant-numeric: tabular-nums; }

.activity { display: flex; align-items: center; gap: .6rem; margin: .4rem 0 1rem; flex-wrap: wrap; }
.dots { display: flex; gap: 4px; }
.dot { width: 13px; height: 13px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); }
.dot.l1 { background: #f3b4bf; border-color: transparent; }
.dot.l2 { background: #e0607a; border-color: transparent; }
.dot.l3 { background: var(--red); border-color: transparent; }
.dot.today { outline: 2px solid var(--navy); outline-offset: 1px; }
@media (prefers-color-scheme: dark) {
    .dot.l1 { background: #6b2a38; } .dot.l2 { background: #a83a52; } .dot.l3 { background: #f0566f; }
    .dot.today { outline-color: var(--muted); }
}

.wotd { margin: 1rem 0; border-left: 4px solid var(--accent); }
.eyebrow { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.wotd-word { font-size: 1.6rem; font-weight: 700; display: flex; align-items: center; gap: .4rem; }
.wotd-en { font-size: 1.05rem; }
.example { font-style: italic; margin: .5rem 0 0; }

.account { margin-top: 2rem; }
.account summary { cursor: pointer; font-weight: 600; }
.account .stack { margin-top: 1rem; max-width: 380px; }

/* ---------- pills / bars ---------- */

.statline { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-top: .3rem; }
.pill {
    display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem;
    border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill.due { background: var(--warn-soft); color: var(--warn); }
.pill.new { background: var(--blue-soft); color: var(--navy); }
.pill.learning { background: var(--surface-2); }
.pill.done { background: var(--good-soft); color: var(--good); }
@media (prefers-color-scheme: dark) { .pill.new { color: #9db6ea; } }
.deck-title .pill { margin-left: .4rem; vertical-align: middle; }

.bar { display: flex; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: .5rem; }
.bar.thin { height: 4px; margin-top: .3rem; }
.b-mastered { background: var(--good); }
.b-learning { background: #e9b949; }

.deck-title { font-weight: 700; font-size: 1.05rem; }
.deck.all { margin: 1rem 0; }

/* ---------- buttons / inputs ---------- */

.btn {
    font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    padding: .55rem 1rem; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.bad { background: var(--surface); border-color: var(--bad); color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.big { padding: .8rem 1.2rem; font-size: 1.05rem; width: 100%; margin-top: .8rem; }
.btn.icon { padding: .15rem .4rem; border-radius: 8px; font-size: .95rem; background: transparent; border-color: transparent; }
.btn.icon:hover { background: var(--surface-2); }
.btn.letter { width: 2.6rem; padding: .35rem 0; font-size: 1.1rem; }
.small-btn { align-self: flex-start; font-size: .85rem; padding: .3rem .7rem; }

input[type=text], input[type=password], input[type=search], select {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 10px; padding: .55rem .75rem; width: 100%;
}
select { width: auto; }
input:focus, select:focus, .btn:focus-visible, .option:focus-visible, .chip:focus-visible, .gloss:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
label.row { flex-direction: row; font-weight: 500; }
input.correct { border-color: var(--good); background: var(--good-soft); }
input.wrong { border-color: var(--bad); background: var(--bad-soft); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg-btn { font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted); padding: .35rem .9rem; border-radius: 8px; cursor: pointer; }
.seg-btn.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.back { display: inline-block; text-decoration: none; color: var(--muted); font-size: .9rem; margin-bottom: .3rem; }
.back:hover { color: var(--text); }

/* ---------- flashcards ---------- */

.deck-head .row.wrap { justify-content: space-between; }
.session-meta { margin: .4rem 0 .8rem; }
.flashcard {
    background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
    box-shadow: var(--shadow); padding: 1.2rem 1.2rem 1.6rem; min-height: 260px;
    display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center;
    cursor: pointer; position: relative; user-select: none;
}
.fc-top { position: absolute; top: .7rem; left: 1rem; right: 1rem; display: flex; justify-content: space-between; }
.face-main { font-size: 1.9rem; font-weight: 700; line-height: 1.25; display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; justify-content: center; }
.back-side { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px dashed var(--border); width: 100%; }
.face-answer { font-size: 1.45rem; font-weight: 600; color: var(--accent); }
.note { margin-top: .5rem; color: var(--muted); font-size: .95rem; }
.back-side .example { margin-top: .7rem; }
.rate { gap: .6rem; }
.rate .btn { flex: 1; }
.done-box { padding: 2rem 1.2rem; }
.big-emoji { font-size: 3rem; }

.word-list { display: flex; flex-direction: column; margin-top: .8rem; }
.word-row { display: flex; justify-content: space-between; gap: 1rem; padding: .6rem .2rem; border-bottom: 1px solid var(--border); }
.word-row .right { flex-shrink: 0; max-width: 45%; }
.example-inline { font-style: italic; color: var(--muted); }

/* ---------- quiz ---------- */

.question { margin-bottom: .2rem; }
.q-text { font-size: 1.2rem; font-weight: 600; margin-bottom: 1rem; white-space: pre-line; }
.options { display: grid; gap: .5rem; }
.option {
    font: inherit; text-align: left; cursor: pointer; padding: .75rem 1rem; border-radius: 10px;
    border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option:disabled { cursor: default; }
.option.correct { border-color: var(--good); background: var(--good-soft); }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.feedback { margin-top: 1rem; padding: .8rem 1rem; border-radius: 10px; }
.feedback.ok { background: var(--good-soft); }
.feedback.bad { background: var(--bad-soft); }
.feedback .explain { margin-top: .4rem; font-size: .92rem; }
.hint { margin: -.4rem 0 .8rem; color: var(--muted); }
.hint summary { cursor: pointer; }

.order-line {
    min-height: 3.2rem; padding: .5rem; border-radius: 10px; border: 1.5px dashed var(--border);
    display: flex; flex-wrap: wrap; gap: .4rem; align-items: center;
}
.order-line.correct { border: 1.5px solid var(--good); background: var(--good-soft); }
.order-line.wrong { border: 1.5px solid var(--bad); background: var(--bad-soft); }
.order-bank { display: flex; flex-wrap: wrap; gap: .4rem; min-height: 2.5rem; }
.chip {
    font: inherit; font-weight: 600; cursor: pointer; padding: .4rem .75rem; border-radius: 9px;
    border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.chip.in { background: var(--surface); border-color: var(--muted); }
.chip:disabled { cursor: default; }

.mistakes { text-align: left; margin-top: 1.2rem; }
.mistake { padding: .6rem 0; border-top: 1px solid var(--border); }
.strike { text-decoration: line-through; color: var(--bad); }

/* ---------- stories ---------- */

.story { font-size: 1.12rem; line-height: 1.8; margin: 1rem 0 1.5rem; }
.story p { margin: 0 0 1rem; }
.gloss {
    font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer;
    text-decoration: underline dotted var(--accent) 2px; text-underline-offset: 4px;
}
.gloss:hover { background: var(--red-soft); border-radius: 3px; }
.gloss-pop {
    position: absolute; z-index: 5; max-width: 260px; min-width: 150px;
    background: var(--navy); color: #fff; padding: .55rem .8rem; border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25); font-size: .95rem;
}
.gloss-pop .btn.icon { color: #fff; }
@media (prefers-color-scheme: dark) { .gloss-pop { background: #2e3a5c; } }

/* ---------- grammar prose ---------- */

.prose { line-height: 1.65; }
.prose h1 { margin-top: .5rem; }
.prose table { border-collapse: collapse; width: 100%; margin: .8rem 0 1.2rem; font-size: .95rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--border); padding: .4rem .6rem; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }
.prose code { background: var(--surface-2); padding: .05rem .3rem; border-radius: 4px; font-size: .92em; }
.prose blockquote { margin: 1rem 0; padding: .6rem 1rem; border-left: 4px solid var(--accent); background: var(--surface); border-radius: 0 10px 10px 0; }
.prose blockquote p { margin: .2rem 0; }

/* ---------- errors / login ---------- */

.errors {
    max-width: 880px; margin: 1rem auto 0; padding: .8rem 1rem; border-radius: 10px;
    background: var(--warn-soft); color: var(--text); border: 1px solid var(--warn); font-size: .9rem;
}
.errors ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.form-error { background: var(--bad-soft); color: var(--bad); padding: .6rem .8rem; border-radius: 10px; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
    width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 18px; padding: 2rem 1.6rem; box-shadow: var(--shadow);
}
.login-flag { width: 44px; height: 32px; border-radius: 5px;
    background:
        linear-gradient(90deg, transparent 12px, var(--navy) 12px 17px, transparent 17px),
        linear-gradient(transparent 13.5px, var(--navy) 13.5px 18.5px, transparent 18.5px),
        linear-gradient(90deg, transparent 10px, #fff 10px 19px, transparent 19px),
        linear-gradient(transparent 11.5px, #fff 11.5px 20.5px, transparent 20.5px),
        var(--red);
}
.login-card h1 { font-size: 2rem; margin-top: .8rem; }

/* ---------- Mine ord ---------- */

.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; gap: 0; margin-top: .2rem; }
.word-form { max-width: 520px; }
.word-form h2 { margin-top: 0; }
.gloss-pop .pop-add { margin-top: .5rem; background: rgba(255, 255, 255, .15); color: #fff; border-color: rgba(255, 255, 255, .35); }
.gloss-pop .pop-add:disabled { opacity: .8; cursor: default; }

/* ---------- admin ---------- */

textarea {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 10px; padding: .55rem .75rem; width: 100%; resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; line-height: 1.5; }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; accent-color: var(--red); }
label.check { flex-direction: row; align-items: center; gap: .5rem; }

.btn.danger { color: var(--bad); border-color: var(--bad); background: var(--surface); }
.btn.danger:hover { background: var(--bad-soft); }
.btn:disabled { opacity: .45; cursor: default; }
.row.wrap-tight { flex-wrap: wrap; gap: .4rem; }
.no-top { margin-top: 0; }
.stack.tight { gap: .5rem; }

.admin-row { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; }
.admin-title { text-decoration: none; flex: 1; min-width: 12rem; }
.admin-title:hover strong { text-decoration: underline; }
.admin-actions { justify-content: flex-end; }
.link-box { border: 2px solid var(--good); }
.link-box input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }

.danger-zone { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: .8rem; }
.danger-zone summary { cursor: pointer; color: var(--muted); }
.danger-zone .stack { margin-top: .6rem; }

.editor { margin-top: 1rem; }
.fld { font-weight: 600; font-size: .85rem; gap: .25rem; }
.fld > span:first-child { color: var(--muted); }
.fld input, .fld textarea, .fld select { font-weight: 400; font-size: 1rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.meta-row { display: grid; grid-template-columns: 5rem 1fr; gap: .6rem; }
.icon-input { text-align: center; font-size: 1.3rem; padding: .35rem; }
@media (max-width: 560px) { .two { grid-template-columns: 1fr; } }

.le { display: flex; flex-direction: column; gap: .7rem; }
.le-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .9rem .9rem; }
.le-tools { display: flex; align-items: center; gap: .1rem; justify-content: flex-end; margin-bottom: .2rem; }
.le-tools .muted { margin-right: auto; }
.le > .btn { align-self: flex-start; }
.preview { margin-top: .5rem; }

.save-bar {
    position: sticky; bottom: 0; z-index: 5; margin: 1.5rem -16px 0; padding: .7rem 16px calc(.7rem + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 14px rgba(20, 25, 40, .06);
}
.save-bar .form-error { margin: 0 0 .5rem; }
.unsaved { color: var(--warn); font-weight: 600; }
.saved { color: var(--good); font-weight: 600; }
@media (max-width: 720px) {
    .save-bar { bottom: calc(3.6rem + env(safe-area-inset-bottom)); padding-bottom: .7rem; }
}

/* Buttons next to a full-width input keep their natural size instead of wrapping. */
.row > input:not([type=checkbox]) { flex: 1; min-width: 0; }
.row > .btn { flex-shrink: 0; white-space: nowrap; }
.admin-form { margin-top: 1.5rem; }
.admin-new { margin-bottom: .8rem; }
.admin-form h2 { margin-bottom: 0; }
