[hidden] { display: none !important; }
:root {
  --bg: #f3f5f4; --fg: #17201d; --muted: #5c6864; --line: #d3dad7; --card: #ffffff;
  --brand: #16332c; --brand-fg: #ffffff; --accent: #1f6f5c;
  --eave: #1e7be6; --valley: #e0362c; --hip: #8a8f8d; --rake: #e8a317; --warn-bg: #fbf0dc; --warn-fg: #8a520c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111715; --fg: #e3e9e6; --muted: #9aa5a1; --line: #2c3532; --card: #19201e;
    --brand: #0d1f1b; --accent: #5cc3a6; --warn-bg: #33281a; --warn-fg: #e9b56a; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.bar {
  position: sticky; top: 0; z-index: 5; background: var(--brand); color: var(--brand-fg);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between;
}
.brand { font-weight: 700; letter-spacing: .02em; }
nav { display: flex; gap: 4px; }
.tab { background: transparent; color: var(--brand-fg); border: 0; padding: 8px 12px; border-radius: 8px; font: inherit; opacity: .75; }
.tab[aria-current="page"] { background: rgba(255,255,255,.14); opacity: 1; }
main { max-width: 640px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(32px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.view { display: flex; flex-direction: column; gap: 14px; }
h2 { margin: 4px 0 0; font-size: 1.2rem; }
label { font-weight: 600; font-size: .95rem; }
.row { display: flex; gap: 8px; }
.row > input { flex: 1; min-width: 0; }
input, select { font: inherit; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg); width: 100%; }
button { font: inherit; padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--eave); outline-offset: 2px; }
#search { display: flex; flex-direction: column; gap: 8px; }
.status { margin: 0; color: var(--muted); min-height: 1.4em; }
.where { margin: 0; font-weight: 600; }
.photo-wrap { display: flex; flex-direction: column; gap: 8px; }
canvas { width: 100%; height: auto; border-radius: 10px; background: #000; max-width: 100%; touch-action: pinch-zoom; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .85rem; color: var(--muted); }
.legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.k-eave { background: var(--eave); } .k-valley { background: var(--valley); } .k-hip { background: var(--hip); } .k-rake { background: var(--rake); }
.nums { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.nums div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.nums dt { font-size: .8rem; color: var(--muted); }
.nums dd { margin: 2px 0 0; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.nums div:nth-child(-n+3) dd { color: var(--accent); }
.warn { margin: 0; background: var(--warn-bg); color: var(--warn-fg); padding: 10px 12px; border-radius: 10px; font-size: .95rem; }
details { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
summary { font-weight: 600; cursor: pointer; }
.fix-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; margin: 12px 0; }
.fine { margin: 0; font-size: .85rem; color: var(--muted); }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history li { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.history b { display: block; }
.history .meta { font-size: .85rem; color: var(--muted); }
@media (max-width: 420px) { .nums { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
h3 { margin: 8px 0 0; font-size: 1rem; }
.choices { display: flex; flex-direction: column; gap: 6px; }
.choices button { text-align: left; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; counter-reset: s; }
.steps li { counter-increment: s; font-size: .8rem; text-align: center; padding: 6px 2px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); color: var(--muted); }
.steps li::before { content: counter(s) ". "; }
.steps li.now { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.steps li.done { color: var(--accent); }
.canvas-wrap { width: 100%; }
#cv { width: 100%; aspect-ratio: 1; display: block; border-radius: 10px; background: #000; touch-action: none; }
.hint { margin: 0; font-weight: 600; }
.verdict { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.verdict button { padding: 14px; font-size: 1.05rem; }
.verdict button[hidden] { display: none; }
#btn-done { grid-column: 1 / -1; }
.totals { display: flex; flex-direction: column; gap: 10px; }
.score, .params { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.score div, .params div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.score dt, .params dt { font-size: .8rem; color: var(--muted); }
.score dd, .params dd { margin: 2px 0 0; font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 420px) { .score, .params { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
