:root {
  color-scheme: light;
  --bg: #f3f2ee;
  --surface: #fffcf7;
  --inset: #f7f5f0;
  --text: #201d18;
  --muted: #615c53;
  --edge: #ded9d0;
  --field-edge: #cec8bc;
  --selected: #fffcf7;
  --accent: #8b4b00;
  --accent-fill: #ffb750;
  --gain: #176043;
  --loss: #9a362e;
  --focus: #9a5505;
  --shadow: 0 12px 40px #36260f08;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111215;
  --surface: #1a1c21;
  --inset: #15171b;
  --text: #f6f2ea;
  --muted: #b0aea7;
  --edge: #34363c;
  --field-edge: #42454d;
  --selected: #2b2d34;
  --accent: #ffc26e;
  --accent-fill: #ffb750;
  --gain: #8bd8b3;
  --loss: #ffada3;
  --focus: #ffc26e;
  --shadow: 0 12px 40px #0002;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
p, h1, h2, dl, dd { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, summary:focus-visible, input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.app {
  max-width: 1000px;
  margin-inline: auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.app-bar, .brand, .theme-picker, .theme-picker button, .panel-head, summary {
  display: flex;
  align-items: center;
}
.app-bar { min-height: 52px; justify-content: space-between; gap: 8px; }
.brand { gap: 8px; font-size: 15px; font-weight: 750; letter-spacing: -0.025em; white-space: nowrap; }
.brand img { flex: none; }
.theme-picker { gap: 2px; padding: 2px; border-radius: 14px; border: 1px solid var(--edge); background: var(--inset); }
.theme-picker button {
  justify-content: center;
  min-height: 40px;
  gap: 4px;
  border: 0;
  border-radius: 10px;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 650;
}
.theme-picker button[aria-pressed="true"] { color: var(--text); background: var(--selected); box-shadow: 0 0 0 1px var(--edge); }
.theme-picker svg, .chevron { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.intro { display: grid; gap: 6px; padding-block: 20px 18px; }
.eyebrow { display: flex; gap: 7px; align-items: center; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: 0.055em; }
.eyebrow span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-fill); border: 1px solid var(--accent); }
.intro h1 { font-size: clamp(2rem, 7vw, 3.55rem); letter-spacing: -0.065em; line-height: 1.03; font-weight: 760; }
.intro > p:last-child { color: var(--muted); font-size: 14px; }

.dashboard { display: grid; grid-template-areas: "position" "result" "assumptions" "breakdown"; gap: 12px; align-items: start; }
.position { grid-area: position; }
.result { grid-area: result; }
.assumptions { grid-area: assumptions; }
.breakdown { grid-area: breakdown; }
.panel { min-width: 0; padding: 15px; border: 1px solid var(--edge); border-radius: 19px; background: var(--surface); box-shadow: var(--shadow); }
.panel h2, summary { font-weight: 720; font-size: 15px; letter-spacing: -0.018em; }
.panel-head { justify-content: space-between; gap: 8px; margin: -3px 0 9px; }
.reset { min-height: 40px; padding: 0 2px 0 8px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 650; }
.reset:hover { color: var(--text); }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 10px; }
.fields label { display: flex; flex-direction: column; gap: 6px; min-width: 0; justify-content: flex-end; color: var(--muted); font-size: 12px; font-weight: 650; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input {
  width: 100%;
  min-width: 0;
  min-height: 47px;
  padding: 9px 37px 9px 10px;
  border: 1px solid var(--field-edge);
  border-radius: 10px;
  background: var(--inset);
  color: var(--text);
  font-size: 16px;
  font-weight: 660;
  font-variant-numeric: tabular-nums;
}
.input-wrap input::placeholder { color: var(--muted); opacity: 1; font-weight: 500; }
.input-wrap input[aria-invalid="true"] { border-color: var(--loss); }
.input-wrap > span { position: absolute; right: 8px; pointer-events: none; color: var(--muted); font-size: 10px; white-space: nowrap; }

.result-top { display: grid; gap: 7px; }
.result-top h2, .small-label { color: var(--muted); font-size: 13px; font-weight: 650; }
.net { font-size: clamp(1.95rem, 7.1vw, 3.4rem); font-weight: 770; letter-spacing: -0.045em; line-height: 1; overflow-wrap: anywhere; }
.net[data-tone="gain"] { color: var(--gain); }
.net[data-tone="loss"] { color: var(--loss); }
.net, .liquidation-value, .distance, .result-context, .breakdown dd { font-variant-numeric: tabular-nums; }
.result-context { display: flex; flex-wrap: wrap; gap: 4px 9px; color: var(--muted); font-size: 11px; }
.result-context [data-value="total"]:not(:empty) { font-weight: 650; color: var(--text); }
.liquidation { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px; padding-block-start: 12px; margin-block-start: 13px; border-top: 1px solid var(--edge); }
.liquidation-value { margin-top: 4px; font-size: clamp(1.06rem, 4vw, 1.48rem); font-weight: 720; letter-spacing: -0.035em; overflow-wrap: anywhere; }
.distance { color: var(--accent); font-size: 12px; font-weight: 650; }
.notice { margin-top: 9px; color: var(--loss); font-size: 13px; font-weight: 650; }

.assumptions { padding-block: 0; }
summary { min-height: 65px; justify-content: space-between; gap: 6px; cursor: pointer; list-style: none; }
summary::-webkit-details-marker { display: none; }
.summary-hint, .field-note, .model-note { font-size: 12px; font-weight: 450; color: var(--muted); line-height: 1.5; }
.summary-hint { display: block; margin-top: 3px; }
.chevron { color: var(--muted); }
.assumptions[open] .chevron { transform: rotate(180deg); }
.assumptions-fields { margin: 0 0 10px; }
.field-note { margin-block-end: 14px; }
.breakdown dl { margin-top: 9px; font-size: 13px; }
.breakdown dl > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 9px; padding-block: 6px; }
.breakdown dt { color: var(--muted); }
.breakdown dd { font-weight: 680; text-align: right; max-width: 30ch; overflow-wrap: anywhere; }
.breakdown .subtotal { margin-top: 3px; padding-top: 9px; border-top: 1px solid var(--edge); }
.breakdown .subtotal dt { color: var(--text); font-weight: 670; }
.model-note { max-width: 72ch; padding: 14px 2px 0; }

@media (min-width: 660px) {
  .app { padding: 20px 24px 32px; }
  .intro { padding-block: 30px 24px; }
  .dashboard { grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr); grid-template-areas: "position result" "assumptions breakdown"; gap: 15px; }
  .panel { padding: 20px; }
  .position, .result { align-self: stretch; }
  .assumptions { padding-block: 0; }
  .fields { gap: 13px 12px; }
  .app-bar { min-height: 56px; }
  .brand { font-size: 17px; gap: 9px; }
  .theme-picker button { padding-inline: 12px; font-size: 13px; }
}
@media (pointer: coarse) {
  .theme-picker button, .reset { min-height: 44px; }
}
