:root {
  --bg: #f6f3ee; --paper: #fffdf9; --ink: #1f1d1a; --soft: #6f6a62; --line: #e4ded4;
  --accent: #b4532a; --accent-soft: #f3e1d4; --good: #2f7d4f; --bad: #b8433a; --mark: #fbe3a6;
  --radius: 14px; --tabs: 58px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16161a; --paper: #1f1f24; --ink: #ece8e1; --soft: #9a958c; --line: #2f2f36;
    --accent: #e0875c; --accent-soft: #3a2a22; --good: #5fbf85; --bad: #e57368; --mark: #5a4a1c; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: .5em .9em; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: none; border-color: transparent; color: var(--soft); }
button:disabled { opacity: .5; }
input, textarea { width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: .6em .75em; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: none; min-height: 3.2em; line-height: 1.45; display: block; }
label.lbl { display: block; font-size: .8rem; color: var(--soft); margin: .9em 0 .3em; letter-spacing: .02em; }
.muted { color: var(--soft); }
.small { font-size: .85rem; }
.row { display: flex; gap: .5rem; align-items: center; }
.grow { flex: 1; }
h1, h2 { font-family: var(--serif); font-weight: 600; margin: .2em 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; }

#view { max-width: 720px; margin: 0 auto; padding: 14px 14px calc(var(--tabs) + 24px + env(safe-area-inset-bottom)); min-height: 100dvh; }

/* ---------------------------------------------------------------- tabs */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); z-index: 10; }
#tabs a { flex: 0 1 140px; display: flex; flex-direction: column; align-items: center; gap: 1px; text-decoration: none;
  color: var(--soft); font-size: .72rem; padding: 5px 0; border-radius: 10px; position: relative; }
#tabs a.on { color: var(--accent); }
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
#badge { position: absolute; top: 2px; left: calc(50% + 8px); font-size: .65rem; background: var(--accent); color: #fff;
  border-radius: 9px; padding: 0 5px; min-width: 18px; text-align: center; line-height: 16px; }
#badge:empty { display: none; }
body.typing #tabs { display: none; }

/* ------------------------------------------------------------- content */
.md { font-family: var(--serif); font-size: 1.2rem; line-height: 1.45; overflow-wrap: anywhere; }
.md img { max-width: 100%; max-height: 60vh; border-radius: 8px; display: block; margin: .4em 0; }
.md code { font-family: var(--mono); font-size: .85em; background: var(--accent-soft); padding: .05em .3em; border-radius: 4px; }
.md pre { font-family: var(--mono); font-size: .8rem; background: var(--bg); border: 1px solid var(--line); padding: .6em .8em;
  border-radius: 8px; overflow-x: auto; white-space: pre; }
.md pre code { background: none; padding: 0; font-size: inherit; }
.md ul { margin: .2em 0; padding-left: 1.2em; }
.md h3 { font-size: 1.1em; margin: .6em 0 .3em; } .md h3:first-child { margin-top: 0; }
.md p { margin: 0 0 .5em; } .md p:last-child { margin-bottom: 0; }
.md blockquote { margin: .3em 0; padding-left: .8em; border-left: 3px solid var(--line); color: var(--soft); }
.cloze { color: var(--accent); font-weight: 600; font-family: system-ui, sans-serif; font-size: .9em; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 .15em; }

/* -------------------------------------------------------------- review */
.rv-top { display: flex; align-items: center; gap: .6rem; font-size: .85rem; color: var(--soft); min-height: 34px; }
.rv-top .grow { font-variant-numeric: tabular-nums; }
.bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin: 4px 0 12px; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .25s; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 20px;
  box-shadow: 0 1px 2px rgb(0 0 0 / .04), 0 8px 24px -12px rgb(0 0 0 / .12); min-height: 38dvh; cursor: pointer;
  display: flex; flex-direction: column; }
.card .src { font-size: .75rem; color: var(--soft); margin-bottom: 10px; letter-spacing: .02em; }
.card hr { border: 0; border-top: 1px dashed var(--line); margin: 18px 0; width: 100%; }
.card .back { animation: rise .18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
.answer { position: fixed; left: 0; right: 0; bottom: calc(var(--tabs) + env(safe-area-inset-bottom)); padding: 10px 14px;
  display: flex; gap: 10px; max-width: 720px; margin: 0 auto; }
.answer button { flex: 1; padding: 16px 0; font-size: 1.05rem; font-weight: 600; border-radius: 14px; }
.answer .forgot { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.answer .got { background: var(--good); border-color: var(--good); color: #fff; }
.answer .show { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.done { text-align: center; padding: 12vh 10px 0; }
.done .big { font-family: var(--serif); font-size: 2rem; margin-bottom: .2em; }
.keys { font-size: .75rem; color: var(--soft); text-align: center; margin-top: 10px; }
@media (hover: none) { .keys { display: none; } }

/* ----------------------------------------------------------------- add */
.seg { display: inline-flex; background: var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: .3em .8em; border-radius: 8px; font-size: .9rem; color: var(--soft); }
.seg button.on { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .1); }
.field { position: relative; }
.field textarea { padding-bottom: 2.4em; }
.field .tools { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 4px; }
.tools button { padding: 3px 8px; font-size: .8rem; border-radius: 8px; color: var(--soft); background: var(--bg); }
.tools svg { width: 18px; height: 18px; vertical-align: -4px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.field.drop textarea { border-color: var(--accent); border-style: dashed; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.thumbs img { height: 56px; border-radius: 6px; border: 1px solid var(--line); }
.savebar { position: sticky; bottom: calc(var(--tabs) + 8px + env(safe-area-inset-bottom)); margin-top: 16px; display: flex; gap: 8px; align-items: center;
  background: var(--bg); padding: 6px 0; }
body.typing .savebar { bottom: 8px; }
.savebar .primary { flex: 1; padding: 14px; font-size: 1.05rem; border-radius: 12px; }
.check { display: flex; align-items: center; gap: .4em; font-size: .9rem; color: var(--soft); white-space: nowrap; }
.check input { width: auto; }
.preview { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 12px; }
.preview .card { min-height: 0; cursor: default; }
.hint { font-size: .85rem; color: var(--accent); margin-top: 6px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips button { white-space: nowrap; padding: 3px 10px; font-size: .8rem; border-radius: 20px; color: var(--soft); }
.chips button.on { border-color: var(--accent); color: var(--accent); }

/* -------------------------------------------------------------- browse */
.search { position: sticky; top: 0; background: var(--bg); padding: 4px 0 10px; z-index: 5; }
.search input { padding: .7em .9em; font-size: 1rem; border-radius: 12px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: block; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  text-decoration: none; color: inherit; }
.item .md { font-size: 1rem; }
.item .md img { max-height: 120px; }
.item .a { color: var(--soft); margin-top: 4px; }
.item .a.md { font-size: .95rem; }
.item .meta { font-size: .72rem; color: var(--soft); margin-top: 6px; display: flex; gap: 10px; flex-wrap: wrap; }
.item.susp { opacity: .55; }
.src-item { display: flex; align-items: baseline; gap: 10px; }
.src-item .name { font-family: var(--serif); font-size: 1.1rem; flex: 1; overflow-wrap: anywhere; }
.src-item .n { font-size: .8rem; color: var(--soft); font-variant-numeric: tabular-nums; }
.section { margin: 20px 0 8px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--soft); display: flex; align-items: center; gap: 8px; }
.section .grow { height: 1px; background: var(--line); }
.section a { text-transform: none; letter-spacing: 0; text-decoration: none; font-size: .85rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0 4px; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; min-width: 0; }
.stat b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { display: block; font-size: .7rem; line-height: 1.25; color: var(--soft); }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 40px; margin-top: 8px; }
.spark i { flex: 1; background: var(--accent); opacity: .75; border-radius: 2px 2px 0 0; }
.spark i[style*="height:0%"] { height: 2px !important; background: var(--line); }
.notes { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.notes .md { font-size: 1.05rem; }
.notes-empty { color: var(--soft); font-style: italic; }
.srclink { margin: -6px 0 12px; font-size: .9rem; overflow-wrap: anywhere; }
.srclink:empty { display: none; }
.srclink a { text-decoration: none; }
.back-link { display: inline-block; margin-bottom: 8px; text-decoration: none; color: var(--soft); font-size: .9rem; }
.danger { color: var(--bad); }
.info { font-size: .8rem; color: var(--soft); display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin-top: 14px; }

/* --------------------------------------------------------------- misc */
#toast { position: fixed; left: 50%; bottom: calc(var(--tabs) + 90px); transform: translateX(-50%) translateY(10px); background: var(--ink); color: var(--bg);
  padding: 8px 16px; border-radius: 20px; font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 20; white-space: nowrap; }
#toast.on { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 0 0 0 10px; }
body.login { display: grid; place-items: center; min-height: 100dvh; }
body.login form { width: min(320px, 90vw); display: flex; flex-direction: column; gap: 10px; }
body.login h1 { text-align: center; font-size: 2.2rem; }
body.login button { padding: .7em; }
#msg { color: var(--bad); text-align: center; min-height: 1.5em; margin: 0; }
