:root {
  --bg: #1b1f23;
  --panel: #22272c;
  --panel-border: #313941;
  --text: #dfe4e8;
  --text-dim: #8b95a1;
  --accent-design: #5b8aa6;
  --accent-operate: #e8a33d;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  padding: 32px 24px 48px;
}

.page-header {
  max-width: 1000px;
  margin: 0 auto 28px;
}

.page-header h1 {
  font-size: 1.8rem;
  font-weight: 600;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin: 0 0 12px;
}

.intro {
  color: var(--text);
  font-size: 1rem;
  line-height: 1.5;
  margin: 0 0 16px;
  max-width: 640px;
}

.advanced-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.advanced-toggle input {
  accent-color: var(--accent-operate);
  width: 19px;
  height: 19px;
  cursor: pointer;
}

.layout {
  max-width: 1000px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 24px;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 24px;
}

.panel h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  color: var(--accent-design);
  border: 1px solid var(--accent-design);
  border-radius: 3px;
  padding: 2px 6px;
}

.eyebrow-live {
  color: var(--accent-operate);
  border-color: var(--accent-operate);
}

.control {
  margin-bottom: 22px;
}

.control label {
  display: block;
  font-size: 0.92rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.control input[type="range"] {
  width: 100%;
  accent-color: var(--accent-design);
  height: 8px;
  border-radius: 4px;
  cursor: pointer;
}

.control input[type="range"]::-webkit-slider-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
}

.control input[type="range"]::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
}

.panel-operate .control input[type="range"] {
  accent-color: var(--accent-operate);
}

.control .value {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--text);
  margin-top: 6px;
}

.derived {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px dashed var(--panel-border);
  font-family: var(--mono);
  font-size: 0.9rem;
}

.derived > div {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.derived-label { color: var(--text-dim); }
.derived-value { color: var(--accent-design); }

.betz-note {
  color: var(--text-dim);
  font-size: 0.72rem;
  margin-top: 8px;
}

.viz {
  display: flex;
  justify-content: center;
  margin: 8px 0 18px;
}

#turbineCanvas {
  background: radial-gradient(circle at 50% 35%, #262c32 0%, #1e2327 70%);
  border-radius: 6px;
  border: 1px solid var(--panel-border);
}

.readout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.readout-item {
  background: #1e2327;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px 14px;
}

.readout-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.readout-value {
  font-family: var(--mono);
  font-size: 1.15rem;
  color: var(--text);
}

.readout-highlight {
  grid-column: 1 / -1;
  border-color: var(--accent-operate);
}

.readout-highlight .readout-value {
  color: var(--accent-operate);
  font-size: 1.5rem;
}

.readout-status {
  grid-column: 1 / -1;
}

.readout-status .readout-value {
  font-size: 1rem;
  color: var(--accent-design);
}

.page-footer {
  max-width: 1000px;
  margin: 24px auto 0;
}

.page-footer p {
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.55;
}

/* Material picker */
.material-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.material-btn {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--text-dim);
  background: #1e2327;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.material-btn:hover {
  color: var(--text);
  border-color: var(--accent-design);
}

.material-btn.active {
  color: var(--bg);
  background: var(--accent-design);
  border-color: var(--accent-design);
  font-weight: 600;
}

.material-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Stress bars */
.stress-panel {
  margin-top: 4px;
  margin-bottom: 22px;
}

.stress-row {
  margin-bottom: 12px;
}

.stress-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.stress-label {
  color: var(--text-dim);
}

.stress-value {
  font-family: var(--mono);
  color: var(--text);
}

.stress-track {
  height: 10px;
  border-radius: 5px;
  background: #1e2327;
  border: 1px solid var(--panel-border);
  overflow: hidden;
}

.stress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-design);
  transition: width 0.2s ease, background 0.2s ease;
}

.stress-fill.danger {
  background: #d9534f;
}

/* Failure overlay */
.failure-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 14, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
  z-index: 100;
}

.failure-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.failure-box {
  background: var(--panel);
  border: 1px solid #d9534f;
  border-radius: 10px;
  padding: 32px;
  max-width: 420px;
  text-align: center;
}

.failure-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.failure-box h2 {
  margin: 0 0 12px;
  color: #d9534f;
  font-size: 1.3rem;
}

.failure-box p {
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0 0 22px;
}

.failure-box button {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--bg);
  background: var(--accent-operate);
  border: none;
  border-radius: 6px;
  padding: 10px 24px;
  cursor: pointer;
}

.failure-box button:hover {
  filter: brightness(1.1);
}
