:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --text: #16202f;
  --muted: #5b6678;
  --line: #dde1e8;
  --accent: #1f5fd6;
  --accent-text: #ffffff;
  --alert: #fff3df;
  --alert-line: #e9b35c;
  --danger: #c0342b;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101826;
    --surface: #1a2433;
    --text: #edf1f7;
    --muted: #a4afc0;
    --line: #2d3a4e;
    --accent: #6ea2ff;
    --accent-text: #0c1320;
    --alert: #3a2e18;
    --alert-line: #8c6a2d;
    --danger: #ff8a7f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px calc(92px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 { font-size: 1.55rem; line-height: 1.2; margin: 0; }
h2 { font-size: 1.08rem; margin: 0 0 10px; }
p { margin: 0; }
img { display: block; max-width: 100%; border-radius: 10px; }

.hero { padding: 36px 0 12px; }
.hero h1 { font-size: 2.1rem; }
.hero p { color: var(--muted); margin-top: 6px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0; }
.card.alert { background: var(--alert); border-color: var(--alert-line); }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.note { color: var(--muted); font-size: 0.92rem; }
.strong { font-weight: 650; }
.error { color: var(--danger); font-weight: 600; }

label { font-weight: 600; }

input:not([type=radio]), select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

button, .button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
}

button:disabled { opacity: 0.55; cursor: progress; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.primary, .button.big { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.big { min-height: 84px; font-size: 1.15rem; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; min-height: 44px; }
.link.danger { color: var(--danger); }
.danger-solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.small { width: auto; min-height: 44px; padding: 6px 14px; font-size: 0.95rem; }

input.visually-hidden { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; border: 0; opacity: 0; overflow: hidden; pointer-events: none; }
.visually-hidden:focus-visible + .preview + .button, .visually-hidden:focus-visible ~ .button { outline: 3px solid var(--accent); outline-offset: 2px; }

.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; font-weight: 500; }
.choice:has(input:checked) { border-color: var(--accent); }
.choice input { width: 20px; height: 20px; accent-color: var(--accent); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.row p { flex: 1; }
.row .button { width: auto; flex: none; }
.buttons { display: flex; gap: 8px; flex: none; }
.list { list-style: none; margin: 0; padding: 0; }
.list span { overflow-wrap: anywhere; }

[hidden] { display: none !important; }
.preview { width: 100%; max-height: 70dvh; object-fit: contain; background: var(--bg); }
/* The viewfinder has the photo's exact shape, so what is visible is what gets saved. */
.viewfinder { width: min(100%, calc(70dvh * 4 / 3)); aspect-ratio: 4 / 3; margin-inline: auto; overflow: hidden; border-radius: 12px; background: #000; }
.viewfinder video { display: block; width: 100%; height: 100%; object-fit: cover; }
button.big { min-height: 84px; font-size: 1.15rem; }

.answer { padding: 8px 0; text-align: center; }
.distance { font-size: 3.6rem; font-weight: 800; line-height: 1.05; letter-spacing: -0.02em; }
.map { width: 100%; }
figcaption { margin-top: 8px; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; counter-reset: step; }
.steps li { display: flex; flex-direction: column; gap: 8px; counter-increment: step; }
.steps .strong::before { content: counter(step) ". "; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.tile img { aspect-ratio: 4 / 3; object-fit: cover; width: 100%; }

.spinner { width: 48px; height: 48px; margin: 8px auto 14px; border: 5px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.badge { margin-left: 6px; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: var(--surface); font-size: 0.8rem; line-height: 20px; display: inline-block; }

#tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs[hidden] { display: none; }
#tabs a { flex: 1; min-height: 58px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 650; text-decoration: none; }
#tabs a.active { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
