/* ==========================================================================
   Base: reset, typography, page frame, header, tab bar, footer
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html {
  font-size: clamp(1rem, .42vw + .625rem, 1.3125rem);     /* 16 px up to about 1400 px wide, then grows to 21 px on very large screens */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 14px);
  background: var(--chassis);
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.55;
  font-feature-settings: "ss01", "cv11";
  color: var(--ink);
  background-color: var(--chassis);
  background-image: radial-gradient(circle at center, var(--dots) 1px, transparent 1.6px);
  background-size: 18px 18px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
}
body.modal-open { overflow: hidden; }
main { flex: 1 0 auto; outline: none; min-width: 0; }
main:focus, main:focus-visible { outline: none; }
img, svg, canvas { max-width: 100%; }
img { height: auto; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.022em; line-height: 1.12; text-wrap: balance; }
h1 { font-size: clamp(2rem, 1.3rem + 2.8vw, 3.5rem); letter-spacing: -.035em; line-height: 1.02; }
h2 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.9rem); }
h3 { font-size: 1.15rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 .85em; text-wrap: pretty; }
a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--ink); }
ul, ol { margin: 0; padding: 0; }
small { font-size: .84em; }
button { font: inherit; color: inherit; }
button:disabled { cursor: not-allowed; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
::selection { background: var(--accent); color: var(--accent-ink); }
:root[data-theme="dark"] ::selection { background: var(--accent); }

.ico { display: inline-flex; vertical-align: middle; flex: none; }
.muted { color: var(--ink-2); }
.small { font-size: .88rem; }
.mono { font-family: var(--font-mono); }
.num { font-variant-numeric: tabular-nums; }
.sci, i.sci { font-style: italic; color: var(--ink-2); font-weight: 400; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.skip { position: absolute; left: -999px; top: 8px; z-index: 200; padding: 10px 16px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 650; text-decoration: none; }
.skip:focus { left: 8px; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: .25; } }
main > * { animation: rise .32s var(--ease) both; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- printed-on-the-case labels ---------- */

.legend {
  margin: 0;
  font: 500 0.6875rem/1.25 var(--font-mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.legend b { color: var(--accent-text); font-weight: 600; margin-right: .5em; }

/* ---------- page frame ---------- */

.wrap { width: 100%; max-width: var(--page-max); margin: 0 auto; padding-left: max(var(--gutter), env(safe-area-inset-left)); padding-right: max(var(--gutter), env(safe-area-inset-right)); }
.page { padding-top: clamp(16px, 2.6vw, 36px); padding-bottom: clamp(36px, 5vw, 72px); }
.page > * + * { margin-top: clamp(18px, 2.4vw, 30px); }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 18px 28px; flex-wrap: wrap; }
.page-head > div:first-child { min-width: 0; flex: 1 1 320px; }
.page-head .legend { margin-bottom: 12px; }
.page-head h1 { max-width: 20ch; }
.lead { color: var(--ink-2); font-size: clamp(1rem, .95rem + .3vw, 1.15rem); margin: 12px 0 0; max-width: 62ch; }

.section-title {
  display: flex; align-items: baseline; gap: 6px 14px; flex-wrap: wrap;
  margin: clamp(26px, 3.4vw, 44px) 0 14px;
  font-size: clamp(1.2rem, 1.05rem + .6vw, 1.55rem);
  letter-spacing: -.02em;
}
.section-title small { font: 500 0.6875rem/1.3 var(--font-mono); letter-spacing: .09em; text-transform: uppercase; color: var(--ink-2); }
.section-title::after {
  content: ""; flex: 1 1 60px; min-width: 40px; height: 8px; align-self: center;
  background: var(--wave) repeat-x center / 24px 8px;
}
.sub-h { margin: 16px 0 8px; font: 600 0.6875rem/1.3 var(--font-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); }

/* ---------- header ---------- */

.site-header {
  position: sticky; top: 0; z-index: 40;
  background: var(--chassis);
  background: color-mix(in srgb, var(--chassis) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.3) blur(14px);
  backdrop-filter: saturate(1.3) blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-t);
}
.header-in { display: flex; align-items: center; gap: 18px; min-height: var(--header-h); }
.brand { display: flex; align-items: center; gap: 11px; min-height: 44px; min-width: 44px; text-decoration: none; color: var(--ink); flex: none; }
.brand-logo { display: block; width: 38px; height: 38px; border-radius: 10px; box-shadow: 0 2px 0 rgba(19, 19, 18, .25), 0 6px 12px rgba(255, 90, 18, .22); }
.brand-text { display: flex; flex-direction: column; gap: 3px; line-height: 1; }
.brand-text strong { font: 900 1.5625rem/1 var(--font-lcd); font-variation-settings: "ROND" 100; letter-spacing: .06em; color: var(--ink); }
.brand-text small { font: 500 0.625rem/1 var(--font-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); }
.brand:hover { color: var(--ink); }

.nav {
  display: flex; gap: 5px; margin-left: auto; padding: 5px;
  background: var(--chassis-2); border-radius: 15px;
  box-shadow: inset 0 1px 3px rgba(19, 19, 18, .16), 0 1px 0 var(--key-hi);
}
.nav a {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 14px; border-radius: 10px;
  font: 600 0.75rem/1 var(--font-mono); letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink); text-decoration: none;
  background: linear-gradient(var(--key-face), var(--key-face-2)), var(--key-face-2);
  box-shadow: var(--key-shadow);
  transition: transform .08s, box-shadow .08s, background .15s;
}
.nav a .nav-n { color: var(--accent-text); font-weight: 600; }
.nav a:hover { color: var(--ink); background: var(--key-face); }
.nav a:active, .nav a.active { transform: translateY(2px); box-shadow: var(--key-shadow-down); background: var(--panel-3); }
.nav a.active::after { content: ""; position: absolute; right: 7px; top: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.header-tools { display: flex; gap: 8px; align-items: center; margin-left: 10px; }
.nav + .header-tools { margin-left: 0; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; padding: 0; border: 0; border-radius: 12px; cursor: pointer;
  color: var(--ink); background: linear-gradient(var(--key-face), var(--key-face-2)), var(--key-face-2); box-shadow: var(--key-shadow);
  transition: transform .08s, box-shadow .08s;
}
.icon-btn:active { transform: translateY(2px); box-shadow: var(--key-shadow-down); }
.icon-btn:hover { color: var(--accent-text); }

@media (pointer: coarse) { .nav a { height: 44px; } }

/* theme: a two-position switch, light on the left and night on the right */
.theme-btn {
  position: relative; display: inline-grid; grid-template-columns: 1fr 1fr; align-items: center; justify-items: center;
  width: 84px; height: 40px; padding: 0; border: 0; border-radius: 13px; cursor: pointer; flex: none;
  background: var(--chassis-2); color: var(--ink-2);
  box-shadow: inset 0 1px 3px rgba(19, 19, 18, .2), 0 1px 0 var(--key-hi);
}
.theme-btn::before {
  content: ""; position: absolute; top: 4px; left: 4px; width: 38px; height: 32px; border-radius: 9px;
  background: linear-gradient(var(--key-face), var(--key-face-2)), var(--key-face-2); box-shadow: var(--key-shadow); transition: transform .22s var(--ease);
}
.theme-btn[data-mode="dark"]::before { transform: translateX(38px); }
.theme-btn .ico { position: relative; z-index: 1; }
.theme-btn[data-mode="light"] .t-sun, .theme-btn[data-mode="dark"] .t-moon { color: var(--accent-text); }

/* ---------- bottom key bar (phones and small tablets) ---------- */

.tabbar { display: none; }
body.in-quiz .site-header, body.in-quiz .site-footer, body.in-quiz .tabbar { display: none !important; }

@media (max-width: 1023.98px) {
  html { scroll-padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); }
  .nav { display: none; }
  .header-in .header-tools { margin-left: auto; }
  .brand-text small { display: none; }
  .header-in { min-height: 56px; }
  :root { --header-h: 56px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    padding: 8px max(10px, env(safe-area-inset-right)) calc(8px + var(--safe-b)) max(10px, env(safe-area-inset-left));
    background: var(--chassis);
    background: color-mix(in srgb, var(--chassis) 92%, transparent);
    -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
  }
  .tab {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
    min-height: 52px; padding: 7px 2px 6px; border-radius: 12px; text-decoration: none; color: var(--ink);
    font: 600 .625rem/1 var(--font-mono); letter-spacing: .05em; text-transform: uppercase;
    background: linear-gradient(var(--key-face), var(--key-face-2)), var(--key-face-2); box-shadow: var(--key-shadow);
    transition: transform .08s, box-shadow .08s;
  }
  .tab:active, .tab.active { transform: translateY(2px); box-shadow: var(--key-shadow-down); background: var(--panel-3); }
  .tab.active { color: var(--ink); }
  .tab.active::after { content: ""; position: absolute; top: 5px; right: 6px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
  .tab .ico svg { width: 20px; height: 20px; }
  body:not(.in-quiz) .site-footer { padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
}
@media (min-width: 1024px) and (max-width: 1279.98px) {
  .nav a { padding: 0 11px; gap: 6px; letter-spacing: .05em; }
  .nav a .nav-n { display: none; }
  .brand-text small { display: none; }
}
/* small phones: the logo alone, so the safety key, the account key and the theme switch fit beside it */
@media (max-width: 379.98px) {
  .brand-text { display: none; }
}
/* a phone on its side: every pixel of height counts, so the header scrolls away and the key bar shrinks to icons */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --header-h: 48px; --tabbar-h: 58px; }
  .site-header { position: static; }
  .header-in { min-height: 48px; }
  .brand-logo { width: 32px; height: 32px; }
  .brand-text strong { font-size: 1.3rem; }
  .tabbar { padding-top: 6px; padding-bottom: calc(6px + var(--safe-b)); }
  .tab { min-height: 44px; padding: 0; gap: 0; }
  .tab > span:not(.ico) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* ---------- footer ---------- */

.site-footer {
  position: relative; margin-top: clamp(28px, 5vw, 64px);
  border-top: 1px solid var(--line-2); color: var(--ink-2); font-size: .92rem;
  background-color: var(--chassis-2);
  background-image: linear-gradient(color-mix(in srgb, var(--chassis-2) 72%, transparent), color-mix(in srgb, var(--chassis-2) 72%, transparent)), var(--scales);
  background-size: auto, 28px 14px;
}
.footer-in { padding-top: clamp(22px, 3vw, 36px); padding-bottom: clamp(22px, 3vw, 36px); display: grid; gap: 22px; }
.foot-cols { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.4fr); gap: 22px clamp(20px, 4vw, 64px); align-items: start; }
.foot-cols p { margin: 0 0 .5em; max-width: 58ch; }
.foot-title { margin-bottom: 8px; }
.foot-links { display: flex; flex-direction: column; gap: 4px; }
.foot-links a { color: var(--ink); text-decoration: none; font-weight: 550; padding: 4px 0; min-height: 30px; display: inline-flex; align-items: center; }
.foot-links a:hover { color: var(--accent-text); text-decoration: underline; }
@media (pointer: coarse) { .foot-links a { min-height: 44px; } }
.foot-warn { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); background: var(--panel); border: 1px solid var(--line); color: var(--ink); }
.foot-warn .ico { color: var(--bad-ink); margin-top: 3px; }
.foot-spec { padding-top: 14px; border-top: 1px dashed var(--line-2); display: flex; flex-wrap: wrap; gap: 6px 18px; }
@media (max-width: 1023.98px) {
  .foot-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .foot-warn { grid-column: 1 / -1; }
}
@media (max-width: 599.98px) {
  .foot-cols { grid-template-columns: 1fr; }
}

/* ---------- first paint ---------- */

.boot { display: grid; place-items: center; min-height: 50vh; }
.boot .lcd { padding: 14px 22px; font: 900 1.375rem/1 var(--font-lcd); letter-spacing: .12em; }
