:root {
  color-scheme: dark;
  --ink: #111111;
  --paper: #fff8df;
  --paper-2: #f8efd0;
  --line: #2a2924;
  --muted: #8d866f;
  --red: #ff3b30;
  --red-dark: #bd1f17;
  --yellow: #ffd43b;
  --cyan: #24c6b7;
  --green: #6ddc8f;
  --pink: #ff4d8d;
  --white: #ffffff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--ink);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--paper);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px) 0 0 / 28px 28px,
    var(--ink);
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--yellow);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px 24px;
  border-bottom: 3px solid var(--line);
  background: rgba(17, 17, 17, 0.92);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--paper);
  text-decoration: none;
  font-weight: 900;
}

.brand-mark {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 3px solid var(--paper);
  border-radius: 6px;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 5px 5px 0 var(--red);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-button,
.preset {
  border: 2px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--red);
  font-weight: 900;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease;
}

.icon-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
}

.icon-button.compact {
  min-height: 36px;
  padding: 0 11px;
  font-size: 0.9rem;
}

.icon-button.ghost {
  background: var(--paper);
  box-shadow: 4px 4px 0 var(--cyan);
}

.icon-button:hover,
.preset:hover {
  transform: translate(-1px, -1px);
  box-shadow: 6px 6px 0 var(--red);
}

.icon-button:active,
.preset:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--red);
}

main {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 24px 52px;
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
  gap: 20px;
  align-items: stretch;
}

.result-stage,
.control-panel,
.scenario-panel,
.analysis-panel,
.assumption-band {
  max-width: 100%;
  min-width: 0;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.result-stage {
  position: relative;
  overflow: hidden;
  min-height: 520px;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 248, 223, 0.94)),
    var(--paper);
}

.result-stage::after {
  content: none;
}

.ticker {
  position: relative;
  z-index: 1;
  display: grid;
  min-width: 0;
  min-height: 74px;
  align-content: center;
  gap: 7px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--paper);
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0 8px, transparent 8px 16px),
    var(--red-dark);
}

.ticker > span {
  line-height: 1;
  font-size: 0.86rem;
  font-weight: 800;
}

.ticker strong {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-width: 0;
  max-width: 100%;
  font-size: 1.05rem;
  line-height: 1.35;
  text-align: left;
}

.scenario-token {
  white-space: nowrap;
  font-weight: 900;
}

.scenario-token + .scenario-token::before {
  content: "+ ";
}

.judgement {
  position: relative;
  z-index: 1;
  padding: 38px 0 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--red-dark);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.judgement h1 {
  display: grid;
  gap: 4px;
  margin: 0;
  font-size: 3.6rem;
  line-height: 1;
}

.judgement h1 > span:first-child {
  color: var(--ink);
  font-size: 1.35rem;
}

.damage-number {
  overflow-wrap: anywhere;
  color: var(--red);
  text-shadow: 4px 4px 0 var(--yellow);
}

.verdict {
  max-width: 680px;
  margin: 22px 0 0;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.metrics-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.metric-card {
  display: grid;
  min-height: 126px;
  gap: 10px;
  align-content: center;
  border: 3px solid var(--ink);
  border-radius: 8px;
  padding: 14px;
  background: var(--ink);
  color: var(--paper);
}

.metric-card span,
.metric-card small {
  color: #d8cfac;
  font-weight: 800;
}

.metric-card strong {
  color: var(--yellow);
  font-size: 1.38rem;
  overflow-wrap: anywhere;
}

.control-panel {
  padding: 18px;
}

.control-panel,
.assumption-band {
  box-shadow: none;
}

.panel-heading,
.impact-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-heading h2,
.impact-header h2,
.assumption-band h2 {
  margin: 0;
  font-size: 1.35rem;
}

.input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 900;
}

label > span,
.slider-row strong {
  color: #332f26;
  font-size: 0.9rem;
}

.unit-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fffdf2;
  overflow: hidden;
}

.unit-input input {
  width: 100%;
  min-width: 0;
  height: 46px;
  border: 0;
  padding: 0 11px;
  color: var(--ink);
  background: transparent;
  font-weight: 900;
  outline: none;
}

.unit-input span {
  display: inline-flex;
  height: 100%;
  align-items: center;
  border-left: 2px solid var(--line);
  padding: 0 10px;
  background: var(--paper-2);
  color: #625a47;
  font-size: 0.86rem;
  font-weight: 900;
  white-space: nowrap;
}

.preset-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.preset {
  display: grid;
  min-height: 82px;
  align-content: center;
  gap: 4px;
  padding: 12px;
  text-align: left;
}

.preset span {
  color: #5b2a24;
  font-size: 0.82rem;
}

.preset strong {
  font-size: 1rem;
}

.preset.active {
  background: var(--red);
  color: var(--white);
  box-shadow: 4px 4px 0 var(--yellow);
}

.preset.active span {
  color: #ffe2d7;
}

.scenario-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.92fr) minmax(0, 1.08fr);
  gap: 20px;
}

.hero-grid > *,
.scenario-layout > * {
  min-width: 0;
}

.scenario-panel,
.analysis-panel {
  padding: 18px;
}

.switch-list {
  display: grid;
  gap: 12px;
}

.switch-row {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  min-height: 74px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffdf2;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-ui {
  position: relative;
  display: inline-block;
  width: 58px;
  height: 34px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #d9cfab;
  transition: background 140ms ease;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 3px;
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  transform: translateY(-50%);
  transition: transform 140ms ease;
}

.switch-row input:checked + .switch-ui {
  background: var(--red);
}

.switch-row input:checked + .switch-ui::after {
  transform: translate(22px, -50%);
  background: var(--yellow);
}

.switch-row strong {
  display: block;
  margin-bottom: 4px;
}

.switch-row small,
.slider-row small {
  display: block;
  color: #625a47;
  font-weight: 800;
  line-height: 1.35;
}

.scenario-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition:
    max-height 180ms ease,
    opacity 180ms ease;
}

.scenario-options.single {
  grid-template-columns: minmax(0, 1fr);
}

.scenario-options.open {
  max-height: 180px;
  opacity: 1;
}

.slider-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 10px;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffdf2;
}

.slider-row input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--red);
}

.slider-row output {
  justify-self: end;
  border: 2px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--paper);
  background: var(--ink);
  font-weight: 900;
}

.impact-header {
  align-items: center;
}

.bar-list {
  display: grid;
  gap: 10px;
}

.impact-bar {
  display: grid;
  gap: 7px;
}

.impact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  font-weight: 900;
}

.impact-row span {
  overflow-wrap: anywhere;
}

.bar-track {
  position: relative;
  height: 28px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 6px;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.08) 0 8px, transparent 8px 16px),
    #efe5bf;
}

.bar-fill {
  width: var(--bar-width, 0%);
  height: 100%;
  border-right: 2px solid var(--line);
  background: var(--bar-color, var(--red));
}

.assumption-band {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 20px;
  margin-top: 20px;
  padding: 18px;
}

.assumption-band ul {
  margin: 0;
  padding-left: 18px;
  color: #3e392e;
  font-weight: 800;
  line-height: 1.65;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  transform: translateY(24px);
  opacity: 0;
  border: 3px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
  color: var(--ink);
  background: var(--green);
  box-shadow: 5px 5px 0 var(--ink);
  font-weight: 900;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  pointer-events: none;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1080px) {
  .hero-grid,
  .scenario-layout,
  .assumption-band {
    grid-template-columns: 1fr;
  }

  .result-stage {
    min-height: auto;
  }

  .judgement h1 {
    font-size: 3rem;
  }
}

@media (max-width: 760px) {
  .topbar {
    position: static;
    align-items: flex-start;
    padding: 14px;
  }

  .topbar,
  .topbar-actions {
    flex-direction: column;
  }

  .topbar-actions,
  .icon-button.ghost {
    width: 100%;
  }

  main {
    max-width: 100vw;
    padding: 16px 12px 36px;
    overflow: hidden;
  }

  .hero-grid,
  .scenario-layout,
  .assumption-band {
    display: block;
  }

  .hero-grid > * + *,
  .scenario-layout > * + * {
    margin-top: 20px;
  }

  .result-stage,
  .control-panel,
  .scenario-panel,
  .analysis-panel,
  .assumption-band {
    border-width: 2px;
  }

  .result-stage {
    padding: 18px 10px;
  }

  .judgement,
  .metrics-grid,
  .metric-card,
  .control-panel,
  .scenario-panel,
  .analysis-panel,
  .assumption-band {
    width: 100%;
    min-width: 0;
  }

  .ticker {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding: 10px 12px;
  }

  .ticker strong {
    font-size: 0.95rem;
    line-height: 1.4;
    text-align: left;
  }

  .input-grid,
  .metrics-grid,
  .preset-strip,
  .scenario-options {
    grid-template-columns: 1fr;
  }

  .judgement h1 {
    font-size: 2.25rem;
  }

  .damage-number {
    font-size: clamp(2rem, 16vw, 3.1rem);
  }

  .verdict {
    font-size: 1.02rem;
    overflow-wrap: anywhere;
  }

  .metric-card {
    min-height: 114px;
  }

  .metric-card strong {
    font-size: clamp(1.2rem, 7vw, 1.7rem);
  }

  .impact-header,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}
