:root {
  --bg: #f7f5ef;
  --surface: #ffffff;
  --surface-2: #efebe0;
  --text: #1b2421;
  --muted: #5c6763;
  --line: #e2ddd0;
  --brand: #0f3b34;
  --brand-ink: #f4efe1;
  --accent: #b08a22;
  --accent-soft: #f3e9cc;
  --ok: #2f7a4f;
  --danger: #a33a2c;
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1513; --surface: #16201d; --surface-2: #1d2a26; --text: #e9ece8;
    --muted: #9aa6a1; --line: #26332f; --brand: #c9a43a; --brand-ink: #0e1513;
    --accent: #e2c46a; --accent-soft: #2a2a1c; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1513; --surface: #16201d; --surface-2: #1d2a26; --text: #e9ece8;
  --muted: #9aa6a1; --line: #26332f; --brand: #c9a43a; --brand-ink: #0e1513;
  --accent: #e2c46a; --accent-soft: #2a2a1c; color-scheme: dark;
}

* { 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.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .85rem; }

/* App shell */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar img { width: 32px; height: 32px; border-radius: 8px; }
.topbar .title { font-weight: 700; font-size: 1.05rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back {
  border: 0; background: var(--surface-2); border-radius: 999px;
  width: 36px; height: 36px; display: grid; place-items: center; font-size: 1.1rem;
}
main {
  max-width: 720px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .72rem; font-weight: 600;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button[aria-current="page"] { color: var(--brand); }

/* Pieces */
.hero {
  background: var(--brand); color: var(--brand-ink);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}
.hero p { opacity: .9; margin: 0; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 0 10px; }
.section-title button { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 0; }
.card {
  display: block; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
button.card:active { transform: scale(.99); }
.card .meta { color: var(--muted); font-size: .85rem; }
.row { display: flex; align-items: center; gap: 12px; }
.icon-badge {
  flex: none; width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; font-size: 1.4rem; background: var(--accent-soft);
}
.chip {
  display: inline-block; font-size: .75rem; font-weight: 600;
  padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text);
}
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; background: var(--ok); }
.search {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); margin-bottom: 14px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600;
  background: var(--brand); color: var(--brand-ink); width: 100%;
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.article { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.article ul { padding-left: 1.2rem; margin: 0 0 .85rem; }
.article li { margin-bottom: .35rem; }
.notice {
  font-size: .85rem; color: var(--muted);
  border-left: 3px solid var(--accent); padding: 8px 12px; margin: 16px 0 0;
  background: var(--surface-2); border-radius: 0 10px 10px 0;
}
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  background: var(--surface); border: 0; border-bottom: 1px solid var(--line);
  padding: 14px 16px; text-align: left; text-decoration: none; color: var(--text);
}
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.list > :last-child { border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 2.4rem; }
.quiz-option {
  display: block; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 8px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
}
.quiz-option.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.quiz-option.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); }
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px; font-weight: 600; }
.segmented button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* First-launch notice */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 90vh; overflow: auto;
}
@media (min-width: 600px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; }
}

/* Standalone legal pages */
.page { max-width: 720px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 24px) 16px 48px; }
.page header { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.page header img { width: 40px; height: 40px; border-radius: 10px; }
.page h2 { margin-top: 1.4rem; }
.page .meta { color: var(--muted); font-size: .9rem; }
