/* Design tokens copied verbatim from callum-science-tools/src/styles/global.css so this
   subdomain reads as part of the same site. The chart series, sequential ramp and
   Canvas2D plot tokens are dropped — this tool draws no charts. */
:root {
  color-scheme: light;

  --canvas: oklch(98.4% 0.003 247);
  --surface: oklch(100% 0 0);
  --surface-2: oklch(96.8% 0.005 247);
  --border: oklch(92.4% 0.008 247);
  --border-strong: oklch(85% 0.012 247);

  --ink: oklch(21% 0.03 253);
  --ink-muted: oklch(46% 0.025 253);
  --ink-subtle: oklch(62% 0.02 253);

  --accent: oklch(52% 0.11 214);
  --accent-hover: oklch(45% 0.11 214);
  --accent-soft: oklch(95% 0.03 214);
  --on-accent: oklch(100% 0 0);

  --energy: oklch(58% 0.14 62);
  --energy-soft: oklch(95.5% 0.04 75);
  --chemistry: oklch(52% 0.17 295);
  --chemistry-soft: oklch(96% 0.03 295);
  --physics: oklch(50% 0.17 258);
  --physics-soft: oklch(95.5% 0.035 258);
  --maths: oklch(52% 0.15 158);
  --maths-soft: oklch(96% 0.03 158);

  --grid-line: oklch(90% 0.01 247);
  --danger: oklch(52% 0.19 25);
  --danger-soft: oklch(96% 0.03 25);
  --ok: oklch(52% 0.13 150);

  /* System stacks only — no font CDN, so the site makes zero third-party requests. */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono",
    "Roboto Mono", Menlo, Consolas, monospace;
}

.dark {
  color-scheme: dark;

  --canvas: oklch(17% 0.014 250);
  --surface: oklch(21.5% 0.017 250);
  --surface-2: oklch(25.5% 0.019 250);
  --border: oklch(30% 0.02 250);
  --border-strong: oklch(38% 0.022 250);

  --ink: oklch(94% 0.008 247);
  --ink-muted: oklch(74% 0.016 247);
  --ink-subtle: oklch(60% 0.018 247);

  --accent: oklch(78% 0.12 205);
  --accent-hover: oklch(85% 0.11 205);
  --accent-soft: oklch(30% 0.05 205);
  --on-accent: oklch(17% 0.014 250);

  --energy: oklch(80% 0.14 78);
  --energy-soft: oklch(30% 0.05 70);
  --chemistry: oklch(76% 0.13 295);
  --chemistry-soft: oklch(30% 0.06 295);
  --physics: oklch(75% 0.13 255);
  --physics-soft: oklch(30% 0.06 255);
  --maths: oklch(76% 0.13 158);
  --maths-soft: oklch(30% 0.06 158);

  --grid-line: oklch(30% 0.02 250);
  --danger: oklch(70% 0.16 25);
  --danger-soft: oklch(30% 0.06 25);
  --ok: oklch(75% 0.14 155);
}

/* Minimal reset. There is no Tailwind preflight here, so these carry the same load. */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

main {
  flex: 1 1 auto;
  width: 100%;
}

h1,
h2,
h3,
p,
dl,
dd {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Numeric readouts should not reflow as digits change. */
/* A class that sets its own display would otherwise beat the hidden attribute, which
   is how the cancel button, the progress bar and the error notes are shown and
   hidden. */
[hidden] {
  display: none !important;
}

.tabular {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

::selection {
  background-color: var(--accent-soft);
  color: var(--ink);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Visually hidden but still reachable by assistive tech. */
.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;
}

/* Off-screen textarea used only to run execCommand('copy'); never visible. */
.copy-scratch {
  position: fixed;
  top: 0;
  left: 0;
  opacity: 0;
  pointer-events: none;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: 0.5rem;
  z-index: 50;
  transform: translateY(-150%);
  background: var(--surface);
  color: var(--ink);
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.15);
  transition: transform 0.15s ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.container {
  max-width: 72rem;
  margin-inline: auto;
  padding-inline: 1rem;
}

@media (min-width: 640px) {
  .container {
    padding-inline: 1.5rem;
  }
}

/* --- Header --- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid var(--border);
  /* Tailwind's bg-canvas/85 + backdrop-blur, translated to plain CSS. */
  background: color-mix(in oklab, var(--canvas) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  padding-block: 0.75rem;
}

.wordmark {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  margin-right: auto;
}

.accent {
  color: var(--accent);
}

.all-tools-link {
  font-size: 0.875rem;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 0.375rem 0.625rem;
  border-radius: 0.375rem;
  transition: background-color 0.15s, color 0.15s;
}

.all-tools-link:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  transition: border-color 0.15s, color 0.15s;
}

.icon-btn:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

.icon-btn svg {
  width: 1rem;
  height: 1rem;
}

.icon-moon {
  display: none;
}

.dark .icon-sun {
  display: none;
}

.dark .icon-moon {
  display: block;
}

/* --- Page / title block --- */

.page {
  padding-block: 2rem 4rem;
}

@media (min-width: 640px) {
  .page {
    padding-block: 3rem 4rem;
  }
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.breadcrumb a {
  color: var(--ink-subtle);
  text-decoration: none;
  transition: color 0.15s;
}

.breadcrumb a:hover {
  color: var(--accent);
}

.breadcrumb .sep {
  color: var(--ink-subtle);
}

.crumb-maths {
  color: var(--maths) !important;
  font-weight: 500;
}

.crumb-maths:hover {
  opacity: 0.8;
}

.title-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 640px) {
  .title-row {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }
}

.title-block {
  max-width: 42rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

@media (min-width: 640px) {
  h1 {
    font-size: 1.875rem;
  }
}

.lede {
  margin-top: 0.75rem;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink-muted);
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  transition: border-color 0.15s, color 0.15s;
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--ink);
}

.btn-outline:disabled {
  opacity: 0.5;
}

.btn-outline svg {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
}

.share-btn {
  align-self: flex-start;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 0.375rem;
  padding: 0.5rem 1.125rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color 0.15s, border-color 0.15s;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
}

/* --- Tabs --- */

.tablist {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-top: 2rem;
}

.tab {
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--ink);
}

.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tabpanel {
  padding-top: 1.5rem;
}

/* The Quick/Advanced strip nests inside a panel that already has its own padding, so
   it needs far less air above it than the page-level tabs do. */
.tablist.tablist-nested {
  margin-top: 1.25rem;
}

.tabpanel.tabpanel-nested {
  padding-top: 1rem;
}

/* --- Layout grid, panels --- */

.tool-grid {
  display: grid;
  gap: 1.5rem;
}

@media (min-width: 1024px) {
  .tool-grid {
    grid-template-columns: 20rem minmax(0, 1fr);
  }

  /* The breaker's left column holds a ciphertext box rather than a column of small
     controls, so it gets an even split instead of the settings-panel width. */
  .tool-grid.breaker-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.col-stack {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panel {
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 1.25rem;
}

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.panel-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-subtle);
}

/* --- Fields --- */

.field {
  display: block;
}

.field + .field {
  margin-top: 1rem;
}

.field > label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 0.375rem;
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  background: var(--canvas);
  color: var(--ink);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  transition: border-color 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  outline: none;
}

/* Advanced's "I know X" checkboxes disable rather than hide their fields, so a
   dimmed control is the only signal that it is not in play. */
.field input:disabled,
.field select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.field textarea {
  resize: vertical;
  min-height: 6rem;
  line-height: 1.5;
}

.field textarea[readonly] {
  background: var(--surface-2);
}

.field-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.field-row .field-grow {
  flex: 1 1 auto;
  min-width: 0;
}

.letter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  height: 2.125rem;
  padding-inline: 0.5rem;
  border-radius: 0.375rem;
  background: var(--surface-2);
  color: var(--ink-muted);
  font-size: 0.875rem;
  font-weight: 600;
  flex-shrink: 0;
}

.rotor-slot {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem;
  background: var(--surface-2);
}

.rotor-slot + .rotor-slot,
.rotor-slot + .field,
.field + .rotor-slot {
  margin-top: 0.75rem;
}

.rotor-slot .field + .field {
  margin-top: 0.625rem;
}

.slot-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-subtle);
  margin-bottom: 0.5rem;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  margin-top: 0.75rem;
  cursor: pointer;
}

.checkbox-field input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.readout-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem 2rem;
  margin-top: 1rem;
}

.readout-row dt {
  font-size: 0.75rem;
  color: var(--ink-subtle);
}

.readout-row dd {
  margin-top: 0.125rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink);
}

.hint {
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--ink-subtle);
}

.note {
  margin-top: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  line-height: 1.5;
}

.note-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid color-mix(in oklab, var(--danger) 35%, transparent);
}

/* A caution rather than a failure — thorough mode's confirmation gate — so it borrows
   the "medium confidence" amber rather than the error red. */
.note-warning {
  background: var(--energy-soft);
  color: var(--ink);
  border: 1px solid color-mix(in oklab, var(--energy) 35%, transparent);
}

.note-warning .checkbox-field {
  color: var(--ink);
}

/* --- Example chips --- */

.example-chips {
  margin-top: 1rem;
}

.chips-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-subtle);
  margin-bottom: 0.5rem;
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.chip {
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-muted);
  padding: 0.3125rem 0.625rem;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  transition: border-color 0.15s, color 0.15s;
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--ink);
}

/* --- Breaker run controls --- */

.btn-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.progress-wrap {
  margin-top: 1.25rem;
}

progress {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 0.5rem;
  border: none;
  border-radius: 9999px;
  overflow: hidden;
  background: var(--surface-2);
}

progress::-webkit-progress-bar {
  background: var(--surface-2);
  border-radius: 9999px;
}

progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 9999px;
  transition: width 0.2s ease;
}

progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 9999px;
}

.progress-stage {
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--ink-muted);
}

.progress-elapsed {
  margin-top: 0.125rem;
  font-size: 0.75rem;
  color: var(--ink-subtle);
}

/* --- Result --- */

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

@media (min-width: 480px) {
  .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.stat {
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0.625rem 0.75rem;
  min-width: 0;
}

.stat dt {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--ink-subtle);
}

.stat dd {
  margin-top: 0.25rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  overflow-wrap: break-word;
}

.confidence-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1875rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* --ok has no --ok-soft counterpart in the shared token set, so its soft
   background is mixed here the same way the other soft tokens were made. */
.badge-high {
  background: color-mix(in oklab, var(--ok) 20%, var(--surface));
  color: var(--ok);
}

.badge-medium {
  background: var(--energy-soft);
  color: var(--energy);
}

.badge-low {
  background: var(--danger-soft);
  color: var(--danger);
}

.confidence-note {
  font-size: 0.8125rem;
  color: var(--ink-muted);
}

#brk-result .field {
  margin-top: 1.25rem;
}

#brk-open-sim {
  margin-top: 1rem;
}

/* --- Advanced breaker: docs --- */

.docs {
  margin-top: 1.25rem;
}

.docs details {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
}

.docs details + details {
  margin-top: 0.75rem;
}

.docs summary {
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink);
}

.docs details[open] summary {
  margin-bottom: 0.75rem;
}

.docs p + p {
  margin-top: 0.5rem;
}

/* Wrapped so a table wider than its column can scroll on its own rather than the
   whole page — the 400px layout this site has to work at is narrower than any of
   these tables read comfortably at. */
.table-wrap {
  overflow-x: auto;
  margin-top: 0.5rem;
}

.docs-table {
  width: 100%;
  min-width: 22rem;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.docs-table th,
.docs-table td {
  padding: 0.4375rem 0.625rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.docs-table th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-subtle);
}

/* --- Footer --- */

.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 40%, transparent);
}

.footer-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-block: 2rem;
  font-size: 0.8125rem;
  color: var(--ink-subtle);
}

@media (min-width: 640px) {
  .footer-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
  }
}

.footer-row .wordmark.small {
  font-size: 0.875rem;
  margin-right: 0;
}

.footer-row .privacy-note {
  max-width: 28rem;
}

.footer-row a {
  text-decoration: none;
  white-space: nowrap;
}

.footer-row a:hover {
  color: var(--accent);
}

/* The advanced panel repeats the simulator's three rotor slots, but here they sit in a
   settings column that already carries a crib, a thorough-mode warning and everything
   the user knows. Running each slot's fields across instead of down keeps that column
   scannable; below 480px they stack again, where the width is not there to spare. */
@media (min-width: 480px) {
  #mode-panel-advanced .rotor-slot {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem 0.75rem;
    align-items: end;
  }

  #mode-panel-advanced .rotor-slot .slot-title {
    grid-column: 1 / -1;
  }

  #mode-panel-advanced .rotor-slot .field {
    margin-top: 0;
  }
}
