/* Paper Plane: paper and pencil interface. System fonts only. */
:root {
  --ink: #3b3a3f;
  --ink-soft: #6c6a70;
  --paper: #fbf9f3;
  --paper-2: #f5f0e4;
  --highlight: #fbe7a1;
  --accent: #c8473a;
  --blue: #3d7ebf;
  --hand: "Noteworthy", "Chalkboard SE", "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --wobble: 255px 15px 225px 15px / 15px 225px 15px 255px;
  --wobble-2: 15px 255px 15px 225px / 225px 15px 255px 15px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper-2); color: var(--ink); font-family: var(--body); -webkit-text-size-adjust: 100%; }
body { background-image: var(--paper-bg, none); overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
h1, h2, .brand { font-family: var(--hand); font-weight: 700; margin: 0 0 0.4em; line-height: 1.1; }
h1 { font-size: clamp(2.4rem, 8vw, 3.6rem); letter-spacing: 0.01em; }
h2 { font-size: 1.45rem; }
.brand { font-size: 2rem; }
p { line-height: 1.45; margin: 0 0 0.8em; }
.small { font-size: 0.85rem; }
.muted { color: var(--ink-soft); }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l)); pointer-events: none; z-index: 5; }
.screen.bottom { align-items: flex-end; }
.screen > * { pointer-events: auto; }
.card { background: rgba(251, 249, 243, 0.95); border: 2px solid var(--ink); border-radius: var(--wobble); box-shadow: 4px 5px 0 rgba(59, 58, 63, 0.18); padding: 22px 24px; max-width: 540px; width: 100%; max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#loading .card { text-align: center; max-width: 320px; }
.tagline { font-size: 1.05rem; }

.btn { font: 600 1rem var(--body); color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: var(--wobble-2); padding: 10px 18px; min-height: 46px; cursor: pointer; touch-action: manipulation; transition: transform 0.08s ease, background 0.15s ease; }
.btn:active { transform: translate(1px, 2px); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn:focus-visible, .seg:focus-visible, .opt:focus-visible, .loc:focus-visible, .icon-btn:focus-visible { outline: 3px dashed var(--blue); outline-offset: 3px; }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 6px; }
.btn-col { display: flex; flex-direction: column; gap: 10px; }

.bests { width: 100%; border-collapse: collapse; font-size: 0.95rem; margin-bottom: 6px; }
.bests th, .bests td { text-align: left; padding: 6px 4px; border-bottom: 1px dashed rgba(59, 58, 63, 0.35); }
.bests th { font-family: var(--hand); font-weight: 700; }
.bests td:first-child { font-weight: 600; }

.topbar { position: fixed; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); display: flex; gap: 8px; z-index: 20; }
.icon-btn { width: 46px; height: 46px; border: 2px solid var(--ink); background: rgba(251, 249, 243, 0.92); border-radius: var(--wobble); display: grid; place-items: center; cursor: pointer; padding: 0; touch-action: manipulation; }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .snd-off { display: none; }
.icon-btn.muted .snd-on { display: none; }
.icon-btn.muted .snd-off { display: block; }

/* folding */
.panel-screen { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.panel { pointer-events: auto; position: absolute; top: calc(66px + var(--safe-t)); right: calc(12px + var(--safe-r)); bottom: calc(12px + var(--safe-b)); width: 370px; background: rgba(251, 249, 243, 0.95); border: 2px solid var(--ink); border-radius: var(--wobble); box-shadow: 4px 5px 0 rgba(59, 58, 63, 0.18); padding: 18px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; }
.panel .nav-row { margin-top: auto; padding-top: 8px; }
.panel .nav-row .btn { flex: 1; }
.steps { display: flex; gap: 6px; margin-bottom: 8px; }
.steps span { flex: 1; height: 6px; border-radius: 3px; background: rgba(59, 58, 63, 0.15); }
.steps span.done { background: var(--ink-soft); }
.steps span.now { background: var(--accent); }
.step-count { font-size: 0.85rem; color: var(--ink-soft); margin: 0 0 2px; text-transform: uppercase; letter-spacing: 0.08em; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0 8px; }
.opt { font: 600 0.95rem var(--body); color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: var(--wobble-2); padding: 10px 8px; min-height: 48px; cursor: pointer; touch-action: manipulation; text-align: center; }
.opt.selected { background: var(--highlight); box-shadow: inset 0 -6px 0 rgba(200, 71, 58, 0.18); }
.note { min-height: 2.9em; font-size: 0.95rem; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; margin: 4px 0 6px; }
.stat-name { font-family: var(--hand); font-weight: 700; font-size: 0.98rem; }
.bar { position: relative; height: 14px; border: 1.5px solid var(--ink); border-radius: 8px 3px 9px 4px; overflow: hidden; background: var(--paper); }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: repeating-linear-gradient(-55deg, var(--ink-soft) 0 2px, transparent 2px 5px); transition: width 0.45s cubic-bezier(.3, 1.4, .5, 1); }
.bar b { position: absolute; top: -1px; bottom: -1px; width: 2px; background: var(--accent); transition: left 0.45s ease; opacity: 0.8; }
.spec { margin-top: 2px; }
.hint { position: fixed; left: calc(16px + var(--safe-l)); bottom: calc(14px + var(--safe-b)); margin: 0; font-family: var(--hand); color: var(--ink-soft); pointer-events: none; }

/* where */
.mode-toggle { display: inline-flex; border: 2px solid var(--ink); border-radius: var(--wobble-2); overflow: hidden; margin-bottom: 8px; }
.seg { font: 600 1rem var(--body); background: var(--paper); color: var(--ink); border: 0; padding: 10px 18px; min-height: 44px; cursor: pointer; touch-action: manipulation; }
.seg + .seg { border-left: 2px solid var(--ink); }
.seg.selected { background: var(--ink); color: var(--paper); }
.locations { display: grid; gap: 10px; }
.loc { display: block; width: 100%; text-align: left; font: inherit; color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: var(--wobble); padding: 12px 14px; cursor: pointer; touch-action: manipulation; }
.loc:active { transform: translate(1px, 2px); }
.loc h3 { font-family: var(--hand); margin: 0 0 2px; font-size: 1.25rem; }
.loc p { margin: 0; font-size: 0.92rem; }
.loc .loc-best { margin-top: 4px; font-weight: 600; font-size: 0.85rem; color: var(--accent); }

/* hud */
.hud { position: fixed; left: 0; right: 0; top: 0; padding: calc(10px + var(--safe-t)) calc(116px + var(--safe-r)) 0 calc(12px + var(--safe-l)); display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; z-index: 6; gap: 10px; }
.hud-left, .hud-centre, .wind { background: rgba(251, 249, 243, 0.88); border: 2px solid var(--ink); border-radius: var(--wobble-2); padding: 6px 12px; }
.hud-place { font-family: var(--hand); font-weight: 700; font-size: 1.05rem; }
.hud-sub { font-size: 0.82rem; color: var(--ink-soft); }
.hud-centre { text-align: center; min-width: 110px; }
.hud-dist { font-family: var(--hand); font-weight: 700; font-size: 1.6rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.wind { position: fixed; top: calc(64px + var(--safe-t)); right: calc(10px + var(--safe-r)); display: flex; flex-direction: column; align-items: center; padding: 6px 8px; min-width: 70px; }
.wind-arrow { width: 30px; height: 30px; transition: transform 0.3s ease; }
.wind-arrow svg { width: 100%; height: 100%; fill: none; stroke: var(--blue); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.wind-text { font-size: 0.75rem; font-weight: 600; white-space: nowrap; }

.aim-ui { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); width: min(440px, calc(100% - 24px)); background: rgba(251, 249, 243, 0.92); border: 2px solid var(--ink); border-radius: var(--wobble); padding: 10px 14px; z-index: 6; }
.aim-help { margin: 0 0 6px; font-size: 0.92rem; text-align: center; }
.power { height: 10px; border: 1.5px solid var(--ink); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
.power span { display: block; height: 100%; width: 0; background: var(--accent); }
.angle { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; }
.angle input { width: 100%; height: 34px; accent-color: var(--ink); touch-action: pan-x; }

.speed-btn { position: fixed; right: calc(12px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); z-index: 7; background: rgba(251, 249, 243, 0.92); }
.popup { position: fixed; left: 50%; top: 34%; transform: translate(-50%, -50%); font-family: var(--hand); font-weight: 700; font-size: 2rem; color: var(--accent); background: rgba(251, 249, 243, 0.9); border: 2px solid var(--ink); border-radius: var(--wobble); padding: 6px 18px; pointer-events: none; z-index: 8; animation: pop 1.4s ease forwards; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -80%) scale(1); } }

.result-card { max-width: 480px; text-align: center; }
.result-card .btn-row { justify-content: center; }
.result-kicker { margin: 0; color: var(--ink-soft); }
.result-big { font-family: var(--hand); font-weight: 700; font-size: 3rem; line-height: 1.1; }
.result-best { font-weight: 600; margin: 4px 0 0; }
.result-best .new { color: var(--accent); }
.noscript { position: fixed; inset: auto 0 40%; text-align: center; }

/* phones and portrait: folding panel becomes a bottom sheet */
@media (max-width: 760px), (max-aspect-ratio: 1/1) {
  .panel { top: auto; left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); bottom: calc(8px + var(--safe-b)); width: auto; max-height: 54%; padding: 12px 14px; }
  .panel h2 { font-size: 1.2rem; margin-bottom: 0.2em; }
  .options { gap: 6px; }
  .opt { min-height: 44px; padding: 8px 6px; font-size: 0.9rem; }
  .note { min-height: 0; font-size: 0.88rem; margin-bottom: 0.4em; }
  .stats { gap: 4px 8px; }
  .hint { top: calc(16px + var(--safe-t)); bottom: auto; }
  .card { padding: 18px 16px; }
  .hud { padding-right: calc(112px + var(--safe-r)); }
  .hud-left { display: none; }
  .hud-dist { font-size: 1.35rem; }
  .result-big { font-size: 2.4rem; }
  .btn { padding: 10px 14px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .panel { top: calc(8px + var(--safe-t)); bottom: calc(8px + var(--safe-b)); right: calc(8px + var(--safe-r)); left: auto; width: 340px; max-height: none; }
  .hint { top: auto; bottom: calc(10px + var(--safe-b)); }
}
@media (min-width: 761px) and (min-aspect-ratio: 1/1) {
  #title, #where { justify-content: flex-start; padding-left: calc(5vw + var(--safe-l)); }
  #title .card, #where .card { max-width: 470px; }
}
@media (prefers-reduced-motion: reduce) { .speed-btn { position: fixed; right: calc(12px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); z-index: 7; background: rgba(251, 249, 243, 0.92); }
.popup { animation-duration: 0.01s; } .bar i, .bar b, .wind-arrow { transition: none; } }
