:root {
  color-scheme: light;

  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #d3dae3;
  --text: #16202c;
  --text-muted: #4c5a6b;
  --text-placeholder: #78859a;
  --accent: #1b5e9c;
  --accent-soft: #e7f0f9;
  --error: #a02020;
  --warning-bg: #fdf4e3;
  --warning-border: #d9a441;
  --warning-text: #6b4a08;
  --accent-deep: #123f6b;
  --accent-bright: #3d8fd8;
  --hero-bore-a: #d3e6f8;
  --hero-bore-b: #a8cbea;
  --shadow: 0 1px 2px rgba(18, 43, 71, 0.06), 0 8px 24px rgba(18, 43, 71, 0.07);
  --radius: 14px;
  --gap: 1.25rem;
}

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

body {
  margin: 0;
  padding: 0 1rem 3rem;
  /* A soft wash in the corners over a faint dot grid, so the page reads as a
     surface rather than a blank sheet. Fixed attachment on the washes keeps
     them anchored while the grid scrolls with the content. */
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 12% -8%, rgba(61, 143, 216, 0.16), transparent 46%),
    radial-gradient(circle at 92% 2%, rgba(27, 94, 156, 0.12), transparent 40%),
    radial-gradient(circle at 1px 1px, rgba(18, 63, 107, 0.055) 1px, transparent 0);
  background-size: auto, auto, 22px 22px;
  background-attachment: fixed, fixed, scroll;
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 {
  font-size: clamp(1.6rem, 3.4vw, 2rem);
  margin: 0 0 0.3rem;
  letter-spacing: -0.015em;
  /* One flat colour. A gradient renders unevenly across Han characters, whose
     strokes are distributed differently from Latin ones, so 「分子數量計算機」
     would not read as the same colour as the English title. */
  color: #ffffff;
  font-weight: 750;
  text-shadow:
    0 1px 2px rgba(4, 18, 32, 0.55),
    0 2px 18px rgba(4, 18, 32, 0.6);
}

h2 {
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

h3 {
  font-size: 0.95rem;
  margin: 1.25rem 0 0.4rem;
}

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

/* ------------------------------------------------------------------ header */

.topbar {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.25rem 0 0;
  display: flex;
  justify-content: flex-end;
}

.page-header {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.75rem 0 1.5rem;
}

/* The title sits on the banner, so it is light-on-dark and must clear the
   artwork behind it. */
.page-header__text {
  position: relative;
  z-index: 1;
  max-width: 34rem;
}

/* Spans the full width of both columns; the title and subtitle sit on top. */
.brand-banner {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 168px;
  padding: 1.75rem 1.9rem;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  /* The favicon's tile gradient and sheen, as CSS so they fill whatever height
     the title ends up needing. */
  background-image:
    radial-gradient(
      circle at 16% 8%,
      rgba(255, 255, 255, 0.4),
      rgba(255, 255, 255, 0.06) 55%,
      transparent 78%
    ),
    linear-gradient(135deg, #3d8fd8, #1b5e9c 50%, #0e3559);
}

/* Scrim over the artwork but under the text, so a particle drifting behind the
   title can never eat into its contrast. Fades out well before the emblem. */
.brand-banner::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(6, 24, 42, 0.72),
    rgba(6, 24, 42, 0.42) 34%,
    rgba(6, 24, 42, 0.12) 54%,
    transparent 68%
  );
}

.brand-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.brand-orbits ellipse {
  fill: none;
  stroke: #bcdcfa;
  stroke-opacity: 0.18;
  stroke-width: 1.5;
}

.subtitle {
  margin: 0;
  color: rgba(255, 255, 255, 0.94);
  font-size: 1.02rem;
  text-shadow:
    0 1px 2px rgba(4, 18, 32, 0.5),
    0 2px 14px rgba(4, 18, 32, 0.55);
}

.segmented--language {
  margin-bottom: 0;
  width: max-content;
  background: var(--surface);
}

.segmented--language label {
  padding: 0.35rem 0.85rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

.hero-molecules circle {
  fill: #eaf5ff;
  opacity: var(--o, 0.8);
  /* Brownian jitter rather than a conveyor belt — which is also what molecules
     in a channel actually do. Each circle carries its own amplitude (--ax,
     --ay), period (--t) and phase (--d), so no two ever move in step and the
     field reads as random without any script. */
  animation: vibrate var(--t, 5s) ease-in-out infinite;
  animation-delay: var(--d, 0s);
}

/* Particles in the left half — the half the title sits on — are dark rather
   than pale, so they read as depth behind the text instead of competing with
   it for the reader's eye. The right half keeps the bright field. */
.hero-molecules circle.is-dim {
  fill: #071f36;
  opacity: calc(var(--o, 0.8) * 0.78);
}

@keyframes vibrate {
  0% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(calc(var(--ax) * 1px), calc(var(--ay) * -1px));
  }
  40% {
    transform: translate(calc(var(--ax) * -0.7px), calc(var(--ay) * 0.85px));
  }
  60% {
    transform: translate(calc(var(--ax) * 0.45px), calc(var(--ay) * 1px));
  }
  80% {
    transform: translate(calc(var(--ax) * -1px), calc(var(--ay) * -0.55px));
  }
  100% {
    transform: translate(0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .hero-molecules circle {
    animation: none;
  }
}

.icon {
  width: 1.85rem;
  height: 1.85rem;
  padding: 0.4rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--accent);
  background: linear-gradient(150deg, var(--accent-soft), #f3f8fd);
  border: 1px solid var(--border);
  border-radius: 9px;
}

/* ------------------------------------------------------------------ layout */

.layout {
  max-width: 1080px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--gap);
  align-items: start;
}

.results-column {
  display: grid;
  gap: var(--gap);
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .brand-banner {
    min-height: 150px;
    padding: 1.4rem 1.25rem;
  }
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem;
  box-shadow: var(--shadow);
}

/* Gradient hairline along the top edge of every card. Radius is matched here
   rather than clipping the card, so focus outlines are never cut off. */
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(
    90deg,
    var(--accent-deep),
    var(--accent-bright) 45%,
    #7fc4f2 75%,
    transparent
  );
}

/* ------------------------------------------------------------------ inputs */

/* A <select> sizes itself to its widest option, and a <fieldset> will not
   shrink below its content's min-content width — together they push the page
   wider than the viewport on a phone. The biomarker list has long option
   labels, so both guards are load-bearing, not defensive. */
.field-group {
  min-width: 0;
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0 0 1rem;
  padding: 1rem 0 0;
}

.field-group:first-of-type {
  border-top: 0;
  padding-top: 0;
}

legend {
  font-weight: 600;
  padding: 0;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.measure {
  margin-bottom: 0.85rem;
}

.measure label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

.measure__controls {
  display: flex;
  gap: 0.5rem;
}

.measure__controls input {
  flex: 1 1 auto;
  min-width: 0;
}

.measure__controls select {
  flex: 0 0 auto;
}

input[type="text"],
select {
  font: inherit;
  padding: 0.5rem 0.6rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

input[type="text"] {
  width: 100%;
}

select {
  max-width: 100%;
}

/* Full width rather than content width, so long biomarker labels are clipped
   by the control instead of stretching the layout. */
#biomarker,
#concentration-type {
  width: 100%;
}

::placeholder {
  color: var(--text-placeholder);
  opacity: 1; /* Firefox dims placeholders by default; we set the colour. */
}

input[aria-invalid="true"] {
  border-color: var(--error);
}

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

.field-error {
  margin: 0.3rem 0 0;
  color: var(--error);
  font-size: 0.85rem;
}

.field-note {
  margin: 0.3rem 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Segmented control, built from radios so it stays a real radio group. */
.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 0.9rem;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label {
  flex: 1;
  text-align: center;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.segmented input:checked + label {
  background: var(--accent);
  color: #fff;
}

.segmented input:focus-visible + label {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.switch label {
  font-size: 0.95rem;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

button {
  font: inherit;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.copy-status {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ----------------------------------------------------------------- results */

.result-card {
  background: linear-gradient(158deg, #ffffff 40%, #eef6fd);
  overflow: hidden; /* clips the watermark; nothing focusable lives in here */
}

.result-watermark {
  position: absolute;
  right: -22px;
  bottom: -30px;
  width: 190px;
  height: 190px;
  color: var(--accent);
  opacity: 0.07;
  pointer-events: none;
}

.result-primary {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 650;
  margin: 0;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.result-readable {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
}

.status-region:not(:empty),
.warning,
.occupancy__heading {
  margin-top: 1rem;
}

.status-region:not(:empty) {
  color: var(--error);
  font-size: 0.9rem;
}

.warning {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-text);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

/* Inside the input panel this is a standing caveat, not a reaction to a
   result, so it does not need the leading gap .warning carries elsewhere. */
#uncertainty-assumption {
  margin-top: 0.6rem;
}

.occupancy__heading {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

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

.occupancy__list li {
  display: flex;
  gap: 0.5rem;
}

.occupancy__value {
  font-variant-numeric: tabular-nums;
  min-width: 5.5ch;
  text-align: right;
  font-weight: 600;
}

.interval {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  overflow-wrap: anywhere;
}

.interval-relative {
  margin: 0.3rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.explanation {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.assumptions {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* --------------------------------------------------------------- breakdown */

summary {
  cursor: pointer;
  font-weight: 600;
}

/* Inline rather than a flex child, so the disclosure triangle survives —
   display:flex on a <summary> suppresses the marker in Chromium and WebKit. */
summary .icon {
  vertical-align: middle;
  margin-right: 0.45rem;
}

.breakdown {
  margin: 1rem 0 0;
  padding-left: 1.3rem;
  display: grid;
  gap: 0.85rem;
}

/* Grid items default to min-content width, which lets a long formula line
   stretch the card instead of scrolling inside its own <pre>. */
.breakdown li {
  min-width: 0;
}

.breakdown__title {
  margin: 0 0 0.2rem;
  font-weight: 600;
  font-size: 0.9rem;
}

.breakdown pre {
  margin: 0;
  font-size: 0.88rem;
  overflow-x: auto;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ------------------------------------------------------------------ footer */

.page-footer {
  max-width: 1080px;
  margin: 2rem auto 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

