:root {
  color-scheme: light dark;
  --background: #f5f6f8;
  --page-surface: #fff;
  --foreground: #0f172a;
  --muted: #53657d;
  --border: rgba(37, 99, 235, .22);
  --border-soft: rgba(148, 163, 184, .24);
  --blue: #2563eb;
  --blue-strong: #1d4ed8;
  --blue-soft: rgba(37, 99, 235, .09);
  --green: #10b981;
  --red: #f43f5e;
  --field-bg: rgba(255, 255, 255, .72);
  --metric-bg: rgba(241, 245, 249, .7);
  --track: rgba(148, 163, 184, .17);
  --radius-field: 12px;
  --radius-panel: 20px;
  --shadow-panel: 0 26px 70px -52px rgba(37, 99, 235, .42), 0 10px 30px -28px rgba(15, 23, 42, .3);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--background);
  color: var(--foreground);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--background); }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--background);
  color: var(--foreground);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
[hidden] { display: none !important; }

.ambient {
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(2px);
}

.ambient-one {
  width: 520px;
  height: 520px;
  top: -260px;
  left: calc(50% - 500px);
  background: radial-gradient(circle, rgba(37, 99, 235, .12), transparent 68%);
}

.ambient-two {
  width: 420px;
  height: 420px;
  right: calc(50% - 570px);
  bottom: -270px;
  background: radial-gradient(circle, rgba(14, 165, 233, .09), transparent 70%);
}

.site-header {
  width: min(100% - 40px, 1024px);
  height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-soft);
}

.brand {
  color: var(--foreground);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 750;
  letter-spacing: -.02em;
}

.brand-mark {
  width: 31px;
  height: 31px;
  color: #fff;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--blue);
  box-shadow: 0 8px 18px -10px rgba(37, 99, 235, .9);
}

.brand-mark svg { width: 20px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.header-note { color: var(--muted); font-size: 12px; letter-spacing: .02em; }

.app-shell {
  width: min(100% - 40px, 1024px);
  max-width: 1024px;
  margin: 0 auto;
  padding: 52px 0 62px;
}

.intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 36px;
  margin-bottom: 28px;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 11px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.eyebrow span { width: 18px; height: 2px; border-radius: 2px; background: currentColor; }
h1 { margin: 0; font-size: clamp(30px, 5vw, 44px); line-height: 1.08; letter-spacing: -.045em; }
.intro-copy { margin: 12px 0 0; color: var(--muted); font-size: 15px; line-height: 1.65; }

.formula-chip {
  min-width: 265px;
  padding: 13px 16px;
  display: grid;
  gap: 4px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-field);
  background: color-mix(in srgb, var(--page-surface) 82%, transparent);
  box-shadow: 0 14px 30px -30px rgba(15, 23, 42, .5);
}

.formula-chip span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; }
.formula-chip strong { font-size: 12px; font-weight: 680; }

.workspace {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 20px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-panel);
  background: color-mix(in srgb, var(--page-surface) 93%, transparent);
  box-shadow: var(--shadow-panel);
}

.input-panel { padding: 24px; }
.result-panel { padding: 24px; }

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.panel-heading > div { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.step { color: var(--blue); font: 750 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; }
h2 { margin: 0; font-size: 17px; line-height: 1.2; letter-spacing: -.02em; }
.panel-kicker { color: var(--muted); font-size: 11px; }

#calculator {
  display: grid;
  grid-template-columns: 1fr;
  gap: 15px;
}

.field { min-width: 0; }
.field.full, .amount-field { grid-column: 1 / -1; }
.field > label {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
  letter-spacing: .02em;
}

input, .control-trigger {
  width: 100%;
  height: 44px;
  min-width: 0;
  color: var(--foreground);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-field);
  outline: none;
  background: var(--field-bg);
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

input { padding: 0 13px; }

.date-control { display: flex; align-items: center; gap: 8px; min-width: 0; }
.date-control .date-input { flex: 1 1 0; cursor: text; }
.date-control .date-picker-button { flex: 0 0 44px; width: 44px; justify-content: center; }

input[aria-invalid="true"] { border-color: var(--red); }
input::placeholder { color: color-mix(in srgb, var(--muted) 64%, transparent); }
input:hover, .control-trigger:hover { border-color: color-mix(in srgb, var(--blue) 38%, var(--border-soft)); }
input:focus, .control-trigger:focus-visible, .control-trigger[aria-expanded="true"] { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); background: var(--page-surface); }

/* All devices use the same Zeno-style custom expansions. */
.control-trigger { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px; text-align: left; cursor: pointer; font-size: 14px; font-variant-numeric: tabular-nums; }
.control-trigger > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.control-trigger svg, .option-check { width: 18px; height: 18px; flex: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.control-trigger svg { color: var(--muted); }
.control-trigger[aria-expanded="true"] svg { color: var(--blue); }
.control-trigger[aria-haspopup="listbox"][aria-expanded="true"] svg { transform: rotate(180deg); }
/* Keep touch text at 16px to avoid iOS focus zoom, without changing controls. */
@media (pointer: coarse) and (hover: none) {
  #calculator input, #calculator .control-trigger { font-size: 16px; }
}
.field-help { margin: 6px 1px 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.control-popover {
  position: fixed;
  z-index: 92;
  inset: auto;
  margin: 0;
  padding: 6px;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--page-surface);
  color: var(--foreground);
  box-shadow: 0 18px 45px -22px rgba(15, 23, 42, .4), 0 3px 12px -6px rgba(15, 23, 42, .15);
  font-size: 13px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.control-popover::backdrop { background: transparent; }
.popover-heading { padding: 6px 8px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border-soft); color: var(--muted); font-size: 11px; font-weight: 600; }
.control-option { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-width: 0; min-height: 40px; padding: 8px 10px; border: 1px solid transparent; border-radius: 12px; background: transparent; color: var(--foreground); font-size: 13px; font-weight: 500; text-align: left; cursor: pointer; }
.select-popover .control-option + .control-option { margin-top: 4px; }
#currency-popover { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
#currency-popover .popover-heading { grid-column: 1 / -1; }
#currency-popover .control-option { margin-top: 0; }
#currency-popover .control-option > span { display: grid; gap: 2px; white-space: normal; overflow: visible; overflow-wrap: anywhere; }
#currency-popover .control-option small { font-size: 11px; line-height: 1.5; color: var(--muted); }
.control-option > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.option-check { visibility: hidden; width: 16px; height: 16px; }
.control-option[aria-selected="true"] .option-check { visibility: visible; }
.control-option:hover, .control-option:focus-visible, .calendar-day:hover, .calendar-header button:hover, .calendar-footer button:hover { color: var(--blue); border-color: var(--border); background: var(--blue-soft); outline: none; }
.control-option[aria-selected="true"], .calendar-day[aria-selected="true"] { color: var(--blue); border-color: color-mix(in srgb, var(--blue) 40%, var(--border)); background: var(--blue-soft); }
.control-popover button:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.date-popover { width: min(312px, calc(100vw - 24px)); padding: 12px; font-variant-numeric: tabular-nums; }
.calendar-header, .calendar-footer { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.calendar-header { padding-bottom: 8px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.calendar-title { display: flex; align-items: center; justify-content: center; gap: 2px; min-width: 0; }
.calendar-header button, .calendar-footer button { min-height: 40px; padding: 0 8px; border: 1px solid transparent; border-radius: 12px; background: transparent; font-size: 13px; cursor: pointer; }
.calendar-header .calendar-nav { flex: none; width: 32px; padding: 0; color: var(--blue); font-size: 24px; }
.calendar-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.calendar-week > [role="columnheader"] { display: grid; place-items: center; height: 28px; color: var(--muted); font-size: 11px; }
.calendar-day { position: relative; min-width: 0; min-height: 40px; padding: 0; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--foreground); font-size: 13px; cursor: pointer; }
.calendar-day.is-outside { color: var(--muted); }
.calendar-day[aria-current="date"]::after { position: absolute; content: ""; left: calc(50% - 2px); bottom: 4px; width: 4px; height: 4px; border-radius: 50%; background: var(--blue); }
.calendar-day:disabled { cursor: default; }
.calendar-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 8px 0; }
.calendar-options .control-option { justify-content: center; text-align: center; }
.calendar-footer { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border-soft); }
.calendar-footer button { color: var(--blue); font-weight: 600; }
.calendar-footer > span { color: var(--muted); font-size: 10px; }
.clipboard-fallback { position: fixed; inset: 0 auto auto -9999px; opacity: 0; }

.amount-control { display: grid; grid-template-columns: minmax(0, 1fr) 108px; gap: 8px; }
.form-error { min-height: 18px; margin: 13px 1px -3px; color: var(--red); font-size: 11px; line-height: 1.5; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--metric-bg);
  font-size: 10px;
  font-weight: 700;
}
.status-pill i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .55; }
.status-pill.is-ready { color: var(--green); background: color-mix(in srgb, var(--green) 11%, transparent); }

.value-card { min-width: 0; padding: 0; }
#result-name { display: block; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; line-height: 1.5; }

.hero-value { display: grid; min-width: 0; padding: 24px 0 26px; }
.hero-value > span { color: var(--muted); font-size: 11px; line-height: 1.6; }
#result-currency { margin-left: 6px; font-size: 10px; font-weight: 400; }
.hero-value strong { max-width: 100%; margin-top: 8px; overflow-wrap: anywhere; color: var(--blue); font-size: clamp(32px, 6vw, 45px); line-height: 1.15; letter-spacing: -.055em; font-variant-numeric: tabular-nums; }
.hero-value strong.is-long { font-size: clamp(22px, 5.3vw, 32px); }

.timeline { padding: 0 0 24px; }
.timeline-labels { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; margin-bottom: 9px; color: var(--muted); font-size: 10px; }
.timeline-labels strong { font-size: 10px; font-weight: 500; font-variant-numeric: tabular-nums; }
.track { height: 5px; overflow: hidden; border-radius: 999px; background: var(--track); }
.track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--blue); transition: width .3s cubic-bezier(.2,.8,.2,1); }

.result-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 0; }
.result-facts > div { min-width: 0; }
.result-facts dt { margin-bottom: 6px; color: var(--muted); font-size: 11px; }
.result-facts dd { margin: 0; overflow-wrap: anywhere; font-size: 15px; font-weight: 600; line-height: 1.5; font-variant-numeric: tabular-nums; }
.valued-caption { margin: 20px 0 6px; color: var(--muted); font-size: 10px; line-height: 1.6; overflow-wrap: anywhere; }

.fx-caption { margin: 12px 0 8px; color: var(--muted); font-size: 10px; line-height: 1.6; overflow-wrap: anywhere; }
.fx-caption a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
#fx-retry { min-height: 44px; padding: 0 8px; border: 1px solid var(--border-soft); border-radius: 8px; background: var(--field-bg); color: var(--blue); cursor: pointer; font-size: 11px; }
#fx-retry:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.export-actions { display: grid; grid-template-columns: 1.12fr 1fr 1fr; gap: 8px; margin-top: 12px; }
.button {
  min-width: 0;
  min-height: 40px;
  padding: 9px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-field);
  cursor: pointer;
  font-size: 11px;
  font-weight: 720;
  transition: transform .15s ease, border-color .15s ease, background .15s ease, opacity .15s ease;
}
.button svg { width: 15px; height: 15px; flex: 0 0 auto; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button.primary { color: #fff; border: 1px solid var(--blue); background: var(--blue); box-shadow: 0 10px 20px -14px rgba(37, 99, 235, .9); }
.button.secondary { color: var(--foreground); border: 1px solid var(--border-soft); background: var(--field-bg); }
.button:not(:disabled):hover { transform: translateY(-1px); }
.button.primary:not(:disabled):hover { background: var(--blue-strong); }
.button.secondary:not(:disabled):hover { border-color: var(--border); background: var(--blue-soft); }
.button:focus-visible { outline: 3px solid var(--blue-soft); outline-offset: 2px; }
.button:disabled { cursor: not-allowed; opacity: .42; }

.share-output { min-width: 0; margin-top: 10px; padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--green) 28%, transparent); border-radius: 11px; background: color-mix(in srgb, var(--green) 7%, transparent); }
.share-output span { display: block; margin-bottom: 3px; color: var(--green); font-size: 9px; font-weight: 700; }
.share-output a { display: block; overflow: hidden; color: var(--foreground); text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }

footer { padding: 0 20px 34px; color: var(--muted); text-align: center; font-size: 10px; }
footer span { padding: 0 5px; color: var(--border); }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 24px; max-width: min(420px, calc(100vw - 32px)); padding: 10px 14px; transform: translate(-50%, 18px); border: 1px solid var(--border-soft); border-radius: var(--radius-field); opacity: 0; pointer-events: none; color: var(--foreground); background: color-mix(in srgb, var(--page-surface) 94%, transparent); box-shadow: 0 20px 45px -25px rgba(15, 23, 42, .6); font-size: 11px; transition: opacity .18s, transform .18s; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

@media (prefers-color-scheme: dark) {
  :root {
    --background: #07111f;
    --page-surface: #0f172a;
    --foreground: #f8fafc;
    --muted: #94a3b8;
    --border: rgba(56, 189, 248, .24);
    --border-soft: rgba(148, 163, 184, .18);
    --blue: #38bdf8;
    --blue-strong: #0ea5e9;
    --blue-soft: rgba(56, 189, 248, .1);
    --field-bg: rgba(15, 23, 42, .64);
    --metric-bg: rgba(226, 232, 240, .055);
    --track: rgba(226, 232, 240, .09);
    --shadow-panel: 0 28px 74px -48px rgba(0, 0, 0, .8), inset 0 1px 0 rgba(255, 255, 255, .05);
  }
}

@media (max-width: 800px) {
  .intro { align-items: stretch; }
  .formula-chip { min-width: 235px; }
  .workspace { grid-template-columns: 1fr; align-items: start; }
}

@media (max-width: 720px) {
  .site-header, .app-shell { width: min(100% - 28px, 1024px); }
  .site-header { height: 62px; }
  .header-note { display: none; }
  .app-shell { padding: 36px 0 46px; }
  .intro { display: grid; gap: 20px; margin-bottom: 20px; }
  h1 { font-size: 34px; }
  .formula-chip { width: 100%; min-width: 0; }
  .panel, .value-card { min-width: 0; }
  .input-panel, .result-panel { padding: 18px; }
  #calculator { grid-template-columns: 1fr; }
  .field, .field.full, .amount-field { grid-column: 1; }
  .export-actions { grid-template-columns: 1fr 1fr; }
  .export-actions .primary { grid-column: 1 / -1; }
}

@media (max-width: 420px) {
  .site-header, .app-shell { width: min(100% - 22px, 1024px); }
  .input-panel, .result-panel { padding: 15px; border-radius: 17px; }
  .button { padding-inline: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
