:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #1c1b19;
  --text-2: #4a4842;
  --muted: #77746c;
  --faint: #8d897f;
  --border: #e6e2d9;
  --hairline: #eeeae2;
  --accent: #2f4a6d;
  --accent-text: #ffffff;
  --danger: #a3402f;
  --user-bubble: #ebe7df;
  --send-bg: #1c1b19;
  --placeholder: #a29e95;
  --serif: "Newsreader", Georgia, serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --surface: #1f1e1b;
    --text: #ece8df;
    --text-2: #cfcabf;
    --muted: #9a958a;
    --faint: #6f6b62;
    --border: #2e2c28;
    --hairline: #2b2925;
    --accent: #c9a86a;
    --accent-text: #161513;
    --danger: #d98a76;
    --user-bubble: #26241f;
    --send-bg: #c9a86a;
    --placeholder: #6f6b62;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding-bottom: calc(52px + env(safe-area-inset-bottom));
}

/* The target language is set in a serif, everywhere it appears. */
.construction, .pattern, .summary-gloss, .gloss, .examples .fr, .hook, .tl,
.related b, .list-row .fr, .msg.user i {
  font-family: var(--serif);
}

header {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 14px) 22px 14px;
}
h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
main { max-width: 720px; margin: 0 auto; }
.view { padding: 4px 16px 12px; }

nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 3;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  flex: 1; border: 0; background: none; color: var(--faint);
  padding: 12px 0; font-size: 13px; border-radius: 0;
  transition: color .15s ease;
}
nav button.on { color: var(--text); font-weight: 600; }
/* Not a pill: just the number, after the label. */
.badge { color: var(--accent); font-weight: 600; }

button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 9px; padding: 8px 14px; font-size: 14px; cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; }
/* Secondary actions are text, not boxes. */
button.text, .seg button, .icon-btn, .pill-btn, nav button, .ws-button, #new-entry, #download-backup,
.msg button.small, #delete-go, .danger-zone button.small {
  border: 0; background: none;
}
button.text { padding: 0; color: var(--text-2); }
button.text.danger { color: var(--danger); }
button.text.accent { color: var(--accent); }
button.text.faint { color: var(--faint); }
button.text:active, .seg button:active, .icon-btn:active, .msg button.small:active { opacity: .6; }

input, textarea, select {
  width: 100%; border: 1px solid var(--border); background: var(--surface);
  border-radius: 12px; padding: 10px 12px; font-size: 16px; /* 16px stops iOS zooming */
}
input[type="search"] { border-color: transparent; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
::placeholder { color: var(--placeholder); }

.row { display: flex; gap: 12px; align-items: center; }
.row > input, .row > textarea { flex: 1; }
.empty { color: var(--muted); }
.count { color: var(--faint); font-size: 13px; margin: 6px 0 2px; }

/* Header: title, the review counter and the workspace switcher */
.header-row { display: flex; align-items: baseline; gap: 12px; }
.header-row h1 { margin-right: auto; }
.header-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.ws-button {
  padding: 0; font-size: 13px; color: var(--muted); max-width: 55%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ws-button .caret { font-size: 10px; color: var(--faint); }

/* Add / chat */
#view-add { padding: 0; }
#chat { padding: 8px 22px 0; }
#add-form {
  position: sticky; bottom: calc(44px + env(safe-area-inset-bottom));
  background: var(--bg); padding: 10px 16px 12px;
}
/* What you sent is a soft pill on the right; the reply is plain text on the page, with no bubble around it. */
.msg { margin: 22px 0; overflow-wrap: anywhere; text-wrap: pretty; }
.msg.user {
  width: fit-content; max-width: 80%; margin-left: auto;
  padding: 9px 16px; border-radius: 18px;
  background: var(--user-bubble); white-space: pre-wrap;
}
.msg.bot.error { color: var(--danger); }
.msg a { color: var(--accent); text-decoration: none; }
/* Target-language words Claude marks up in its reply */
.tl { font-style: italic; font-size: 17.5px; }
.spinner {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 1.5px solid var(--border); border-top-color: var(--accent);
  animation: spin 1s linear infinite; vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* The input pill: the box with the mic and send buttons sitting inside it */
.input-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 5px 5px 5px 16px;
}
.input-pill textarea {
  flex: 1; border: 0; border-radius: 0; background: none;
  padding: 6px 0; max-height: 40vh; resize: none;
}
.input-pill textarea:focus { outline: none; }
.pill-btn {
  flex: none; width: 34px; height: 34px; padding: 0; border-radius: 50%;
  color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
#send-btn { background: var(--send-bg); color: var(--bg); }
#mic-btn.on { color: var(--danger); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .25; } }
#mic-status { font-size: 13px; color: var(--faint); text-align: center; margin: 0 0 6px; }
#mic-status:empty { display: none; }
.msg button.small { margin-left: 8px; padding: 0; font-size: 14px; color: var(--accent); }
.msg.bot .text { white-space: pre-wrap; }
.msg.bot .meta {
  margin: 10px 0 0; font-size: 14px; color: var(--muted);
  text-transform: none; letter-spacing: normal;
}
.msg.bot .meta.error { color: var(--danger); }
.msg.bot .meta a, .msg.bot .meta button.small { margin-left: 10px; }
.msg.bot .cards { margin-top: 12px; }
.msg.bot .actions { margin-top: 12px; }
/* An entry in a reply: a row between hairlines, not a box. */
.msg.bot .cards .list-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  border-top: 1px solid var(--border); border-bottom: 0;
  border-radius: 0; background: none; margin: 0; padding: 12px 0;
}
.msg.bot .cards .list-row:last-child { border-bottom: 1px solid var(--border); }
.msg.bot .cards .list-row .fr { font-size: 19px; font-weight: 400; }
.msg.bot .cards .list-row .en { color: var(--muted); font-size: 14px; }
.msg.bot .cards .list-row .status { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }

/* Entries and cards */
.card {
  background: var(--surface); border: 0;
  border-radius: 16px; box-shadow: 0 1px 0 var(--border);
  padding: 18px; margin: 12px 0;
}
.entry h4 {
  margin: 18px 0 4px; font-size: 11px; font-weight: 400;
  text-transform: uppercase; letter-spacing: .12em; color: var(--faint);
}
.entry h4 + p { font-size: 15px; color: var(--text-2); }
.entry p, .entry ol, .entry ul { margin: 4px 0; }
.entry ol, .entry ul { padding-left: 20px; }
.construction { font-size: 26px; line-height: 1.1; font-weight: 400; }
.meta { color: var(--faint); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.gloss { margin-top: 6px; font-style: italic; font-size: 17px; color: var(--text-2); }
.gloss.big { font-size: 26px; font-style: normal; font-weight: 400; color: var(--text); }
.hook { font-style: italic; font-size: 16px; color: var(--text-2); margin-top: 12px; }

/* A construction and its notes: no rule down the side, just space. */
.pattern-block { margin: 16px 0 0; }
.pattern-block > summary {
  list-style: none; cursor: pointer;
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
}
.pattern-block > summary::-webkit-details-marker { display: none; }
.pattern { font-weight: 500; font-size: 19px; }
.summary-gloss { display: block; color: var(--muted); font-size: 14px; font-family: var(--serif); }
/* Collapsed: a hairline row, the name and gloss on the left, the status on the right */
.pattern-block:not([open]) { border-top: 1px solid var(--hairline); padding-top: 12px; margin-top: 18px; }
.pattern-block:not([open]) .pattern { font-weight: 400; font-size: 17px; }
.pattern-block.suggested:not([open]) { border-top: 0; padding-top: 0; margin-top: 10px; }
.entry h4 + .pattern-block.suggested { margin-top: 6px; }
.pattern-block .meta { margin-top: 2px; }
.row-actions { display: flex; gap: 14px; align-items: baseline; white-space: nowrap; }

.entry ul.senses { list-style: none; padding-left: 0; margin: 8px 0 0; font-size: 15px; color: var(--text-2); }
.entry ul.senses li { margin-bottom: 4px; }
.entry ul.senses b { font-weight: 600; color: var(--text); }
.pattern-block .examples { margin-top: 12px; }
.examples { list-style: none; padding-left: 0; }
.examples li { margin-bottom: 10px; }
.examples .fr { display: block; font-size: 17px; }
.examples .en { display: block; color: var(--muted); font-size: 14px; }
.examples .note { display: block; font-size: 13px; color: var(--faint); font-style: italic; }
.related li { margin-bottom: 6px; }
.related b { font-weight: 400; font-size: 17px; }
.tag { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); white-space: nowrap; }
.source { color: var(--faint); font-size: 13px; }
.warn {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin: 10px 0 12px; font-size: 14px; color: var(--text-2);
}
.actions { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; margin-top: 16px; }

/* Lists (Browse, the review list, workspaces): hairlines, no boxes */
.list-row {
  display: block; background: none; border: 0; border-top: 1px solid var(--hairline);
  border-radius: 0; padding: 12px 0; margin: 0; cursor: pointer;
}
.list-row .fr { font-size: 19px; }
.list-row .en { color: var(--muted); font-size: 14px; }
details.list-row summary { list-style: none; }
details.list-row[open] summary { margin-bottom: 10px; }
#new-entry { padding: 0; color: var(--accent); white-space: nowrap; }
#download-backup { padding: 0; color: var(--text-2); }
#browse + p { margin-top: 22px; }

/* Review */
#view-review { padding: 0; }
.toolbar { display: flex; justify-content: space-between; gap: 14px; padding: 0 22px 12px; }
.seg { display: flex; gap: 14px; align-items: baseline; }
.seg button { padding: 0; font-size: 13px; color: var(--faint); border-radius: 0; }
.seg button.on { color: var(--text); font-weight: 600; }
.progress { height: 2px; margin: 0 22px; background: var(--border); border-radius: 2px; }
.progress span { display: block; height: 2px; background: var(--accent); border-radius: 2px; transition: width .15s ease; }
#review { padding: 16px 16px 0; }
#review .list-row .lead { font-size: 17px; }
.flash { min-height: 180px; cursor: pointer; border-radius: 18px; padding: 30px 22px 20px; margin: 0; }
.flash .front { text-align: center; }
.flash .front .construction { font-size: 34px; }
.flash .front .gloss { margin-top: 0; }
/* The hint on a recall card is a sentence, so it keeps sentence case. */
.flash .front .hint { margin-top: 10px; font-size: 14px; color: var(--muted); }
.flash .front .meta { margin-top: 8px; letter-spacing: .08em; }
.flash .tap { text-align: center; color: var(--faint); font-size: 13px; letter-spacing: .04em; margin: 28px 0 0; }
.flash hr { border: 0; border-top: 1px solid var(--hairline); margin: 24px 0 18px; }
/* The front already says the construction and its kind, so the back starts at the gloss. */
.flash .entry > .construction, .flash .pattern-block.focus > summary, .flash .pattern-block.focus > .meta { display: none; }
.flash .pattern-block.focus { margin-top: 0; }
.flash .pattern-block.focus > .gloss { margin-top: 0; font-style: normal; font-size: 21px; color: var(--text); }
.grades {
  position: sticky; bottom: calc(44px + env(safe-area-inset-bottom));
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px;
  padding: 8px 16px 14px; background: var(--bg);
}
.grades button { padding: 12px 0; font-size: 15px; border-radius: 11px; background: var(--bg); }
.grades button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.grades button[data-grade="again"] { color: var(--danger); }

/* Inbox: one card per word */
.inbox-word > summary {
  list-style: none; cursor: pointer;
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
}
.inbox-word > summary::-webkit-details-marker { display: none; }
.inbox-word:not([open]) > summary .construction { font-size: 22px; }
.inbox-word .entry > .construction { display: none; }
.inbox-count { font-size: 13px; color: var(--faint); white-space: nowrap; }

/* Entry icon buttons (edit / delete / close) */
.entry-icons { display: flex; justify-content: flex-end; gap: 10px; margin-bottom: 6px; }
dialog .entry-icons { position: sticky; top: 0; background: var(--surface); padding: 2px 0 8px; z-index: 1; }
.icon-btn {
  padding: 4px; border-radius: 8px; cursor: pointer; color: var(--faint);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn.danger { color: var(--faint); }
.icon-btn:active { opacity: .6; }

/* Modal */
dialog {
  width: min(680px, calc(100vw - 16px)); max-height: calc(100dvh - 32px);
  border: 0; border-radius: 16px;
  background: var(--surface); color: var(--text); padding: 18px;
}
dialog::backdrop { background: rgba(20, 19, 17, .35); }
dialog h3 { margin: 0 0 12px; font-size: 17px; font-weight: 600; }
dialog h4 { margin: 20px 0 6px; font-size: 11px; font-weight: 400; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); }
#editor label { display: block; margin: 12px 0; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
#editor label small { font-size: 11px; letter-spacing: 0; text-transform: none; }
#editor input, #editor textarea, #editor select { margin-top: 4px; color: var(--text); text-transform: none; letter-spacing: normal; }

/* Workspace rows keep the UI font: the name is not target-language text. */
.list-row[data-ws] .fr { font-family: inherit; font-size: 16px; }
.list-row.current .fr { font-weight: 600; }
#ws-form { margin-top: 18px; }
#ws-form label { display: block; margin: 12px 0; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
#ws-form label small { letter-spacing: 0; text-transform: none; }
#ws-form select, #ws-form input { margin-top: 4px; color: var(--text); }

/* Login */
.login { padding: 48px 22px; max-width: 420px; margin: 0 auto; }
.login .card { box-shadow: none; background: none; padding: 0; }
.login h2 { margin: 0 0 18px; font-family: var(--serif); font-size: 32px; font-weight: 400; }
.login label { display: block; margin: 14px 0; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
.login input { margin-top: 4px; color: var(--text); text-transform: none; letter-spacing: normal; }
.login button { width: 100%; margin-top: 16px; padding: 12px 14px; }
.error { color: var(--danger); font-size: 14px; }

/* Forms worth knowing on a card ("an|rufen, rief an, hat angerufen") */
.forms { font-size: 13px; margin-top: 4px; color: var(--text-2); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Deleting a workspace: kept apart, behind a warning */
.danger-zone { margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--hairline); text-align: right; }
.danger-zone button.small { padding: 0; font-size: 14px; color: var(--danger); }
.danger-box { background: none; border-color: var(--danger); }
.danger-box p { margin: 4px 0; }
#delete-go { padding: 0; color: var(--danger); font-weight: 600; }
.confirm-name { display: block; margin: 16px 0; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
.confirm-name input { margin-top: 4px; color: var(--text); text-transform: none; letter-spacing: normal; }
.confirm-name b { font-family: var(--serif); font-size: 15px; letter-spacing: 0; text-transform: none; }
