/* Perugia Companion — Inclusive Design, WCAG AAA targets.
   Calm warm paper, near-black ink, one colour per meaning:
   green = home, teal = go, amber = help, red = emergency only. */

:root {
  --bg: #FBF7F0;
  --surface: #FFFFFF;
  --surface-calm: #EEF6F1;
  --ink: #1A1A1A;          /* 16.9:1 on bg */
  --ink-soft: #3A3A3A;     /* 10.6:1 on bg */
  --line: #6B6B6B;         /* 5.1:1 — non-text UI ≥ 3:1 */
  --primary: #0B5563;      /* white text 8.4:1 */
  --on-primary: #FFFFFF;
  --home: #1D5C2C;         /* white text 7.9:1 */
  --on-home: #FFFFFF;
  --help: #F4C542;         /* ink text 11.5:1 */
  --on-help: #1A1A1A;
  --danger: #A11B14;       /* white text 8.0:1 */
  --on-danger: #FFFFFF;
  --warn-bg: #FFF1C7;
  --ok-bg: #DDF1E2;
  --focus: #1447E6;
  --progress: #1D5C2C;

  --radius: 18px;
  --radius-sm: 12px;
  --tap: 76px;             /* primary button height (well above 48px) */
  --tap-sm: 60px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 48px;
  --ic: 34px;
  --font: "Atkinson Hyperlegible", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1E1E1E;
    --surface-calm: #16261D;
    --ink: #F5F5F5;
    --ink-soft: #D6D6D6;
    --line: #9A9A9A;
    --primary: #7FD3E0;
    --on-primary: #0A1F24;
    --home: #8FD89F;
    --on-home: #0B1F10;
    --help: #F4C542;
    --on-help: #1A1A1A;
    --danger: #FF8A80;
    --on-danger: #2A0806;
    --warn-bg: #3A3013;
    --ok-bg: #173323;
    --focus: #9DB8FF;
    --progress: #8FD89F;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 18px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.2rem;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--space-2) + env(safe-area-inset-top)) calc(var(--space-3) + env(safe-area-inset-right))
           calc(var(--space-4) + env(safe-area-inset-bottom)) calc(var(--space-3) + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
body.has-lost-bar .screen { padding-bottom: calc(var(--tap) + var(--space-5) + env(safe-area-inset-bottom)); }

p { margin: 0; }
a { color: inherit; }

/* Icons */
.ic { width: var(--ic); height: var(--ic); flex: none; fill: none; stroke: currentColor;
      stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ic-sm { --ic: 22px; }
.ic-lg { --ic: 44px; }
.ic-xl { --ic: 72px; }

/* Focus: always visible, never colour alone */
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; border-radius: var(--radius-sm); }

/* Headings & text */
.h-big { font-size: 1.9rem; font-weight: 700; line-height: 1.25; margin: 0; text-align: center; }
.h-title { font-size: 1.75rem; font-weight: 700; line-height: 1.25; margin: 0;
           display: flex; align-items: center; gap: var(--space-2); }
.h-sub { font-size: 1.4rem; margin: var(--space-2) 0 0; }
.lead { font-size: 1.35rem; color: var(--ink-soft); }
.note { font-size: 1.05rem; color: var(--ink-soft); background: var(--surface); border: 2px solid var(--line);
        border-radius: var(--radius-sm); padding: var(--space-2); }
.note-warn { background: var(--warn-bg); color: var(--ink); }
.note-ok { background: var(--ok-bg); color: var(--ink); }

/* Buttons: large, labelled, no gestures needed */
.btn {
  display: flex; align-items: center; justify-content: center; gap: var(--space-2);
  width: 100%; min-height: var(--tap); padding: var(--space-2) var(--space-3);
  border-radius: var(--radius); border: 3px solid transparent;
  font: inherit; font-size: 1.45rem; font-weight: 700; line-height: 1.2; letter-spacing: 0.01em;
  text-decoration: none; text-align: center; cursor: pointer;
  transition: filter 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
}
.btn:active { filter: brightness(0.88); box-shadow: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-home { background: var(--home); color: var(--on-home); }
.btn-plain { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-plain:active { background: var(--surface-calm); filter: none; }
.btn-lost { background: var(--help); color: var(--on-help); border-color: #8A6A00; }
.btn-danger { background: var(--danger); color: var(--on-danger); min-height: var(--tap-sm); font-size: 1.3rem; }
.btn-left { justify-content: flex-start; text-align: left; }
.btn-tile { flex-direction: column; gap: var(--space-1); min-height: 104px; font-size: 1.3rem; }

.stack { display: flex; flex-direction: column; gap: var(--space-2); }
.stack form { display: contents; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }

.chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: var(--tap-sm); min-width: var(--tap-sm); padding: 0 var(--space-2);
  border: 2px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 1.15rem; font-weight: 700; text-decoration: none; cursor: pointer;
}
.chip .ic { --ic: 28px; }
.chip[aria-pressed="false"] { background: transparent; color: var(--ink-soft); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); }

.card { background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: var(--space-3); }
.card-calm { background: var(--surface-calm); }

/* Welcome */
.hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
        padding-top: var(--space-5); }
.hero-icon { color: var(--primary); }
.lang-tag { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 50%;
            border: 2px solid currentColor; font-size: 1.2rem; }

/* Home */
.greeting { text-align: center; padding-top: var(--space-2); }
.greet { font-size: 1.6rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.clock { font-size: 1.3rem; color: var(--ink-soft); }
.where { display: flex; gap: var(--space-2); align-items: center; }
.where .ic { color: var(--home); }
.where-label { font-size: 1.1rem; color: var(--ink-soft); }
.where-place { font-size: 1.55rem; font-weight: 700; line-height: 1.25; }
.foot { display: flex; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; padding-top: var(--space-2); }
.foot a { display: inline-flex; align-items: center; gap: var(--space-1); min-height: 48px;
          font-size: 1rem; color: var(--ink-soft); }

/* Route choice */
.option {
  display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-3); border-radius: var(--radius); text-decoration: none;
  border: 3px solid var(--line); background: var(--surface); color: var(--ink);
  transition: filter 150ms ease;
}
.option:active { filter: brightness(0.92); }
.option-main { border-color: var(--home); border-width: 4px; }
.option-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.option-name { font-size: 1.6rem; font-weight: 700; }
.badge { order: 2; background: var(--home); color: var(--on-home); border-radius: 999px;
         padding: 4px 14px; font-size: 1rem; font-weight: 700; }
.option-time { font-size: 1.3rem; }
.option-time strong { font-size: 2.4rem; }
.option-facts { font-size: 1.2rem; color: var(--ink-soft); }
.option-cta { display: flex; align-items: center; justify-content: center; gap: var(--space-2);
              margin-top: var(--space-2); min-height: var(--tap); border-radius: var(--radius-sm);
              background: var(--home); color: var(--on-home); font-size: 1.4rem; font-weight: 700; }
.option-cta-quiet { background: transparent; color: var(--ink); border: 2px solid var(--line); min-height: var(--tap-sm);
                    font-size: 1.2rem; }

/* Navigation: one instruction at a time */
.nav { display: flex; flex-direction: column; }
#nav-step { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-2); }
.step-count { font-size: 1rem; color: var(--ink-soft); }
.instr-arrow { --ic: 140px; stroke-width: 2.2; color: var(--primary); }
.instr-title { font-size: clamp(1.8rem, 8.5vw, 2.3rem); line-height: 1.15; margin: 0; letter-spacing: 0.01em; }
.instr-dist { font-size: 1.9rem; font-weight: 700; }
.instr-text { font-size: 1.4rem; line-height: 1.45; max-width: 30ch; }
.progress { width: 100%; height: 22px; border-radius: 999px; border: 2px solid var(--line);
            background: var(--surface); overflow: hidden; margin-top: var(--space-2); }
.progress-fill { height: 100%; width: 0; background: var(--progress); transition: width 300ms ease; }
.progress-label { font-size: 1.3rem; font-weight: 700; }
.next-up { font-size: 1.2rem; color: var(--ink-soft); border-top: 2px solid var(--line); padding-top: var(--space-2);
           width: 100%; }
#nav-step .grid-2 { width: 100%; }

.lost-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: var(--space-2) calc(var(--space-3) + env(safe-area-inset-right)) calc(var(--space-2) + env(safe-area-inset-bottom)) calc(var(--space-3) + env(safe-area-inset-left));
  background: var(--bg); border-top: 2px solid var(--line);
}
.lost-bar .btn { max-width: 512px; margin: 0 auto; font-size: 1.6rem; }

/* Lost */
.safe { display: flex; flex-direction: column; gap: var(--space-2); }
.safe-title { font-size: 2.2rem; margin: 0; }
.safe-where { font-size: 1.6rem; font-weight: 700; line-height: 1.3; }
.safe-home { font-size: 1.35rem; }
.safe-calm { font-size: 1.2rem; color: var(--ink-soft); }

/* Translate */
.field-label { font-size: 1.1rem; font-weight: 700; }
.field { width: 100%; min-height: 56px; padding: 12px 14px; font: inherit; font-size: 1.2rem;
         color: var(--ink); background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius-sm); }
.field-big { font-size: 1.4rem; }
.result { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); text-align: center; }
.result-arrow { color: var(--ink-soft); }
.result-src { color: var(--ink-soft); font-size: 1.2rem; }
.result-it { font-size: 1.9rem; font-weight: 700; line-height: 1.3; }
.result .stack { width: 100%; }
.phrases { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.phrase { width: 100%; min-height: var(--tap-sm); padding: 12px var(--space-2); text-align: left; cursor: pointer;
          font: inherit; font-size: 1.2rem; color: var(--ink); background: var(--surface);
          border: 2px solid var(--line); border-radius: var(--radius-sm); }
.phrase:active { background: var(--surface-calm); }

/* Large text for showing to someone */
.large-overlay { position: fixed; inset: 0; z-index: 50; background: #FFFFFF; color: #000000;
                 display: flex; flex-direction: column; justify-content: space-between; gap: var(--space-3);
                 padding: calc(var(--space-4) + env(safe-area-inset-top)) var(--space-3) calc(var(--space-3) + env(safe-area-inset-bottom)); overflow: auto; }
.large-text { font-size: clamp(2.2rem, 9vw, 4.5rem); font-weight: 700; line-height: 1.2; }
.large-overlay .btn-plain { background: #FFFFFF; color: #000000; border-color: #000000; }

/* Show-to-someone card */
.show-card { background: #FFFFFF; color: #000000; border: 3px solid #000000; border-radius: var(--radius);
             padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.show-line { font-size: 1.6rem; line-height: 1.3; }
.show-address { border-top: 3px solid #000; border-bottom: 3px solid #000; padding: var(--space-2) 0; }
.show-name { font-size: 1.8rem; font-weight: 700; }
.show-addr { font-size: 1.6rem; }
.mini-map { width: 100%; height: 260px; border: 2px solid var(--line); border-radius: var(--radius); }

/* Setup */
.setup-form { display: flex; flex-direction: column; gap: var(--space-3); }
.setup-form fieldset { border: 2px solid var(--line); border-radius: var(--radius); padding: var(--space-2) var(--space-2) var(--space-3);
                       display: flex; flex-direction: column; gap: var(--space-2); margin: 0; }
.setup-form legend { font-weight: 700; font-size: 1.25rem; padding: 0 var(--space-1); }
.setup-form label { display: flex; flex-direction: column; gap: 4px; font-size: 1rem; font-weight: 700; }
.setup-form .check { flex-direction: row; align-items: flex-start; gap: var(--space-2); font-weight: 400; }
.check input { width: 32px; height: 32px; flex: none; }

@media (max-width: 360px) {
  html { font-size: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .instr-arrow { --ic: 90px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Added states */
.where-small { font-size: 1.2rem; font-weight: 400; }
.btn-find { min-height: var(--tap-sm); font-size: 1.2rem; }
.geo-results { display: flex; flex-direction: column; gap: var(--space-1); font-size: 1rem; }
.geo-results .phrase { font-size: 1rem; }
#btn-metro-closed { width: 100%; font-size: 1.2rem; min-height: var(--tap-sm); }
.geo-map { font-size: 1.05rem; font-weight: 700; color: var(--primary); min-height: 44px; display: inline-flex; align-items: center; }

/* Navigation: instruction banner + live map */
.step-row { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); }
.instr-head { width: 100%; display: flex; align-items: center; gap: var(--space-2); text-align: left;
              background: var(--surface); border: 3px solid var(--primary); border-radius: var(--radius);
              padding: var(--space-2); }
.instr-head .instr-arrow { --ic: 88px; flex: none; }
.instr-head-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.instr-head .instr-title { font-size: clamp(1.6rem, 7.5vw, 2.1rem); }
.instr-head .instr-dist { font-size: 1.8rem; }
.instr-text { text-align: left; width: 100%; max-width: none; }

.map-wrap { position: relative; width: 100%; }
.nav-map { width: 100%; height: clamp(240px, 42vh, 460px); border-radius: var(--radius);
           border: 2px solid var(--line); overflow: hidden; background: #E8E4DC; }
.map-recentre { position: absolute; right: 12px; bottom: 28px; z-index: 500;
                display: inline-flex; align-items: center; gap: var(--space-1);
                min-height: var(--tap-sm); padding: 0 var(--space-2); border-radius: 999px;
                background: #1A73E8; color: #FFFFFF; border: 3px solid #FFFFFF;
                font: inherit; font-size: 1.15rem; font-weight: 700; cursor: pointer;
                box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); }
.map-recentre .ic { --ic: 26px; }
.map-gps { position: absolute; left: 12px; right: 12px; top: 12px; z-index: 500; margin: 0;
           background: var(--warn-bg); color: var(--ink); border: 2px solid var(--line);
           border-radius: var(--radius-sm); padding: 8px 12px; font-size: 1rem; }

/* The map turns inside its box ("facing up"); controls stay put */
.nav-map { position: relative; }
.map-rot { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
           transition: transform 250ms ease-out; will-change: transform; }
@media (prefers-reduced-motion: reduce) { .map-rot { transition: none; } }
.map-controls { position: absolute; left: 10px; top: 10px; z-index: 600; display: flex; flex-direction: column; gap: 8px; }
.map-ctl { width: 52px; height: 52px; border-radius: 12px; border: 2px solid #6B6B6B; background: #FFFFFF; color: #1A1A1A;
           font: inherit; font-size: 28px; font-weight: 700; line-height: 1; cursor: pointer;
           box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); display: grid; place-items: center; }
.map-ctl:active { background: #EEF6F1; }
.map-north-n { display: inline-block; font-size: 20px; color: #A11B14; transition: transform 250ms ease-out; }
.map-north-n::before { content: ""; display: block; width: 0; height: 0; margin: 0 auto 1px;
                       border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 9px solid #A11B14; }
.map-north[aria-pressed="true"] { border-color: #1A73E8; border-width: 3px; }
.map-attrib { position: absolute; right: 0; bottom: 0; z-index: 600; background: rgba(255, 255, 255, 0.85);
              color: #333; font-size: 11px; padding: 1px 6px; border-top-left-radius: 6px; }
.map-attrib a { color: #0B5563; }
.face-hint { width: 100%; margin: 6px 0 0; display: flex; align-items: center; gap: var(--space-1);
             min-height: 48px; padding: 4px 12px; border-radius: var(--radius-sm);
             background: var(--warn-bg); color: var(--ink); border: 2px solid #8A6A00;
             font-size: 1.2rem; font-weight: 700; line-height: 1.2; }
.face-hint.face-ok { background: var(--ok-bg); border-color: var(--home); }
.face-arrow { --ic: 32px; flex: none; transition: transform 250ms ease-out; }
@media (prefers-reduced-motion: reduce) { .face-arrow { transition: none; } }
.map-gps { top: auto; bottom: 28px; left: 72px; }

/* The blue "you are here" dot with the direction he is facing */
.me-icon { position: relative; }
.me-dot { position: absolute; left: 20px; top: 20px; width: 24px; height: 24px; border-radius: 50%;
          background: #1A73E8; border: 4px solid #FFFFFF; box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.35), 0 1px 4px rgba(0, 0, 0, 0.4); }
.me-cone { position: absolute; left: 0; top: 0; width: 64px; height: 64px; transform-origin: 50% 50%;
           background: conic-gradient(from -28deg at 50% 50%, rgba(26, 115, 232, 0.55) 0deg 56deg, transparent 56deg);
           border-radius: 50%; -webkit-mask: radial-gradient(circle, transparent 11px, #000 12px);
           mask: radial-gradient(circle, transparent 11px, #000 12px); }
.dest-icon { display: grid; place-items: center; }
.dest-icon .ic { --ic: 40px; color: #A11B14; stroke-width: 2.6; fill: none;
                 filter: drop-shadow(0 0 2px #FFFFFF) drop-shadow(0 0 2px #FFFFFF); }
@media (prefers-reduced-motion: no-preference) {
  .me-dot { animation: me-pulse 2s ease-out infinite; }
}
@keyframes me-pulse {
  0% { box-shadow: 0 0 0 0 rgba(26, 115, 232, 0.5), 0 1px 4px rgba(0, 0, 0, 0.4); }
  100% { box-shadow: 0 0 0 14px rgba(26, 115, 232, 0), 0 1px 4px rgba(0, 0, 0, 0.4); }
}

/* Search results / recent places */
.btn-place { font-size: 1.25rem; }
.place-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; text-align: left; }
.place-name { font-weight: 700; overflow-wrap: anywhere; }
.place-detail { font-size: 1rem; font-weight: 400; color: var(--ink-soft); overflow-wrap: anywhere; }
.nav-dest { font-size: 1.15rem; font-weight: 700; color: var(--ink-soft); margin-bottom: var(--space-1); overflow-wrap: anywhere; }
.credits { font-size: 0.85rem; color: var(--ink-soft); margin: 0; }

/* Route cards: easiest / safest / fastest */
.option-name { display: inline-flex; align-items: center; gap: var(--space-1); }
.option-name .ic { --ic: 30px; }
.option-safety { color: var(--ink); }
.option-also { font-size: 1.05rem; font-weight: 700; color: var(--home); }
.setup-form .radio { flex-direction: row; align-items: flex-start; gap: var(--space-2); font-weight: 400; }
.radio input { width: 28px; height: 28px; flex: none; }
