:root {
  color-scheme: dark;
  font-size: 112.5%;
  --bg: #0a0e14;
  --surface: #121a24;
  --surface-2: #1a2533;
  --text: #e8edf4;
  --muted: #7d8fa3;
  --accent: #3d9cf5;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --border: rgba(255, 255, 255, 0.08);
  --app-gap: 0.4rem;
  --vv-top: 0px;
  --vv-left: 0px;
  --vv-w: 100vw;
  --vv-h: 100svh;
  --pwa-fill-h: 100%;
  --pwa-extra-b: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "DM Sans", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}

html.pwa-standalone,
html.pwa-standalone body {
  height: calc(var(--pwa-fill-h, 100%) + var(--pwa-extra-b, 0px));
  min-height: calc(var(--pwa-fill-h, 100%) + var(--pwa-extra-b, 0px));
  max-height: none;
}

.fit-stage {
  position: fixed;
  top: var(--vv-top, 0px);
  left: var(--vv-left, 0px);
  width: var(--vv-w, 100vw);
  height: var(--vv-h, 100svh);
  right: auto;
  bottom: auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding:
    max(0px, env(safe-area-inset-top, 0px))
    max(0.2rem, env(safe-area-inset-right, 0px))
    0
    max(0.2rem, env(safe-area-inset-left, 0px));
}

html.pwa-standalone .fit-stage {
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: calc(var(--pwa-fill-h, 100%) + var(--pwa-extra-b, 0px));
}

.app {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--app-gap);
  padding: 0.2rem 0.28rem 0;
}

header {
  flex: 0 0 auto;
  text-align: center;
  padding-bottom: 0.05rem;
}

header h1 {
  font-family: "Michroma", system-ui, sans-serif;
  font-size: 1.15rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

.view-tag {
  position: absolute;
  top: 8px;
  z-index: 2;
  margin: 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(232, 237, 244, 0.88);
  pointer-events: none;
}

.view-wind { left: 10px; }
.view-area { right: 10px; }

.cam-hint {
  position: absolute;
  left: 10px;
  bottom: 34px;
  z-index: 2;
  margin: 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.55rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: rgba(125, 143, 163, 0.72);
  pointer-events: none;
  transition: opacity 0.55s ease;
}

.cam-hint.is-gone {
  opacity: 0;
}

.stage-wrap {
  flex: 1 1 auto;
  min-height: 8rem;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #0c1118;
  border: 1px solid var(--border);
}

#view {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
}

#view:active {
  cursor: grabbing;
}

.track-map {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 2px;
  height: 26px;
  z-index: 3;
  cursor: grab;
  touch-action: none;
}

/* The rail is thin but the grab area is a thumb wide. */
.track-map::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 8px;
  margin-top: -4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
}

.track-map:active { cursor: grabbing; }

.track-map:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 99px;
}

.track-map i {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
}

.track-map.is-scrubbing i {
  transform: scale(1.18);
}

.lower {
  flex: 0 0 auto;
  padding-bottom: max(0.35rem, var(--safe-b));
}

.deck-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.readout {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.35fr);
  grid-template-rows: auto 1fr;
  column-gap: 0.4rem;
  align-items: stretch;
}

.readout h2 {
  margin: 0 0 0.2rem;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.readout .big {
  margin: 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 1.45rem;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.meter {
  margin-top: 0.45rem;
}

.meter-top {
  display: flex;
  justify-content: space-between;
  gap: 0.25rem;
  margin-bottom: 0.18rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
}

.meter-top span:first-child {
  color: var(--muted);
  font-weight: 500;
}

.meter-track {
  position: relative;
  width: calc(100% - 5px);
  height: 0.55rem;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.meter-track .zero {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.45);
}

.meter-track .bar,
.meter-track .peak {
  position: absolute;
  top: 0;
  bottom: 0;
}

.meter-track .bar.full {
  left: 0;
  width: 100%;
  transform-origin: left center;
}

.meter-track .bar.make { background: var(--green); }
.meter-track .bar.out {
  left: 50%;
  width: 50%;
  transform-origin: left center;
  background: var(--green);
}
.meter-track .bar.use { background: var(--amber); }
.meter-track .bar.home {
  right: 50%;
  width: 50%;
  transform-origin: right center;
  background: var(--amber);
}

.meter-track .peak {
  width: 2px;
  margin-left: -1px;
  background: #f4f7fb;
}

.now-h {
  grid-column: 1;
  grid-row: 1;
}

.trip-heads {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  width: 100%;
  grid-template-columns: max-content repeat(3, minmax(0, 1fr));
  gap: 0.1rem 0.22rem;
  align-items: baseline;
  margin-bottom: 0.2rem;
  padding: 0 0.32rem;
}

.trip-heads h2 {
  margin: 0;
  text-align: right;
}

.now-col {
  grid-column: 1;
  grid-row: 2;
}

.trip-col {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  display: flex;
  align-items: center;
}

.trip-table {
  display: grid;
  width: 100%;
  grid-template-columns: max-content repeat(3, minmax(0, 1fr));
  gap: 0.1rem 0.22rem;
  align-items: baseline;
  padding: 0.28rem 0.32rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.62rem;
  font-weight: 600;
  white-space: nowrap;
}

.trip-table .lab {
  color: var(--muted);
  font-weight: 500;
}

.trip-table span:not(.lab) {
  text-align: right;
}

.actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}

#run { justify-self: start; }
#specs-btn { justify-self: center; }
#save-btn { justify-self: end; }

.actions button {
  padding: 0.2rem 0.5rem;
  font-size: 0.66rem;
}

button, .btn {
  appearance: none;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.38rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
}

button.primary { background: #1c3f68; border-color: rgba(61, 156, 245, 0.45); }
button.go { background: #145c40; border-color: rgba(52, 211, 153, 0.4); }
button.stop { background: #5c2430; border-color: rgba(248, 113, 113, 0.45); }

.sheet {
  position: absolute;
  left: 0.4rem;
  right: 0.4rem;
  bottom: max(0.35rem, var(--safe-b));
  max-height: 70%;
  overflow: auto;
  background: rgba(18, 26, 36, 0.96);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.42rem 0.58rem 0.55rem;
  z-index: 5;
}

.sheet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.28rem;
  padding-bottom: 0.28rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.sheet h2 {
  font-family: "Michroma", system-ui, sans-serif;
  font-size: 0.68rem;
  font-weight: 400;
  margin: 0;
}

.sheet-area {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.62rem;
  color: var(--amber);
}

.sheet[hidden] { display: none; }

label.field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 0.5rem;
  align-items: center;
  margin-bottom: 0.08rem;
  font-size: 0.62rem;
  color: var(--muted);
  line-height: 1.05;
}

label.field input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  height: 0.85rem;
  margin: -0.7rem 0;
  padding: 0.7rem 0;
  box-sizing: content-box;
  background: none;
}

label.field output {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  color: var(--text);
  font-size: 0.62rem;
}

label.field.is-off,
label.field.is-off output {
  color: var(--amber);
}

#solve.is-needed {
  color: #1a1404;
  background: var(--amber);
  border-color: rgba(255, 225, 74, 0.7);
}

.sheet-actions { display: flex; gap: 0.35rem; justify-content: flex-end; margin-top: 0.15rem; }

.warn {
  color: var(--amber);
  font-size: 0.72rem;
  min-height: 0;
}

.warn:empty { display: none; }
