:root {
  color-scheme: light;
  --bg: #eef3f2;
  --surface: #ffffff;
  --ink: #211f1d;
  --muted: #716b64;
  --line: #cfd9d7;
  --grid: rgba(33, 31, 29, 0.07);
  --panel: rgba(255, 255, 255, 0.94);
  --control: #e6eceb;
  --start: #0f9b8e;
  --end: #e35b4f;
  --route: #2f6df6;
  --amber: #e9a93a;
  --shadow: 0 12px 34px rgba(64, 49, 32, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  min-height: 100vh;
  padding: 14px;
}

.lab-home {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid rgba(33, 31, 29, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 12px 28px rgba(64, 49, 32, 0.14);
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
  backdrop-filter: blur(10px);
}

.lab-home:hover {
  background: #ffffff;
}

.lab-brief {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 12px;
  align-items: stretch;
  padding: 14px;
  border: 1px solid rgba(33, 31, 29, 0.12);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brief-copy {
  align-self: center;
  max-width: 760px;
  padding: 6px;
}

.brief-kicker {
  margin: 0 0 6px;
  color: var(--start);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.brief-copy h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 44px);
  line-height: 1.02;
  letter-spacing: 0;
}

.brief-copy p:not(.brief-kicker) {
  margin-top: 12px;
  max-width: 68ch;
  color: var(--muted);
  font-size: 15px;
}

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

.brief-media figure {
  overflow: hidden;
  margin: 0;
  border: 1px solid rgba(33, 31, 29, 0.12);
  border-radius: 8px;
  background: #ffffff;
}

.brief-media img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}

.brief-media figcaption {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(210px, auto) minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  min-height: 72px;
  padding: 10px;
  border: 1px solid rgba(33, 31, 29, 0.12);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: flex-start;
  min-width: 0;
  gap: 12px;
  padding: 4px 6px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background:
    linear-gradient(90deg, transparent 43%, var(--ink) 44% 56%, transparent 57%),
    linear-gradient(0deg, transparent 43%, var(--ink) 44% 56%, transparent 57%),
    var(--amber);
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.9);
  flex: 0 0 auto;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  font-size: 17px;
  line-height: 1.1;
  font-weight: 800;
}

.brand p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-group,
.shape-group,
.route-group,
.route-tune,
.image-group,
.action-group {
  display: grid;
  min-height: 42px;
  padding: 4px;
  border: 1px solid rgba(33, 31, 29, 0.14);
  border-radius: 8px;
  background: var(--control);
}

.mode-group {
  grid-template-columns: repeat(3, minmax(74px, 1fr));
}

.shape-group {
  grid-template-columns: repeat(4, minmax(42px, 1fr));
}

.route-group {
  grid-template-columns: auto minmax(94px, 1fr);
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
}

.route-tune {
  grid-template-columns: minmax(112px, 1fr) auto minmax(100px, 130px) 58px;
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
}

.route-tune[hidden] {
  display: none;
}

.route-picker {
  display: flex;
  gap: 5px;
  min-width: 0;
  max-width: 210px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.route-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid rgba(33, 31, 29, 0.12);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.route-chip.is-active {
  border-color: rgba(33, 31, 29, 0.42);
  box-shadow: inset 0 -3px 0 var(--route-color, var(--route));
}

.image-group {
  grid-template-columns: auto auto minmax(82px, 118px) auto auto;
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.route-group label,
.route-tune label,
.image-group label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.route-tune input[type="range"] {
  width: 100%;
  min-width: 90px;
  accent-color: var(--ink);
}

.route-tune input[type="number"] {
  width: 58px;
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 850;
  text-align: center;
  box-shadow: 0 8px 18px rgba(64, 49, 32, 0.1);
}

.image-group .toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.image-group input[type="range"] {
  width: 100%;
  min-width: 82px;
  accent-color: var(--ink);
}

.image-group input[type="checkbox"] {
  accent-color: var(--ink);
}

.route-group select {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  padding: 0 28px 0 10px;
  box-shadow: 0 8px 18px rgba(64, 49, 32, 0.12);
}

.mode-button,
.shape-button,
.image-button,
.run-button,
.pattern-button,
.commit-button,
.ghost-button {
  min-height: 34px;
  border-radius: 6px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.mode-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.shape-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 0 9px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mode-button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(64, 49, 32, 0.12);
}

.shape-button.is-active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(64, 49, 32, 0.12);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.dot-start {
  background: var(--start);
}

.dot-end {
  background: var(--end);
}

.dot-obstacle {
  background: #6e625a;
}

.run-button,
.image-button,
.pattern-button,
.commit-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  padding: 0 16px;
  font-weight: 800;
}

.run-button {
  background: var(--ink);
  color: #ffffff;
}

.image-button {
  min-width: 66px;
  background: #ffffff;
  border: 1px solid rgba(33, 31, 29, 0.12);
  color: var(--ink);
}

.pattern-button {
  background: var(--amber);
  color: var(--ink);
}

.commit-button {
  background: #ffffff;
  border: 1px solid rgba(33, 31, 29, 0.18);
  color: var(--ink);
}

.run-button:disabled,
.image-button:disabled,
.pattern-button:disabled,
.commit-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.ghost-button {
  border: 1px solid rgba(33, 31, 29, 0.15);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
}

.mode-button:not(:disabled):hover,
.shape-button:not(:disabled):hover,
.image-button:not(:disabled):hover,
.run-button:not(:disabled):hover,
.pattern-button:not(:disabled):hover,
.commit-button:not(:disabled):hover,
.ghost-button:not(:disabled):hover {
  transform: translateY(-1px);
}

.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(33, 31, 29, 0.12);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 28px rgba(64, 49, 32, 0.09);
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 360px);
  cursor: crosshair;
  touch-action: none;
}

.readout {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: min(620px, calc(100% - 32px));
  padding: 12px;
  border: 1px solid rgba(33, 31, 29, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 24px rgba(64, 49, 32, 0.1);
  backdrop-filter: blur(10px);
}

.readout dl {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.readout div {
  min-width: 0;
}

.readout dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.readout dd {
  overflow: hidden;
  margin: 4px 0 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 850;
}

@media (max-width: 760px) {
  .app-shell {
    gap: 12px;
    padding: 10px;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .lab-brief {
    grid-template-columns: 1fr;
  }

  .brief-media {
    grid-template-columns: 1fr;
  }

  .brand {
    min-width: 0;
  }

  .toolbar {
    justify-content: stretch;
  }

  .mode-group {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .shape-group {
    width: 100%;
  }

  .route-group,
  .route-tune,
  .image-group,
  .action-group {
    width: 100%;
  }

  .route-tune {
    grid-template-columns: minmax(120px, 1fr) auto minmax(110px, 1fr) 58px;
  }

  .route-picker {
    max-width: none;
  }

  .image-group {
    grid-template-columns: auto auto minmax(110px, 1fr) auto auto;
  }

  .run-button,
  .image-button,
  .pattern-button,
  .commit-button,
  .ghost-button {
    flex: 1 1 120px;
  }

  #stage {
    min-height: max(340px, calc(100vh - 560px));
  }

  .readout {
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
  }
}
