/* Percentage Calculator — Committed forest-teal palette, mono-forward type.
   Colour roles (OKLCH, teal-tinted neutrals, no pure black/white):
   --canvas      page surface (cool porcelain, slight teal tint)
   --well        recessed input field rest tint
   --ink         primary text
   --ink-soft    secondary text / working line
   --hairline    borders, field underlines at rest
   --primary     forest teal accent (focus, active field, mode)
   --primary-ink result panel surface (drenched)
   --on-primary  text on the teal panel
*/

:root {
  --canvas: oklch(0.972 0.009 168);
  --well: oklch(0.945 0.013 168);
  --ink: oklch(0.245 0.025 175);
  --ink-soft: oklch(0.505 0.028 170);
  --hairline: oklch(0.86 0.014 165);
  --primary: oklch(0.57 0.135 162);
  --primary-press: oklch(0.50 0.125 162);
  --primary-ink: oklch(0.43 0.115 162);
  --on-primary: oklch(0.975 0.012 165);

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code",
               "Roboto Mono", Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1); /* ease-out-quint-ish */

  --r-lg: 18px;
  --r-md: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  justify-content: center;
  padding: clamp(1.25rem, 5vw, 3.5rem) 1.25rem;
}

.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;
}

.app {
  width: 100%;
  max-width: 33rem;
  display: flex;
  flex-direction: column;
  gap: clamp(1.5rem, 4vw, 2.25rem);
}

/* ---- Masthead ---- */
.masthead { display: flex; flex-direction: column; gap: 0.4rem; }

.title {
  margin: 0;
  font-family: var(--font-mono);
  font-weight: 680;
  font-size: clamp(2rem, 8vw, 2.85rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
}
.title__break { display: inline; }

.lede {
  margin: 0;
  max-width: 32ch;
  color: var(--ink-soft);
  font-size: 1.0625rem;
}

/* ---- Mode segmented control ---- */
.modes {
  margin: 0;
  padding: 4px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--well);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.mode { position: relative; display: block; }

.mode input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  margin: 0;
}

.mode__label {
  display: block;
  text-align: center;
  padding: 0.55rem 0.4rem;
  border-radius: 9px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 560;
  letter-spacing: -0.01em;
  color: var(--ink-soft);
  white-space: nowrap;
  transition: color 0.2s var(--ease), background-color 0.2s var(--ease);
}

.mode input:hover + .mode__label { color: var(--ink); }

.mode input:checked + .mode__label {
  background: var(--canvas);
  color: var(--primary);
  box-shadow: 0 1px 2px oklch(0.35 0.03 170 / 0.12);
}

.mode input:focus-visible + .mode__label {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---- Equation stage ---- */
.stage { display: flex; flex-direction: column; align-items: flex-start; gap: 1rem; }

.equation { width: 100%; }

.equation[hidden] { display: none; }

.equation__sentence {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.6rem;
  font-size: clamp(1.25rem, 5.2vw, 1.6rem);
  line-height: 1.45;
}

.word { color: var(--ink-soft); }

/* fill-in-the-blank number fields */
.field {
  display: inline-flex;
  align-items: baseline;
  gap: 0.15rem;
}

.field__input {
  font-family: var(--font-mono);
  font-size: inherit;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-align: center;
  width: 4.5ch;
  min-width: 2ch;
  field-sizing: content; /* progressive: grows to typed content where supported */
  max-width: 11ch;
  padding: 0.05em 0.2em 0.12em;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--hairline);
  border-radius: 2px 2px 0 0;
  caret-color: var(--primary);
  transition: border-color 0.18s var(--ease), background-color 0.18s var(--ease);
}

.field__input::placeholder { color: oklch(0.74 0.025 168); font-weight: 560; }

.field__input:hover { border-bottom-color: oklch(0.72 0.06 162); }

.field__input:focus {
  outline: none;
  border-bottom-color: var(--primary);
  background: oklch(0.57 0.135 162 / 0.07);
}

.field__unit { font-family: var(--font-mono); font-weight: 620; color: var(--ink); }

.clear {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 560;
  color: var(--ink-soft);
  background: none;
  border: none;
  padding: 0.2rem 0;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}
.clear:hover { color: var(--primary); border-bottom-color: var(--primary); }
.clear:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; border-radius: 2px; }
.clear[hidden] { display: none; }

/* ---- Result panel (drenched) ---- */
.result {
  display: block;
  background: var(--primary-ink);
  color: var(--on-primary);
  border-radius: var(--r-lg);
  padding: clamp(1.4rem, 5vw, 2rem);
  min-height: 7.5rem;
}

.result__main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.result__value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.4rem, 11vw, 3.6rem);
  line-height: 1.0;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.result.is-empty .result__value,
.result.is-undefined .result__value { color: oklch(0.975 0.012 165 / 0.5); }

.result__working {
  margin: 0.85rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  letter-spacing: -0.005em;
  color: oklch(0.975 0.012 165 / 0.78);
}

.result .arrow { font-family: var(--font-sans); }

/* copy button */
.copy {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  align-self: center;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  font-weight: 560;
  color: var(--on-primary);
  background: oklch(0.975 0.012 165 / 0.14);
  border: 1px solid oklch(0.975 0.012 165 / 0.22);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  transition: background-color 0.18s var(--ease), transform 0.18s var(--ease);
}
.copy:hover { background: oklch(0.975 0.012 165 / 0.24); }
.copy:active { transform: translateY(1px); }
.copy:focus-visible { outline: 2px solid var(--on-primary); outline-offset: 2px; }
.copy[hidden] { display: none; }
.copy.is-copied { background: oklch(0.975 0.012 165 / 0.28); }

/* ---- Motion ---- */
@media (prefers-reduced-motion: no-preference) {
  .equation { animation: rise 0.32s var(--ease) both; }
  .result__value, .result__working { transition: opacity 0.2s var(--ease); }
  .result.is-flash .result__value { animation: pop 0.28s var(--ease); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pop {
  0% { transform: scale(0.985); opacity: 0.55; }
  100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 360px) {
  .mode__label { font-size: 0.75rem; padding: 0.55rem 0.2rem; }
}
