/* Hazard perception test pages: the hub (hazard.html) and the test player (hazard.js).
   Layout: landscape puts the clip on the left and the questions on the right;
   portrait stacks the clip (sticky) above the questions. */

:root {
  --hz-top: 60px;
  --hz-pad: clamp(16px, 3vw, 40px);
}

.hz-page {
  background: var(--ink);
  color: var(--cream);
  text-align: left;
}

.hz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--hz-top);
  padding: 0 var(--hz-pad);
}

.hz-back {
  padding: 0.4em 0.9em;
  border: 3px solid currentColor;
  border-radius: 999px;
  color: var(--cream);
  font-weight: 800;
  font-size: 1rem;
  text-decoration: none;
  white-space: nowrap;
}

.hz-back:hover { background: var(--cream); border-color: var(--cream); color: var(--ink); }
.hz-back:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; border-radius: 999px; }

/* The brand lockup, linking home: the roundel beside the name, in cream (the pages are ink or
   blue, so ink would vanish). 40px tall, the lockup's minimum, inside the 60px header, so its
   clear space (an eighth of the mark's width, 5px) stays clear. brand/BRIEF.md has the rules.
   On the tests the "All tests" pill sits beside it and the test's name goes right. */
.hz-brand { display: block; flex: none; }
.hz-brand img { display: block; height: 40px; width: auto; }
.hz-brand:focus-visible { outline: 3px solid var(--amber); outline-offset: 6px; border-radius: 4px; }
.hz-brand + .hz-back { margin-right: auto; }

.hz-page.c-blue { background: var(--blue); }

/* Labels (the header's test name, the clip count) use the Label scale. */
.hz-title,
.hpt-clipno {
  font-weight: 900;
  font-size: clamp(0.9rem, 1.8vw, 1.3rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
}

.hz-title { text-align: right; }

/* Where the lockup, the pill and the name won't fit on one line, the name goes; the line
   above the clip (.hpt-head) names the test. */
@media (max-width: 760px) {
  .hz-title { display: none; }
}

/* ---------- Player layout ---------- */

.hpt {
  --stage-w: 100%;
  display: grid;
  gap: 8px var(--hz-pad);
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 var(--hz-pad) 40px;
}

.hpt-media {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 8px 0 12px;
  background: var(--ink);
}

.hpt-head, .hpt-stage, .hpt-controls { width: var(--stage-w); }

.hpt-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.hpt-head .small { margin: 0; }

.hpt-panel { min-height: 14rem; padding-top: 0.6rem; }

@media (orientation: landscape) and (min-width: 600px) {
  .hpt {
    --chrome: 104px;
    --stage-w: min(100%, calc((100svh - var(--hz-top) - var(--chrome)) * 16 / 11));
    grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr);
    align-items: center;
    min-height: calc(100svh - var(--hz-top));
    padding-bottom: 16px;
  }

  .hpt-media { position: static; padding: 0; }

  .hpt-panel {
    max-height: calc(100svh - var(--hz-top) - 16px);
    overflow-y: auto;
    padding: 0.5rem 0.4rem 0.5rem 0;
  }
}

/* ---------- Stage and clips ---------- */

.hpt-stage {
  position: relative;
  aspect-ratio: 16 / 11;
  background: #0e0e13;
  border: 4px solid rgba(255, 244, 220, 0.9);
  border-radius: 24px;
  overflow: hidden;
}

.hpt-shot { position: absolute; inset: 0; display: none; }
.hpt-shot.on { display: block; }

/* Every animation in a clip shares its duration; hazard.js plays, pauses and seeks them. */
.hpt-shot *,
.hpt-shot *::before,
.hpt-shot *::after {
  animation-duration: var(--dur, 10s);
  animation-fill-mode: both;
  animation-timing-function: ease-in-out;
  animation-play-state: paused;
}

.hpt-clock { position: absolute; animation-name: hpt-clock; animation-timing-function: linear; }
@keyframes hpt-clock { from { opacity: 0; } to { opacity: 0; } }

/* ---------- Player chrome ---------- */

/* Each test places the hazard stamp on a patch of stage that stays dark at every cue. */
.hpt-badge {
  position: absolute;
  left: 50%;
  bottom: 5%;
  translate: -50% 0;
  rotate: -3deg;
  z-index: 9;
  padding: 0.3em 0.9em;
  border: 3px solid currentColor;
  border-radius: 999px;
  color: var(--amber);
  font-weight: 900;
  font-size: clamp(0.7rem, 1.6vw, 1rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  visibility: hidden;
}

.hpt[data-state="asking"] .hpt-badge { visibility: visible; animation: hpt-stamp 0.35s cubic-bezier(.16, 1, .3, 1) both; }

@keyframes hpt-stamp {
  from { scale: 1.7; opacity: 0; }
  to   { scale: 1; opacity: 1; }
}

.hpt-cover {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.6em;
  padding: 6%;
  background: rgba(14, 14, 19, 0.86);
  color: var(--cream);
  text-align: center;
}

.hpt-cover[hidden] { display: none; }
.hpt[data-state="done"] .hpt-cover { background: #0e0e13; }
.hpt-cover .small { margin: 0; }

.hpt-start,
.hpt-again {
  font: inherit;
  font-weight: 900;
  font-size: clamp(1.05rem, 3vw, 1.6rem);
  padding: 0.7em 1.4em;
  border: 0;
  border-radius: 999px;
  background: var(--amber);
  color: var(--ink);
  cursor: pointer;
  transition: scale 0.15s ease;
}

.hpt-start { display: inline-flex; align-items: center; gap: 0.5em; }
.hpt-start svg { width: 0.85em; height: 0.85em; fill: currentColor; }
.hpt-start:hover, .hpt-again:hover { scale: 1.03; }
.hpt-start:focus-visible, .hpt-again:focus-visible,
.hpt-btn:focus-visible, .hpt-opt:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }

.hpt-note { font-weight: 600; font-size: clamp(1rem, 1.8vw, 1.1rem); opacity: 0.7; }

.hpt-score {
  font-size: clamp(3.2rem, 12vw, 8rem);
  font-weight: 900;
  line-height: 0.85;
  letter-spacing: -0.06em;
  font-variant-numeric: tabular-nums;
}

.hpt-grade {
  font-size: clamp(1.4rem, 4vw, 2.6rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
  text-transform: lowercase;
}

.hpt-controls { display: flex; align-items: center; gap: 0.8rem; }

.hpt-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 3px solid rgba(255, 244, 220, 0.6);
  border-radius: 50%;
  background: transparent;
  color: var(--cream);
  cursor: pointer;
}

.hpt-btn svg { width: 20px; height: 20px; fill: currentColor; }
.hpt-btn:hover:not(:disabled) { border-color: var(--amber); }
.hpt-btn:disabled { opacity: 0.35; cursor: default; }
.hpt .i-pause, .hpt .i-off { display: none; }
.hpt[data-running] .i-play { display: none; }
.hpt[data-running] .i-pause { display: block; }
.hpt[data-muted] .i-on { display: none; }
.hpt[data-muted] .i-off { display: block; }

.hpt-track {
  position: relative;
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 244, 220, 0.2);
}

.hpt-fill {
  width: calc(var(--p, 0) * 100%);
  height: 100%;
  border-radius: 999px;
  background: var(--amber);
}

.hpt-mark {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  translate: -50% -50%;
  rotate: 45deg;
  background: var(--cream);
  border: 2px solid var(--ink);
}

.hpt-mark.ok  { background: var(--green); border-color: var(--cream); }
.hpt-mark.bad { background: var(--red); border-color: var(--cream); }

.hpt-time {
  flex: none;
  font-weight: 800;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

/* ---------- Questions and answers ---------- */

.hpt-h {
  font-size: clamp(2.4rem, 5.5vw, 4.6rem);
  font-weight: 900;
  line-height: 0.92;
  letter-spacing: -0.045em;
  text-transform: lowercase;
}

.hpt-h + .hpt-intro { margin-top: 0.8em; }
.hpt-intro + .hpt-intro { margin-top: 0.6em; }

.hpt-intro, .hpt-wait {
  font-weight: 600;
  font-size: clamp(1.05rem, 1.8vw, 1.3rem);
  line-height: 1.4;
  opacity: 0.85;
}

.hpt-q {
  font-size: clamp(1.3rem, 2.4vw, 2rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.hpt-opts { display: grid; gap: 0.7rem; margin-top: 1rem; }

.hpt-opt {
  --i: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.9em;
  padding: 0.8em 1em;
  border: 3px solid rgba(255, 244, 220, 0.5);
  border-radius: 14px;
  background: transparent;
  color: var(--cream);
  font: inherit;
  font-weight: 700;
  font-size: clamp(1rem, 1.6vw, 1.2rem);
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, translate 0.15s ease;
  animation: hpt-in 0.4s cubic-bezier(.2, .8, .2, 1) both;
  animation-delay: calc(var(--i) * 80ms);
}

.hpt-opt b {
  display: grid;
  place-items: center;
  width: 2em;
  height: 2em;
  border-radius: 50%;
  background: var(--cream);
  color: var(--ink);
  font-weight: 900;
}

.hpt-opt:hover { border-color: var(--amber); translate: 4px 0; }

@keyframes hpt-in {
  from { opacity: 0; translate: 0 18px; }
  to   { opacity: 1; translate: 0 0; }
}

.hpt-panel[data-verdict] {
  min-height: 0;
  padding: clamp(1.2rem, 3vw, 2.2rem);
  border-radius: 24px;
  color: var(--cream);
}

.hpt-panel[data-verdict="right"] { background: var(--green); }
.hpt-panel[data-verdict="wrong"] { background: var(--red); }

.hpt-verdict {
  margin: 0 0 0.6em;
  font-size: clamp(1rem, 2vw, 1.35rem);
  animation: hpt-stamp 0.35s cubic-bezier(.16, 1, .3, 1) both;
}

.hpt-say {
  margin-top: 0.6em;
  font-weight: 600;
  font-size: clamp(1.1rem, 2vw, 1.45rem);
  line-height: 1.3;
}

.hpt-answer { margin-top: 0.8em; font-weight: 700; } /* full cream: 90% on red is 3.9:1 */

.hpt-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.6rem; margin-top: 1.2rem; }
.hpt-actions .hpt-again { font-size: 1.15rem; }

@media (max-width: 600px) {
  .hpt-time .tot { display: none; }
  .hpt-controls { gap: 0.6rem; }
}

/* ---------- Hub page (hazard.html): one colour block per idea ---------- */

.hz-hub {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: calc(100svh - var(--hz-top));
}

.hz-hub-title {
  grid-column: 1 / -1;
  display: grid;
  place-content: center;
  padding: 4vh var(--hz-pad) 9vh;
  text-align: center;
}

/* Each door is a poster: centred, like every screen on the home page. */
.hz-door {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.8rem;
  min-height: 48svh;
  padding: clamp(2.2rem, 7vh, 5rem) clamp(1.5rem, 5vw, 4.5rem);
  text-align: center;
  text-decoration: none;
}

.hz-door .big { text-transform: lowercase; }
.hz-door p { max-width: 32ch; font-weight: 600; font-size: clamp(1.05rem, 1.8vw, 1.35rem); line-height: 1.4; text-wrap: pretty; }

.hz-go {
  margin-top: 0.8rem;
  padding: 0.7em 1.4em;
  border-radius: 999px;
  background: var(--ink);
  color: var(--cream);
  font-weight: 900;
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  transition: scale 0.15s ease;
}

.hz-door:hover .hz-go { scale: 1.03; }
.hz-door:focus-visible { outline: 4px solid var(--ink); outline-offset: -14px; border-radius: 0; }

@media (max-width: 760px) {
  .hz-hub { grid-template-columns: 1fr; }
  .hz-door { min-height: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .hpt-opt, .hpt-verdict, .hpt[data-state="asking"] .hpt-badge { animation: none; }
  .hz-go, .hpt-start, .hpt-again, .hpt-opt { transition: none; }
  .hpt-opt:hover { translate: none; }
}

/* Landscape phones: every pixel of height counts. */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --hz-top: 44px; }
  /* The header is too short for the lockup's 40px minimum, so show just its roundel (the
     left 400 units of the 1420-wide lockup), which can go down to 16px. */
  .hz-brand img { width: 32px; height: 32px; object-fit: cover; object-position: left center; }
  .hpt { --chrome: 96px; }
  .hpt-head { display: none; }
  .hpt-media { gap: 6px; }
  .hpt-btn { width: 36px; height: 36px; }
  .hpt-btn svg { width: 16px; height: 16px; }
  .hpt-mark { width: 9px; height: 9px; border-width: 1.5px; }
  .hpt-time { font-size: 0.9rem; }
  .hpt-h { font-size: 1.9rem; }
  .hpt-q { font-size: 1.15rem; }
  .hpt-opts { gap: 0.5rem; margin-top: 0.7rem; }
  .hpt-opt { padding: 0.55em 0.8em; font-size: 1rem; }
  .hpt-say { font-size: 1rem; }
  .hpt-intro, .hpt-wait { font-size: 1rem; }
  .hpt-stage { border-width: 3px; border-radius: 16px; }
}
