/* ===== "A little manga. Still practical." (colours sampled from the mockup) ===== */
:root {
  --paper: #f6eee3;    --paper-2: #fbf7f0;  --desk: #ece3d3;
  --ink: #1c1a17;      --muted: #5f5a50;    --line: #d6ccbb;
  --green: #315e4a;    --green-dark: #1f4535; --green-soft: #e3ebe4;
  --red: #ba3844;      --red-soft: #e25b61;
  --g-a: #2f6b4f; --g-b: #5f7f33; --g-c: #a8781f; --g-d: #b85a28; --g-e: #a93a40;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --hand: "Kalam", "Comic Sans MS", "Segoe Print", cursive;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--body); color: var(--ink); background: var(--desk); line-height: 1.5; }
button, input { font: inherit; color: inherit; }
:where(svg:not(.leaflet-pane svg)) { width: 1.3rem; height: 1.3rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ===== Phone-width column ===== */
.app {
  max-width: 560px; min-height: 100vh; margin: 0 auto; background: var(--paper);
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
}
main { padding: 1.1rem 1.25rem calc(6rem + env(safe-area-inset-bottom, 0px)); view-transition-name: page; }

.topbar {
  position: sticky; top: 0; z-index: 800; display: grid; grid-template-columns: 2.75rem 1fr auto; align-items: center;
  padding: calc(0.5rem + env(safe-area-inset-top, 0px)) 1rem 0.5rem; background: var(--paper); border-bottom: 1px solid var(--line);
}
.wordmark { text-align: center; font-weight: 700; letter-spacing: 0.04em; font-size: 1.05rem; }
.icon-btn { width: 2.75rem; height: 2.75rem; display: grid; place-items: center; background: none; border: 0; border-radius: 8px; cursor: pointer; }
.help-pill {
  border: 1.5px solid var(--red-soft); color: var(--red); background: var(--paper-2); font-weight: 700; font-size: 0.9rem;
  border-radius: 999px; padding: 0.3rem 0.9rem; min-height: 2.2rem; cursor: pointer;
}

.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100%, 560px); z-index: 800;
  display: grid; grid-template-columns: 1fr 1fr; background: var(--paper); border-top: 1px solid var(--line);
  padding: 0.35rem 0 calc(0.35rem + env(safe-area-inset-bottom, 0px));
}
.tabbar button {
  display: grid; justify-items: center; gap: 0.1rem; background: none; border: 0; cursor: pointer;
  font-size: 0.8rem; color: var(--muted); padding: 0.35rem 0;
}
.tabbar button[aria-current="page"] { color: var(--green-dark); font-weight: 700; }
.tabbar button[aria-current="page"] svg { fill: var(--green); stroke: var(--green-dark); }

/* ===== Type ===== */
h1 { font-family: var(--hand); font-weight: 700; font-size: 1.75rem; line-height: 1.2; margin: 0.3rem 0 0.2rem; }
h2 { font-family: var(--hand); font-weight: 700; font-size: 1.3rem; margin: 1.2rem 0 0.5rem; }
.sub { margin: 0 0 1rem; color: var(--muted); }
.sub a { color: var(--green-dark); font-weight: 700; }
.fine { font-size: 0.88rem; color: var(--muted); margin: 0.4rem 0; }
.status { min-height: 1.3rem; margin: 0.5rem 0 0; color: var(--muted); }
.status:empty { min-height: 0; margin: 0; }

/* ===== Screen transitions ===== */
::view-transition-old(page) { animation: out 0.14s ease both; }
::view-transition-new(page) { animation: in 0.3s var(--ease) both; }
@keyframes out { to { opacity: 0; } }
@keyframes in { from { opacity: 0; transform: translateY(10px); } }
.no-vt .view:not([hidden]) { animation: in 0.3s var(--ease) both; }

/* ===== Drawing frames (manga screentone until real drawings arrive) ===== */
.art-frame {
  margin: 0 0 1rem; aspect-ratio: 16 / 9; display: grid; place-items: end start;
  border: 1.5px solid var(--ink); border-radius: 4px;
  background: radial-gradient(#cdbfa8 1px, transparent 1.3px) 0 0 / 7px 7px, #efe6d6;
}
.art-short { aspect-ratio: 16 / 6; margin-top: 1rem; }
.art-frame figcaption { margin: 0.5rem; padding: 0.15rem 0.5rem; background: var(--paper-2); border: 1px solid var(--line); border-radius: 4px; font-size: 0.8rem; color: var(--muted); }
.art-frame img { width: 100%; height: 100%; object-fit: cover; border-radius: 3px; }

/* ===== Buttons and links ===== */
.btn, .btn-outline {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 3rem; margin-top: 0.9rem;
  border-radius: 6px; font-weight: 700; cursor: pointer; transition: transform 0.12s var(--ease), background-color 0.2s;
}
.btn { border: 0; background: var(--green); color: #fff; }
.btn:hover { background: var(--green-dark); }
.btn:disabled { background: #b9b2a5; cursor: not-allowed; }
.btn-outline { border: 1.5px solid var(--ink); background: var(--paper-2); color: var(--ink); }
.btn:active, .btn-outline:active { transform: scale(0.98); }
.link { display: block; margin: 0.8rem auto 0; background: none; border: 0; padding: 0.3rem; color: var(--green-dark); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.back { display: inline-flex; align-items: center; gap: 0.4rem; background: none; border: 0; padding: 0.3rem 0; font-weight: 700; cursor: pointer; }
.em-link {
  display: grid; justify-items: center; gap: 0.15rem; width: 100%; margin-top: 1.4rem;
  background: none; border: 0; color: var(--red); font-weight: 700; cursor: pointer; position: relative;
}
.em-link::before { content: ""; position: absolute; top: 0.65rem; left: 0; right: 0; border-top: 1px solid var(--line); }
.em-link svg { position: relative; background: var(--paper); padding: 0 0.6rem; width: 2.5rem; color: var(--red); }

/* ===== Home rows ===== */
.rows { list-style: none; padding: 0; margin: 0; }
.rows li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 0.9rem; width: 100%; padding: 0.85rem 0.2rem; background: none; border: 0; text-align: left; cursor: pointer; }
.row-ic { width: 1.7rem; height: 1.7rem; color: var(--green-dark); }
.row span { flex: 1; display: grid; }
.row small { color: var(--muted); font-size: 0.9rem; }
.chev { color: var(--muted); }
.tip { margin: 1rem 0 0; padding: 0.8rem 0.9rem; background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px; }

/* ===== Learn ===== */
.learn-frame { display: block; width: 100%; height: calc(100vh - 15rem); height: calc(100dvh - 15rem); min-height: 460px; border: 1.5px solid var(--ink); border-radius: 6px; background: #fff; }

/* ===== Plan form ===== */
.form label { display: block; font-weight: 700; margin: 0.8rem 0 0.3rem; }
.field { display: flex; align-items: center; background: var(--paper-2); border: 1.5px solid var(--line); border-radius: 6px; transition: border-color 0.2s; }
.field:focus-within { border-color: var(--green); }
.field input { flex: 1; min-width: 0; min-height: 2.9rem; padding: 0 0.85rem; border: 0; background: transparent; outline: none; }
.field-btn { width: 2.9rem; height: 2.9rem; display: grid; place-items: center; background: none; border: 0; cursor: pointer; color: var(--muted); }
.field-ic { margin: 0 0.8rem; color: var(--muted); }

/* ===== Compare ===== */
.banner { margin: 0 0 0.8rem; padding: 0.6rem 0.8rem; background: #f7e4d8; border-left: 4px solid var(--red-soft); border-radius: 0 6px 6px 0; font-size: 0.93rem; }
.close-call { margin: 0.8rem 0 0; padding: 0.4rem 0.8rem; border-left: 4px solid var(--green); font-size: 0.93rem; }
.options { border: 0; padding: 0; margin: 0.8rem 0 0; }
.route-opt {
  display: flex; align-items: center; gap: 0.8rem; padding: 0.75rem 0.8rem; margin-bottom: 0.6rem; cursor: pointer;
  background: var(--paper-2); border: 1.5px solid var(--line); border-radius: 8px;
  transition: border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.route-opt:has(input:checked) { border: 2px solid var(--green); background: var(--green-soft); }
.route-opt:has(input:focus-visible) { outline: 3px solid var(--green); outline-offset: 2px; }
.route-opt input { width: 1.25rem; height: 1.25rem; accent-color: var(--green); flex: none; margin: 0; }
.ro-main { flex: 1; display: grid; }
.ro-main .meta { color: var(--muted); font-size: 0.93rem; }
.ro-main .warn { color: var(--red); font-size: 0.9rem; font-weight: 700; }
.tag { font-size: 0.75rem; font-weight: 700; border-radius: 999px; padding: 0 0.45rem; margin-left: 0.35rem; border: 1px solid currentColor; }
.tag-safe { color: var(--green-dark); }
.tag-fast { color: var(--muted); }
.grade {
  flex: none; width: 2.6rem; height: 2.6rem; display: grid; place-items: center; border-radius: 6px;
  color: #fff; font-family: var(--hand); font-size: 1.5rem; line-height: 1; border: 1.5px solid var(--ink);
}
.grade-A { background: var(--g-a); } .grade-B { background: var(--g-b); } .grade-C { background: var(--g-c); }
.grade-D { background: var(--g-d); } .grade-E { background: var(--g-e); }
.grade-none { background: var(--paper-2); color: var(--muted); border-style: dashed; }

/* ===== Map ===== */
.map-box { position: relative; border: 1.5px solid var(--ink); border-radius: 6px; overflow: hidden; background: #efe6d6; }
#map { height: 42vh; min-height: 240px; max-height: 420px; background: #efe6d6; }
.map-note { margin: 0; padding: 0.6rem 0.8rem; font-size: 0.88rem; background: #f7e4d8; border-top: 1.5px solid var(--ink); }
.leaflet-container { font-family: var(--body); }
.leaflet-control-attribution { font-size: 0.65rem; }
.pin { display: grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; border: 2.5px solid var(--green-dark); background: var(--paper-2); color: var(--green-dark); font-weight: 700; font-size: 0.75rem; }
.pin-end { background: var(--green); color: #fff; }

/* ===== Details sheet ===== */
.sheet {
  position: relative; margin-top: -0.8rem; padding: 1.2rem 1rem 0.5rem; z-index: 2;
  background: var(--paper-2); border: 1.5px solid var(--ink); border-radius: 14px 14px 6px 6px;
  animation: sheet-up 0.35s var(--ease) both;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }
.handle { position: absolute; top: 0.45rem; left: 50%; width: 2.6rem; height: 4px; margin-left: -1.3rem; border-radius: 2px; background: var(--line); }
#why h2 { margin-top: 0.2rem; }
.factors { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.factor-top { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.92rem; }
.bar { height: 7px; border: 1px solid var(--ink); border-radius: 4px; background: var(--paper); overflow: hidden; margin-top: 0.15rem; }
.bar span { display: block; height: 100%; background: var(--green); transform-origin: left; animation: grow 0.6s var(--ease) both; }
@keyframes grow { from { transform: scaleX(0); } }
.directions { list-style: none; padding: 0; margin: 0; }
.directions li { display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.directions li span { flex: 1; }
.directions small { color: var(--muted); white-space: nowrap; }
.check { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 1rem; font-weight: 700; cursor: pointer; }
.check input { width: 1.2rem; height: 1.2rem; accent-color: var(--green); }
.check small { flex-basis: 100%; padding-left: 1.7rem; font-weight: 400; color: var(--muted); }

/* ===== Emergency ===== */
.sos-stage { display: grid; justify-items: center; gap: 0.9rem; padding: 0.8rem 0 1.4rem; text-align: center; }
#sos-hint { margin: 0; }
.hold { --p: 0; position: relative; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; }
.hold .ring {
  position: absolute; inset: -10px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(var(--ink) calc(var(--p) * 360deg), rgba(28, 26, 23, 0.12) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
}
.sos-big {
  width: 9.5rem; height: 9.5rem; border-radius: 50%; border: 3px solid var(--ink);
  background: var(--red); color: #fff; font-family: var(--hand); font-size: 2.6rem;
  box-shadow: 5px 5px 0 var(--ink); transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.sos-big.holding { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--ink); }
.em-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.em-tile {
  display: grid; gap: 0.1rem; padding: 0.8rem 0.9rem; text-align: left; text-decoration: none; cursor: pointer;
  background: var(--paper-2); color: var(--ink); border: 1.5px solid var(--ink); border-radius: 8px;
}
.em-tile strong { font-family: var(--hand); font-size: 1.5rem; line-height: 1.1; }
.em-tile span { font-size: 0.88rem; color: var(--muted); }
.em-tile.urgent { background: var(--red); color: #fff; }
.em-tile.urgent span { color: #fff; opacity: 0.9; }
#directory h3 { font-family: var(--hand); font-size: 1.15rem; margin: 1.3rem 0 0.4rem; }
.entry { padding: 0.8rem 0.9rem; margin-bottom: 0.6rem; background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px; }
.entry h4 { margin: 0; font-size: 1rem; }
.entry p { margin: 0.25rem 0; }
.contacts { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.4rem 0; }
.contacts a { text-decoration: none; font-weight: 700; color: #fff; background: var(--green); border-radius: 6px; padding: 0.4rem 0.8rem; }
#directory a:not(.contacts a), .prose a { color: var(--green-dark); font-weight: 700; }
.prose h3 { font-family: var(--hand); font-size: 1.15rem; margin: 1.2rem 0 0.3rem; }
.prose ul { padding-left: 1.2rem; }

/* ===== Menu drawer and Help sheet ===== */
dialog { border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink); padding: 1.1rem; }
dialog::backdrop { background: rgba(28, 26, 23, 0.45); }
.drawer { margin: 0; height: 100%; max-height: 100%; width: min(19rem, 85vw); border-width: 0 1.5px 0 0; padding-top: calc(1rem + env(safe-area-inset-top, 0px)); }
.drawer[open] { animation: slide-in 0.28s var(--ease) both; }
@keyframes slide-in { from { transform: translateX(-100%); } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.8rem; }
.drawer-item { display: block; width: 100%; text-align: left; padding: 0.85rem 0.4rem; background: none; border: 0; border-bottom: 1px solid var(--line); font-weight: 700; cursor: pointer; }
.drawer-note { font-family: var(--hand); color: var(--muted); margin-top: 2rem; }
.sheet-dialog { width: min(26rem, calc(100% - 1.5rem)); border-radius: 12px; box-shadow: 6px 6px 0 var(--ink); }
.sheet-dialog[open] { animation: rise 0.28s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
.sheet-dialog h2 { margin: 0 0 0.8rem; }
.call {
  display: block; width: 100%; margin-bottom: 0.55rem; padding: 0.7rem 0.9rem; text-align: left; text-decoration: none; cursor: pointer;
  font-weight: 700; font-size: 1.1rem; color: var(--ink); background: var(--paper-2); border: 1.5px solid var(--ink); border-radius: 8px;
}
.call span { display: block; font-weight: 400; font-size: 0.88rem; color: var(--muted); }
.call.urgent { background: var(--red); color: #fff; }
.call.urgent span { color: #fff; opacity: 0.9; }

.toast {
  position: fixed; left: 50%; bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px)); z-index: 900; margin: 0;
  transform: translate(-50%, 0.8rem); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 0.6rem 1rem; border-radius: 8px;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
  ::view-transition-old(page), ::view-transition-new(page) { animation: none !important; }
}

/* ===== Learn: lessons, scenario, reflection ===== */
.lesson { margin-top: 1.2rem; }
.lesson h2 { display: flex; align-items: center; gap: 0.6rem; margin: 0 0 0.1rem; }
.lesson h2 svg { color: var(--green-dark); }
.lesson .fine { margin: 0 0 0.3rem 2rem; }
.row .done { flex: none; display: block; font-size: 0.78rem; font-weight: 700; color: var(--green-dark); border: 1px solid var(--green); border-radius: 999px; padding: 0 0.5rem; }
.scene-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.6rem; }
.count { color: var(--muted); font-size: 0.9rem; }
.note { display: flex; gap: 0.6rem; align-items: flex-start; margin: 0 0 0.8rem; padding: 0.7rem 0.8rem; background: var(--paper-2); border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: 6px; font-size: 0.93rem; }
.note svg { margin-top: 0.15rem; color: var(--green-dark); }
.who { margin: 0 0 0.6rem; font-size: 0.93rem; }
.who summary { cursor: pointer; font-weight: 700; }
.who ul { padding-left: 1.1rem; margin: 0.3rem 0; }
.scene-h { margin-top: 0.4rem; }
.q { margin-top: 1.1rem; }
.kind { display: inline-block; font-size: 0.82rem; font-weight: 700; padding: 0.1rem 0.6rem; border-radius: 999px; border: 1.5px solid currentColor; }
.kind-good { color: var(--g-a); } .kind-mid { color: var(--g-c); } .kind-bad { color: var(--g-e); } .kind-care { color: var(--g-d); }
.rh { font-size: 1.3rem; margin: 0.5rem 0 0.4rem; }
.chose { color: var(--muted); margin: 0 0 0.8rem; }
.why { margin: 0 0 0.4rem; padding: 0.2rem 0.9rem; background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px; }
.why dt { margin-top: 0.7rem; font-weight: 700; }
.why dd { margin: 0.1rem 0 0.7rem; }
.ask { padding-left: 0.8rem; border-left: 3px solid var(--green); }
