:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-strong: #eef2ec;
  --panel-bg: rgba(255, 255, 255, 0.72);
  --chart-bg: #fbfcfb;
  --card-muted: #f7f8f7;
  --ink: #17211d;
  --muted: #60706a;
  --line: #d8ded7;
  --line-strong: #bac6be;
  --grid: #e5eae4;
  --danger-bg: #fff6f7;
  --legend-bg: rgba(255, 255, 255, 0.78);
  --accent: #116a68;
  --accent-strong: #0b504e;
  --accent-soft: #d8eeee;
  --danger: #9f2f3c;
  --wash-a: rgba(17, 106, 104, 0.08);
  --wash-b: rgba(148, 91, 42, 0.08);
  --soft-shadow: 0 8px 24px rgba(23, 33, 29, 0.06);
  --swatch-ring: rgba(23, 33, 29, 0.08);
  --shadow: 0 18px 50px rgba(23, 33, 29, 0.1);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121713;
  --surface: #1b221e;
  --surface-strong: #232c27;
  --panel-bg: rgba(27, 34, 30, 0.82);
  --chart-bg: #151b18;
  --card-muted: #171d19;
  --ink: #edf3ee;
  --muted: #a9b8b0;
  --line: #344139;
  --line-strong: #4c5c53;
  --grid: #2a352f;
  --danger-bg: #2a171a;
  --legend-bg: rgba(27, 34, 30, 0.86);
  --accent: #4fb7b2;
  --accent-strong: #8bd8d4;
  --accent-soft: #173c3b;
  --danger: #f08b99;
  --wash-a: rgba(79, 183, 178, 0.12);
  --wash-b: rgba(188, 135, 74, 0.1);
  --soft-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
  --swatch-ring: rgba(237, 243, 238, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, var(--wash-a), transparent 38%),
    linear-gradient(315deg, var(--wash-b), transparent 40%),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="number"],
input[type="text"] {
  border: 1px solid var(--line);
  border-radius: 7px;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  width: min(1540px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  position: relative;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.brand-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  display: block;
  flex: 0 0 auto;
  border-radius: 10px;
  box-shadow: 0 5px 16px rgba(23, 33, 29, 0.14);
}

.brand-copy {
  min-width: 0;
}

.title-with-info {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-info {
  width: 24px;
  height: 24px;
  min-height: 24px;
  position: relative;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-color: var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 840;
}

.model-info::after {
  content: attr(data-tooltip);
  width: max-content;
  max-width: min(340px, calc(100vw - 32px));
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  right: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--soft-shadow);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 680;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-3px);
  transition:
    opacity 120ms ease,
    transform 120ms ease,
    visibility 120ms ease;
}

.model-info:hover::after,
.model-info:focus-visible::after,
.model-info[aria-expanded="true"]::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: none;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.8rem;
  line-height: 1.08;
  letter-spacing: 0;
}

.top-actions,
.command-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.command-row {
  min-height: 58px;
  margin-bottom: 16px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--soft-shadow);
}

.command-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 680;
}

.command-label {
  color: var(--muted);
  font-weight: 760;
  white-space: nowrap;
}

.optimize-row {
  align-items: center;
}

.command-divider {
  width: 1px;
  height: 32px;
  background: var(--line);
}

.frequency-slider {
  flex: 1 1 300px;
  max-width: 560px;
}

.frequency-input {
  width: 118px;
}

.optimize-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.optimizer-visibility {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: var(--muted);
  font-weight: 760;
}

.room-modes-panel {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--soft-shadow);
}

.room-mode-select label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 760;
}

.room-mode-select select {
  width: 100%;
}

.room-dimension-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.room-dimension-field {
  display: grid;
  gap: 8px;
}

.room-dimension-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  min-height: 28px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 780;
  text-align: left;
}

.room-dimension-toggle[aria-pressed="false"] {
  opacity: 0.5;
}

.room-dimension-toggle[aria-pressed="false"] .room-swatch {
  background: transparent !important;
  box-shadow:
    inset 0 0 0 2px currentColor,
    0 0 0 3px var(--swatch-ring);
}

.room-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--swatch-ring);
}

.room-dimension-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
  align-items: center;
}

.room-harmonic-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
}

.room-harmonic-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  min-height: 26px;
}

.room-harmonic-buttons .room-harmonic-button {
  min-width: 0;
  min-height: 26px;
  padding: 0 6px;
  font-size: 0.78rem;
}

.room-harmonic-buttons .room-harmonic-button.is-hidden {
  visibility: hidden;
  pointer-events: none;
}

select,
input[type="number"],
input[type="text"] {
  min-height: 38px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 10px;
}

select {
  min-width: 170px;
}

.primary-button,
.secondary-button,
.quiet-button,
.danger-button,
.icon-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  font-weight: 760;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.secondary-button,
.quiet-button,
.icon-button {
  background: var(--surface);
  color: var(--ink);
}

.danger-button {
  border-color: rgba(159, 47, 60, 0.35);
  background: var(--danger-bg);
  color: var(--danger);
}

.icon-button {
  min-width: 70px;
  padding: 0;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
}

button:not(:disabled):active {
  transform: translateY(0);
}

.switch-control {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 760;
  cursor: pointer;
  user-select: none;
}

.switch-control input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  width: 42px;
  height: 24px;
  position: relative;
  border-radius: 999px;
  background: #cbd4ce;
  transition: background 160ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(23, 33, 29, 0.3);
  transition: transform 160ms ease;
}

.switch-control input:checked + .switch-track {
  background: var(--accent);
}

.switch-control input:checked + .switch-track::after {
  transform: translateX(18px);
}

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

.chart-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
}

.chart-panel {
  min-height: 670px;
  padding: 12px;
  position: sticky;
  top: 18px;
}

#chart {
  width: 100%;
  height: 640px;
}

.chart-footer {
  min-height: 46px;
  display: grid;
  gap: 8px;
  padding: 0 6px 8px;
}

.chart-summary-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.graph-incidence-control {
  flex: 0 0 auto;
}

.temperature-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 760;
  white-space: nowrap;
}

.temperature-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.temperature-field input {
  width: 68px;
}

.chart-status {
  min-width: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 680;
}

.control-panel {
  padding: 0;
}

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

.panel-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.setup-title {
  align-items: flex-start;
  flex-direction: column;
  gap: 4px;
}

.setup-info {
  display: grid;
  gap: 2px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-actions select {
  min-width: 190px;
}

.panel-heading h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

#absorberCount {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

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

.absorber-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.absorber-header {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.trace-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--swatch-ring);
}

.absorber-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sbir-card-title-row {
  justify-content: space-between;
  min-width: 0;
}

.absorber-card[data-enabled="false"] .absorber-body {
  opacity: 0.55;
}

.absorber-title-row input[type="text"] {
  width: 100%;
  min-width: 0;
  font-weight: 800;
}

.absorber-actions {
  grid-column: 2;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 9px;
}

.absorber-body {
  display: grid;
  gap: 14px;
  padding: 14px 12px 15px;
}

.slider-field {
  display: grid;
  gap: 8px;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 780;
}

.slider-label strong {
  color: var(--ink);
  font-weight: 840;
}

.slider-control-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 10px;
  align-items: center;
}

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

input[type="number"] {
  width: 112px;
}

.empty-state {
  min-height: 170px;
  display: grid;
  place-items: center;
  padding: 22px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  font-weight: 720;
}

@media (max-width: 1040px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .room-modes-panel {
    grid-template-columns: 1fr;
  }

  .room-modes-panel[data-room-modes-enabled="false"] {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100vw - 20px, 1540px);
    padding-top: 14px;
  }

  h1 {
    font-size: 1.55rem;
    line-height: 1.02;
  }

  .brand-lockup {
    align-items: flex-start;
    gap: 10px;
  }

  .brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 9px;
  }

  .top-actions,
  .command-row {
    width: 100%;
  }

  .top-actions > *,
  .command-row label,
  .command-row button,
  .command-label,
  .command-divider,
  .frequency-slider,
  .frequency-input,
  .optimize-buttons,
  .optimizer-visibility {
    width: 100%;
  }

  .command-row label {
    align-items: flex-start;
    flex-direction: column;
  }

  .switch-control {
    justify-content: flex-start;
  }

  .command-row .switch-control {
    align-items: center;
    flex-direction: row;
  }

  select {
    width: 100%;
  }

  .optimize-buttons {
    display: grid;
    grid-template-columns: 1fr;
  }

  .optimizer-visibility {
    margin-left: 0;
  }

  .command-divider {
    height: 1px;
  }

  .room-dimension-list {
    grid-template-columns: 1fr;
  }

  .room-dimension-controls,
  .room-harmonic-row {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    min-height: 460px;
    padding: 8px;
  }

  #chart {
    height: 440px;
  }

  .chart-footer {
    padding: 0 2px 6px;
  }

  .chart-summary-row {
    align-items: stretch;
    flex-direction: column;
  }

  .graph-incidence-control,
  .temperature-control {
    width: 100%;
  }

  .temperature-control {
    justify-content: space-between;
  }

  .temperature-field {
    flex: 1;
    justify-content: space-between;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .panel-actions select {
    width: 100%;
  }

  .absorber-title-row {
    align-items: stretch;
    flex-direction: column;
  }

  .slider-control-row {
    grid-template-columns: 1fr;
  }

  input[type="number"] {
    width: 100%;
  }
}
