:root {
  --app-bg: #f5f4ef;
  --app-surface: #edeae1;
  --app-border: #d8d4c7;
  --app-ink: #1f2022;
  --app-muted: #6b6c70;

  --sim-canvas: #fbfaf7;
  --sim-border: #dcd8cc;
  --sim-ink: #1f2022;
  --sim-muted: #58595c;

  --sim-accent-bg: #cde1cd;
  --sim-accent-ink: #133d17;
  --sim-success-bg: #cde1cd;
  --sim-success-ink: #133d17;
  --sim-warning-bg: #e5dec4;
  --sim-warning-ink: #452e00;
  --sim-danger-bg: #e1cfce;
  --sim-danger-ink: #551f1d;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--app-bg);
  color: var(--app-ink);
  font-family: 'IBM Plex Sans', -apple-system, sans-serif;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
}

header.app-header {
  background: var(--app-surface);
  border-bottom: 1px solid var(--app-border);
  padding: 0 clamp(16px, 2.2vw, 36px);
  height: clamp(36px, 4vh, 46px);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-title {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: clamp(14px, 0.75vw + 0.3vh + 4.5px, 19px);
  font-weight: 600;
  letter-spacing: -0.01em;
}

main.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: clamp(260px, 13vw + 60px, 320px) 1fr;
  overflow: hidden;
}

aside.control-pane {
  background: var(--app-surface);
  border-right: 1px solid var(--app-border);
  padding: clamp(12px, 1.6vh, 22px) clamp(12px, 1.3vw, 22px);
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.4vh, 18px);
  overflow-y: auto;
}

.control-section {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 0.8vh, 10px);
}

.pane-divider {
  height: 1px;
  background: var(--app-border);
  opacity: 0.75;
  margin: 1px 0;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.1vh, 14px);
}

.slider-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.slider-row {
  display: flex;
  justify-content: space-between;
  font-size: clamp(11.5px, 0.4vw + 0.22vh + 4.2px, 13px);
  font-weight: 500;
}

.slider-val {
  color: var(--app-muted);
}

.mono {
  font-family: 'IBM Plex Sans', sans-serif;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 4px;
  background: var(--app-border);
  border-radius: 2px;
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: clamp(12px, 0.7vw + 4px, 15px);
  height: clamp(12px, 0.7vw + 4px, 15px);
  border-radius: 50%;
  background: var(--app-ink);
  cursor: pointer;
}

.vision-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(3px, 0.5vh, 6px);
}

button.mode-btn {
  background: var(--app-bg);
  border: 1px solid var(--app-border);
  color: var(--app-ink);
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: clamp(10.5px, 0.4vw + 0.18vh + 4.2px, 12px);
  font-weight: 500;
  padding: clamp(6px, 0.75vh, 9px) clamp(8px, 0.6vw, 12px);
  border-radius: 4px;
  text-align: left;
  cursor: pointer;
  transition: all 0.12s ease;
}

button.mode-btn:hover {
  border-color: var(--app-muted);
}

button.mode-btn.active {
  background: var(--app-ink);
  color: var(--app-bg);
  border-color: var(--app-ink);
}

button.mode-btn .mode-sub {
  display: block;
  font-size: clamp(9px, 0.35vw + 0.14vh + 3.8px, 10.5px);
  opacity: 0.65;
  font-family: 'IBM Plex Sans', sans-serif;
  margin-top: 1px;
}

.diag-card {
  background: var(--app-bg);
  border: 1px solid var(--app-border);
  border-radius: 4px;
  padding: clamp(8px, 1.1vh, 14px) clamp(10px, 0.8vw, 16px);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.diag-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: clamp(3px, 0.45vh, 5px) 0;
  border-bottom: 1px solid var(--app-border);
  font-size: clamp(11px, 0.4vw + 0.18vh + 4.2px, 12.5px);
}

.diag-row:last-child {
  border-bottom: none;
}

.metric-val {
  font-weight: 600;
  color: var(--app-ink);
  white-space: nowrap;
}

.metric-val.status-warn {
  color: #d97706;
  background: transparent;
  padding: 0;
}

section.paper-stage {
  background: var(--app-bg);
  padding: clamp(8px, 1.4vh, 24px) clamp(16px, 1.8vw, 40px);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

article.paper-sheet {
  background: var(--sim-canvas);
  border: 1px solid var(--sim-border);
  border-radius: 6px;
  width: 100%;
  max-width: min(1180px, 96%);
  margin: auto 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.03), 0 8px 24px -4px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  transition: background 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

header.paper-head {
  padding: clamp(10px, 1.4vh, 18px) clamp(18px, 2.2vw, 36px) clamp(6px, 0.9vh, 12px);
  border-bottom: 1px solid var(--sim-border);
  flex-shrink: 0;
  transition: border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.paper-title {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: clamp(18px, 0.8vw + 0.45vh + 5px, 25px);
  font-weight: 600;
  color: var(--sim-ink);
  letter-spacing: -0.015em;
  margin-bottom: 3px;
  transition: color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.paper-subtitle {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: clamp(11px, 0.3vw + 0.2vh + 4.5px, 13.5px);
  color: var(--sim-muted);
  line-height: 1.45;
  transition: color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.paper-body {
  padding: clamp(8px, 1.2vh, 18px) clamp(18px, 2.2vw, 36px);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.1vh, 14px);
}

.paper-body p {
  font-family: 'IBM Plex Sans', -apple-system, sans-serif;
  font-size: clamp(12.5px, 0.35vw + 0.35vh + 5.0px, 15px);
  line-height: clamp(1.44, 1.38 + 0.1vh, 1.54);
  color: var(--sim-ink);
  transition: color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.term {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.92em;
  background: rgba(127, 127, 127, 0.11);
  color: var(--sim-ink);
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 400;
  cursor: pointer;
  display: inline-block;
  line-height: 1.32;
  vertical-align: baseline;
  transition: background 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.term:hover,
.term.term-active {
  background: rgba(127, 127, 127, 0.22);
}

.tooltip-popover {
  position: fixed;
  z-index: 1000;
  width: clamp(320px, 25vw, 400px);
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06), 0 16px 36px -4px rgba(0, 0, 0, 0.12);
  padding: clamp(14px, 1.8vh, 20px) clamp(16px, 1.8vw, 22px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.22s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.tooltip-popover.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.tooltip-title {
  font-size: clamp(12.5px, 0.45vw + 0.25vh + 4.5px, 14px);
  font-weight: 400;
  color: var(--app-ink);
  font-family: 'IBM Plex Sans', sans-serif;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}

.tooltip-desc {
  font-size: clamp(11.5px, 0.38vw + 0.18vh + 4.5px, 13px);
  line-height: 1.58;
  color: var(--app-muted);
  font-family: 'IBM Plex Sans', sans-serif;
}

.paper-callout {
  font-family: 'IBM Plex Sans', sans-serif;
  background: var(--sim-accent-bg);
  color: var(--sim-accent-ink);
  border-left: 3.5px solid var(--sim-accent-ink);
  border-radius: 0 4px 4px 0;
  padding: clamp(8px, 1.1vh, 13px) clamp(12px, 1.2vw, 18px);
  font-size: clamp(12px, 0.35vw + 0.3vh + 4.8px, 14.5px);
  line-height: clamp(1.44, 1.38 + 0.1vh, 1.54);
  font-weight: 500;
  transition: background 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.paper-components {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: clamp(8px, 1.1vh, 14px);
  border-top: 1px solid var(--sim-border);
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 2px;
  transition: border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.comp-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-row {
  display: flex;
  gap: clamp(3px, 0.4vw, 6px);
  flex-wrap: wrap;
}

.spectrum-btn {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--sim-border);
  padding: clamp(3px, 0.4vh, 6px) clamp(7px, 0.6vw, 11px);
  border-radius: 3px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: clamp(9.5px, 0.38vw + 0.18vh + 4px, 11.5px);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.1s ease,
              box-shadow 0.15s ease;
}

.spectrum-btn:hover {
  transform: translateY(-1px);
}

.spectrum-btn.active {
  box-shadow: 0 0 0 1.5px var(--sim-ink);
  border-color: var(--sim-ink);
}

.comp-right {
  display: flex;
  gap: clamp(5px, 0.5vw, 9px);
  flex-shrink: 0;
}

.btn-action {
  background: var(--app-bg);
  color: var(--sim-ink);
  border: 1px solid var(--sim-border);
  padding: clamp(4px, 0.5vh, 7px) clamp(10px, 0.8vw, 16px);
  border-radius: 3px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: clamp(10px, 0.38vw + 0.18vh + 4px, 12px);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.2s ease;
}

.btn-action:hover {
  background: var(--app-surface);
  border-color: var(--app-muted);
}

.btn-action.btn-invert.active {
  background: rgba(127, 127, 127, 0.18);
  border-color: var(--sim-ink);
}

.paper-sheet.sheet-inverted {
  --sim-canvas: #222428;
  --sim-border: #363942;
  --sim-ink: #eae8e0;
  --sim-muted: #9da0aa;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2), 0 12px 32px -6px rgba(0, 0, 0, 0.35);
}

.paper-sheet.sheet-inverted .term {
  background: rgba(255, 255, 255, 0.13);
  color: #eae8e0;
}

.paper-sheet.sheet-inverted .term:hover,
.paper-sheet.sheet-inverted .term.term-active {
  background: rgba(255, 255, 255, 0.24);
}

.paper-sheet.sheet-inverted .btn-action {
  background: #2a2c32;
  color: #eae8e0;
  border-color: #424650;
}

.paper-sheet.sheet-inverted .btn-action:hover {
  background: #33363e;
  border-color: #585d6c;
}

.paper-sheet.sheet-inverted .btn-action.btn-invert.active {
  background: #3a3e49;
  border-color: #eae8e0;
  color: #ffffff;
}

footer.app-footer {
  background: var(--app-surface);
  border-top: 1px solid var(--app-border);
  padding: 0 clamp(16px, 2.2vw, 36px);
  height: clamp(26px, 3.2vh, 34px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: clamp(10px, 0.4vw + 0.18vh + 4px, 11.5px);
  color: var(--app-muted);
  flex-shrink: 0;
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-sep {
  opacity: 0.4;
  font-size: 8px;
}

footer.app-footer a {
  color: var(--app-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}

footer.app-footer a:hover {
  color: var(--app-ink);
  text-decoration: underline;
}

@media (max-width: 860px) {
  main.workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  aside.control-pane {
    border-right: none;
    border-bottom: 1px solid var(--app-border);
  }
}
