/* Spotlight: a dim hall, one pool of light on the case, the crowd and the slider. */

*,
*::before,
*::after { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
}

body {
  overflow: hidden;
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, var(--ak-bg-art));
  background-size: cover;
  background-position: center;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; }

.hall {
  --edge: 12px;
  --gap: clamp(8px, 1.6dvh, 16px);
  --handle-w: 52px;
  --handle-h: 65px;
  --light-ms: 900ms;
  /* The crowd's floor: a slate between ink and paper, so rings, coral and gold all read on it. */
  --floor-plate: color-mix(in srgb, var(--ak-ink) 80%, var(--ak-surface));
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  padding:
    max(var(--edge), env(safe-area-inset-top))
    max(var(--edge), env(safe-area-inset-right))
    max(var(--edge), env(safe-area-inset-bottom))
    max(var(--edge), env(safe-area-inset-left));
  isolation: isolate;
}

/* The shadow at the edges of the hall. It lifts when the house lights come up. */
.hall::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(
    ellipse 70% 66% at 50% 54%,
    transparent 58%,
    color-mix(in srgb, var(--ak-ink) 38%, transparent) 86%,
    color-mix(in srgb, var(--ak-ink) 62%, transparent) 100%
  );
  transition: opacity 1800ms ease;
}

.hall.lights-up::before { opacity: 0; }

/* ---------- the rail: dim chrome ---------- */

.rail {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 48px;
  padding: 0 60px;
}

.mute {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  cursor: pointer;
  touch-action: manipulation;
  opacity: 0.82;
}

.mute .mute-off { display: none; }
.mute[aria-pressed="true"] .mute-on { display: none; }
.mute[aria-pressed="true"] .mute-off { display: inline; }
.mute:focus-visible { outline: 3px solid var(--ak-focus); outline-offset: 3px; }

.mark {
  display: block;
  height: clamp(30px, 5.2dvh, 44px);
  width: auto;
  max-width: 60%;
  object-fit: contain;
}

/* ---------- the pool of light ---------- */

.pool {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "case" "floor" "desk";
  gap: var(--gap);
  width: min(100%, 720px);
  min-height: 0;
  margin: var(--gap) auto 0;
  --pool-pad: clamp(12px, 3dvw, 24px);
  padding: clamp(10px, 2dvh, 20px) var(--pool-pad);
  border-radius: 28px;
  background:
    radial-gradient(ellipse 80% 60% at 50% 42%, color-mix(in srgb, var(--ak-accent-2) 6%, var(--ak-surface)), var(--ak-surface) 70%);
  box-shadow: 0 0 56px 30px var(--ak-surface);
  touch-action: manipulation;
}

.pool[hidden] { display: none; }

/* The light follows what the player can act on: the slider while asking, the crowd after a check. */
.floor::before,
.desk::before {
  content: '';
  position: absolute;
  inset: -14px;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse 60% 62% at 50% 50%, color-mix(in srgb, var(--ak-accent-2) 13%, transparent), transparent 100%);
  opacity: 0;
  transition: opacity 1400ms ease;
}

.pool { isolation: isolate; }
.pool[data-light="floor"] .floor::before,
.pool[data-light="desk"] .desk::before { opacity: 1; }

/* ---------- the case ---------- */

.case { grid-area: case; min-width: 0; }

.case-label {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.ticks { display: inline-flex; gap: 5px; }

.ticks i {
  display: block;
  width: 3px;
  height: 14px;
  background: color-mix(in srgb, var(--ak-ink-muted) 35%, transparent);
}

.ticks i.is-done { background: var(--ak-ink-muted); }
.ticks i.is-now { background: var(--ak-accent-2); height: 18px; }

.facts {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 2.7dvh, 23px);
  font-weight: 500;
  line-height: 1.3;
}

.facts li { padding: 3px 0; }
.facts li + li { border-top: 1px solid color-mix(in srgb, var(--ak-outline) 70%, transparent); }

.short {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ak-ink-muted);
}

.ask {
  margin: 8px 0 0;
  font-family: var(--ak-font-display);
  font-size: clamp(20px, 3dvh, 26px);
  font-weight: var(--ak-title-weight);
  line-height: 1.2;
}

.verdict { margin-top: 6px; }

.says {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(17px, 2.4dvh, 20px);
  font-weight: 700;
  line-height: 1.3;
}

.why {
  margin: 6px 0 0;
  padding-left: 12px;
  border-left: 3px solid var(--ak-accent-2);
  font-size: clamp(15px, 2.1dvh, 17px);
  line-height: 1.4;
}

/* ---------- the floor: the crowd ---------- */

.floor {
  grid-area: floor;
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 0;
  min-width: 0;
}

.crowd-box {
  container-type: size;
  display: grid;
  place-items: center;
  min-height: 0;
}

.crowd {
  display: block;
  width: min(100cqw, 160cqh, 94dvw);
  aspect-ratio: 40 / 25;
  border-radius: 6px;
  background: var(--floor-plate);
}

.legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.15;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.lg {
  display: grid;
  line-height: 1.15;
}

.lg b {
  font-family: var(--ak-font-display);
  font-size: 16px;
  font-weight: var(--ak-title-weight);
  font-variant-numeric: tabular-nums;
}

.lg b:empty { display: none; }

.pc {
  flex: none;
  display: block;
  width: 44px;
  height: 44px;
  background: center / 72% no-repeat;
}

.pc-well { background-image: url("./art/well-dot.png"); }
.pc-ill { background-image: url("./art/ill-dot.png"); }

.pc-lit {
  position: relative;
  background: color-mix(in srgb, var(--ak-accent-2) 22%, var(--ak-surface));
}

.pc-lit .pc-well { position: absolute; inset: 0; width: auto; height: auto; }

/* The painted frame, with its middle cut away so the person inside shows. */
.pc-frame {
  position: absolute;
  inset: 0;
  background: url("./art/positive-frame.png") center / 100% 100% no-repeat;
  clip-path: polygon(evenodd, 0 0, 100% 0, 100% 100%, 0 100%, 0 0, 13% 13%, 13% 87%, 87% 87%, 87% 13%, 13% 13%);
}

/* ---------- the desk: slider and actions ---------- */

.desk {
  grid-area: desk;
  position: relative;
  min-width: 0;
}

.slider {
  --bubble-h: 34px;
  position: relative;
  height: calc(var(--bubble-h) + var(--handle-h));
  cursor: pointer;
  touch-action: none;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}

.slider.is-locked { cursor: default; }

.track {
  position: absolute;
  left: calc(var(--handle-w) / 2 - 8px);
  right: calc(var(--handle-w) / 2 - 8px);
  top: calc(var(--bubble-h) + var(--handle-h) / 2);
  height: 26px;
  translate: 0 -50%;
  border-radius: 13px;
  background: var(--ak-ink);
}

.notches,
.band {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 8px;
  right: 8px;
}

.notches i {
  position: absolute;
  top: 7px;
  bottom: 7px;
  width: 2px;
  margin-left: -1px;
  background: color-mix(in srgb, var(--ak-surface) 55%, transparent);
}

.notches i.is-half { top: 4px; bottom: 4px; background: var(--ak-surface); }

.band {
  right: auto;
  border-radius: 4px;
  background: color-mix(in srgb, var(--ak-accent-2) 70%, transparent);
  box-shadow: 0 0 0 2px var(--ak-accent-2);
}

.handle {
  position: absolute;
  top: var(--bubble-h);
  left: calc(var(--handle-w) / 2 + (100% - var(--handle-w)) * var(--v, 0.5));
  width: var(--handle-w);
  height: var(--handle-h);
  margin-left: calc(var(--handle-w) / -2);
  pointer-events: none;
  filter: drop-shadow(0 0 0 transparent);
  transition: filter var(--light-ms) ease;
}

.handle-art {
  position: absolute;
  inset: 0;
  background: url("./art/brass-slider.png") -218px 0 / 384px 65px no-repeat;
  clip-path: polygon(50% 0, 96% 50%, 50% 100%, 4% 50%);
}

.slider:not(.is-locked) .handle {
  filter: drop-shadow(0 0 6px color-mix(in srgb, var(--ak-accent-2) 80%, transparent));
}

/* The value rides above the diamond, so the guess is always in plain view. */
.bubble {
  position: absolute;
  top: 0;
  left: calc(var(--handle-w) / 2 + (100% - var(--handle-w)) * var(--v, 0.5));
  translate: -50% 0;
  min-width: 56px;
  padding: 3px 8px;
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: inset 0 0 0 2px var(--ak-accent-2);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 20px;
  font-weight: var(--ak-title-weight);
  line-height: 1.2;
  text-align: center;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.slider:focus-visible .track { box-shadow: 0 0 0 3px var(--ak-focus); }

.scale {
  display: flex;
  justify-content: space-between;
  padding: 0 calc(var(--handle-w) / 2 - 14px);
  font-size: 13px;
  font-weight: 600;
  color: var(--ak-ink-muted);
}

.act {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
}

.act[hidden] { display: none; }

.readout {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  column-gap: 10px;
  margin: 0;
  min-width: 0;
  line-height: 1;
}

.readout-label {
  grid-column: 1 / -1;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.readout-num {
  position: relative;
  justify-self: start;
  margin-top: 4px;
  font-family: var(--ak-font-display);
  font-size: clamp(34px, 5.6dvh, 50px);
  font-weight: var(--ak-title-weight);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.readout-sub {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
  color: var(--ak-ink-muted);
}

/* The flourish under a right answer: one amber line drawn across. */
.readout.is-hit .readout-num::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -4px;
  height: 3px;
  background: var(--ak-accent-2);
  transform-origin: left center;
}

.go {
  flex: none;
  min-height: 52px;
  min-width: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: var(--ak-radius);
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: box-shadow var(--light-ms) ease;
}

.go:active { background: var(--ak-btn-active); }
.go:focus-visible { outline: 3px solid var(--ak-focus); outline-offset: 3px; }
.go.is-lit { box-shadow: 0 0 0 2px var(--ak-surface), 0 0 0 4px var(--ak-accent-2); }

.go-big { min-height: 56px; width: 100%; font-size: 20px; }

.go-quiet {
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  box-shadow: inset 0 0 0 2px var(--ak-choice-border);
}

.go-quiet:active { background: var(--ak-choice-bg); }

@media (hover: hover) {
  .go:hover { background: var(--ak-btn-hover); }
  .go-quiet:hover { background: var(--ak-choice-bg); box-shadow: inset 0 0 0 2px var(--ak-choice-selected-border); }
  .mute:hover { opacity: 1; }
}

.note {
  min-height: 1.35em;
  margin: 6px 0 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ak-ink);
}

.note:empty { display: none; }
.note.is-wrong { padding-left: 10px; border-left: 3px solid var(--ak-accent-2); }

.teach {
  margin-top: 8px;
  padding: 12px 14px;
  border-left: 4px solid var(--ak-accent-2);
  background: var(--ak-surface);
}

.teach-cap {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--ak-ink);
}

/* ---------- the house lights: the ending ---------- */

.house {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--gap);
  width: min(100%, 1040px);
  min-height: 0;
  margin: var(--gap) auto 0;
  padding: clamp(10px, 2dvh, 20px) clamp(12px, 3dvw, 24px);
  border-radius: 28px;
  background: var(--ak-surface);
  box-shadow: 0 0 120px 80px var(--ak-surface);
}

.house[hidden] { display: none; }

.six {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: center;
  gap: clamp(8px, 1.6dvh, 18px) clamp(8px, 2dvw, 20px);
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Each case: its crowd on top, then the true number with its tally and your guess beside it. */
.six li {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.six .mini-box {
  flex: none;
  display: grid;
  place-items: end center;
  min-height: 0;
}

.six canvas {
  display: block;
  width: 100%;
  aspect-ratio: 40 / 25;
  border-radius: 4px;
  background: var(--floor-plate);
}

.six .row {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.six .meta { min-width: 0; margin-top: 2px; }


.six .big {
  flex: none;
  margin: 4px 0 0;
  font-family: var(--ak-font-display);
  font-size: clamp(26px, 4.6dvh, 44px);
  font-weight: var(--ak-title-weight);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.six .count {
  margin: 0;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 700;
  color: var(--ak-ink);
}

.six .you {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 600;
  color: var(--ak-ink-muted);
}

.six .you svg { flex: none; }

.curtain {
  padding: 4px 0 0;
  border-top: 1px solid var(--ak-outline);
}

.curtain[hidden] { display: none; }

.end-says {
  margin: 8px 0 0;
  font-family: var(--ak-font-display);
  font-size: clamp(19px, 2.8dvh, 24px);
  font-weight: 700;
  line-height: 1.3;
}

.end-count {
  margin: 4px 0 0;
  font-size: 16px;
  color: var(--ak-ink-muted);
}

.end-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.end-btns .go { flex: 1 1 140px; padding: 0 12px; }

/* ---------- sideways: board on one side, case and controls on the other ---------- */

@media (orientation: landscape) {
  .hall { grid-template-rows: auto minmax(0, 1fr); }

  .pool {
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "floor case" "floor desk";
    column-gap: clamp(14px, 3dvw, 32px);
    width: min(100%, 1180px);
  }

  .desk { align-self: end; }

  .house {
    grid-template-columns: minmax(0, 1.6fr) minmax(240px, 1fr);
    grid-template-rows: minmax(0, 1fr);
    column-gap: clamp(14px, 3dvw, 32px);
  }

  .six { grid-template-rows: repeat(2, minmax(0, 1fr)); align-content: stretch; }
  .six .mini-box { flex: 1 1 0; container-type: size; }
  .six .row { flex-direction: row; align-items: flex-start; gap: 8px; }
  .six .meta { flex: 1 1 0; margin-top: 6px; }
  .six canvas { width: min(100cqw, 160cqh); }

  .curtain {
    align-self: center;
    padding: 0 0 0 clamp(12px, 2dvw, 24px);
    border-top: 0;
    border-left: 1px solid var(--ak-outline);
  }
}

/* A phone on its side: little height, so the chrome gets thin. */
@media (orientation: landscape) and (max-height: 500px) {
  .hall { --edge: 8px; --gap: 6px; }
  .rail { min-height: 40px; justify-content: flex-start; padding-left: 60px; }
  .mute { width: 44px; height: 44px; }
  .mark { height: 30px; }
  .pool {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 1fr);
    padding: 8px 14px;
    border-radius: 20px;
    box-shadow: 0 0 36px 18px var(--ak-surface);
  }
  .case-label { margin-bottom: 2px; font-size: 12px; }
  .facts { font-size: 17px; line-height: 1.22; }
  .facts li { padding: 1px 0; }
  .ask { margin-top: 4px; font-size: 19px; }
  .short { font-size: 14px; }
  .verdict { margin-top: 2px; }
  .says { font-size: 15px; line-height: 1.25; }
  .why { margin-top: 4px; font-size: 14px; line-height: 1.3; }
  .readout-num { margin-top: 0; font-size: 30px; }
  .readout-label { font-size: 11px; }
  .scale { display: none; }
  .slider { --bubble-h: 30px; }
  .bubble { font-size: 18px; padding: 2px 6px; }
  .act { margin-top: 2px; }
  .go { min-height: 48px; font-size: 17px; }
  .note { font-size: 15px; margin-top: 4px; }
  .teach { padding: 8px 12px; margin-top: 4px; }
  .teach-cap { margin-bottom: 6px; line-height: 1.28; }
  .go-big { min-height: 48px; }
  .legend { font-size: 14px; }
  .end-says { font-size: 18px; }
  .six .big { font-size: 26px; }
}

/* An upright phone with little height: smaller type so the crowd keeps its room. */
@media (orientation: portrait) and (max-height: 740px) {
  .hall { --edge: 8px; --gap: 6px; }
  .rail { min-height: 44px; }
  .mute { width: 44px; height: 44px; }
  .mark { height: 30px; }
  .pool { --pool-pad: 12px; padding: 8px var(--pool-pad); }
  .facts { font-size: 17px; line-height: 1.22; }
  .facts li { padding: 1px 0; }
  .ask { margin-top: 4px; font-size: 19px; }
  .says { font-size: 16px; }
  .why { font-size: 14px; line-height: 1.32; }
  .readout-num { font-size: 32px; }
  .go { min-height: 48px; font-size: 17px; }
  .note { font-size: 15px; margin-top: 4px; }
  .teach-cap { font-size: 18px; }
  .pool.is-checked .scale { display: none; }
}

@media (max-width: 380px) {
  .legend { gap: 6px 10px; font-size: 14px; }
  .legend li { gap: 6px; }
  .lg b { font-size: 15px; }
}

/* Upright, the crowd runs to the edges of the light so it gets every pixel of width. */
@media (orientation: portrait) {
  .hall { --edge: 8px; }
  .floor { margin-inline: calc(-1 * var(--pool-pad) + 2px); }
}

/* A tall upright phone has room for bigger crowds at the end. */
@media (orientation: portrait) and (min-height: 900px) {
  .six { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .six .row { flex-direction: row; align-items: flex-start; gap: 8px; }
  .six .meta { flex: 1 1 0; margin-top: 6px; }
}

/* During the worked example the caption asks the question and names the 50%, so the card drops both. */
.pool.is-example .ask,
.pool.is-example .bubble { display: none; }
.pool.is-example .slider { --bubble-h: 0px; }

/* ---------- slow light ---------- */

@media (prefers-reduced-motion: no-preference) {
  .slider.is-inviting .handle { animation: breathe 2600ms ease-in-out infinite; }
  .handle.is-settling .handle-art { animation: settle 420ms cubic-bezier(0.22, 1, 0.36, 1); }
  .handle.is-settling { animation: settle-glow 900ms ease-out; }
  .verdict:not([hidden]) { animation: fade-up 900ms ease both; }
  .readout.is-truth .readout-num,
  .readout.is-truth .readout-sub { animation: fade-up 400ms ease both; }
  .readout.is-hit .readout-num::after { animation: draw-line 900ms ease 500ms both; }
  .band:not([hidden]) { animation: fade-in 900ms ease both; }
  .teach:not([hidden]) { animation: fade-in 700ms ease both; }
  .six li { animation: fade-up 900ms ease both; animation-delay: calc(var(--i, 0) * 140ms + 300ms); }
  .curtain:not([hidden]) { animation: fade-up 900ms ease both; }
  .house:not([hidden]) { animation: fade-in 1200ms ease both; }
}

@keyframes breathe {
  0%, 100% { filter: drop-shadow(0 0 4px color-mix(in srgb, var(--ak-accent-2) 60%, transparent)); }
  50% { filter: drop-shadow(0 0 12px var(--ak-accent-2)); }
}

@keyframes settle {
  0% { transform: translateY(-3px) scale(1.06); }
  60% { transform: translateY(1px) scale(0.98); }
  100% { transform: none; }
}

@keyframes settle-glow {
  0% { filter: drop-shadow(0 0 14px var(--ak-accent-2)); }
  100% { filter: drop-shadow(0 0 6px color-mix(in srgb, var(--ak-accent-2) 80%, transparent)); }
}

@keyframes fade-up {
  from { opacity: 0; translate: 0 8px; }
  to { opacity: 1; translate: 0 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes draw-line {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}
