/* P3 "One zoomable object": the printed wheel on screen, with a camera on it.
 * Colours and the wheel's own classes come from ../core/theme.css. */

:root {
  --ease: cubic-bezier(0.23, 1, 0.32, 1);          /* the 2016 site's curve */
  --table: #e7ebf1;                                  /* what the wheel lies on */
  --ink: #14213d;
  --muted: #5a6478;
  --bar-h: 48px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--mec-font);
  color: var(--ink);
  background: var(--mec-navy);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---- top bar ------------------------------------------------------------------- */
#bar {
  flex: 0 0 var(--bar-h); height: var(--bar-h); display: flex; align-items: center; gap: 8px;
  padding: 0 2px 0 10px; background: var(--mec-navy); color: #fff; position: relative; z-index: 5;
  padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(2px, env(safe-area-inset-right));
}
.bar-logos { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.bar-logos img { display: block; width: auto; }
.bar-logos .logo-who { height: 19px; }
.bar-logos .logo-hrp { height: 21px; }
body.chrome-b .bar-logos, body.chrome-c .bar-logos { display: none; }
#title {
  margin: 0; font-size: 16px; line-height: 1; font-weight: 700; font-stretch: 87.5%; letter-spacing: .01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto;
}
.bar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.icon-btn { width: 40px; height: 44px; display: grid; place-items: center; background: none; border: 0; padding: 0; color: #fff; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.icon-btn:focus-visible, .bar-btn:focus-visible, .hud-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.bar-btn {
  height: 34px; padding: 0 12px; border-radius: 17px; border: 1px solid rgba(255, 255, 255, .45);
  background: transparent; color: #fff; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.bar-btn[aria-pressed="true"] { background: #fff; color: var(--mec-navy); }
.desk-only { display: none; }
body.bar-ui .desk-only { display: inline-block; }

/* ---- stage: the table the wheel lies on ------------------------------------------ */
#stage { flex: 1 1 auto; position: relative; overflow: hidden; background: var(--table); perspective: 1400px; }
#front, #backface { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
#front { transform-origin: 50% 50%; }
#viewport { position: absolute; inset: 0; overflow: hidden; outline: none; cursor: grab; }
#viewport:active { cursor: grabbing; }
#camera { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
.p3-layer { position: absolute; display: block; overflow: visible; }

/* The wheel's own shadow on the table: one soft disc under the rotor. */
.p3-shadow { position: absolute; border-radius: 50%; box-shadow: 0 10px 40px rgba(0, 20, 60, .28), 0 2px 6px rgba(0, 20, 60, .2); pointer-events: none; }

/* Cover method labels slide back to the print slit when the loupe closes (overview). */
.p3-cover .mec-t-method { transition: transform .24s var(--ease); transform-box: view-box; transform-origin: 0 0; }
#front:not(.loupe-open) .p3-cover .mec-t-method { transform: rotate(var(--slide, 0deg)); }

/* The loupe: the window straightened to the width it has at the cover's edge. */
.p3-loupe { transition: opacity .2s var(--ease); filter: drop-shadow(0 2px 5px rgba(0, 12, 40, .55)); }
#front:not(.loupe-open) .p3-loupe { opacity: 0; pointer-events: none; }
.loupe-bg { fill: #fff; }
.loupe-cell { stroke: #fff; stroke-width: .8px; }
.loupe-cell.is-green { fill: var(--mec-green); }
.loupe-cell.is-amber { fill: var(--mec-amber); }
.loupe-cell.is-red { fill: var(--mec-red); }
.loupe-cell.is-blank { fill: #fff; stroke: #c8cfdb; }
.loupe-v { fill: #fff; font-weight: 600; pointer-events: none; transition: opacity .12s linear; }
.p3-loupe.fast .loupe-v { opacity: .28; }
.loupe-frame { fill: none; stroke: #fff; stroke-width: 2px; stroke-linejoin: round; pointer-events: none; }
.loupe-glass { pointer-events: none; }
.loupe-hit { fill: transparent; cursor: pointer; }

/* Legend: the cover's lower half, reflowed, reached by panning the camera down. */
#legend {
  position: absolute; background: var(--mec-navy); color: #fff; border-radius: 0 0 18px 18px;
  font-size: 13px; line-height: 1.28; padding: 10px 10px 14px; opacity: 0; visibility: hidden;
  transition: opacity .25s var(--ease), visibility 0s linear .25s; font-stretch: 87.5%;
}
.state-legend #legend { opacity: 1; visibility: visible; transition: opacity .25s var(--ease); }
/* the panel replaces the core's printed strips while it is shown */
.p3-cover .mec-cover-lower { transition: opacity .25s var(--ease); }
.state-legend .p3-cover .mec-cover-lower { opacity: 0; }
#legend .lg-handle {
  display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; height: 34px; margin: 0 0 8px;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .3); border-radius: 17px; color: #fff; font-weight: 600; font-size: 14px;
}
#legend .lg-title { font-weight: 700; text-align: center; margin: 0 0 8px; font-size: 13px; letter-spacing: .02em; }
#legend .lg-row { display: grid; grid-template-columns: 31% 1fr; }
#legend .lg-heads { font-style: italic; opacity: .9; margin-bottom: 4px; font-size: 12.5px; }
#legend .lg-heads > div { padding: 0 8px; }
#legend .lg-block { margin-bottom: 4px; border-radius: 4px; overflow: hidden; }
#legend .lg-block > div { padding: 6px 8px; }
#legend .lg-left { font-weight: 700; }
#legend .lg-block.is-green { background: var(--mec-green); }
#legend .lg-block.is-red { background: var(--mec-red); }
#legend .lg-block.is-amber { background: var(--mec-amber); color: var(--mec-navy); }
#legend .lg-item { margin: 0 0 3px; display: grid; grid-template-columns: 1.6em 1fr; }
#legend .lg-item b { font-weight: 700; }
#legend .lg-notes { margin: 10px 0 0; padding: 0 0 0 1.1em; }
#legend .lg-notes li { margin: 0 0 4px; }

/* ---- HUD (phone): sits over the hub and the cover's lower corners ------------------ */
#hud {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 0 8px 8px; display: grid;
  grid-template-columns: auto 1fr auto auto; gap: 6px; align-items: end; pointer-events: none;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.hud-btn {
  pointer-events: auto; height: 40px; min-width: 40px; padding: 0 12px; border-radius: 20px; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; background: rgba(0, 32, 92, .94); color: #fff; border: 1.5px solid rgba(255, 255, 255, .55);
  font-size: 14px; font-weight: 600; font-stretch: 87.5%; white-space: nowrap; box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.hud-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.hud-legend { justify-self: center; }
.hud-zoom { padding: 0; width: 40px; }
.hud-zoom span { display: none; }
.dots { display: inline-flex; gap: 3px; }
.dots b { width: 9px; height: 9px; border-radius: 50%; display: block; border: 1px solid rgba(255, 255, 255, .7); }
.dots .g { background: var(--mec-green); } .dots .r { background: var(--mec-red); } .dots .a { background: var(--mec-amber); }
.state-legend #hud, .state-back #hud { display: none; }

/* Compact HUD (short phones): two corner stacks, icons only, nothing over the loupe. */
#hud.compact { grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; }
#hud.compact .hud-btn { width: 40px; padding: 0; }
#hud.compact .hud-btn span { display: none; }
#hud.compact [data-act="legend"] { grid-column: 1; grid-row: 1; justify-self: start; }
#hud.compact [data-act="back"] { grid-column: 1; grid-row: 2; }
#hud.compact [data-act="zoom"] { grid-column: 3; grid-row: 1; }
#hud.compact [data-act="more"] { grid-column: 3; grid-row: 2; }

/* Desktop: actions live in the top bar; only the legend tab stays, over the hub. */
body.bar-ui #hud { grid-template-columns: 1fr; justify-items: center; }
body.bar-ui #hud .hud-btn:not(.hud-legend) { display: none; }
body.bar-ui .state-overview #hud, body.bar-ui #hud.no-tab { display: none; }   /* the tab would sit on the rim or the loupe */
body.bar-ui:not(.desktop) .bar-btn { padding: 0 9px; font-size: 13px; }

#hint {
  position: absolute; left: 50%; bottom: 60px; transform: translateX(-50%); margin: 0; max-width: calc(100% - 24px);
  background: rgba(0, 16, 46, .88); color: #fff; padding: 8px 12px; border-radius: 8px; font-size: 14px; text-align: center; pointer-events: none;
}

#intro-logos {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 18px; align-items: center;
  opacity: 0; pointer-events: none; transition: opacity .3s var(--ease);
}
#intro-logos img { height: 30px; width: auto; display: block; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .3)); }
#intro-logos img + img { height: 34px; }
body.desktop #intro-logos { left: 24px; transform: none; flex-direction: column; align-items: flex-start; }
.intro-logos-on #intro-logos { opacity: 1; }
/* The logos are white: give them a navy plate on the light table. */
#intro-logos { background: var(--mec-navy); padding: 8px 14px; border-radius: 10px; }

/* ---- the back of the wheel (after the flip) --------------------------------------- */
#backface { background: #fff; overflow-y: auto; overscroll-behavior: contain; visibility: hidden; -webkit-overflow-scrolling: touch; }
.state-back #backface { visibility: visible; }
.back-dome { background: var(--mec-navy); color: #fff; padding: 14px 18px 40px; border-radius: 0 0 50% 50% / 0 0 36px 36px; }
.back-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.page-btn {
  height: 38px; padding: 0 14px; border-radius: 19px; border: 1.5px solid currentColor; background: transparent; font-weight: 600; font-size: 14px;
}
.back-dome h2 { font-size: 17px; line-height: 1.25; margin: 6px 0 10px; }
.back-dome h3 { font-size: 14px; margin: 12px 0 4px; text-transform: none; color: #bfe3ff; }
.back-dome ul { margin: 0; padding-left: 1.1em; font-size: 15px; line-height: 1.4; }
.back-dome li { margin: 2px 0; }
.back-dome .refer { font-weight: 700; font-style: italic; font-size: 14px; margin: 14px 0 0; }
.back-body { padding: 8px 18px 40px; max-width: 760px; margin: 0 auto; font-size: 15px; line-height: 1.45; }
.back-body h2 { font-size: 18px; color: var(--mec-navy); margin: 18px 0 8px; }
.expl { display: grid; grid-template-columns: 1.6em 1fr; gap: 0 6px; margin: 0 0 8px; padding: 4px 6px; border-radius: 6px; }
.expl b.k { color: var(--mec-navy); font-size: 15px; }
.flash { animation: flash 1.6s var(--ease); }
@keyframes flash { 0%, 40% { background: #fff2b3; } 100% { background: transparent; } }
.abbr { margin: 0 0 6px; }

/* ---- bottom sheet (value explanation) --------------------------------------------- */
#scrim { position: fixed; inset: 0; z-index: 20; background: transparent; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; margin: 0 auto; max-width: 560px;
  max-height: 45vh; max-height: 45dvh; overflow-y: auto; overscroll-behavior: contain; background: #fff; color: var(--ink);
  border-radius: 16px 16px 0 0; box-shadow: 0 -6px 30px rgba(0, 16, 46, .35); padding: 8px 16px 18px;
  transform: translateY(105%); transition: transform .32s var(--ease);
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}
#sheet.open { transform: translateY(0); }
.sheet-grab { width: 40px; height: 4px; border-radius: 2px; background: #c9d0dc; margin: 0 auto 8px; }
.sheet-head { display: flex; gap: 12px; align-items: flex-start; }
.chip {
  flex: 0 0 auto; min-width: 58px; height: 48px; padding: 0 8px; border-radius: 6px; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 24px; font-stretch: 87.5%;
}
.chip sup { font-size: 14px; }
.chip.is-green { background: var(--mec-green); } .chip.is-amber { background: var(--mec-amber); } .chip.is-red { background: var(--mec-red); }
.chip.is-blank { background: #fff; border: 1.5px solid #c8cfdb; color: var(--muted); font-size: 15px; }
#sheet-title { margin: 0; font-size: 16px; line-height: 1.3; }
#sheet-title .m { color: var(--mec-navy); }
.sheet-close { margin-left: auto; width: 40px; height: 40px; border: 0; background: #eef1f6; border-radius: 20px; font-size: 22px; line-height: 1; flex: 0 0 auto; }
.sheet-sec { margin: 12px 0 0; font-size: 15px; line-height: 1.4; }
.sheet-sec h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 4px; }
.cat { border-left: 6px solid; padding: 2px 0 2px 10px; }
.cat.is-green { border-color: var(--mec-green); } .cat.is-amber { border-color: var(--mec-amber); } .cat.is-red { border-color: var(--mec-red); } .cat.is-blank { border-color: #c8cfdb; }
.cat p { margin: 0 0 4px; }

/* ---- search ------------------------------------------------------------------------ */
#search, #more { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: #f4f6f9; }
#search[hidden], #more[hidden], #drawer[hidden], #sheet[hidden], #scrim[hidden] { display: none; }
.ov-head { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; background: var(--mec-navy); color: #fff; min-height: var(--bar-h); }
.ov-head h2 { margin: 0; font-size: 16px; flex: 1 1 auto; }
.ov-close { width: 44px; height: 44px; border: 0; background: none; color: #fff; font-size: 26px; line-height: 1; }
.search-input {
  flex: 1 1 auto; min-width: 0; height: 38px; border-radius: 19px; border: 0; padding: 0 14px; font: inherit; font-size: 16px; color: var(--ink);
}
.search-list { flex: 1 1 auto; overflow-y: auto; padding: 4px 0 24px; overscroll-behavior: contain; }
.sg { padding: 10px 14px 2px; font-size: 13px; font-weight: 700; color: var(--mec-navy); letter-spacing: .03em; text-transform: uppercase; }
.sr {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: #fff; padding: 10px 14px; min-height: 48px;
  border-bottom: 1px solid #e3e7ee; font-size: 15px; line-height: 1.3;
}
.sr .sig { display: flex; gap: 1px; margin-left: auto; flex: 0 0 auto; }
.sr .sig i { width: 7px; height: 18px; display: block; border: 1px solid transparent; }
.sr .sig .is-green { background: var(--mec-green); } .sr .sig .is-amber { background: var(--mec-amber); } .sr .sig .is-red { background: var(--mec-red); } .sr .sig .is-blank { border-color: #c8cfdb; }
.sr small { color: var(--muted); display: block; font-size: 13px; }
.search-empty { padding: 20px 14px; color: var(--muted); }

/* ---- more (jacket pages) ------------------------------------------------------------- */
#more { background: #fff; }
.tabs { flex: 0 0 auto; display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px; background: #eef1f6; scrollbar-width: none; }
.tabs button {
  flex: 0 0 auto; height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid #c9d0dc; background: #fff; font-size: 14px; font-weight: 600; color: var(--mec-navy);
}
.tabs button[aria-selected="true"] { background: var(--mec-navy); color: #fff; border-color: var(--mec-navy); }
.page { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }
.page article { max-width: 680px; margin: 0 auto; padding: 14px 18px 48px; font-size: 16px; line-height: 1.5; }
.page h2 { color: var(--mec-navy); font-size: 20px; line-height: 1.25; margin: 6px 0 10px; }
.page h3 { color: var(--mec-navy); font-size: 17px; margin: 18px 0 6px; }
.page p { margin: 0 0 10px; }
.page ul, .page ol { margin: 0 0 12px; padding-left: 1.3em; }
.page li { margin: 0 0 4px; }
.page dl { margin: 0; }
.page dt { font-weight: 700; color: var(--mec-navy); margin-top: 8px; }
.page dd { margin: 0 0 4px; }
.page .note { font-size: 14px; color: var(--muted); }
.spr-card { border: 1px solid #d6dce6; border-radius: 10px; margin: 0 0 12px; overflow: hidden; }
.spr-card h3 { margin: 0; padding: 10px 12px; background: var(--mec-navy); color: #fff; font-size: 15px; line-height: 1.3; }
.spr-card dl { display: grid; grid-template-columns: minmax(84px, 30%) 1fr; }
.spr-card dt, .spr-card dd { margin: 0; padding: 7px 12px; border-top: 1px solid #e6eaf0; font-size: 15px; }
.spr-card dt { color: var(--mec-navy); }
.more-logos { display: flex; gap: 16px; align-items: center; background: var(--mec-navy); padding: 12px 14px; border-radius: 10px; margin: 0 0 14px; }
.more-logos img { height: 32px; width: auto; }
.more-logos img + img { height: 38px; }

/* ---- settings drawer ---------------------------------------------------------------- */
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 40; width: min(330px, 92vw); background: #fff; color: var(--ink);
  box-shadow: -8px 0 30px rgba(0, 16, 46, .3); display: flex; flex-direction: column; font-size: 15px;
}
#drawer .ov-head { padding-left: 14px; }
.drawer-body { padding: 12px 14px 24px; overflow-y: auto; }
.drawer-body fieldset { border: 1px solid #d6dce6; border-radius: 8px; margin: 0 0 12px; padding: 8px 10px 10px; }
.drawer-body legend { font-weight: 700; color: var(--mec-navy); padding: 0 4px; }
.drawer-body label { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; line-height: 1.3; }
.drawer-body input[type="radio"] { margin-top: 2px; width: 18px; height: 18px; flex: 0 0 auto; }
.drawer-body pre { white-space: pre-wrap; font: 12.5px/1.45 ui-monospace, Menlo, monospace; background: #f2f4f8; border-radius: 8px; padding: 8px 10px; margin: 0 0 12px; }
.drawer-body .page-btn { color: var(--mec-navy); }

#boot-error { position: fixed; inset: auto 12px 12px; background: #fff; color: #900; padding: 12px; border-radius: 8px; z-index: 50; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after { transition-duration: 0s !important; animation-duration: 0s !important; }

/* Narrow phones (320-359): logos and title shrink so nothing in the bar is cut. */
@media (max-width: 359px) {
  #bar { gap: 6px; padding-left: max(8px, env(safe-area-inset-left)); }
  .bar-logos { gap: 5px; }
  .bar-logos .logo-who { height: 15px; }
  .bar-logos .logo-hrp { height: 17px; }
  #title { font-size: 15px; font-stretch: 80%; }
  .icon-btn { width: 36px; }
  #hud { gap: 4px; padding-left: 6px; padding-right: 6px; }
  .hud-btn { padding: 0 10px; font-size: 13.5px; }
}
