:root {
  color-scheme: light;
  --bg: #fbf4e7;
  --panel: #fffaf0;
  --ink: #17201d;
  --muted: #4d5953;
  --line: #d9cfbd;
  --sky: #bdf3ed;
  --surface: #46645b;
  --layer-1: #8bc79a;
  --layer-2: #6fac70;
  --layer-3: #9b7a61;
  --red: #6d1d17;
  --magenta: #8d3a31;
  --blue: #355f65;
  --accent: #6d1d17;
  --accent-dark: #43130f;
  --shadow: 0 18px 45px rgba(55, 45, 30, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(109, 29, 23, 0.08), rgba(251, 244, 231, 0) 340px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.app-hero {
  background:
    linear-gradient(135deg, rgba(109, 29, 23, 0.10), rgba(109, 29, 23, 0) 48%),
    #fffdf8;
  border: 1px solid var(--line);
  border-top: 6px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.5rem, 4vw, 2.3rem) clamp(1.2rem, 4vw, 2.25rem);
}

.eyebrow {
  margin: 0 0 0.55rem;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.85rem, 4vw, 3.2rem);
  line-height: 1.02;
}

h2 {
  font-size: 1rem;
}

.header-actions,
.plot-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  min-width: 72px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 7px 20px rgba(24, 37, 33, 0.08);
  padding: 0 13px;
  font-size: 0.9rem;
  font-weight: 850;
}

.icon-button:focus-visible,
.toggle-button:focus-visible,
.segmented button:focus-visible {
  outline: 3px solid rgba(109, 29, 23, 0.28);
  outline-offset: 2px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.visual-stack {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel,
.controls-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 240, 0.94);
  box-shadow: var(--shadow);
}

.panel {
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 16px 11px;
  border-bottom: 1px solid var(--line);
}

.panel-header p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.readout-pill {
  min-width: max-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--accent-dark);
  background: #fffdf8;
  font-size: 0.82rem;
  font-weight: 800;
}

canvas {
  display: block;
  width: 100%;
  touch-action: none;
}

#modelCanvas {
  height: clamp(290px, 31vw, 390px);
}

#plotCanvas {
  height: clamp(430px, 44vw, 610px);
}

.controls-panel {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 15px;
  padding: 16px;
}

.control-group {
  display: grid;
  gap: 13px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

.control-group:last-of-type {
  padding-bottom: 0;
  border-bottom: 0;
}

.group-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.group-title span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.range-control {
  display: grid;
  gap: 8px;
}

.range-control > span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #36413d;
  font-size: 0.9rem;
  font-weight: 750;
}

output {
  color: var(--accent-dark);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f5ecdd;
}

.segmented button,
.toggle-button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #47534f;
  font-weight: 850;
}

.segmented button.is-active,
.toggle-button.is-active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 7px 15px rgba(109, 29, 23, 0.24);
}

.toggle-button {
  min-width: 74px;
  border: 1px solid var(--line);
  background: #fffdf8;
}

.check-control {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #36413d;
  font-size: 0.9rem;
  font-weight: 750;
}

.check-control input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

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

.stats-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fffdf8;
}

.stats-grid span,
.stats-grid strong {
  display: block;
  overflow-wrap: anywhere;
}

.stats-grid span {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stats-grid strong {
  color: var(--ink);
  font-size: 0.96rem;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1060px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .controls-panel {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
  }

  .stats-grid {
    grid-column: 1 / -1;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
  }

  .app-header,
  .panel-header {
    align-items: flex-start;
  }

  .app-header {
    gap: 10px;
  }

  .panel-header {
    flex-direction: column;
  }

  .plot-actions {
    width: 100%;
  }

  .toggle-button {
    flex: 1;
  }

  .controls-panel {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #modelCanvas {
    height: 320px;
  }

  #plotCanvas {
    height: 500px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-shell {
    padding: 0;
  }

  .controls-panel,
  .header-actions,
  .plot-actions {
    display: none;
  }

  .workspace {
    display: block;
  }

  .panel {
    margin-bottom: 12px;
    box-shadow: none;
    break-inside: avoid;
  }
}
