/*
 * Layout and components. The page uses the fixed colour tokens below; the
 * calculator overrides them with its theme tokens from themes.css.
 */

:root {
  color-scheme: light;
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-text: #1b2430;
  --color-text-muted: #5a6474;
  --color-border: #d9dee6;
  --color-accent: #2457c5;
  --color-error: #b42318;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --radius-card: 20px;
  --radius-key: 12px;
  --gutter: 16px;
  --shadow-card: 0 1px 2px rgb(0 0 0 / 0.06), 0 8px 24px rgb(0 0 0 / 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
}

a {
  color: var(--color-accent);
}

:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* Component display rules (e.g. display: grid) must not override [hidden]. */
[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.container {
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Header */

.site-header {
  padding-block: 28px 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  color: var(--color-text);
  text-decoration: none;
  border-radius: 10px;
}

.brand__logo {
  display: block;
  width: 40px;
  height: 40px;
}

.brand__name {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand__accent {
  color: var(--color-accent);
}

/* Site navigation (Spain's homepage and calculator pages): brand and links share
   one row; on narrow screens the links wrap to a full-width row of equal items. */

.site-header__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 16px;
}

.site-header__bar .brand {
  margin-bottom: 0;
}

.site-nav__list {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-nav__link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.site-nav__link:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.site-nav__link[aria-current] {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.site-nav__link[aria-current="page"] {
  background: var(--color-accent);
  color: #ffffff;
}

@media (max-width: 559px) {
  .site-nav {
    width: 100%;
  }

  .site-nav__list > li {
    flex: 1 1 0;
  }

  .site-nav__link {
    padding-inline: 8px;
  }
}

.site-header h1 {
  margin: 0 0 4px;
  font-size: clamp(1.75rem, 5vw, 2.4rem);
  line-height: 1.2;
}

.site-header p {
  margin: 0;
  color: var(--color-text-muted);
}

/* App layout: calculator + side panel */

.app {
  display: grid;
  gap: 20px;
  padding-block: 20px 40px;
  align-items: start;
}

@media (min-width: 860px) {
  .app {
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  }
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 16px;
}

.status-message {
  margin: 0 0 16px;
  padding: 12px 16px;
  border: 2px solid var(--color-error);
  border-radius: var(--radius-key);
  color: var(--color-error);
  font-weight: 600;
}

.status-message:empty {
  display: none;
}

.calculator {
  color: var(--color-text);
}

/* Theme dropdown (inside the calculator, so it follows the active theme) */

.theme-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.theme-control label {
  color: var(--color-text-muted);
  font-weight: 600;
}

.theme-select {
  min-height: 36px;
  padding: 4px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  cursor: pointer;
}

/* Calculator display */

.display {
  display: grid;
  gap: 2px;
  min-height: 132px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--color-display-bg);
  color: var(--color-display-text);
  border: 1px solid var(--key-border);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.display__secondary {
  min-height: 1.6em;
  color: var(--color-display-muted);
  font-size: 1.1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.display__primary {
  display: block;
  font-size: clamp(2.25rem, 10vw, 3rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.display__error {
  min-height: 1.4em;
  margin: 0;
  color: var(--color-error);
  font-size: 0.95rem;
  font-weight: 600;
}

/* Keypad */

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.key {
  min-height: 58px;
  border: 2px solid var(--key-border);
  border-radius: var(--radius-key);
  background: var(--color-key-bg);
  color: var(--color-key-text);
  font: inherit;
  font-size: 1.4rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 80ms ease, filter 120ms ease;
}

.key:hover {
  filter: brightness(var(--key-hover-brightness));
}

.key:active,
.key.is-pressed {
  transform: scale(0.95);
}

.key--function {
  background: var(--color-key-fn-bg);
  color: var(--color-key-fn-text);
  font-size: 1.2rem;
}

.key--operator {
  background: var(--color-key-op-bg);
  color: var(--color-key-op-text);
  font-weight: 600;
}

.key--equals {
  background: var(--color-key-eq-bg);
  color: var(--color-key-eq-text);
  font-weight: 700;
}

/* A key spanning two keypad columns (e.g. ± and % on the last row). */
.key--wide {
  grid-column: span 2;
}

.keyboard-hint {
  margin: 14px 0 0;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  text-align: center;
}

/* Side panel: history and themes */

.side-panel {
  display: grid;
  gap: 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.panel-title {
  margin: 0;
  font-size: 1.15rem;
}

.text-button {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.text-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.history-list {
  display: grid;
  gap: 6px;
  max-height: 320px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.history-entry {
  display: grid;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  text-align: right;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.history-entry:hover {
  border-color: var(--color-accent);
}

.history-entry__expression {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.history-entry__result {
  font-size: 1.15rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.history-empty {
  margin: 0;
  color: var(--color-text-muted);
}

/* SEO content */

.content {
  max-width: 72ch;
  padding-block: 8px 48px;
}

.content h2 {
  margin: 40px 0 8px;
  font-size: 1.45rem;
  line-height: 1.3;
}

.content h3 {
  margin: 0;
  font-size: 1.05rem;
}

.content ul,
.content ol {
  padding-left: 1.25rem;
}

.shortcut-table {
  width: 100%;
  border-collapse: collapse;
}

.shortcut-table th,
.shortcut-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
}

/* Example tables in the Scientific calculator article: long numbers and
   formulas (1628,89462677744, √(3^2+4^2)) may wrap so a table never widens
   the page on a phone. */
.example-table th,
.example-table td {
  overflow-wrap: anywhere;
}

@media (max-width: 479px) {
  .example-table th,
  .example-table td {
    padding-inline: 6px;
  }
}

kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 1px 6px;
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--color-surface);
  font-family: var(--font-mono);
  font-size: 0.9em;
  text-align: center;
}

.faq details {
  border-bottom: 1px solid var(--color-border);
  padding-block: 12px;
}

.faq summary {
  cursor: pointer;
}

.faq summary h3 {
  display: inline;
}

.faq details p {
  margin: 8px 0 0;
}

.site-footer {
  padding-block: 24px;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* Footer country navigation (homepages only): label, then the five countries
   as small pills; they wrap on narrow screens. Focus uses the global
   :focus-visible outline. */

.country-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-top: 12px;
}

.country-nav__list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.country-nav__link {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 4px 12px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
}

.country-nav__link:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.country-nav__link[aria-current="page"] {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: #ffffff;
  font-weight: 600;
}

/* Scientific calculator (provisional page /calculadora-cientifica/) */

.sci-page {
  max-width: 560px;
  padding-block: 20px 40px;
}

.angle-control {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 0 0 12px;
  padding: 0;
  border: 0;
  font-size: 0.95rem;
}

.angle-control legend {
  float: left;
  width: 100%;
  margin-bottom: 2px;
  color: var(--color-text-muted);
  font-weight: 600;
}

.angle-control label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  cursor: pointer;
}

.display__top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.display__top .display__secondary {
  flex: 1;
}

.display__badge {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--color-key-op-bg);
  color: var(--color-key-op-text);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.keypad--sci {
  /* minmax(0, 1fr): five equal columns at every width. Plain 1fr cannot shrink
     below its widest label, so at 320 px "sen⁻¹ cos⁻¹ tan⁻¹" widened the first
     three columns and squeezed the C column to 29 px. */
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.keypad--sci .key {
  min-height: 52px;
  padding-inline: 2px;
  font-size: 1.2rem;
}

.key--fn {
  background: var(--color-key-fn-bg);
  color: var(--color-key-fn-text);
  font-size: 1rem;
}

.keypad--sci .key--fn {
  font-size: 1rem;
}

.key--span4 {
  grid-column: span 4;
}

/* Scientific keypad placement: every key has a named grid area.
   Phones and narrow cards: 5 columns, Deg/Rad on top.
   Wide screens (≥ 760 px): functions | digits | operators, like a desk calculator. */
.keypad--sci {
  grid-template-areas:
    "angle angle angle angle angle"
    "sin   cos   tan   clr   bs"
    "asin  acos  atan  open  close"
    "log   ln    sqrt  cbrt  e"
    "d7    d8    d9    div   pi"
    "d4    d5    d6    mul   sq"
    "d1    d2    d3    sub   pow"
    "d0    dec   neg   add   fact"
    "eq    eq    eq    eq    exp";
}

.key-area--angle { grid-area: angle; }
.key-area--neg { grid-area: neg; }
.key-area--open { grid-area: open; }
.key-area--close { grid-area: close; }
.key-area--clr { grid-area: clr; }
.key-area--bs { grid-area: bs; }
.key-area--sin { grid-area: sin; }
.key-area--cos { grid-area: cos; }
.key-area--tan { grid-area: tan; }
.key-area--log { grid-area: log; }
.key-area--asin { grid-area: asin; }
.key-area--acos { grid-area: acos; }
.key-area--atan { grid-area: atan; }
.key-area--ln { grid-area: ln; }
.key-area--sqrt { grid-area: sqrt; }
.key-area--cbrt { grid-area: cbrt; }
.key-area--pi { grid-area: pi; }
.key-area--e { grid-area: e; }
.key-area--sq { grid-area: sq; }
.key-area--pow { grid-area: pow; }
.key-area--fact { grid-area: fact; }
.key-area--exp { grid-area: exp; }
.key-area--d0 { grid-area: d0; }
.key-area--d1 { grid-area: d1; }
.key-area--d2 { grid-area: d2; }
.key-area--d3 { grid-area: d3; }
.key-area--d4 { grid-area: d4; }
.key-area--d5 { grid-area: d5; }
.key-area--d6 { grid-area: d6; }
.key-area--d7 { grid-area: d7; }
.key-area--d8 { grid-area: d8; }
.key-area--d9 { grid-area: d9; }
.key-area--dec { grid-area: dec; }
.key-area--eq { grid-area: eq; }
.key-area--add { grid-area: add; }
.key-area--sub { grid-area: sub; }
.key-area--mul { grid-area: mul; }
.key-area--div { grid-area: div; }

.keypad--sci .angle-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.keypad--sci .angle-control label {
  position: relative;
  justify-content: center;
  min-height: 44px;
  border-radius: 10px;
  background: var(--color-key-fn-bg);
  color: var(--color-key-fn-text);
}

.keypad--sci .angle-control label:has(input:checked) {
  background: var(--color-accent);
  color: #ffffff;
}

.keypad--sci .angle-control label:has(input:focus-visible) {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.keypad--sci .angle-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

@media (min-width: 760px) {
  .sci-page {
    max-width: 920px;
  }

  .keypad--sci {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-areas:
      "angle angle angle neg  open close clr bs"
      "sin   cos   tan   log  d7   d8    d9  div"
      "asin  acos  atan  ln   d4   d5    d6  mul"
      "sqrt  cbrt  pi    e    d1   d2    d3  sub"
      "sq    pow   fact  exp  d0   dec   eq  add";
  }

  .keypad--sci .angle-control label {
    min-height: 52px;
  }
}

/* Percentage calculators (provisional pages /calculadora-de-porcentajes/…) */

.pct-page {
  display: grid;
  gap: 20px;
  max-width: 760px;
  padding-block: 20px 40px;
}

.pct-visible,
.pct-more__body {
  display: grid;
  gap: 16px;
}

.pct-mode {
  display: grid;
  gap: 12px;
}

.pct-mode__title {
  margin: 0;
  font-size: 1.2rem;
}

.pct-fields {
  display: grid;
  gap: 12px;
}

@media (min-width: 560px) {
  .pct-fields {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

.pct-mode[data-mode^='frac-'] .pct-fields {
  grid-template-columns: 1fr 1fr;
}

.pct-mode[data-mode='frac-1'] .field:has(select) {
  grid-column: 1 / -1;
}

.pct-mode[data-mode='frac-4'] .pct-fields {
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 4px;
  align-content: start;
  min-width: 0;
}

.field label,
.field legend {
  font-weight: 600;
}

.field input[type="text"],
.field input[type="date"],
.field input[type="time"],
.field select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--color-text-muted);
  border-radius: 10px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

/* Placeholders are examples, not values: italic tells them apart from typed text. */
.field input::placeholder {
  font-style: italic;
}

.field input[aria-invalid="true"] {
  border: 2px solid var(--color-error);
}

.field input:disabled {
  opacity: 0.55;
}

.field--choice,
.field--list {
  margin: 0;
  padding: 0;
  border: 0;
}

.field--choice {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.field--choice legend {
  width: 100%;
  margin-bottom: 4px;
}

.field--choice > label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  font-weight: 400;
  cursor: pointer;
}

.field--nested {
  width: 100%;
}

.field-list__rows {
  display: grid;
  gap: 8px;
}

.field-list__actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.field__message {
  min-height: 0;
  margin: 0;
  font-size: 0.9rem;
}

.field__message.is-error {
  color: var(--color-error);
  font-weight: 600;
}

.chip-ambiguous {
  margin: 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--color-display-bg);
  color: var(--color-display-text);
  font-size: 0.9rem;
}

.pct-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button {
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-key-fn-bg);
  color: var(--color-key-fn-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.button--primary {
  border-color: transparent;
  background: var(--color-key-eq-bg);
  color: var(--color-key-eq-text);
}

.pct-result {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--color-display-bg);
  color: var(--color-display-text);
}

.pct-result__label {
  margin: 0;
  color: var(--color-display-muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pct-result__main-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.pct-result__main {
  font-size: clamp(1.8rem, 8vw, 2.4rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.pct-result__copied {
  font-size: 0.9rem;
  font-weight: 600;
}

.pct-result__sentence {
  margin: 0;
  font-size: 1.05rem;
}

.pct-result__warnings,
.pct-result__notes {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 1.2em;
}

.pct-result__warnings:empty,
.pct-result__notes:empty {
  display: none;
}

.pct-result__warnings {
  color: var(--color-error);
  font-weight: 600;
}

.pct-result a,
.pct-link a {
  color: inherit;
  font-weight: 600;
}

.pct-formula {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: 0.95rem;
}

@media (max-width: 479px) {
  .pct-formula {
    grid-template-columns: 1fr;
  }
}

.pct-formula dt {
  color: var(--color-display-muted);
  font-weight: 600;
}

.pct-formula dd {
  margin: 0;
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

.pct-steps summary {
  font-weight: 600;
  cursor: pointer;
}

.pct-steps ol {
  margin: 8px 0 0;
  padding-left: 1.4em;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.pct-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.pct-table th,
.pct-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--color-border);
  text-align: right;
}

.pct-table th[scope="row"] {
  text-align: left;
  font-weight: 600;
}

.pct-link,
.pct-note {
  margin: 0;
  font-size: 0.95rem;
}

.pct-more > summary {
  padding: 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-key);
  background: var(--color-surface);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.pct-more[open] > summary {
  margin-bottom: 16px;
}

/* "Más cálculos" is the h2 of the three extra tools (their titles are h3). */
.pct-more__title {
  display: inline;
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
}

/* Guide and FAQ under the percentage calculators. */
.pct-content {
  padding-block: 0;
}

/* Their example tables: words wrap whole (a word breaks only if it cannot fit
   on a line at all), so headings and labels never split mid-word on a phone. */
.pct-guide-table th,
.pct-guide-table td {
  overflow-wrap: break-word;
}

@media (max-width: 479px) {
  .pct-guide-table th,
  .pct-guide-table td {
    padding-inline: 6px;
  }
}

.tabs__list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tabs__list [role="tab"] {
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.tabs__list [role="tab"][aria-selected="true"] {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: #ffffff;
  font-weight: 600;
}

.tabs__panel + .tabs__panel {
  margin-top: 16px;
}

.pct-related ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chip {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  font-weight: 600;
  text-decoration: none;
}

@media (prefers-reduced-motion: reduce) {
  .key {
    transition: none;
  }

  .key:active,
  .key.is-pressed {
    transform: none;
  }
}

/* Fit the calculator on the first screen (no scrolling) on short screens:
   laptops (≈ 650–800 px of visible height), tablets and phones. Spacing is
   tighter and the keys take their height from the screen height (svh), so the
   whole keypad stays visible; they never shrink below a comfortable tap size. */
@media (max-height: 860px) {
  .site-header {
    padding-block: 16px 4px;
  }

  .brand {
    margin-bottom: 10px;
  }

  .app {
    padding-block: 12px 32px;
  }

  .sci-page {
    padding-block: 12px 32px;
  }

  .display {
    min-height: 96px;
    margin-bottom: 10px;
    padding: 10px 14px;
  }

  .display__primary {
    font-size: clamp(2rem, 7vw, 2.6rem);
  }

  .keypad {
    gap: 8px;
  }

  .theme-control {
    margin-bottom: 8px;
  }

  /* Basic calculator: 6 rows of keys. */
  .key {
    min-height: clamp(38px, calc((100svh - 420px) / 6 - 10px), 58px);
  }

  /* Scientific, phones and narrow cards: 9 rows (Deg/Rad + 8 rows of keys). */
  .keypad--sci .key,
  .keypad--sci .angle-control label {
    min-height: clamp(36px, calc((100svh - 420px) / 9 - 8px), 52px);
  }
}

@media (max-height: 860px) and (max-width: 559px) {
  /* Phones: the navigation takes its own row, so the keypad starts lower. */
  .key {
    min-height: clamp(40px, calc((100svh - 460px) / 6 - 10px), 58px);
  }
}

@media (max-height: 860px) and (min-width: 760px) {
  /* Scientific, wide screens: 5 rows of keys. */
  .keypad--sci .key,
  .keypad--sci .angle-control label {
    min-height: clamp(38px, calc((100svh - 330px) / 5 - 8px), 52px);
  }
}

/* Rows with two fields (grade + percentage, grade + credits) on the grade calculator. */
.field--pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  align-items: start;
}

.pair__cell {
  display: grid;
  gap: 4px;
  min-width: 0;
}

/* Tools index (/calculadoras/) */
.tools-index {
  display: grid;
  gap: 28px;
  max-width: 760px;
  padding-block: 20px 40px;
}

.tools-group h2 {
  margin: 0 0 12px;
  font-size: 1.25rem;
}

.tools-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tools-list a {
  display: grid;
  gap: 2px;
  padding: 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
}

.tools-list a:hover {
  border-color: var(--color-accent);
}

.tools-list span {
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

/* A date field with its "Hoy" button. */
.date-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.date-row input[type='date'] {
  flex: 1 1 auto;
  min-width: 0;
}

.field--check label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

/* On calculator pages the colour menu is a small, quiet control so the calculator sits higher. */
.pct-page .theme-control {
  margin: -6px 0 8px;
  font-size: 0.8rem;
}

.pct-page .theme-select {
  min-height: 30px;
  padding: 2px 8px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-block: 8px;
}

/* Quick answer at the top of each guide, with a picture of the calculator. */
.answer-box {
  display: grid;
  gap: 12px;
  margin: 0 0 24px;
  padding: 14px 16px;
  border-left: 4px solid var(--color-accent);
  border-radius: 10px;
  background: var(--color-surface);
}

.answer-box p {
  margin: 0;
}

.answer-box__figure {
  margin: 0;
}

.answer-box__figure img {
  display: block;
  width: 100%;
  max-width: 600px;
  height: auto;
  border: 1px solid var(--color-border);
  border-radius: 10px;
}
