:root {
  --sb-w: 210px;
  --sb-bg: #1e293b;
  --primary: #2563eb;
  --bg: #f1f5f9;
  --card: #fff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --radius: 8px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
       background: var(--bg); color: var(--text); }

/* ── Layout ── */
.app { display: flex; height: 100vh; height: 100dvh; }

/* ── Sidebar ── */
.sb {
  width: var(--sb-w); background: var(--sb-bg);
  display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.sb-brand {
  padding: 1.1rem 1rem .9rem;
  border-bottom: 1px solid #334155;
}
.sb-brand h2 { color: #f1f5f9; font-size: .95rem; font-weight: 700; }
.sb-brand p  { color: #64748b;  font-size: .72rem; margin-top: .15rem; }

.sb-nav { padding: .85rem .65rem; flex: 1; }
.sb-group-lbl {
  font-size: .65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: #475569;
  padding: .4rem .5rem .3rem;
}
.nav-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .5rem .7rem; border-radius: 6px;
  font-size: .84rem; color: #94a3b8;
  cursor: pointer; transition: background .12s, color .12s;
  user-select: none;
}
.nav-item:hover { background: #263446; color: #cbd5e1; }
.nav-item.active { background: var(--primary); color: #fff; }

.sb-footer {
  padding: .65rem 1rem;
  border-top: 1px solid #334155;
  font-size: .7rem; color: #475569;
}

/* ── Main ── */
.main {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 1.1rem 1.1rem max(6rem, calc(env(safe-area-inset-bottom) + 6rem)); display: flex; flex-direction: column; gap: 1rem;
}

/* ── Cards ── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.15rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card-title {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted);
  margin-bottom: .85rem; padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

/* ── Settings card ── */
.settings-bar { display: flex; flex-wrap: wrap; gap: 1.4rem; align-items: flex-start; }
.sgroup { display: flex; flex-direction: column; gap: .45rem; }
.sgroup-lbl { font-size: .75rem; font-weight: 600; color: var(--muted); margin-bottom: .1rem; }

/* ── Field rows ── */
.fields { display: flex; flex-direction: column; gap: .5rem; }
.frow { display: flex; align-items: center; gap: .45rem; }
.flbl {
  min-width: 34px; display: flex; align-items: center; justify-content: flex-end;
  font-size: .95rem;
}
.feq { color: var(--muted); font-size: .95rem; }
.finput {
  width: 105px; border: 1px solid var(--border); border-radius: 5px;
  padding: .38rem .5rem; font-size: .9rem; color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.finput:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.finput.invalid { border-color: #f87171; }
.funit-wrap {
  position: relative; display: inline-flex; align-items: center;
}
.funit-disp {
  border: 1px solid var(--border); border-radius: 5px;
  padding: .18rem .5rem; background: #f8fafc;
  min-width: 54px; text-align: center;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none; line-height: 1;
}
.funit-overlay {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0; cursor: pointer; z-index: 1;
}
.funit-overlay:focus + .funit-disp,
.funit-wrap:focus-within .funit-disp {
  border-color: var(--primary);
}

/* ── Kappa row ── */
.krow { display: flex; align-items: center; gap: .45rem; }
.kinput {
  width: 72px; border: 1px solid var(--border); border-radius: 5px;
  padding: .38rem .5rem; font-size: .9rem; color: var(--text); outline: none;
}
.kinput:focus { border-color: var(--primary); }
.khint { font-size: .75rem; color: var(--muted); }

/* ── Proc select ── */
.proc-sel {
  border: 1px solid var(--border); border-radius: 5px;
  padding: .38rem .5rem; font-size: .85rem; color: var(--text);
  background: #fff; outline: none; min-width: 215px; cursor: pointer;
}
.proc-sel:focus { border-color: var(--primary); }

.proc-eq {
  display: inline-flex; align-items: center; gap: .4rem;
  margin-top: .4rem; padding: .28rem .55rem;
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 4px; font-size: .85rem;
}
.pdot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.poly-row { display: flex; align-items: center; gap: .45rem; margin-top: .3rem; }

/* ── Two-col grid ── */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media(max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

/* ── Diagrams ── */
.diag-title { font-weight: 700; font-size: .95rem; text-align: center; margin-bottom: .65rem; }
.diag-wrap { position: relative; }
canvas { display: block; width: 100%; aspect-ratio: 4/3;
         border: 1px solid var(--border); border-radius: 4px; }

.legend { display: flex; justify-content: center; margin-top: .55rem; }
.leg-item { display: flex; align-items: center; gap: .35rem; font-size: .78rem; color: var(--muted); }
.leg-line { width: 22px; height: 3px; border-radius: 2px; }

.work-ctrl-lbl { font-size: .78rem; color: var(--muted); font-weight: 600; }
.work-cb-lbl { display: flex; align-items: center; gap: .28rem; font-size: .78rem; cursor: pointer; white-space: nowrap; }
.work-cb-lbl.work-cb-total { font-weight: 600; border-left: 1px solid var(--border); padding-left: .7rem; }

.tt {
  position: absolute; background: rgba(15,23,42,.88); color: #fff;
  padding: .25rem .48rem; border-radius: 4px; font-size: .74rem;
  pointer-events: none; display: none; white-space: nowrap; z-index: 10;
}

/* ── Auto-calculated (p·v=R·T) ── */
.finput[data-auto="calc"] {
  background: #eff6ff; color: #1d4ed8;
  border-color: #bfdbfe; font-style: italic;
}
/* ── Propagated from other state ── */
.finput[data-auto="prop"] {
  background: #f0fdf4; color: #15803d;
  border-color: #86efac; font-style: italic;
}

/* ── Berechnung view ── */
.bc-grid {
  display: grid;
  grid-template-columns: max-content max-content 105px max-content auto;
  column-gap: .45rem; row-gap: .55rem;
  align-items: center;
}
.bc-field { display: contents; }
.bc-unk-lbl {
  display: flex; align-items: center; gap: .3rem;
  font-size: .78rem; color: var(--muted);
  cursor: pointer; margin-left: .4rem; user-select: none;
}
.bc-unk-lbl input[type="checkbox"] { cursor: pointer; }
.finput:disabled { cursor: not-allowed; opacity: .7; }
.finput[readonly],
.kinput[readonly] { background: #f8fafc; cursor: default; color: var(--muted); }

/* ── Zustandsänderung view ── */
.za-grid {
  display: grid;
  grid-template-columns: max-content max-content 105px max-content;
  column-gap: .45rem; row-gap: .55rem;
  align-items: center;
}
.za-grid-5 {
  display: grid;
  grid-template-columns: max-content max-content 105px max-content auto;
  column-gap: .45rem; row-gap: .55rem;
  align-items: center;
}
.za-grid-6 {
  display: grid;
  grid-template-columns: max-content max-content 105px max-content max-content auto;
  column-gap: .45rem; row-gap: .55rem;
  align-items: center;
}
.za-ratio-sel {
  font-size: .72rem; padding: .1rem .25rem;
  border: 1px solid var(--border); border-radius: 4px;
  background: #f8fafc; color: var(--text); cursor: pointer;
}
.za-field { display: contents; }

.za-process-sketch {
  margin: .85rem 0 1rem;
  display: none;
}
.za-process-sketch.is-visible {
  display: flex;
  justify-content: center;
}
.za-sketch-panel {
  width: min(100%, 700px);
  padding: .75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.za-sketch-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
}
.za-sketch-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .35rem;
}
.za-sketch-sub {
  font-size: .74rem;
  color: var(--muted);
  margin-bottom: .35rem;
}
.za-sketch-play {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--primary);
  font-size: .82rem;
  line-height: 1;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.za-sketch-play:hover {
  background: #eff6ff;
  border-color: #bfdbfe;
}
.za-sketch-controls {
  display: inline-flex;
  gap: .4rem;
}
.za-motor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(200px, .75fr);
  align-items: start;
  gap: 1rem;
}
.za-cycle-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(220px, .8fr);
  align-items: center;
  gap: 1rem;
}
.za-cycle-graphic,
.za-cycle-info {
  min-width: 0;
}
.za-cycle-info {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  padding: .2rem 0;
}
.za-cycle-step {
  font-size: .8rem;
  line-height: 1.4;
  color: var(--text);
}
.za-motor-graphic {
  min-width: 0;
}
.za-motor-graphic .za-sketch-svg {
  min-height: 320px;
}
.za-motor-info {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  padding: .2rem 0;
}
.za-motor-step {
  font-size: .8rem;
  line-height: 1.4;
  color: #cbd5e1;
  transition: color .16s ease;
}
.za-motor-step.is-active {
  color: var(--text);
}
.za-sketch-svg {
  width: 100%;
  height: auto;
  display: block;
  min-height: 300px;
}
.za-sketch-svg text {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  fill: var(--text);
}
.za-sketch-svg text.za-sketch-muted { fill: var(--muted); }
.za-sketch-svg text.za-sketch-force { fill: #ef4444; }
.za-sketch-svg text.za-sketch-heat-label { fill: #f97316; }
.za-sketch-arrow {
  stroke: var(--primary);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.za-sketch-accent { fill: #dbeafe; stroke: #93c5fd; stroke-width: 2; }
.za-sketch-gas { fill: #ccfbf1; stroke: #14b8a6; stroke-width: 2; }
.za-brayton-line {
  fill: none;
  stroke: #334155;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.za-brayton-machine {
  fill: #ffffff;
  stroke: #64748b;
  stroke-width: 2.5;
}
.za-brayton-blade {
  fill: none;
  stroke: #64748b;
  stroke-width: 3;
  stroke-linecap: round;
}
.za-brayton-heater {
  fill: #fff7ed;
  stroke: #fb7185;
  stroke-width: 2;
}
.za-brayton-cooler {
  fill: #eff6ff;
  stroke: #60a5fa;
  stroke-width: 2;
}
.za-brayton-coil,
.za-brayton-coil-cool {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.za-brayton-coil { stroke: #ef4444; }
.za-brayton-coil-cool { stroke: #2563eb; }
.za-brayton-turbine {
  fill: #94a3b8;
  stroke: #475569;
  stroke-width: 2;
}
.za-brayton-heat-in,
.za-brayton-heat-out {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
}
.za-brayton-heat-in { stroke: #ef4444; }
.za-brayton-heat-out { stroke: #f59e0b; }
.za-brayton-label {
  font-size: 13px;
  font-weight: 600;
}
.za-brayton-vertical {
  writing-mode: vertical-rl;
  glyph-orientation-vertical: 0;
}
.za-brayton-state {
  font-size: 14px;
  font-weight: 700;
  fill: #64748b;
}
.za-brayton-shaft {
  font-size: 13px;
  fill: #475569;
}
.za-brayton-shaft-line {
  fill: none;
  stroke: #475569;
  stroke-width: 5;
  stroke-linecap: round;
}
.za-brayton-heat-text-in {
  fill: #ef4444;
  font-size: 15px;
  font-weight: 700;
}
.za-brayton-heat-text-out {
  fill: #d97706;
  font-size: 15px;
  font-weight: 700;
}
.za-brayton-work-text {
  fill: #2563eb;
  font-size: 14px;
  font-weight: 700;
}
.vd-sketch-stage {
  font-size: 12px;
  font-weight: 700;
  fill: #475569;
}
.za-sketch-hatch {
  fill: none;
  stroke: #64748b;
  stroke-width: 2;
  stroke-linecap: round;
  opacity: .8;
}
.za-sketch-heat {
  stroke: #f97316;
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 10 8;
}
.za-sketch-heat-out { opacity: 0; }
.za-process-sketch.is-playing .za-sketch-heat-wave {
  animation: zaHeatWave 1.05s linear infinite;
}
.za-process-sketch.is-playing .za-sketch-heat-in {
  animation: zaHeatIn 3.2s linear infinite;
}
.za-process-sketch.is-playing .za-sketch-heat-out {
  animation: zaHeatOut 3.2s linear infinite;
}
@media (max-width: 760px) {
  .za-motor-layout {
    grid-template-columns: 1fr;
    gap: .75rem;
  }
  .za-cycle-layout {
    grid-template-columns: 1fr;
    gap: .75rem;
  }
}
.za-sketch-wall { fill: #e2e8f0; stroke: #94a3b8; stroke-width: 2; }
.za-sketch-isobar-piston { transform-box: fill-box; transform-origin: center; }
.za-process-sketch.is-playing .za-sketch-isobar-piston {
  animation: zaIsobarPiston 3.2s ease-in-out infinite;
}
.za-process-sketch.is-playing .za-sketch-isobar-gas {
  animation: zaIsobarGas 3.2s ease-in-out infinite;
}
.za-process-sketch.is-playing .za-sketch-isochor-gas {
  animation: zaIsobarGas 3.2s ease-in-out infinite;
}
.za-sketch-adiabatic-piston { transform-box: fill-box; transform-origin: center; }
.za-process-sketch.is-playing .za-sketch-adiabatic-piston {
  animation: zaAdiabaticPiston 3.2s ease-in-out infinite;
}
.za-process-sketch.is-playing .za-sketch-adiabatic-gas {
  animation: zaIsobarGas 3.2s ease-in-out infinite;
}
@keyframes zaIsobarPiston {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-24px); }
}
@keyframes zaAdiabaticPiston {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(24px); }
}
@keyframes zaIsobarGas {
  0%, 100% { fill: #ccfbf1; stroke: #14b8a6; }
  25% { fill: #fef08a; stroke: #eab308; }
  50% { fill: #fb923c; stroke: #f97316; }
  70% { fill: #fca5a5; stroke: #ef4444; }
}
@keyframes zaHeatWave {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: -36; }
}
@keyframes zaHeatIn {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}
@keyframes zaHeatOut {
  0%, 49% { opacity: 0; }
  50%, 100% { opacity: 1; }
}

.bc-section-lbl {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted);
  margin: 1rem 0 .35rem;
}
.bc-eq-block {
  display: flex; flex-direction: column; gap: .55rem;
  padding: .65rem .9rem;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 6px;
}
.bc-eq-row {
  display: flex; align-items: baseline; gap: .7rem;
  font-size: 1rem; line-height: 1.7;
}
.bc-eq-num {
  font-size: .78rem; color: var(--muted); min-width: 2rem;
  font-family: -apple-system, sans-serif;
}
.bc-error { color: #ef4444; font-size: .88rem; }

/* ── Kreisprozess-Auswertung ── */
.kp-table-wrap { overflow-x: auto; margin: .4rem 0 .75rem; }
.kp-table { border-collapse: collapse; width: 100%; font-size: .84rem; }
.kp-table th, .kp-table td {
  border: 1px solid var(--border); padding: .28rem .6rem; text-align: right; white-space: nowrap;
}
.kp-table th:nth-child(1), .kp-table th:nth-child(2),
.kp-table td:nth-child(1), .kp-table td:nth-child(2) { text-align: left; }
.kp-table thead th {
  background: #f1f5f9; font-weight: 600; font-size: .76rem;
  color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
}
.kp-table .kp-pos { color: #16a34a; font-weight: 600; }
.kp-table .kp-neg { color: #dc2626; font-weight: 600; }
.kp-table .kp-sum-row td { background: #f8fafc; border-top: 2px solid #cbd5e1; }
.kp-eta-block {
  display: flex; align-items: center; gap: 1.4rem; flex-wrap: wrap;
  background: linear-gradient(135deg,#eff6ff,#dbeafe);
  border: 1px solid #bfdbfe; border-radius: 8px;
  padding: .75rem 1.2rem; margin-top: .9rem;
}
.kp-eta-block-pump {
  background: linear-gradient(135deg,#f5f3ff,#ede9fe);
  border-color: #c4b5fd;
}
.kp-eta-block-carnot {
  background: linear-gradient(135deg,#f0fdf4,#dcfce7);
  border-color: #86efac;
}
.kp-eta-block-carnot .kp-eta-value { color: #15803d; }
.kp-eta-block-carnot .kp-eta-label { color: #16a34a; }
.kp-eta-block-carnot .kp-eta-detail { color: #166534; }
.kp-eta-value { font-size: 1.7rem; font-weight: 700; color: #1d4ed8; line-height: 1.1; }
.kp-eta-block-pump .kp-eta-value { color: #6d28d9; }
.kp-eta-label { font-size: .72rem; font-weight: 700; color: #3b82f6; text-transform: uppercase; letter-spacing: .06em; margin-bottom: .15rem; }
.kp-eta-block-pump .kp-eta-label { color: #7c3aed; }
.kp-eta-detail { font-size: .81rem; color: #1e40af; line-height: 1.5; }
.kp-eta-block-pump .kp-eta-detail { color: #5b21b6; }

/* ── Step card header (title + remove btn) ── */
.step-card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: .85rem; padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.btn-remove-step {
  background: none; border: none; color: var(--muted);
  font-size: 1.25rem; line-height: 1; cursor: pointer;
  padding: .1rem .35rem; border-radius: 4px;
  transition: background .12s, color .12s;
}
.btn-remove-step:hover { background: #fee2e2; color: #ef4444; }

/* ── Datei-laden button ── */
.btn-datei-laden {
  display: inline-flex; align-items: center;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: .42rem .9rem; font-size: .85rem; font-weight: 500;
  cursor: pointer; transition: background .12s, border-color .12s;
  user-select: none;
}
.btn-datei-laden:hover { background: #e2e8f0; border-color: #94a3b8; }

/* ── Add-step button ── */
.btn-add-step {
  display: flex; align-items: center; gap: .45rem;
  background: #fff; color: var(--primary);
  border: 2px dashed var(--primary); border-radius: 8px;
  padding: .5rem 1.4rem; font-size: .88rem; font-weight: 600;
  cursor: pointer; transition: background .15s, color .15s;
}
.btn-add-step:hover { background: #eff6ff; }
.btn-add-icon { font-size: 1.1rem; line-height: 1; }

/* ── Berechnen button ── */
.btn-berechnen {
  background: var(--primary); color: #fff;
  border: none; border-radius: 6px;
  padding: .55rem 1.6rem; font-size: .92rem; font-weight: 600;
  cursor: pointer; transition: background .15s;
  letter-spacing: .02em;
}
.btn-berechnen:hover { background: #1d4ed8; }
.btn-berechnen:active { background: #1e40af; }

/* ── Verdichter-Tabelle ── */
.vd-table {
  border-collapse: collapse; font-size: .88rem;
  width: auto; max-width: 100%;
}
.vd-table th, .vd-table td {
  padding: .3rem .7rem; border: 1px solid var(--border);
  white-space: nowrap;
}
.vd-table thead th {
  background: #f8fafc; font-weight: 600; font-size: .78rem;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
.vd-table tbody tr:nth-child(even) { background: #f8fafc; }

/* ── Responsive sidebar ── */
@media(max-width: 600px) { .sb { display: none; } }
