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

:root {
  /* Typography — system font stacks */
  --font-sans:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    "Noto Sans",
    sans-serif,
    "Apple Color Emoji",
    "Segoe UI Emoji",
    "Noto Color Emoji";
  --font-serif:
    Charter,
    "Bitstream Charter",
    "Iowan Old Style",
    "Palatino Linotype",
    Palatino,
    Georgia,
    serif;
  --font-math:
    "STIX Two Math",
    "Cambria Math",
    "Latin Modern Math",
    math,
    serif;

  /* Responsive type scale — fluid between 320px and 1200px viewports */
  --fs-xs:   clamp(0.7rem,   0.65rem  + 0.25vw, 0.8rem);
  --fs-sm:   clamp(0.8rem,   0.74rem  + 0.3vw,  0.9rem);
  --fs-base: clamp(0.9rem,   0.84rem  + 0.3vw,  1.05rem);
  --fs-md:   clamp(1rem,     0.92rem  + 0.4vw,  1.2rem);
  --fs-xl:   clamp(1.4rem,   1.2rem   + 0.9vw,  2rem);
  --fs-2xl:  clamp(1.8rem,   1.5rem   + 1.3vw,  3rem);

  /* Line heights */
  --lh-tight: 1.1;
  --lh-snug:  1.3;
  --lh-base:  1.5;
  --lh-relaxed: 1.65;

  /* Letter spacing */
  --ls-tight:   -0.01em;
  --ls-wide:    0.04em;
  --ls-wider:   0.08em;
  --ls-widest:  0.12em;

  /* Core palette */
  --bg: #ffffff;
  --fg: #000000;
  --border: #000000;
  --border-strong: #000000;
  --muted: #000000;

  /* Cell states */
  --cell-bg: #ffffff;
  --cell-hover: var(--fg);
  --cell-active: var(--fg);
  --cell-filled: #ffffff;
  --given-bg: transparent;
  --given-fg: var(--fg);
  --locked-bg: var(--fg);
  --locked-fg: var(--bg);

  /* Gate connectors */
  --gate-bg: transparent;
  --gate-fg: #000000;

  /* Accents */
  --accent: #2563eb;
  --error: #e53935;

  /* Overlays */
  --modal-bg: var(--bg);
  --backdrop: rgba(0, 0, 0, 0.5);

  /* Elevation system */
  --shadow-lg: none;
  --shadow-cell: none;

  /* Radii */
  --radius: 0;
  --radius-lg: 0;

  /* Focus */
  --focus-ring: 0 0 0 2.5px var(--accent);

  /* Safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --fg: #ffffff;
    --border: #ffffff;
    --border-strong: #ffffff;
    --muted: #ffffff;

    --cell-bg: #000000;
    --cell-hover: var(--fg);
    --cell-active: var(--fg);
    --cell-filled: #000000;
    --given-bg: transparent;
    --given-fg: var(--fg);
    --locked-bg: var(--fg);
    --locked-fg: var(--bg);

    --gate-bg: transparent;
    --gate-fg: #ffffff;

    --accent: #60a5fa;
    --error: #e53935;

    --modal-bg: #111111;
    --backdrop: rgba(0, 0, 0, 0.7);

    --shadow-lg: none;
    --shadow-cell: none;
  }
}

html {
  font-size: clamp(100%, 0.95rem + 0.15vw, 112.5%);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html,
body {
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font-sans);
  line-height: var(--lh-base);
  background: var(--bg);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  hanging-punctuation: first last;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  overflow-y: auto;
}

main {
  display: contents;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

bf-game {
  flex: none;
}

/* --- Rules section -------------------------------------------------------- */

.how-to-play {
  display: flex;
  flex-direction: column;
  width: var(--grid-size, 100%);
  max-width: 100%;
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 3rem) calc(var(--grid-size, 0px) * 1.4 / 42.2);
  color: var(--fg);
  line-height: var(--lh-relaxed);
}

#qr {
  order: 99;
  margin: 0 auto;
  line-height: 1;
  padding: clamp(1.5rem, 4vw, 3rem) 0;
  max-width: min(33vw, 33vh);
}
#qr svg {
  display: block;
  width: 100%;
  height: auto;
}

.how-to-play .intro {
  font-family: var(--font-serif);
  font-size: var(--fs-md);
  line-height: var(--lh-relaxed);
  margin-bottom: clamp(1.75rem, 5vw, 3rem);
  text-wrap: pretty;
}

.how-to-play h3 {
  font-family: var(--font-serif);
  font-size: var(--fs-md);
  font-weight: 700;
  letter-spacing: var(--ls-wider);
  text-transform: uppercase;
  line-height: var(--lh-snug);
  margin-top: clamp(1.75rem, 5vw, 3rem);
  margin-bottom: clamp(0.5rem, 1.5vw, 0.75rem);
  text-wrap: balance;
  break-after: avoid;
}


.how-to-play p {
  font-family: var(--font-serif);
  font-size: var(--fs-base);
  line-height: var(--lh-relaxed);
  margin-bottom: clamp(0.5rem, 1.5vw, 1rem);
  text-wrap: pretty;
  hanging-punctuation: first last;
}

.how-to-play .daily-note {
  margin-top: clamp(1rem, 2.5vw, 1.5rem);
  font-style: italic;
  font-size: var(--fs-sm);
}

#print-note {
  display: none;
}

/* Gate demos */
.how-to-play .gate-demos {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(1rem, 3vw, 1.75rem);
  margin-top: clamp(1rem, 2.5vw, 1.5rem);
  margin-bottom: clamp(1.25rem, 3vw, 2rem);
}
@container (max-width: 28rem) {
  .how-to-play .gate-demos {
    grid-template-columns: repeat(2, 1fr);
  }
}

.how-to-play {
  container-type: inline-size;
}


bf-gate-demo:not(:defined) {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(0.5rem, 1.5vw, 0.75rem);
  border: 1px solid var(--border);
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  line-height: var(--lh-snug);
}
bf-gate-demo:not(:defined)::after {
  content: attr(type);
}


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


@media print {
  html {
    font-size: 10pt;
    -webkit-font-smoothing: auto;
    -moz-osx-font-smoothing: auto;
  }
  html, body {
    height: 100%;
    min-height: 0;
    overflow: visible;
    line-height: 1.4;
  }
  body { justify-content: center; }
  bf-game {
    height: 65%;
    flex: 0 0 auto;
  }
  .how-to-play {
    display: block;
    width: 100%;
    max-width: 100%;
    padding: 0.2cm 0 0;
    font-size: 8pt;
    line-height: 1.4;
  }
  .how-to-play h3 {
    font-size: 10pt;
    letter-spacing: 0.06em;
    margin-top: 0.3cm;
    margin-bottom: 0.1cm;
  }
  .how-to-play p { margin-bottom: 0.1cm; }
  .how-to-play .intro { margin-bottom: 0.15cm; font-size: 8.5pt; }
  .how-to-play .gate-demos {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.2cm;
    margin-top: 0.15cm;
    margin-bottom: 0.1cm;
  }
  .how-to-play .daily-note { display: none; }
  #qr {
    display: block;
    float: right;
    width: 2.5cm;
    max-width: 2.5cm;
    padding: 0;
    margin: 0 0 0.2cm 0.3cm;
  }
  @page { margin: 1cm 1.5cm; }
}
@media print and (orientation: landscape) {
  body { flex-direction: row; gap: 0.6cm; align-items: center; }
  bf-game {
    height: 100%;
    width: auto;
    aspect-ratio: 1;
  }
  .how-to-play { flex: 1 1 0; padding: 0; height: 100%; }
  .how-to-play .gate-demos { grid-template-columns: repeat(2, 1fr); }
  #qr { float: none; margin: 0.4cm auto 0; width: 2cm; max-width: 2cm; }
}
