:root {
  --bg: #081019;
  --bg-alt: #0f1824;
  --panel: rgba(15, 24, 36, 0.92);
  --panel-soft: rgba(20, 33, 48, 0.88);
  --line: rgba(140, 163, 193, 0.26);
  --line-strong: rgba(175, 202, 230, 0.42);
  --text: #eff6ff;
  --muted: #9eb1c9;
  --accent: #ff8f3f;
  --accent-soft: rgba(255, 143, 63, 0.22);
  --success: #56d36f;
  --support: #56d36f;
  --load: #ffb84f;
  --hover: #5bb9ff;
  --shadow: 0 20px 60px rgba(1, 7, 14, 0.45);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Fira Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(255, 143, 63, 0.15), transparent 22%),
    radial-gradient(circle at bottom left, rgba(91, 185, 255, 0.16), transparent 24%),
    linear-gradient(145deg, #060c14, #0d1622 42%, #101a27);
}

body {
  min-height: 100vh;
}

.app-shell {
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(8, 16, 25, 0.96), rgba(12, 20, 31, 0.9));
  padding: 24px 20px 28px;
  overflow-y: auto;
  backdrop-filter: blur(10px);
}

.workspace {
  padding: 22px 22px 28px;
  display: grid;
  grid-template-rows: auto minmax(440px, 1fr) auto;
  gap: 18px;
}

.brand-block {
  margin-bottom: 14px;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2vw, 1.8rem);
  line-height: 1.05;
}

.panel,
.viewport-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(18, 30, 45, 0.95), rgba(13, 22, 33, 0.9));
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 1rem;
}

.field,
.direction-panel {
  display: block;
  margin-bottom: 12px;
}

.field > span,
.field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}

.field input,
.field select,
.file-input span {
  width: 100%;
}

input,
select,
button,
a {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(4, 11, 19, 0.65);
  color: var(--text);
  padding: 11px 12px;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid rgba(255, 143, 63, 0.65);
  outline-offset: 2px;
}

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

.file-input {
  display: block;
  border: 1px dashed rgba(255, 143, 63, 0.55);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 143, 63, 0.08);
}

.file-input input {
  margin-top: 10px;
  border: none;
  background: transparent;
  padding: 0;
}

.hint,
.selection-summary,
.contour-range {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.selection-summary {
  margin-top: 10px;
}

.mode-buttons,
.direction-buttons,
.toggle-row,
.report-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-button,
.toggle-button,
.direction-button,
.secondary-button,
.primary-button {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(8, 15, 24, 0.8);
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.mode-button:hover,
.toggle-button:hover,
.direction-button:hover,
.secondary-button:hover,
.primary-button:hover,
.report-link:hover {
  transform: translateY(-1px);
}

.mode-button.is-active,
.toggle-button.is-active {
  background: rgba(255, 143, 63, 0.18);
  border-color: rgba(255, 143, 63, 0.72);
}

.primary-button {
  width: 100%;
  justify-content: center;
  background: linear-gradient(135deg, rgba(255, 143, 63, 0.24), rgba(255, 181, 79, 0.26));
  border-color: rgba(255, 181, 79, 0.75);
  font-weight: 700;
}

.secondary-button {
  padding: 8px 12px;
  font-size: 0.82rem;
  background: rgba(12, 20, 31, 0.88);
}

#run-high-quality {
  width: 100%;
  margin-top: 10px;
  border-color: rgba(91, 185, 255, 0.42);
  background: rgba(91, 185, 255, 0.1);
  color: #d7ecff;
}

#reset-simulation {
  width: 100%;
  margin-top: 10px;
}

.wide-button {
  width: 100%;
}

.primary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.secondary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.region-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.region-item {
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(140, 163, 193, 0.18);
  background: rgba(4, 10, 16, 0.5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.region-item strong {
  margin: 0;
  font-size: 0.9rem;
  text-align: right;
}

.region-item span {
  color: var(--muted);
  font-size: 0.82rem;
}

.region-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.badge {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-support {
  background: rgba(86, 211, 111, 0.18);
  color: #8df4a0;
}

.badge-load {
  background: rgba(255, 184, 79, 0.18);
  color: #ffd08c;
}

.workspace-header {
  display: flex;
  justify-content: flex-end;
  gap: 18px;
  align-items: center;
}

.status-pill {
  border-radius: 999px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 143, 63, 0.45);
  background: rgba(255, 143, 63, 0.14);
  color: #ffd7b3;
  min-width: 110px;
  text-align: center;
}

.viewport-card {
  position: relative;
  overflow: hidden;
  min-height: 460px;
}

#viewer {
  width: 100%;
  height: 100%;
  min-height: 460px;
}

.viewer-overlay {
  position: absolute;
  left: 18px;
  top: 18px;
  max-width: 240px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(7, 13, 21, 0.76);
  border: 1px solid rgba(140, 163, 193, 0.2);
  color: var(--muted);
  backdrop-filter: blur(8px);
}

.results-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: 18px;
}

.persistent-panel {
  grid-column: 1 / -1;
}

.panel-header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-header-row h2 {
  margin-bottom: 0;
}

.progress-card {
  border-radius: 14px;
  padding: 14px;
  border: 1px solid rgba(140, 163, 193, 0.16);
  background: rgba(4, 10, 16, 0.5);
  margin-bottom: 12px;
}

.progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(10, 19, 29, 0.9);
  border: 1px solid rgba(140, 163, 193, 0.12);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3c7dff, #46d68b 48%, #ffd34d 76%, #ff684d);
  transition: width 180ms ease;
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: baseline;
  margin-top: 10px;
  flex-wrap: wrap;
}

.progress-copy strong {
  font-size: 0.96rem;
}

.progress-copy span {
  color: var(--muted);
  font-size: 0.88rem;
}

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

.persistent-item {
  border-radius: 14px;
  padding: 12px;
  border: 1px solid rgba(140, 163, 193, 0.16);
  background: rgba(4, 10, 16, 0.56);
}

.persistent-topline,
.persistent-meta,
.persistent-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.persistent-topline strong {
  font-size: 0.96rem;
}

.persistent-status {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border: 1px solid rgba(140, 163, 193, 0.2);
  background: rgba(12, 20, 31, 0.88);
}

.persistent-status.is-completed {
  color: #9ef3b6;
  border-color: rgba(86, 211, 111, 0.35);
  background: rgba(86, 211, 111, 0.12);
}

.persistent-status.is-running {
  color: #ffe4a8;
  border-color: rgba(255, 184, 79, 0.35);
  background: rgba(255, 184, 79, 0.12);
}

.persistent-status.is-failed {
  color: #ffd0d0;
  border-color: rgba(255, 106, 106, 0.35);
  background: rgba(255, 106, 106, 0.12);
}

.persistent-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.persistent-actions {
  margin-top: 10px;
}

.persistent-actions button {
  min-width: 88px;
}

.persistent-empty {
  color: var(--muted);
  padding: 10px 0 4px;
}

.metric-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric-card {
  border-radius: 14px;
  padding: 14px;
  border: 1px solid rgba(140, 163, 193, 0.16);
  background: rgba(4, 10, 16, 0.5);
}

.metric-label {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
  font-size: 0.82rem;
}

.metric-card strong {
  font-size: 1.1rem;
}

.setup-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(140, 163, 193, 0.12);
}

.setup-block h3 {
  margin: 0;
  font-size: 0.98rem;
}

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

.setup-item,
.setup-empty {
  border-radius: 14px;
  padding: 12px;
  border: 1px solid rgba(140, 163, 193, 0.16);
  background: rgba(4, 10, 16, 0.5);
}

.setup-item span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 6px;
}

.setup-item strong {
  display: block;
  font-size: 0.95rem;
  line-height: 1.35;
  word-break: break-word;
}

.setup-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.section-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(140, 163, 193, 0.12);
}

.section-grid {
  align-items: end;
}

.section-flip-row {
  margin-bottom: 0;
  min-height: 46px;
}

#section-readout {
  margin-top: 8px;
}

.checkbox-row {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  margin-bottom: 10px;
}

.checkbox-row input {
  width: auto;
}

.report-link {
  text-decoration: none;
  color: #ffd7b3;
  border: 1px solid rgba(255, 143, 63, 0.4);
  border-radius: 999px;
  padding: 10px 13px;
  background: rgba(255, 143, 63, 0.1);
}

.report-link.disabled {
  opacity: 0.4;
  pointer-events: none;
}

code {
  font-family: "Consolas", "SFMono-Regular", monospace;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

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

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

@media (max-width: 760px) {
  .workspace {
    padding: 16px;
  }

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

  .field-grid,
  .metric-cards {
    grid-template-columns: 1fr;
  }

  .viewport-card,
  #viewer {
    min-height: 360px;
  }
}
