:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e5e0d8;
  --accent: #1a7f4b;
  --accent-ink: #ffffff;
  --bad: #c0392b;
  --warn: #9a6700;
  --good-bg: #e7f5ec;
  --bad-bg: #fbeaea;
  --rule-bg: #eef6f1;
  --de-bg: #fff8e1;
  --tr-bg: #e8f1fb;
  --en-bg: #f1edf9;
  --tip-bg: #fdecea;
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --ink: #e8e6e3;
    --muted: #9aa0a6;
    --line: #2f3338;
    --accent: #4cc38a;
    --accent-ink: #0b1f14;
    --bad: #ff7b72;
    --warn: #e3b341;
    --good-bg: #173225;
    --bad-bg: #3a1d1d;
    --rule-bg: #16281f;
    --de-bg: #332b12;
    --tr-bg: #17293b;
    --en-bg: #2a2438;
    --tip-bg: #3a1d1d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 64px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-wrap: break-word;
  -webkit-tap-highlight-color: transparent;
}
/* env(safe-area-inset-*): keep clear of the notch and the home indicator */
main {
  max-width: 760px; margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
button, .btn, nav a, summary { touch-action: manipulation; -webkit-user-select: none; user-select: none; }
h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
h3 { font-size: 1.05rem; margin: 0; }
a { color: var(--accent); }
em { color: var(--muted); }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.center { text-align: center; }
.big { font-size: 2.5rem; margin: 0; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; }

header {
  position: sticky; top: 0; z-index: 2;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none; }
.brand small { color: var(--muted); font-weight: 400; }
nav { display: flex; gap: 4px; }
nav a { padding: 6px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
nav a.active { background: var(--accent); color: var(--accent-ink); }
nav .ico { display: none; }
#notice { max-width: 760px; margin: 12px auto 0; padding: 10px 14px; border-radius: var(--radius); background: var(--de-bg); cursor: pointer; }

.card, .word, .step, .toc a {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.card { padding: 20px; margin: 16px 0; }
.hero { margin-bottom: 16px; }

.btn, .options button, .tiles button, .built button, .accents button, .word-tools button {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 16px;
  cursor: pointer; text-decoration: none; display: inline-block; min-height: 44px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--bad); }
button:disabled { cursor: default; opacity: 0.6; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.say { border: 0; background: none; padding: 6px; margin: -6px -4px; cursor: pointer; font-size: 0.95em; }
[lang="it"] { cursor: pointer; }
@media (hover: hover) { [lang="it"]:hover { text-decoration: underline dotted; } }
@media (hover: none) { .options kbd { display: none; } }
progress { width: 100%; height: 8px; accent-color: var(--accent); }

/* today */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.step { display: flex; align-items: center; gap: 14px; padding: 16px; }
.step > div { flex: 1; }
.step p { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }
.tick {
  flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center; font-weight: 700; color: var(--accent-ink);
}
.step.done .tick { background: var(--accent); border-color: var(--accent); }

/* quiz */
.quiz-top { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.85rem; }
.quiz .eyebrow { margin-top: 16px; }
.prompt { font-size: 1.45rem; line-height: 1.3; margin: 4px 0; }
.sub { margin: 4px 0 0; color: var(--muted); }
.answer { margin-top: 18px; }
.options { display: grid; gap: 8px; }
.options button { text-align: left; }
.options kbd { color: var(--muted); font: inherit; font-size: 0.8rem; margin-right: 6px; }
.options .right { border-color: var(--accent); background: var(--good-bg); opacity: 1; }
.options .wrong { border-color: var(--bad); background: var(--bad-bg); opacity: 1; }
.typed input {
  width: 100%; font: inherit; font-size: 1.15rem; padding: 10px 12px;
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.accents { display: flex; gap: 6px; margin: 8px 0 12px; }
.accents button { padding: 4px 11px; min-width: 44px; }
.built { min-height: 50px; padding: 6px 0; margin-bottom: 10px; border-bottom: 2px dashed var(--line); }
.built, .tiles { display: flex; flex-wrap: wrap; gap: 8px; }
.tiles { margin-bottom: 14px; }
.tiles button:disabled { visibility: hidden; }
.feedback { margin-top: 18px; padding: 14px 16px; border-radius: var(--radius); }
.feedback.good { background: var(--good-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback p { margin: 4px 0; }
.solution { font-size: 1.1rem; margin: 6px 0; }
.why { font-size: 0.92rem; color: var(--muted); }
.yours { text-decoration: line-through; color: var(--muted); }
.missed { list-style: none; padding: 0; text-align: left; display: grid; gap: 8px; }

/* words */
.words { display: grid; gap: 10px; margin: 12px 0; }
.word { padding: 12px 14px; }
.word-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.word-head strong { font-size: 1.2rem; }
.word-en { margin-top: 2px; }
.word-ex { margin-top: 6px; font-size: 0.95rem; }
.note { color: var(--muted); font-size: 0.88rem; font-style: italic; }
.cf { color: var(--muted); font-size: 0.88rem; }
.cf::before { content: "↔ "; color: var(--accent); }
.pl { color: var(--muted); font-size: 0.9rem; }
.tag { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.word-tools { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.85rem; }
.word-tools button { padding: 3px 10px; font-size: 0.85rem; min-height: 36px; }
.badge { margin-left: auto; padding: 1px 8px; border-radius: 99px; font-size: 0.72rem; border: 1px solid var(--line); color: var(--muted); }
.badge.known, .badge.done { background: var(--good-bg); color: var(--accent); border-color: transparent; }
.badge.weak { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.learning, .badge.current { background: var(--de-bg); color: var(--warn); border-color: transparent; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.toolbar input, .toolbar select, .card select {
  font: inherit; padding: 9px 12px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
}
.toolbar input { flex: 1; min-width: 180px; }
.card select, .card textarea { max-width: 100%; }
.code { width: 100%; font: 0.75rem/1.4 ui-monospace, monospace; padding: 8px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }

/* grammar book */
.toc { list-style: none; margin: 16px 0; padding: 0; display: grid; gap: 8px; }
.toc a { display: flex; gap: 14px; padding: 12px 14px; color: var(--ink); text-decoration: none; }
.toc .num { flex: none; width: 2ch; font-weight: 700; color: var(--accent); text-align: right; }
.toc-main { flex: 1; display: grid; gap: 2px; }
.toc-title { display: flex; align-items: baseline; gap: 8px; }
.toc small { font-size: 0.86rem; }
.toc .upcoming { opacity: 0.75; }
.subtitle { color: var(--muted); margin: 0 0 16px; }
.book { font-family: var(--serif); font-size: 1.08rem; line-height: 1.65; }
.book h3 { font-family: system-ui, sans-serif; font-size: 1.1rem; margin: 28px 0 6px; }
.book [lang="it"] { color: var(--accent); font-weight: 600; }
.book table { border-collapse: collapse; margin: 12px 0; display: block; overflow-x: auto; max-width: 100%; }
.book th, .book td { border: 1px solid var(--line); padding: 6px 12px; text-align: left; }
.book th { background: var(--rule-bg); font-family: system-ui, sans-serif; font-size: 0.85rem; }
.book .rule, .book .de, .book .tr, .book .en, .book .tip { padding: 12px 16px; margin: 14px 0; border-radius: var(--radius); }
.book .rule { background: var(--rule-bg); border-left: 4px solid var(--accent); }
/* language bridges: what German, Turkish and English already give the learner */
.book .de { background: var(--de-bg); }
.book .tr { background: var(--tr-bg); }
.book .en { background: var(--en-bg); }
.book .tip { background: var(--tip-bg); }
.book s { color: var(--bad); }
.book ul.ex { list-style: none; padding-left: 0; }
.book ul.ex li { padding: 3px 0; }
.reread { margin: 12px 0; }
.reread summary { cursor: pointer; color: var(--accent); }
.pager { display: flex; justify-content: space-between; gap: 8px; margin-top: 24px; }

/* progress */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 16px 0; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stats b { display: block; font-size: 1.5rem; }
.stats span { color: var(--muted); font-size: 0.85rem; }
.bar { display: block; margin: 12px 0; color: var(--muted); font-size: 0.9rem; }

/* say-anything corner button */
#say { position: fixed; right: 16px; bottom: 16px; z-index: 3; }
#say summary {
  list-style: none; margin-left: auto; width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.4rem; cursor: pointer;
  background: var(--accent); box-shadow: 0 4px 14px rgb(0 0 0 / 25%);
}
#say summary::-webkit-details-marker { display: none; }
#say form {
  width: min(320px, calc(100vw - 32px)); margin-top: 8px; padding: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 20%);
}
#say[open] { display: flex; flex-direction: column-reverse; }
#say[open] form { margin: 0 0 8px; }
#say label { font-size: 0.85rem; color: var(--muted); }
#say textarea {
  width: 100%; margin-top: 6px; font: inherit; padding: 8px; resize: vertical;
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}

/* phones: tabs move to the thumb, buttons grow to full width */
@media (max-width: 640px) {
  main { padding-top: 16px; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.45rem; }
  .card { padding: 16px; }
  header nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; gap: 0;
    padding: 4px max(4px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
    background: var(--surface); border-top: 1px solid var(--line);
  }
  header nav a { flex: 1; display: grid; justify-items: center; padding: 4px 2px; font-size: 0.72rem; }
  header nav .ico { display: block; font-size: 1.3rem; line-height: 1.3; }
  header nav a.active { background: none; color: var(--accent); font-weight: 600; }
  /* the speak-anything button moves into the top bar, where it covers nothing */
  #say { top: calc(4px + env(safe-area-inset-top)); bottom: auto; right: max(12px, env(safe-area-inset-right)); }
  #say summary { width: 40px; height: 40px; font-size: 1.1rem; box-shadow: none; }
  #say[open] { flex-direction: column; }
  #say[open] form { margin: 8px 0 0; }
  .prompt { font-size: 1.25rem; }
  .typed .btn, .answer > .check, .feedback .btn, #start, .step .btn { width: 100%; text-align: center; }
  .accents button { flex: 1; min-width: 0; padding: 8px 0; }
  .step { flex-wrap: wrap; }
  .step > div { flex-basis: calc(100% - 42px); }
  .book { font-size: 1.02rem; }
  .book th, .book td { padding: 6px 8px; }
  .book .rule, .book .de, .book .tr, .book .en, .book .tip { padding: 10px 12px; }
  .pager .btn { padding: 9px 10px; }
}
