:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --ink: #2a211b;
  --muted: #7a6b60;
  --line: #eadfd3;
  --accent: #b4532a;
  --accent-ink: #ffffff;
  --soft: #f6e7dc;
  --ok: #2f7d4f;
  --warn: #a15c00;
  --warn-bg: #fdf0d8;
  --mine: #b4532a;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714;
    --surface: #26201c;
    --ink: #f3ebe4;
    --muted: #b3a296;
    --line: #3a312b;
    --accent: #e07a4c;
    --accent-ink: #1b1714;
    --soft: #3a2a20;
    --ok: #6fc28f;
    --warn: #f0b45a;
    --warn-bg: #3a2c14;
    --mine: #8a3f1f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; display: grid; gap: 14px; text-align: center; }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 6px; text-align: left; font-size: 14px; color: var(--muted); }
input, textarea { font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.login-card button[type=submit] { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 13px; font-weight: 600; }
.error { color: #c0392b; min-height: 1.2em; font-size: 14px; }
.logo { width: 56px; height: 56px; margin: 0 auto; border-radius: 16px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 30px; }
.logo.small { width: 28px; height: 28px; border-radius: 8px; font-size: 16px; margin: 0; }

/* app layout */
.app { height: 100%; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line); background: var(--bg); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.who { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--soft); white-space: nowrap; }
.pill.alert { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.link { background: none; border: 0; color: var(--muted); font-size: 13px; padding: 4px; text-decoration: underline; }

.chat { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; -webkit-overflow-scrolling: touch; }
.hint { color: var(--muted); }
.hint ul { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.ex { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; color: var(--ink); font-size: 14px; }

.msg-me { align-self: flex-end; max-width: 85%; background: var(--mine); color: #fff; padding: 9px 13px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-ai { align-self: stretch; background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 12px 14px; overflow-wrap: anywhere; }
.msg-ai.loading { color: var(--muted); font-style: italic; }

.meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--accent); }
.badge.new { background: var(--warn-bg); color: var(--warn); }
.ms { font-size: 11px; color: var(--muted); }

.entry { padding: 8px 0; border-top: 1px solid var(--line); }
.entry:first-of-type { border-top: 0; padding-top: 0; }
.entry .head { font-size: 18px; font-weight: 600; }
.entry .art { color: var(--muted); font-weight: 400; }
.entry .tr { margin-top: 2px; }
.entry .info { font-size: 13px; color: var(--muted); margin-top: 2px; }
.entry .exs { font-size: 14px; margin-top: 4px; }
.entry .exs i { color: var(--muted); }
.flag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); vertical-align: middle; margin-left: 6px; }
.mini { background: none; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; padding: 2px 9px; color: var(--ok); margin-left: 6px; }

.grammar p { margin: 6px 0; white-space: pre-line; }
.grammar ul { margin: 6px 0; padding-left: 18px; }

.verb-head { font-size: 20px; font-weight: 700; }
.verb-head small { font-size: 14px; font-weight: 400; color: var(--muted); }
details.tense { border-top: 1px solid var(--line); padding: 6px 0; }
details.tense summary { font-weight: 600; cursor: pointer; list-style: none; display: flex; align-items: baseline; gap: 8px; }
details.tense summary > span:first-child { flex: 0 1 auto; }
details.tense summary > .en { flex: 1; }
details.tense summary::-webkit-details-marker { display: none; }
details.tense summary::after { content: "▾"; color: var(--muted); }
details.tense:not([open]) summary::after { content: "▸"; }
.tense .en { font-weight: 400; color: var(--muted); font-size: 13px; }
table.forms { width: 100%; border-collapse: collapse; margin-top: 4px; font-size: 15px; }
table.forms td { padding: 4px 6px 4px 0; vertical-align: top; }
table.forms td.p { color: var(--muted); width: 38%; white-space: nowrap; }
table.forms td.f { font-weight: 600; }
.exline { font-weight: 400; font-size: 13px; color: var(--ink); margin: 2px 0 4px; }
.exline i { color: var(--muted); }

.list { columns: 2 200px; column-gap: 18px; margin: 6px 0 0; padding: 0; list-style: none; font-size: 14px; }
.list li { break-inside: avoid; padding: 2px 0; }
.list .es { font-weight: 600; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.actions button { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 7px 12px; font-size: 14px; font-weight: 600; }
.actions button.secondary { background: transparent; color: var(--accent); }
.done { font-size: 13px; color: var(--ok); margin-top: 8px; }

.ask { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.ask textarea { resize: none; min-height: 46px; max-height: 140px; border-radius: 22px; padding: 12px 16px; }
.ask button { flex: 0 0 46px; height: 46px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 18px; }
.ask button:disabled { opacity: .5; }
