@layer reset, tokens, base, components;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, p, ul { margin: 0; }
  button { font: inherit; }
}

@layer tokens {
  /* White on black is the default whatever the OS setting: cataracts scatter light, so a dark screen cuts glare. */
  :root {
    color-scheme: dark;
    --bg: oklch(0.15 0.006 250);
    --fg: oklch(0.97 0.006 250);
    --button-bg: oklch(0.24 0.012 250);
    --button-active: oklch(0.34 0.014 250);
    --focus: oklch(0.88 0.17 92);

    /* Card text steps 2rem to 4rem (32px to 64px); app.js sets --card-size from the saved choice. */
    --card-size: 2.5rem;
    --button-size: 1.75rem;
    --button-height: 5rem;
    --bar-height: 13rem;
    --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  }

  :root[data-theme="light"] {
    color-scheme: light;
    --bg: oklch(0.985 0.004 250);
    --fg: oklch(0.17 0.01 250);
    --button-bg: oklch(0.93 0.008 250);
    --button-active: oklch(0.85 0.012 250);
    --focus: oklch(0.42 0.2 262);
  }
}

@layer base {
  html {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    font-weight: 700;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-block-end: calc(var(--bar-height) + 1rem);
  }

  body {
    min-block-size: 100dvh;
    padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
    padding-block: max(1rem, env(safe-area-inset-top)) calc(var(--bar-height) + 1.5rem);
  }

  h1, h2, p, li {
    font-size: var(--card-size);
    font-weight: 700;
    line-height: 1.5;
    text-align: start;
    /* Breaks a word only when it is wider than the line, such as "Representatives" at 64px on a 320px screen. */
    overflow-wrap: break-word;
  }

  :focus-visible {
    outline: 0.3125rem solid var(--focus);
    outline-offset: 0.1875rem;
  }

  main:focus { outline: none; }
}

@layer components {
  .skip {
    position: absolute;
    inset-inline-start: 1rem;
    inset-block-start: -100rem;
    padding: 1rem;
    background: var(--bg);
    color: var(--fg);
    font-size: var(--button-size);
  }

  .skip:focus { inset-block-start: 1rem; }

  .settings,
  .controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }

  .settings { margin-block-end: 2rem; }

  button {
    min-block-size: var(--button-height);
    min-inline-size: 0;
    padding: 0.5rem 0.25rem;
    border: 0.25rem solid var(--fg);
    border-radius: 0;
    background: var(--button-bg);
    color: var(--fg);
    font-family: var(--font);
    font-size: var(--button-size);
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    /* Labels wrap between words only; a split word such as "Answe-r" is hard to read. The tests flag any label wider than its button. */
    overflow-wrap: normal;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  button:active { background: var(--button-active); }

  /* A disabled size button keeps full contrast; the dashed edge marks the limit without dimming the label. */
  button:disabled {
    border-style: dashed;
    cursor: default;
  }

  button:disabled:active { background: var(--button-bg); }

  .card h1 { margin-block-end: 1rem; }

  #answer {
    margin-block-start: 2rem;
    padding-block-start: 1.5rem;
    border-block-start: 0.25rem solid var(--fg);
    scroll-margin-block-start: 1rem;
  }

  /* font-size here makes the 1.2em indent scale with the card text, so the bullet stays on screen at 64px. */
  #answer-list {
    font-size: var(--card-size);
    padding-inline-start: 1.2em;
    list-style: disc;
  }

  #answer-list li + li { margin-block-start: 0.5rem; }

  #answer-note { margin-block-start: 1rem; }

  .controls {
    position: fixed;
    inset-inline: 0;
    inset-block-end: 0;
    z-index: 1;
    padding-block: 1rem max(1rem, env(safe-area-inset-bottom));
    padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right));
    border-block-start: 0.25rem solid var(--fg);
    background: var(--bg);
  }

  /* Phone in landscape: about 380px tall, so the bar's padding shrinks to leave more room for the card. */
  @media (max-height: 30rem) {
    .controls { padding-block: 0.5rem max(0.5rem, env(safe-area-inset-bottom)); }
  }

  @media (min-width: 44rem) {
    .settings,
    .controls { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  }

  @media (forced-colors: active) {
    button { border-color: ButtonText; }
  }
}
