/* ASKT: one question per screen, set like a Swiss poster.
   Three grounds, one per depth: paper (light), red (medium), ink (deep). */

:root {
  --color-paper: #f3f1ec;
  --color-ink: #0b0b0b;
  --color-red: #e30613;
  --color-white: #ffffff;
  --color-scrim: #0b0b0b99;
  --color-divider: #f3f1ec47;

  --spacing-05: 0.125rem;
  --spacing-1: 0.25rem;
  --spacing-2: 0.5rem;
  --spacing-3: 0.75rem;
  --spacing-4: 1rem;
  --spacing-5: 1.25rem;
  --spacing-6: 1.5rem;
  --spacing-8: 2rem;
  --spacing-edge: clamp(1rem, 5vw, 2.5rem);
  --spacing-card-top: clamp(1rem, 4vh, 2.5rem);
  --spacing-meta-top: clamp(1rem, 3vh, 1.75rem);
  --spacing-dock-bottom: clamp(0.75rem, 3vh, 1.5rem);
  /* Pulls an icon button's glyph onto the page edge. */
  --spacing-bleed: -0.75rem;
  /* Side room: the page edge, or the device's own inset where that is larger. */
  --spacing-left: max(var(--spacing-edge), env(safe-area-inset-left));
  --spacing-right: max(var(--spacing-edge), env(safe-area-inset-right));

  --font-size-micro: 0.6875rem;
  --font-size-label: 0.8125rem;
  --font-size-body: 1rem;
  --font-size-action: 1.0625rem;
  --font-size-language: 1.125rem;
  --font-size-title: 1.25rem;
  --font-size-option: 1.375rem;
  --font-size-tally: 2.5rem;
  --font-size-number: clamp(4.5rem, min(34vw, 26vh), 15rem);
  /* The script fits the question between these two sizes (both in rem). */
  --font-size-question-min: 1.125rem;
  --font-size-question-max: 8rem;

  --size-column: 58rem;
  --size-sheet: 30rem;
  --size-control: 3rem;
  --size-tab: 2.75rem;
  --size-action: 4rem;
  --size-action-sheet: 3.5rem;
  --size-option: 3.25rem;
  --size-language: 9.5rem;
  --size-icon: 1.5rem;
  /* The least height the card's text keeps; below it the card scrolls. */
  --size-line-min: 4.5rem;
  /* Room for the numeral and the two arrows when they sit beside the text. */
  --size-side: 10.5rem;
  --size-pip: 0.625rem;
  --size-mark: 0.875rem;
  --size-badge: 1.25rem;

  --border-rule: 4px;
  --border-line: 2px;
  --border-pip: 1.5px;
  --border-thin: 1px;

  --font-family: 'Helvetica Neue', Helvetica, 'Nimbus Sans', 'Liberation Sans', Arial, system-ui, sans-serif;
  --font-family-urdu: 'Noto Nastaliq Urdu', 'Jameel Noori Nastaleeq', 'Urdu Typesetting', var(--font-family);
  /* Every transition and animation, in the styles and in the script, reads this. */
  --motion-snap: 160ms cubic-bezier(0.2, 0.8, 0.2, 1);
  /* Multiplies every letter-spacing: 1 for Latin-like scripts, 0 where spacing would damage the script. */
  --tracking: 1;

  color-scheme: light;
}

/* The ground carries meaning before a word is read: the depth of a question
   (paper light, red medium, ink deep). An icebreaker is always on paper. */
body[data-ground='paper'] {
  --bg: var(--color-paper);
  --fg: var(--color-ink);
  --mark: var(--color-red);
}
body[data-ground='red'] {
  --bg: var(--color-red);
  --fg: var(--color-white);
  --mark: var(--color-ink);
}
body[data-ground='ink'] {
  --bg: var(--color-ink);
  --fg: var(--color-paper);
  --mark: var(--color-red);
}

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

html {
  font-family: var(--font-family);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding-block: env(safe-area-inset-top) env(safe-area-inset-bottom);
  padding-left: max(var(--spacing-left), calc((100vw - var(--size-column)) / 2));
  padding-right: max(var(--spacing-right), calc((100vw - var(--size-column)) / 2));
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  transition:
    background-color var(--motion-snap),
    color var(--motion-snap);
}

/* Until a language is applied there is nothing true to show but the name. */
body:not([data-ready='true']) :is(.tools, .modes, .card__top, .meta, .question, .dock) {
  visibility: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* The ring takes the ground's text colour, so it shows around a filled button too. */
:focus-visible {
  outline: var(--border-rule) solid var(--fg);
  outline-offset: var(--border-line);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: var(--size-icon);
  height: var(--size-icon);
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

[dir='rtl'] .icon--directional {
  transform: scaleX(-1);
}

/* ── Top bar ─────────────────────────────────────────────── */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-4);
  padding-block: var(--spacing-2);
  border-block-end: var(--border-rule) solid currentColor;
}

.wordmark {
  margin: 0;
  font-size: var(--font-size-title);
  font-weight: 900;
  letter-spacing: calc(var(--tracking) * 0.02em);
}

.tools {
  display: flex;
  align-items: center;
  gap: var(--spacing-1);
  margin-inline-end: var(--spacing-bleed);
}

.tool {
  position: relative;
  display: inline-grid;
  place-items: center;
  min-width: var(--size-control);
  height: var(--size-control);
  transition: transform var(--motion-snap);
}

.tool:active {
  transform: scale(0.9);
}

.tool--text {
  padding-inline: var(--spacing-3);
  font-size: var(--font-size-body);
  font-weight: 800;
  letter-spacing: calc(var(--tracking) * 0.04em);
}

.tool--text span {
  border-block-end: var(--border-line) solid currentColor;
}

.badge {
  position: absolute;
  inset-block-start: var(--spacing-1);
  inset-inline-end: 0;
  min-width: var(--size-badge);
  padding: var(--spacing-05) var(--spacing-1);
  background: var(--fg);
  color: var(--bg);
  font-size: var(--font-size-micro);
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

/* Share: the pressed control itself says whether the copy worked. */
.icon--done,
.icon--failed {
  display: none;
}
.tool.is-confirmed,
.tool.is-failed {
  background: var(--fg);
  color: var(--bg);
}
.tool:is(.is-confirmed, .is-failed) .icon--rest {
  display: none;
}
.tool.is-confirmed .icon--done,
.tool.is-failed .icon--failed {
  display: block;
}

/* The two parts of the site. The current one carries a rule under its name. */
.modes {
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--spacing-6);
}

.mode {
  min-height: var(--size-tab);
  border-block-end: var(--border-rule) solid transparent;
  font-size: var(--font-size-label);
  font-weight: 800;
  letter-spacing: calc(var(--tracking) * 0.08em);
  text-transform: uppercase;
  white-space: nowrap;
}

.mode[aria-pressed='true'] {
  border-block-end-color: currentColor;
}

/* ── The card ────────────────────────────────────────────── */

/* A column whose last band, the text, takes whatever height is left. When
   the reader's text size leaves the text too little room, the card scrolls. */
.card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-block-start: var(--spacing-card-top);
  overflow: hidden auto;
  touch-action: pan-y;
}

.card__top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--spacing-2);
}

.number {
  margin: 0;
  color: var(--mark);
  font-size: var(--font-size-number);
  font-weight: 900;
  line-height: 0.8;
  letter-spacing: calc(var(--tracking) * -0.06em);
  font-variant-numeric: tabular-nums;
  transition: color var(--motion-snap);
}

.number span {
  display: inline-block;
}

.steps {
  display: flex;
  gap: var(--spacing-2);
  padding-block-end: var(--spacing-1);
}

.step {
  display: grid;
  place-items: center;
  width: var(--size-control);
  height: var(--size-control);
  border: var(--border-line) solid currentColor;
  transition:
    background-color var(--motion-snap),
    color var(--motion-snap);
}

.step:active {
  background: var(--fg);
  color: var(--bg);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-2) var(--spacing-6);
  margin-block-start: var(--spacing-meta-top);
  padding-block: var(--spacing-3);
  border-block-start: var(--border-rule) solid currentColor;
  font-size: var(--font-size-label);
  font-weight: 700;
  letter-spacing: calc(var(--tracking) * 0.08em);
  text-transform: uppercase;
}

.meta__depth {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-2);
}

.pips {
  display: inline-flex;
  gap: var(--spacing-05);
}

.pips i {
  width: var(--size-pip);
  height: var(--size-pip);
  border: var(--border-pip) solid currentColor;
}

.pips[data-level='1'] i:nth-child(-n + 1),
.pips[data-level='2'] i:nth-child(-n + 2),
.pips[data-level='3'] i:nth-child(-n + 3) {
  background: currentColor;
}

.question {
  position: relative;
  flex: 1 1 0;
  min-height: var(--size-line-min);
  padding-block: var(--spacing-2) var(--spacing-6);
  overflow: hidden;
}

/* A text that does not fit at the smallest size: its box grows to hold it. */
.question[data-spill='true'] {
  flex: 0 0 auto;
}

/* The script sets the size so the whole question always fits the box. */
.question h1 {
  margin: 0;
  font-size: var(--font-size-question-min);
  font-weight: 700;
  line-height: 1.06;
  letter-spacing: calc(var(--tracking) * -0.025em);
  text-wrap: balance;
  overflow-wrap: break-word;
  hyphens: auto;
}

.fatal {
  margin: 0;
  padding-block: var(--spacing-4);
  font-size: var(--font-size-title);
  font-weight: 700;
}

/* ── The one big action ──────────────────────────────────── */

.dock {
  container-type: inline-size;
  padding-block: var(--spacing-3) var(--spacing-dock-bottom);
}

.primary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-4);
  width: 100%;
  min-height: var(--size-action);
  padding-inline: var(--spacing-5);
  background: var(--fg);
  color: var(--bg);
  font-size: var(--font-size-action);
  font-weight: 800;
  letter-spacing: calc(var(--tracking) * 0.04em);
  text-transform: uppercase;
  white-space: nowrap;
  transition:
    transform var(--motion-snap),
    background-color var(--motion-snap),
    color var(--motion-snap);
}

.primary:active {
  transform: translateY(var(--border-rule));
}

/* The label stays on one line. When the bar is narrow for the reader's text
   size, the glyph goes and the label takes its room. */
@container (max-width: 22rem) {
  .primary .icon {
    display: none;
  }
}

@media (hover: hover) {
  .primary:hover {
    box-shadow: inset 0 calc(-1 * var(--border-rule)) 0 var(--mark);
  }
  .step:hover {
    background: var(--fg);
    color: var(--bg);
  }
}

/* ── Sheets (filters, languages) ─────────────────────────── */

.sheet {
  --bg: var(--color-ink);
  --fg: var(--color-paper);
  --mark: var(--color-red);

  inset: 0;
  inset-inline-start: auto;
  width: 100%;
  max-width: var(--size-sheet);
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--fg);
}

.sheet[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  animation: sheet-in var(--motion-snap);
}

.sheet::backdrop {
  background: var(--color-scrim);
}

@keyframes sheet-in {
  from {
    transform: translateY(var(--spacing-6));
    opacity: 0;
  }
}

/* The three bands fill the sheet edge to edge, so no part of the sheet itself
   is left bare for a tap to land on. Their side room is padding. */
.sheet__head,
.sheet__body,
.sheet__foot {
  padding-left: var(--spacing-left);
  padding-right: var(--spacing-right);
}

.sheet__head {
  padding-block-start: env(safe-area-inset-top);
}

.sheet__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: var(--spacing-2);
  border-block-end: var(--border-rule) solid currentColor;
}

.sheet__bar .tool {
  margin-inline-end: var(--spacing-bleed);
}

.sheet h2 {
  margin: 0;
  font-size: var(--font-size-title);
  font-weight: 900;
  letter-spacing: calc(var(--tracking) * 0.02em);
  text-transform: uppercase;
}

.sheet__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-block-end: calc(var(--spacing-6) + env(safe-area-inset-bottom));
}

.sheet h3 {
  margin: var(--spacing-8) 0 var(--spacing-1);
  font-size: var(--font-size-label);
  font-weight: 700;
  letter-spacing: calc(var(--tracking) * 0.08em);
  text-transform: uppercase;
  opacity: 0.7;
}

.options {
  margin: 0;
  padding: 0;
  list-style: none;
}

.option {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-1) var(--spacing-4);
  width: 100%;
  min-height: var(--size-option);
  padding-block: var(--spacing-3);
  border-block-end: var(--border-thin) solid var(--color-divider);
  font-size: var(--font-size-option);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: calc(var(--tracking) * -0.015em);
  text-align: start;
}

.option__label {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-3);
}

/* The chosen option is marked by a red block, not by colour on the words. */
.option__mark {
  flex: none;
  width: var(--size-mark);
  height: var(--size-mark);
  border: var(--border-line) solid currentColor;
}

.option[aria-pressed='true'] .option__mark,
.option[aria-current='true'] .option__mark {
  border-color: var(--color-red);
  background: var(--color-red);
}

/* A language that is loading fills its own mark; nothing else on the sheet changes. */
.option[aria-busy='true'] .option__mark {
  background: currentColor;
}

.option__count {
  font-size: var(--font-size-label);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: calc(var(--tracking) * 0.04em);
  opacity: 0.7;
}

/* What went wrong, on its own line under the option that was pressed. */
.option__note {
  flex-basis: 100%;
  font-size: var(--font-size-label);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
}

.option__note:empty {
  display: none;
}

.option:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

@media (hover: hover) {
  .option:not(:disabled):hover .option__mark {
    border-color: var(--color-red);
  }
}

.options--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--size-language), 1fr));
  column-gap: var(--spacing-6);
  margin-block-start: var(--spacing-2);
}

/* Names in one row share the height of the tallest, so the dividers line up. */
.options--grid li {
  display: grid;
}

.options--grid .option {
  justify-content: flex-start;
  font-size: var(--font-size-language);
}

/* A research finding: what it says in large type, how it was found, then the
   study, quiet. Declared after `.sheet h3` so the title is not set as a label. */
.finding {
  padding-block: var(--spacing-6);
  border-block-end: var(--border-thin) solid var(--color-divider);
}

.finding h3 {
  margin: 0;
  font-size: var(--font-size-option);
  line-height: 1.15;
  letter-spacing: calc(var(--tracking) * -0.015em);
  text-transform: none;
  text-wrap: balance;
  opacity: 1;
}

.finding p {
  margin: var(--spacing-3) 0 0;
  font-size: var(--font-size-body);
  line-height: 1.45;
}

.finding .finding__source {
  font-size: var(--font-size-label);
  font-weight: 700;
  line-height: 1.3;
  opacity: 0.7;
}

.sheet__foot {
  padding-block-end: env(safe-area-inset-bottom);
}

/* The tally and the button share a row only while both fit; otherwise they stack. */
.sheet__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-3) var(--spacing-5);
  padding-block: var(--spacing-3);
  border-block-start: var(--border-rule) solid currentColor;
}

.tally {
  margin: 0;
  color: var(--color-red);
  font-size: var(--font-size-tally);
  font-weight: 900;
  line-height: 1;
  letter-spacing: calc(var(--tracking) * -0.04em);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tally__of {
  color: var(--fg);
  font-size: var(--font-size-body);
  letter-spacing: 0;
}

.primary--sheet {
  flex: 1 1 auto;
  width: auto;
  min-height: var(--size-action-sheet);
}

/* ── Scripts that Latin spacing would damage ─────────────── */

:lang(ar),
:lang(ur),
:lang(hi),
:lang(bn),
:lang(zh),
:lang(ja),
:lang(ko) {
  --tracking: 0;
}

/* These always hold Latin letters or digits, whatever the page's language.
   Declared after the rule above so it wins on the same element. */
.wordmark,
.number,
.tally,
.badge,
.option__count,
.tool--text {
  --tracking: 1;
}

.question h1:lang(vi) {
  line-height: 1.22;
}
.question h1:lang(zh),
.question h1:lang(ja),
.question h1:lang(ko) {
  line-height: 1.28;
  hyphens: manual;
}
.question h1:lang(ja),
.question h1:lang(zh) {
  line-break: strict;
}
.question h1:lang(ko) {
  word-break: keep-all;
}
.question h1:lang(hi),
.question h1:lang(bn) {
  line-height: 1.34;
}
.question h1:lang(ar) {
  line-height: 1.4;
}
:lang(ur) {
  font-family: var(--font-family-urdu);
}
.question h1:lang(ur) {
  line-height: 1.9;
}

/* ── Short screens ───────────────────────────────────────── */

/* The fixed bands shrink so the text keeps several lines. */
@media (max-height: 30rem) {
  :root {
    --font-size-number: clamp(2.5rem, 16vh, 6rem);
    --size-action: 3rem;
    --size-tab: 2rem;
    --spacing-card-top: var(--spacing-2);
    --spacing-meta-top: var(--spacing-2);
    --spacing-dock-bottom: var(--spacing-2);
  }
  .question {
    padding-block-end: var(--spacing-2);
  }
}

/* A phone held sideways has too little height for the bands stacked and room
   to spare in the width, so the text moves beside the numeral, in a wider
   second column. An upright short screen keeps the single column: it has no
   width to give. */
@media (max-height: 30rem) and (orientation: landscape) {
  .card {
    display: grid;
    grid-template-columns: minmax(var(--size-side), 1fr) minmax(0, 2fr);
    grid-template-rows: auto 1fr;
    column-gap: var(--spacing-6);
  }
  .card__top,
  .meta {
    grid-column: 1;
  }
  .meta {
    align-self: start;
  }
  /* Beside the numeral the text starts level with it. */
  .question {
    grid-column: 2;
    grid-row: 1 / span 2;
    padding-block-start: 0;
  }
}

/* An element the script hides stays hidden whatever layout its class gives it.
   Kept after every component rule so it wins at equal weight. */
[hidden] {
  display: none;
}

/* Zeroing the one motion token stops every transition and animation. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-snap: 0ms linear;
  }
}
