:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --ink: #1f2926;
  --muted: #66716c;
  --line: #d8ded8;
  --panel: #ffffff;
  --green: #15935f;
  --orange: #d88725;
  --blue: #2f6fed;
  --red: #c84c41;
}

* {
  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;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  font-weight: 740;
}

h2 {
  font-size: 15px;
  font-weight: 720;
}

.topbar p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 14px;
  color: var(--muted);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--orange);
}

.dot.connected,
.dot.demo,
.dot.wifi {
  background: var(--green);
}

.dot.error {
  background: var(--red);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 16px;
  align-items: start;
}

.stage,
.panel,
.log-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stage {
  min-height: 520px;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: min(66vh, 720px);
  min-height: 520px;
  touch-action: none;
}

canvas.dragging {
  cursor: grabbing !important;
}

.side {
  display: grid;
  gap: 12px;
}

.panel {
  padding: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.metric-grid div {
  min-height: 68px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric-grid span,
.stats span,
.field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
  text-transform: uppercase;
}

.metric-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  font-weight: 760;
  white-space: nowrap;
}

.field {
  display: grid;
  grid-template-columns: 1fr 98px 34px;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

.anchor-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.anchor-form {
  display: grid;
  gap: 12px;
}

.background-config {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.background-field {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.background-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
}

.anchor-edit-row {
  display: grid;
  grid-template-columns: 16px minmax(36px, auto) minmax(0, 1fr) minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.anchor-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.anchor-edit-row strong {
  font-size: 14px;
}

.anchor-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px;
  align-items: center;
}

.anchor-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
}

input[type="number"] {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  font: inherit;
}

.anchor-field input {
  min-width: 0;
  min-height: 32px;
  padding: 0 8px;
  font-size: 14px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

button {
  min-height: 36px;
  border: 1px solid #1f2926;
  border-radius: 8px;
  padding: 0 14px;
  background: #1f2926;
  color: #ffffff;
  font: inherit;
  font-size: 14px;
  font-weight: 720;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.form-actions span {
  color: var(--muted);
  font-size: 13px;
}

input[type="range"] {
  width: 100%;
}

.field em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.stats {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px 12px;
  margin-top: 14px;
  align-items: center;
}

.stats strong {
  max-width: 180px;
  overflow-wrap: anywhere;
  text-align: right;
  font-size: 15px;
}

.log-panel {
  margin-top: 16px;
  padding: 16px;
}

.log-panel pre {
  margin: 12px 0 0;
  max-height: 180px;
  overflow: auto;
  color: #26322e;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.mini-log {
  margin: 12px 0 0;
  max-height: 124px;
  overflow: auto;
  color: #26322e;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 960px) {
  .shell {
    width: min(100vw - 20px, 760px);
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  canvas {
    min-height: 420px;
    height: 52vh;
  }
}
