/* Hello Map under the house system (Template/HOUSE.md; ART.md). The plate keeps the map's daylight
   in both themes, and so do the marks on it; the chrome follows the phone. The one bold thing is
   the collar (js/collar.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 */
  --sheet: #f6f9fa;           /* key plates, the card, About, 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;
  --plate: #dfe5e3;           /* the plate under the map while it loads, or when it cannot */
  --collar: #0f1c23;          /* the signature: ticks, crosses and degrees, one style in both themes */
  --collar-halo: rgba(246, 249, 250, 0.88);
  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;
    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 { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.keyplate button, .ghost, .card-close { 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; }

/* ── header: the name, the status line, the units key and About ── */
.head, .caption { flex: 0 0 auto; }
.head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  padding: calc(6px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 4px calc(16px + env(safe-area-inset-left));
}
.head h1 { grid-area: 1 / 1; font-size: 15px; font-weight: 650; line-height: 22px; }
.stamp-home { grid-area: 2 / 1; min-width: 0; padding-bottom: 4px; }
.hkeys { grid-area: 1 / 2 / 3 / 3; align-self: center; display: flex; gap: 4px; margin: -8px -8px -8px 0; }
.stamp { position: relative; display: block; max-width: 100%; text-align: left; font-size: 11.5px; line-height: 16px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stamp::before { content: ''; position: absolute; inset: -22px 0 -6px 0; }
.caption > .textkey { display: block; margin: -7px 0 -8px -8px; }

/* ── the plate: the map, edge to edge, and the collar over it ── */
.plate { position: relative; flex: 1 1 auto; min-height: 180px; overflow: hidden; background: var(--plate); user-select: none; -webkit-user-select: none; }
#map, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#map { touch-action: none; cursor: grab; }
#map:focus-visible { outline-offset: -2px; }
#overlay { pointer-events: none; }

/* 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); }
.textkey:active { background: color-mix(in srgb, currentColor 12%, transparent); border-radius: 4px; }
.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; }

/* the layer switch: two words on one plate at the plate's foot, the chosen one inked and filled; it
   stays in focus mode */
.viewkey { position: absolute; right: calc(8px + env(safe-area-inset-right)); bottom: 26px; z-index: 3; display: flex; height: 38px; border: 1px solid var(--line); border-radius: 6px; background: var(--sheet); }
.viewkey button { position: relative; min-width: 44px; height: 44px; margin: -4px 0; padding: 0 10px; font-size: 12.5px; color: var(--ink-2); }
.viewkey button + button::after { content: ''; position: absolute; left: 0; top: 12px; bottom: 12px; width: 1px; background: var(--line); }
.viewkey button::before { content: ''; position: absolute; inset: 8px 4px; border-radius: 4px; }
.viewkey button[aria-checked="true"] { color: var(--ink); font-weight: 620; }
.viewkey button[aria-checked="true"]::before { background: color-mix(in srgb, var(--ink) 12%, transparent); }
.viewkey button:active::before { background: color-mix(in srgb, currentColor 22%, transparent); }

/* the ghost key: no plate, a halo under the mark, the collar's one style (it stands on the map) */
.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: var(--collar-halo); stroke-width: 3.4; }
.ghost .halo circle { fill: var(--collar-halo); }
.ghost .mark { stroke: var(--collar); stroke-width: 1.4; }
.ghost .mark .fill { fill: var(--collar); }
@keyframes fade-in { from { opacity: 0; } }

/* the card: the tapped point */
.card {
  position: absolute;
  left: calc(8px + env(safe-area-inset-left));
  top: 8px;
  z-index: 3;
  width: min(280px, calc(100% - 76px));
  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: 74px; }
.focus .card:not(.low) { top: calc(8px + env(safe-area-inset-top)); }
.card-kind { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.card-kind span { min-width: 0; }
.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 dl { display: grid; grid-template-columns: auto 1fr; 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; overflow-wrap: anywhere; }

/* a problem is a sentence on the plate */
.notice {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  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: the scale bar and the caption line ── */
.caption { padding: 4px calc(16px + env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left)); font-size: 11px; line-height: 15px; color: var(--ink-2); }
.inst { display: flex; align-items: center; gap: 8px; height: 22px; white-space: nowrap; overflow: hidden; }
#scale-len { color: var(--ink); font-size: 11.5px; font-weight: 600; }
#scale-sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* the bar scale drawn as a quadrangle's: four segments, alternately filled, on one frame */
.sbar { flex: 0 0 auto; display: flex; height: 6px; border: 1px solid var(--ink); }
.sbar i { flex: 1 1 0; }
.sbar i:nth-child(odd) { background: var(--ink); }
/* fixed height, whatever it says, so the plate never resizes */
.capbox { height: 30px; overflow: hidden; }

/* ── About: a full-height sheet ── */
.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 { display: grid; grid-template-columns: auto 1fr; margin: 0 0 8px; gap: 3px 12px; line-height: 1.45; }
.dlg dt { color: var(--ink-2); }
.dlg dd { margin: 0; overflow-wrap: anywhere; }
.textkey { 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; }
.units { font-weight: 600; }
.dlg-foot { margin-top: 8px; }

/* ── focus mode: the chrome leaves; the plate, the layer switch and the caption band 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, .viewkey button: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 phone on its side: the header one row, the caption band one row, the keys along the plate's top */
@media (orientation: landscape) and (max-height: 500px) {
  .head { grid-template-columns: auto minmax(0, 1fr) auto; height: calc(46px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); padding-bottom: 0; align-content: center; }
  .stamp-home { padding-bottom: 0; }
  .hkeys { grid-area: 1 / 3 / 3 / 4; }
  .stamp::before { inset: -26px 0 -2px 0; }
  .caption { display: flex; align-items: center; column-gap: 16px; padding-top: 0; padding-bottom: env(safe-area-inset-bottom); }
  .capbox { flex: 1 1 260px; height: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; scroll-behavior: auto !important; }
}
