/* Besseggen under the house system (Template/HOUSE.md; ART.md). The plate keeps its daylight in
   both themes; the chrome follows the phone. The one bold thing is the Burn (js/track.js). */

@font-face {
  font-family: 'Ysabeau Office';
  src: url(fonts/ysabeau-office-gw.woff2) format('woff2');
  font-weight: 400 650;
  font-display: block;
}

:root {
  --page: #e8eef0;            /* header, caption band, player, sheet */
  --sheet: #f6f9fa;           /* key plates, the card, About and Layers, notices */
  --ink: #0f1c23;
  --ink-2: #45555d;
  --ink-3: #5b6a72;
  --line: #c9d4d8;
  --line-strong: #74858c;
  --draw: cubic-bezier(0.2, 0, 0, 1);
  --sheet-in: cubic-bezier(0.32, 0.72, 0, 1);
  --face: 'Ysabeau Office', system-ui, -apple-system, sans-serif;
  --burn: #1b110b;            /* the signature: the burned day on the track */
  --plate-ink: #0f1c23;       /* the plate's labels, over their halo, in both themes */
  --plate-ink-2: #45555d;
  --plate-halo: rgba(246, 249, 250, 0.85);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #141d21;
    --sheet: #1c272c;
    --ink: #e6edee;
    --ink-2: #a3b1b6;
    --ink-3: #8b9a9f;
    --line: #2a373c;
    --line-strong: #64757b;
    --burn: #fcf2e5;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--page);
  color: var(--ink);
  font: 400 13.5px/1.35 var(--face);
  font-variant-numeric: tabular-nums lining-nums;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
h1, h2, h3, h4, p { margin: 0; }
button, input, output { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; margin: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.keyplate button, .ghost, .card-close, .tkey, .shutter, .box { display: flex; align-items: center; justify-content: center; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; margin: -1px; }
.note { font-size: 11.5px; color: var(--ink-2); }

/* ── header: the name, the stamp while loading, About ── */
.head, .caption, .player { flex: 0 0 auto; }
.head { display: grid; grid-template-columns: minmax(0, 1fr) auto; padding: calc(6px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 6px calc(16px + env(safe-area-inset-left)); }
.head h1 { font-size: 15px; font-weight: 650; line-height: 22px; }
.head:has(#stamp-home[hidden]) h1 { grid-row: 1 / 3; align-self: center; }
.stamp-home { min-width: 0; }
.hkeys { grid-area: 1 / 2 / 3 / 3; align-self: center; margin: -8px -8px -8px 0; }
.caption > .textkey { display: block; margin: -7px 0 -8px -8px; }
.stamp { position: relative; display: block; max-width: 100%; text-align: left; font-size: 11.5px; line-height: 16px; color: var(--ink-2); }
.stamp::before { content: ''; position: absolute; inset: -22px 0 -6px 0; }

/* ── the plate: the terrain, edge to edge ── */
.plate { position: relative; flex: 1 1 auto; min-height: 180px; overflow: hidden; background: #dfe7ef; user-select: none; -webkit-user-select: none; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
/* labels: the face over a halo, no pill (ART.md section 3) */
.lbl {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 4px 2px;
  white-space: nowrap;
  font: 560 11.5px/14px var(--face);
  color: var(--plate-ink);
  paint-order: stroke fill;
  -webkit-text-stroke: 3px var(--plate-halo);
}
.lbl small { font-size: 10.5px; font-weight: 400; color: var(--plate-ink-2); }
.lbl.peak { font-size: 11px; font-weight: 400; }
.lbl.km { font-size: 10.5px; font-weight: 400; }
.lbl span { position: relative; }
.lbl.wp span::before { content: ''; position: absolute; left: -9px; top: 5px; width: 4px; height: 4px; border-radius: 50%; background: var(--route); outline: 1.5px solid var(--plate-halo); }
.lbl.mark span::after, .word[aria-pressed="true"]::after, .word[aria-checked="true"]::after {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 9px;
  height: 4px;
  background:
    radial-gradient(circle at calc(100% - 2px) 50%, var(--ink) 1.9px, transparent 2.1px),
    linear-gradient(90deg, transparent, var(--ink) calc(100% - 3px), transparent calc(100% - 3px)) 0 1px / 100% 2px no-repeat;
  animation: tracer-in 160ms var(--draw);
}
.lbl.mark span::after { --ink: var(--plate-ink); left: -1px; right: -3px; bottom: -5px; animation: none; }
@keyframes tracer-in { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* the key column: plates of --sheet, each key a 44 px hit, the plate 36 px wide */
.keys { position: absolute; top: 8px; right: calc(8px + env(safe-area-inset-right)); z-index: 3; display: flex; flex-direction: column; gap: 8px; }
.keyplate { width: 38px; border: 1px solid var(--line); border-radius: 6px; background: var(--sheet); }
.keyplate button { position: relative; width: 44px; height: 44px; margin: 0 -4px; color: var(--ink-2); }
.keyplate button + button::after { content: ''; position: absolute; left: 4px; right: 4px; top: 0; height: 1px; background: var(--line); }
.keyplate button svg { position: relative; }
.keyplate button::before { content: ''; position: absolute; inset: 8px; border-radius: 4px; }
.keyplate button:active::before { background: color-mix(in srgb, currentColor 22%, transparent); }
.tkey:active > svg, .textkey:active, .word:active { background: color-mix(in srgb, currentColor 12%, transparent); border-radius: 4px; }
/* a plate too short for the column: the keys run as a row along the top, the card below them */
.keys-row .keys { flex-direction: row; }
.keys-row .keyplate { display: flex; width: auto; height: 38px; }
.keys-row .keyplate button { margin: -4px 0; }
.keys-row .keyplate button + button::after { left: 0; right: auto; top: 8px; bottom: 8px; width: 1px; height: auto; }
.keys-row .card:not(.low) { top: 54px; }
.keys-row .card { max-height: min(max(34%, 66px), calc(100% - 62px)); }

/* the ghost key: no plate, a halo under the mark, one style in both themes (the plate is one) */
.ghost { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: calc(8px + env(safe-area-inset-right)); z-index: 4; width: 44px; height: 44px; opacity: 0.72; animation: fade-in 200ms var(--draw); }
.ghost:focus-visible, .ghost:active { opacity: 1; }
.ghost .halo { stroke: rgba(246, 249, 250, 0.6); stroke-width: 3.4; }
.ghost .halo circle { fill: rgba(246, 249, 250, 0.6); }
.ghost .mark { stroke: #0f1c23; stroke-width: 1.4; }
.ghost .mark .fill { fill: #0f1c23; }
@keyframes fade-in { from { opacity: 0; } }

/* the card: the tapped point, or a tool's result */
.card {
  position: absolute;
  left: calc(8px + env(safe-area-inset-left));
  top: 8px;
  z-index: 3;
  width: min(280px, calc(100% - 76px));
  max-height: max(34%, 66px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 4px 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--sheet);
  animation: card-in 120ms var(--draw);
}
@keyframes card-in { from { opacity: 0; transform: translateY(4px); } }
.card.low { top: auto; bottom: 8px; }
.focus .card:not(.low) { top: calc(8px + env(safe-area-inset-top)); }
.card-kind { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; color: var(--ink-2); }
.card-close { flex: 0 0 auto; width: 44px; height: 44px; margin: -8px -4px -10px 0; color: var(--ink-2); }
.card-fig { padding-right: 8px; font-size: 21px; font-weight: 600; line-height: 1.2; }
.card-fig .unit { font-size: 13.5px; font-weight: 400; color: var(--ink-2); }
.card dl, .dlg dl { display: grid; grid-template-columns: auto 1fr; }
.card dl { margin: 6px 8px 0 0; padding-top: 6px; border-top: 1px solid var(--line); gap: 1px 14px; font-size: 12.5px; }
.card dt { color: var(--ink-2); }
.card dd { margin: 0; text-align: right; font-weight: 560; }
.card .note { margin: 4px 8px 0 0; }
.xs { width: calc(100% - 8px); height: 88px; margin-top: 6px; }
.xs .terr { fill: color-mix(in srgb, var(--ink) 6%, transparent); stroke: var(--ink-2); stroke-width: 1; vector-effect: non-scaling-stroke; }
.xs .sight { stroke: var(--ink); vector-effect: non-scaling-stroke; }
.xs .blocked { stroke-dasharray: 4 3; }
.peaks { margin: 6px 8px 0 0; padding: 0; list-style: none; font-size: 12.5px; }
.peaks li { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.peaks li span + span { color: var(--ink-2); text-align: right; }

/* a problem with the data is a sentence on the plate */
.notice {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 5;
  width: max-content;
  max-width: min(300px, calc(100% - 32px));
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--sheet);
  font-size: 13.5px;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}

/* ── the caption band: north and the scale, the legend rows, the caption ── */
.caption { padding: 4px calc(16px + env(safe-area-inset-right)) 4px calc(16px + env(safe-area-inset-left)); font-size: 11px; line-height: 15px; color: var(--ink-2); }
.inst { display: flex; align-items: center; gap: 6px; height: 24px; white-space: nowrap; overflow: hidden; }
#compass { flex: 0 0 auto; overflow: visible; color: var(--ink); }
#compass .gn { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 1.5 1.5; }
#compass .tail { stroke-width: 1; }
#compass text { fill: var(--ink); stroke: none; font: 600 10.5px var(--face); text-anchor: middle; dominant-baseline: central; }
#scale-len { color: var(--ink); }
#scale-sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sbar { flex: 0 0 auto; height: 6px; border: 2px solid var(--ink); border-top: 0; }
.legend { display: flex; align-items: flex-start; gap: 12px; height: 30px; }
.lt { flex: 0 1 auto; min-width: 0; font-size: 11.5px; font-weight: 600; color: var(--ink); padding-top: 1px; }
.ls { flex: 1 1 150px; min-width: 150px; padding-top: 5px; }
.lb { height: 6px; outline: 1px solid color-mix(in srgb, var(--line-strong) 60%, transparent); }
.lk { position: relative; height: 15px; font-size: 10.5px; }
.lk span { position: absolute; top: 3px; transform: translateX(-50%); line-height: 12px; }
.lk span::before { content: ''; position: absolute; left: 50%; top: -3px; width: 1px; height: 3px; background: var(--line-strong); }
.lk .first { left: 0; transform: none; }
.lk .first::before { left: 0; }
.lk .last { right: 0; transform: none; }
.lk .last::before { left: auto; right: 0; }
/* fixed height, whatever it says, so the plate never resizes (shoot.mjs measures the longest) */
.capbox { height: 30px; overflow: hidden; }
#cap-tool:empty { display: none; }
#cap-tool { color: var(--ink); }
#s-updown + .k { white-space: nowrap; }
.k .sw { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 2px; vertical-align: -1px; background: var(--trail); }

/* ── the player: the time row, the transport and the track with the Burn ── */
.player { padding: 2px calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left)); border-top: 1px solid var(--line); }
.time-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 6px 4px 0; white-space: nowrap; }
.valid { font-size: 21px; line-height: 1; font-weight: 600; }
.zone, .lead { font-size: 12.5px; font-weight: 400; color: var(--ink-2); }
@media (max-width: 359px) { .wide { display: none; } }
.controls { display: flex; align-items: flex-start; }
.tkey { flex: 0 0 auto; width: 44px; height: 44px; color: var(--ink-2); }
.tkey.play { color: var(--page); }
.shutter { width: 32px; height: 32px; border-radius: 8px; background: var(--ink); }
.shutter svg { fill: currentColor; stroke: none; }
.track { position: relative; flex: 1 1 auto; min-width: 0; height: 58px; margin-left: 4px; cursor: pointer; touch-action: none; }
.track canvas { display: block; width: 100%; height: 58px; }
.track:focus-visible { outline-offset: -2px; }
/* no transition, ever, on what carries a step */
.valid, .lead, .track, .track canvas { transition: none; animation: none; }

/* ── the controls sheet: the walk; sun and camera; everything else ── */
.sheet {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 calc(16px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  border-top: 1px solid var(--line);
}
.grip { position: sticky; top: 0; z-index: 2; display: block; width: 100%; height: 44px; background: var(--page); }
.grip .bar { display: block; width: 36px; height: 4px; margin: 0 auto; border-radius: 2px; background: var(--line-strong); }
.grip .chev { position: absolute; right: 0; top: 16px; color: var(--ink-2); }
.s2 .grip .chev { transform: rotate(180deg); }
.s0 #more1, .s0 #more2, .s1 #more2 { display: none; }
.walk { font-size: 12.5px; line-height: 20px; color: var(--ink-2); }
.walk b { font-weight: 560; color: var(--ink); }
#profile { width: 100%; height: 88px; display: block; touch-action: none; cursor: crosshair; }
.pfill { fill: color-mix(in srgb, var(--ink) 6%, transparent); }
.pline, .pso, .psteep, .pgrid, .pkm, .pcur, .pring, .pdot, .pwp { vector-effect: non-scaling-stroke; }
.pline { fill: none; stroke: var(--ink-2); stroke-width: 1.5; }
.pso { fill: none; stroke: var(--ink); stroke-width: 2; }
.psteep { fill: none; stroke: var(--trail); stroke-width: 3; }
.pgrid { stroke: var(--line); stroke-width: 1; }
.pkm { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.pcur { stroke: var(--ink); stroke-width: 1.5; }
.pring { fill: var(--page); stroke: none; }
.pdot, .pwp { fill: var(--ink); stroke: none; }
#profile text { font: 400 10.5px var(--face); fill: var(--ink-3); stroke: none; }
#profile .pax { fill: var(--ink-2); }
#profile .pwpt { font-weight: 560; fill: var(--ink); paint-order: stroke fill; stroke: var(--page); stroke-width: 3px; }
.foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
.foot p { font-size: 11.5px; line-height: 15px; color: var(--ink-2); }
.textkey, .word { position: relative; min-width: 44px; min-height: 44px; padding: 0 8px; font-size: 12.5px; color: var(--ink); }
.framed { flex: 0 0 auto; }
.framed::before { content: ''; position: absolute; inset: 8px 0; border: 1px solid var(--line-strong); border-radius: 6px; }
.sheet section { padding-bottom: 4px; }
.sheet h2 { padding: 12px 0 2px; border-top: 1px solid var(--line); margin-top: 8px; font-size: 13.5px; font-weight: 650; }
.row { display: grid; grid-template-columns: 76px 1fr auto; align-items: center; gap: 8px; min-height: 44px; font-size: 12.5px; }
.row label { color: var(--ink-2); }
.row output { min-width: 64px; text-align: right; }
.row + .note { padding-top: 2px; }   /* the face's glyphs stand taller than the line: keep them off the slider */
.words { display: flex; flex-wrap: wrap; margin: 0 -8px; }
.word { color: var(--ink-2); }
.word[aria-pressed="true"], .word[aria-checked="true"] { color: var(--ink); font-weight: 620; }
/* a native range drawn in the house's language: a baseline, the value so far, a tracer-head thumb */
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 44px; margin: 0; background: transparent; touch-action: manipulation; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(var(--ink), var(--ink)) 0 0 / var(--v, 0%) 2px no-repeat, linear-gradient(var(--line-strong), var(--line-strong)) 0 0.5px / 100% 1px no-repeat;
}
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -6px; border: 3px solid var(--page); border-radius: 50%; background: var(--ink); }

/* ── About and Layers: full-height sheets ── */
.dlg { position: fixed; inset: 0; z-index: 20; }
.dlg-panel { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--sheet); animation: sheet-in 220ms var(--sheet-in); }
@keyframes sheet-in { from { transform: translateY(100%); } }
.dlg-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: env(safe-area-inset-top) calc(8px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left)); border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 15px; font-weight: 650; }
.dlg-body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 0 calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); }
.dlg-body > p, .dlg-body section { max-width: 62ch; }
.ab-lead { padding: 12px 0; line-height: 1.5; }
.ab-lead b { font-weight: 600; }
.dlg-body section { padding: 12px 0; border-top: 1px solid var(--line); }
.dlg h3 { margin-bottom: 6px; font-size: 13.5px; font-weight: 650; }
.dlg h4 { margin: 12px 0 4px; font-size: 13.5px; font-weight: 600; }
.dlg-body section p { margin-bottom: 8px; line-height: 1.5; overflow-wrap: anywhere; }
.dlg dl { margin: 0 0 8px; gap: 3px 12px; line-height: 1.45; }
.dlg dt { color: var(--ink-2); }
.dlg dd { margin: 0; overflow-wrap: anywhere; }
.layer-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 4px 0; border-bottom: 1px solid var(--line); text-align: left; }
.box { flex: 0 0 auto; width: 28px; height: 28px; border: 1px solid var(--line-strong); border-radius: 4px; }
.box svg { visibility: hidden; }
.layer-row[aria-pressed="true"] .box { border-color: transparent; background: color-mix(in srgb, var(--ink) 12%, transparent); }
.layer-row[aria-pressed="true"] .box svg { visibility: visible; }
.layer-row .t, .layer-row .s { display: block; }
.layer-row .s { font-size: 11.5px; color: var(--ink-2); }
#layer-note { padding: 8px 0; }
.dlg-foot { margin-top: 8px; }

/* ── focus mode: the chrome leaves; the plate, About, the caption and the player stay ── */
.leaving { opacity: 0; transition: opacity 160ms var(--draw); }

@media (hover: hover) {
  .keyplate button:hover svg { background: color-mix(in srgb, currentColor 7%, transparent); border-radius: 4px; }
  .stamp:hover, .textkey:hover, .word:hover, .tkey:hover { color: var(--ink); }
  .ghost:hover { opacity: 1; }
}
@media (min-width: 700px) {
  .head, .caption { padding-left: calc(20px + env(safe-area-inset-left)); padding-right: calc(20px + env(safe-area-inset-right)); }
}
/* a wide screen, or a phone on its side: the sheet is a column at the right */
@media (min-width: 820px) and (min-height: 480px), (orientation: landscape) and (max-height: 500px) {
  body { display: grid; grid-template-columns: minmax(0, 1fr) 372px; grid-template-rows: auto minmax(0, 1fr) auto auto; }
  .head, .plate, .caption, .player { grid-column: 1; }
  .plate { grid-row: 2; }
  .caption { grid-row: 3; }
  .player { grid-row: 4; }
  .sheet { grid-column: 2; grid-row: 1 / -1; border-top: 0; border-left: 1px solid var(--line); padding-top: calc(8px + env(safe-area-inset-top)); }
  .focus { grid-template-columns: minmax(0, 1fr) 0; }
  .grip { display: none; }
  .s0 #more1, .s0 #more2, .s1 #more2 { display: block; }
}
@media (orientation: landscape) and (max-height: 500px) {
  body { grid-template-columns: minmax(0, 1fr) min(330px, 46%); }
  .head { align-content: center; height: calc(46px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); padding-bottom: 0; }
  .stamp { white-space: nowrap; }
  .caption { padding-top: 2px; padding-bottom: 2px; }
  .stamp::before { inset: -26px 0 -2px 0; }
  .player { display: flex; align-items: center; gap: 8px; padding-top: 0; }
  .time-row { flex: 0 0 auto; flex-direction: column; align-items: flex-start; gap: 3px; padding: 0 4px; }
  .controls { flex: 1 1 auto; min-width: 0; align-items: center; }
  #profile { height: 104px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; scroll-behavior: auto !important; }
}
