:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #17212b;
  --muted: #5b6875;
  --line: #d8dee4;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --accent-soft: #e3eef6;
  --chosen: #1f5f8b;
  --chosen-ink: #ffffff;
  --focus: #f0a020;
  --ok: #2e7d4f;
  --warn: #b25b00;
  --danger: #b3261e;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12171c;
    --card: #1b2229;
    --text: #e6ebf0;
    --muted: #9aa7b3;
    --line: #2f3a44;
    --accent: #6fb0e0;
    --accent-ink: #0d1a24;
    --accent-soft: #1f3343;
    --chosen: #6fb0e0;
    --chosen-ink: #0d1a24;
    --focus: #f0b040;
    --ok: #6cc28f;
    --warn: #e9a352;
    --danger: #ef7d74;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12171c; --card: #1b2229; --text: #e6ebf0; --muted: #9aa7b3; --line: #2f3a44;
  --accent: #6fb0e0; --accent-ink: #0d1a24; --accent-soft: #1f3343; --chosen: #6fb0e0; --chosen-ink: #0d1a24;
  --focus: #f0b040; --ok: #6cc28f; --warn: #e9a352; --danger: #ef7d74; color-scheme: dark;
}

* { box-sizing: border-box; }
/* layout rules (display: grid/flex) must never un-hide an element hidden by the app */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { max-width: 820px; margin: 0 auto; padding: 0 16px 96px; }

/* top bar */
.bar {
  position: sticky; top: 0; z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) 0 0;
}
.bar-in { max-width: 820px; margin: 0 auto; padding: 8px 12px; display: flex; align-items: center; gap: 8px; min-height: 56px; }
.bar h1 { font-size: 1.05rem; margin: 0; flex: 1; min-width: 0; }
.bar h1 .tt, .bar h1 .sub { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .sub { font-size: .8rem; color: var(--muted); font-weight: 400; }
.progress { height: 4px; background: var(--line); }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .2s; }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 10px 14px; min-height: 44px; font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.btn.big { width: 100%; padding: 16px; font-size: 1.05rem; }
.icon-btn { border: 0; background: transparent; min-width: 44px; min-height: 44px; border-radius: 10px; font-size: 1.3rem; }
.icon-btn:hover { background: var(--accent-soft); }

.pill {
  border: 0; border-radius: 999px; padding: 6px 12px; min-height: 36px;
  background: var(--accent-soft); color: var(--text); font-weight: 600; font-size: .9rem; white-space: nowrap;
}

h2 { font-size: 1rem; margin: 24px 0 8px; color: var(--muted); font-weight: 600; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* home */
.newform { padding: 16px; display: grid; gap: 12px; margin-top: 16px; }
.newform .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label.field { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .text-in, textarea.text-in {
  width: 100%; padding: 10px 12px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 1rem; font-weight: 400;
}
textarea.text-in { min-height: 80px; resize: vertical; }
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--line); }
.list a, .list button.rowbtn {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; text-decoration: none; color: inherit;
  width: 100%; border: 0; background: transparent; text-align: left;
}
.list a:hover, .list button.rowbtn:hover { background: var(--accent-soft); }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow-wrap: anywhere; }
.status { font-size: .85rem; color: var(--muted); white-space: nowrap; text-align: right; }
.status.done { color: var(--ok); font-weight: 600; }
.status.part { color: var(--warn); font-weight: 600; }
.chev { color: var(--muted); }
.tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.search { margin: 16px 0 8px; }

/* questionnaire */
.consigne { margin-top: 16px; padding: 12px 16px; white-space: pre-line; font-size: .95rem; }
.consigne summary { cursor: pointer; font-weight: 600; }
.sec-title { margin: 28px 4px 8px; font-size: .95rem; font-weight: 700; color: var(--text); }

.item {
  margin-top: 10px; padding: 14px 16px; border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--card); scroll-margin-top: 140px; scroll-margin-bottom: 140px;
}
.item.answered { border-color: var(--line); }
.item.active { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.item.sub { margin-left: 20px; }
.q { display: flex; gap: 10px; margin-bottom: 10px; }
.q .n { font-weight: 700; color: var(--muted); min-width: 1.6em; }
.q .t { flex: 1; }
.desc { white-space: pre-line; font-size: .9rem; color: var(--muted); margin: -4px 0 10px; }
.field-label { font-size: .85rem; font-weight: 600; color: var(--muted); margin: 10px 0 6px; }

.opts { display: grid; gap: 6px; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); }
.opts.stack { grid-template-columns: 1fr; }
.opts.fit { grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--min, 120px)), 1fr)); }
.opt {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; min-height: 48px; padding: 6px 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center;
  line-height: 1.15; touch-action: manipulation; min-width: 0;
  hyphens: auto; overflow-wrap: break-word;
}
.opts.stack .opt { flex-direction: row; justify-content: flex-start; text-align: left; padding: 10px 12px; gap: 10px; }
.opt .code { font-weight: 700; font-size: 1.1rem; }
.opt .lbl { font-size: .8rem; }
.opts.stack .opt .lbl { font-size: .95rem; }
.opt .hint { font-size: .7rem; color: var(--muted); }
.opt:hover { border-color: var(--accent); }
.opt[aria-pressed="true"] { background: var(--chosen); color: var(--chosen-ink); border-color: var(--chosen); }
.opt[aria-pressed="true"] .hint { color: inherit; }
.opt.clear { color: var(--muted); }

.num-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.num-row .text-in { width: 8em; font-size: 1.2rem; font-weight: 700; }
.num-row input[type="range"] { flex: 1; min-width: 160px; accent-color: var(--accent); height: 36px; }
.range-labels { display: flex; justify-content: space-between; gap: 12px; font-size: .75rem; color: var(--muted); margin-top: 4px; }
.err { color: var(--danger); font-size: .85rem; }
.text-in.bad { border-color: var(--danger); }

.scores { margin-top: 24px; padding: 16px; }
.scores h3 { margin: 0 0 8px; font-size: 1rem; }
.score-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.score-row:first-of-type { border-top: 0; }
.score-row > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.score-row .v { font-weight: 700; white-space: nowrap; text-align: right; }
.score-row .r { display: block; font-weight: 400; font-size: .85rem; color: var(--muted); }
.missing { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.missing button { border: 1px solid var(--warn); color: var(--warn); background: transparent; border-radius: 8px; min-width: 40px; min-height: 36px; font-weight: 600; }
.nextbar { display: flex; gap: 8px; margin-top: 16px; }
.nextbar .btn { flex: 1; }
.kbd-hint { font-size: .8rem; color: var(--muted); margin-top: 12px; }
@media (hover: none) { .kbd-hint { display: none; } }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }

@media (max-width: 520px) {
  .wrap { padding: 0 12px 96px; }
  .item { padding: 12px; }
  .item.sub { margin-left: 8px; }
  .opt { padding: 6px 3px; }
  .opts { gap: 5px; }
  .opt .lbl { font-size: .72rem; }
  .newform .row { grid-template-columns: 1fr; }
}
.group .field-active { outline: 2px dashed var(--focus); outline-offset: 4px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { border-color: var(--line); }

/* multi-select answers (CAPS) show a tick box so they read as "tick all that apply" */
.opts.multi .opt { flex-direction: row; gap: 8px; justify-content: flex-start; text-align: left; padding: 8px 10px; }
.opts.multi .opt::before {
  content: ""; flex: none; width: 18px; height: 18px; border: 2px solid currentColor; border-radius: 4px; opacity: .6;
}
.opts.multi .opt[aria-pressed="true"]::before {
  opacity: 1; background: currentColor;
  -webkit-mask: none; box-shadow: inset 0 0 0 3px var(--chosen);
}
input[type="range"].unset { opacity: .35; }

@media (min-width: 600px) {
  .item.inline { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 34%); align-items: center; gap: 16px; }
  .item.inline .q { margin: 0; }
}

.install { margin-top: 16px; padding: 12px 16px; }
.install summary { cursor: pointer; font-weight: 600; }
.install p { margin: 10px 0 0; }
.install .btn { margin-top: 12px; }
.install-os { margin-top: 14px; }
.install-os h3 { font-size: 1rem; margin: 0 0 4px; }
.install-os.here h3 { color: var(--accent); }
.install-os ol { margin: 0; padding-left: 1.4em; }
.install-os li { margin: 3px 0; }
.theme-row { display: flex; align-items: center; gap: 12px; margin-top: 24px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: transparent; padding: 8px 14px; min-height: 40px; font-weight: 600; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
