:root {
  --paper: #f5f1e8;
  --paper-raised: #fffdf7;
  --ink: #1c1a15;
  --ink-soft: #5a5646;
  --rule: #d8d0bc;
  --rule-strong: #b9ae8c;
  --accent: #b5482f;
  --accent-soft: #f0ded7;
  --focus: #1c1a15;
  --radius: 3px;
  --radius-sm: 3px;
  --radius-md: 6px;
}

/* ---------- Dark theme ----------
   Toggled via [data-theme="dark"] on <html> (set by the anti-FOUC inline
   script in index.html). Same token names as the light palette above are
   redefined here — every rule below already reads var(--paper)/var(--ink)/
   etc., so the whole page repaints without touching component styles. */
html[data-theme="dark"] {
  --paper: #1b1914;
  --paper-raised: #262319;
  --ink: #ece6d6;
  --ink-soft: #b7ae95;
  --rule: #3a362a;
  --rule-strong: #55503e;
  --accent: #e2825f;
  --accent-soft: #3a2620;
  --focus: #ece6d6;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  background: var(--paper);
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px);
  background-size: 100% 2.4rem;
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  line-height: 1.5;
  min-height: 100vh;
  /* Defense-in-depth for 320-500px viewports (verified via CDP: no
     overflow found today, but nothing on this page needs horizontal
     scroll, so guard against future regressions at the document level). */
  overflow-x: hidden;
}

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

/* ---------- Masthead (standardized 2-line header — same class names as
   the portal/web-countdown; keep in sync if this pattern changes) ---------- */

.masthead {
  padding-bottom: 1.15rem;
}

.masthead-rule {
  border: none;
  border-top: 2px solid var(--ink);
  margin: 0 0 2.5rem;
}

.masthead-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.masthead-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.home-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  flex-shrink: 0;
  border-radius: 50%;
  color: var(--ink-soft);
  text-decoration: none;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.home-icon:hover {
  background: var(--accent-soft);
  color: var(--ink);
}

.home-icon:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .home-icon {
    transition: none;
  }
}

.brand-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: var(--paper);
  font-size: 1.05rem;
}

.brand-tile img {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  /* External <img> SVGs do not inherit currentColor. Brand-tile is ink-on-paper
     inverted (dark tile / paper glyph). Force monochrome paint to match. */
  filter: brightness(0) invert(1);
}
html[data-theme="dark"] .brand-tile img {
  /* Dark theme: --ink tile is light; keep icon dark. */
  filter: brightness(0);
}


.brand-title {
  font-size: clamp(1.3rem, 3.2vw, 1.6rem);
  margin: 0;
  min-width: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.masthead-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.theme-toggle {
  position: relative;
  width: 2.1rem;
  height: 2.1rem;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule-strong);
  border-radius: 50%;
  background: var(--paper-raised);
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, transform 0.1s ease;
}

.theme-toggle:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.theme-toggle:active {
  transform: scale(0.94);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.theme-icon {
  position: absolute;
  width: 1.1rem;
  height: 1.1rem;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.theme-icon--sun {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.theme-icon--moon {
  opacity: 0;
  transform: scale(0.5) rotate(-40deg);
}

html[data-theme="dark"] .theme-icon--sun {
  opacity: 0;
  transform: scale(0.5) rotate(40deg);
}

html[data-theme="dark"] .theme-icon--moon {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-icon {
    transition: none;
  }
}

.masthead-sub {
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0.6rem 0 0;
  max-width: 46ch;
}

.converter {
  max-width: 640px;
  margin: 2.5rem auto 0;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1.5rem;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1.75rem;
}

.tab {
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  padding: 0.6rem 0.9rem;
  cursor: pointer;
}

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

.tab:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

.panel[hidden] {
  display: none;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field label {
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.field input,
.field select {
  font-family: inherit;
  font-size: 1.05rem;
  padding: 0.6rem 0.65rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--ink);
}

.field input:focus-visible,
.field select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.result-output {
  font-size: 1.05rem;
  padding: 0.6rem 0.65rem;
  background: var(--accent-soft);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.swap-row {
  display: flex;
  justify-content: center;
  color: var(--ink-soft);
  margin: 0.85rem 0;
}

.swap-glyph {
  font-size: 1rem;
}

.page-footer {
  margin-top: 2.5rem;
  text-align: center;
  font-family: "SFMono-Regular", "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.app-version {
  margin-top: 0.35rem;
  opacity: 0.6;
}

.app-version:empty {
  display: none;
}

@media (max-width: 480px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

/* Verified via CDP at 320/375/414/500px: no horizontal overflow found on
   this page. This block only lifts the masthead's two interactive
   controls to the 44x44px minimum touch target. */
@media (max-width: 500px) {
  .home-icon,
  .theme-toggle {
    width: 2.75rem;
    height: 2.75rem;
  }

  /* When the title wraps and pushes .masthead-actions to its own line,
     margin-left: auto keeps it pinned to the right instead of collapsing
     to flex-start (space-between has nothing to distribute for a lone
     item on a wrapped line). */
  .masthead-actions {
    margin-left: auto;
  }
}
