:root {
  color-scheme: dark;
  --background: #101214;
  --panel: #171a1d;
  --canvas: #070a0d;
  --text: #e2e5e8;
  --muted: #9aa1a8;
  --line: #3a4046;
  --accent: #6fc9e8;
  font: 13px/1.35 Arial, Helvetica, sans-serif;
  background: var(--background);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--background);
}

body {
  width: min(1280px, calc(100% - 20px));
  margin: 0 auto;
}

a {
  color: var(--accent);
}

.masthead {
  display: grid;
  grid-template-areas:
    "identity controls"
    "config config";
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 48px;
  column-gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.identity {
  grid-area: identity;
  display: flex;
  min-width: 0;
  gap: 9px;
  align-items: baseline;
  overflow: hidden;
  white-space: nowrap;
}

h1 {
  margin: 0;
  font-size: 15px;
  line-height: 1;
}

h1 a {
  color: var(--text);
  text-decoration: none;
}

.identity span,
#scene-description,
.hint {
  color: var(--muted);
}

.controls {
  grid-area: controls;
  display: flex;
  gap: 4px;
  align-items: center;
  margin: 0;
  white-space: nowrap;
}

.controls label {
  color: var(--muted);
}

select,
button,
.tool-buttons {
  height: 28px;
  border: 1px solid #59616a;
  border-radius: 2px;
  background: #202429;
  color: var(--text);
  font: inherit;
}

select {
  padding: 0 24px 0 7px;
}

#scene-select {
  width: 158px;
}

.tool-buttons {
  display: flex;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.tool-buttons legend {
  float: left;
  margin: 5px 4px 0 0;
  padding: 0;
  color: var(--muted);
}

.tool-button {
  display: grid;
  min-width: 28px;
  width: 28px;
  place-items: center;
  margin-left: -1px;
  padding: 4px;
  border-radius: 0;
}

.tool-button:first-of-type {
  margin-left: 0;
  border-radius: 2px 0 0 2px;
}

.tool-button:last-of-type {
  border-radius: 0 2px 2px 0;
}

.tool-button[aria-pressed="true"] {
  position: relative;
  border-color: var(--accent);
  background: #183542;
  color: #a8e7fa;
}

.tool-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.capacity-select {
  width: 82px;
}

.rate-select {
  width: 76px;
}

.sleep-toggle {
  display: inline-flex;
  height: 28px;
  gap: 4px;
  align-items: center;
  padding: 0 4px;
  color: var(--muted);
}

.sleep-toggle input {
  margin: 0;
}

button {
  min-width: 54px;
  padding: 0 9px;
  cursor: pointer;
}

select:disabled {
  color: #6f767d;
  cursor: not-allowed;
}

button:disabled {
  color: #6f767d;
  cursor: not-allowed;
}

#config-state {
  grid-area: config;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
}

#config-state.pending {
  color: #f1c36b;
}

#config-state.error {
  text-align: left;
  color: #ff9aa5;
}

select:hover,
button:hover {
  border-color: #89939d;
}

select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

main {
  padding-top: 8px;
}

.stage {
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
}

.stage-copy {
  display: flex;
  min-height: 35px;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 6px 9px;
  border-bottom: 1px solid var(--line);
}

.stage-copy p {
  margin: 0;
}

.hint {
  flex: none;
}

.canvas-shell {
  position: relative;
  height: clamp(420px, calc(100vh - 138px), 720px);
  background: var(--canvas);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: default;
}

canvas:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: -2px;
}

canvas[data-tool="drag"] {
  cursor: grab;
}

canvas[data-tool="drag"]:active {
  cursor: grabbing;
}

canvas[data-tool="box"] {
  cursor: copy;
}

canvas[data-tool="water"] {
  cursor: crosshair;
}

canvas[data-tool="pan"] {
  cursor: move;
}

.status {
  position: absolute;
  right: 7px;
  bottom: 7px;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 3px 6px;
  border: 1px solid var(--line);
  background: rgba(16, 18, 20, 0.86);
  color: var(--muted);
  font-size: 11px;
  max-width: calc(100% - 14px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #73cf96;
}

#fatal-error {
  position: absolute;
  inset: 12px 12px auto;
  margin: 0;
  padding: 8px;
  border: 1px solid #98525a;
  background: #351a1e;
  color: #ffd7dc;
}

@media (max-width: 1100px) {
  .identity span {
    display: none;
  }
}

@media (max-width: 900px) {
  body {
    width: calc(100% - 10px);
  }

  .masthead {
    grid-template-areas:
      "identity"
      "controls"
      "config";
    grid-template-columns: 1fr;
    min-height: 78px;
    align-items: flex-start;
    row-gap: 4px;
    justify-content: center;
  }

  .controls {
    width: 100%;
    flex-wrap: wrap;
  }

  #scene-select {
    width: 158px;
  }

  .stage-copy {
    align-items: flex-start;
  }

  .hint {
    display: none;
  }

  .canvas-shell {
    height: max(340px, calc(100dvh - 152px));
  }
}

@media (max-width: 600px) {
  .controls > label,
  .tool-buttons legend {
    position: absolute;
    overflow: hidden;
    width: 1px;
    height: 1px;
    clip: rect(0 0 0 0);
  }

  #config-state {
    display: none;
  }
}
