:root {
  color-scheme: dark;
  --ink: #eef4e7;
  --muted: #a3ae9e;
  --canvas: #202a20;
  --panel: #172018;
  --panel-raised: #1d281e;
  --line: #344136;
  --line-soft: #29352b;
  --leaf: #9bd36b;
  --leaf-strong: #b7eb83;
  --soil: #d39a62;
  --danger: #ff8f80;
  --focus: #d8f7ac;
  --shadow: 0 18px 46px rgba(4, 10, 5, 0.32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 1060px;
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  background: #111812;
}

[hidden] { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 20%, rgba(155, 211, 107, 0.12), transparent 35%),
    #111812;
}

.login-card {
  width: min(400px, 100%);
  padding: 30px;
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-card h1 { font-size: 22px; }
.login-card > p { color: var(--muted); font-size: 12px; line-height: 1.55; }
.login-card label { display: block; }
.login-card input { width: 100%; }
.login-mark { margin-bottom: 2px; }
.login-error { min-height: 18px; color: var(--danger) !important; }
.login-card .button { min-height: 42px; }

button, input { font: inherit; }
button { color: inherit; }

.topbar {
  height: 76px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: #141d15;
}

.brand, .top-actions, .stage-actions, .paired-inputs {
  display: flex;
  align-items: center;
}

.brand { gap: 12px; }
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid #567044;
  border-radius: 12px;
  color: #14200f;
  background: var(--leaf);
  font-weight: 900;
  letter-spacing: -0.06em;
}

h1, h2, p { margin: 0; }
h1 { font-size: 17px; line-height: 1.25; }
h2 { margin-top: 3px; font-size: 19px; }
.brand p { margin-top: 2px; color: var(--muted); font-size: 12px; }
.top-actions { gap: 9px; }

.workspace {
  height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: 238px minmax(570px, 1fr) 250px;
  gap: 1px;
  background: var(--line-soft);
}

.panel { background: var(--panel); }
.levels-panel, .inspector-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel-heading {
  padding: 20px 18px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.eyebrow {
  color: var(--leaf);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.button, .icon-button {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

.button {
  min-height: 36px;
  padding: 0 13px;
  font-size: 12px;
  font-weight: 760;
}

.button:hover, .icon-button:hover { border-color: #607161; background: #263128; }
.button:active, .icon-button:active { transform: translateY(1px); }
.button.primary { border-color: var(--leaf); color: #14200f; background: var(--leaf); }
.button.primary:hover { background: var(--leaf-strong); }
.button.secondary { border-color: #647b55; color: var(--leaf-strong); background: #233020; }
.button.ghost { color: #d2dbce; }
.button.danger { color: var(--danger); }
.button.compact { min-height: 31px; padding: 0 10px; }
.icon-button { width: 34px; height: 34px; color: var(--leaf); font-size: 22px; line-height: 1; }
.button:focus-visible, .icon-button:focus-visible, input:focus-visible, .stage:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.save-state { margin-right: 5px; color: var(--muted); font-size: 11px; }
.save-state.dirty { color: #f0c27b; }
.signed-in-user {
  max-width: 170px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-list {
  min-height: 0;
  padding: 0 9px;
  overflow-y: auto;
}

.level-row {
  width: 100%;
  margin: 3px 0;
  padding: 11px 10px;
  display: grid;
  grid-template-columns: 27px 1fr;
  gap: 9px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #c5d0c2;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.level-row:hover { background: #1e2920; }
.level-row.active { border-color: #506443; color: var(--ink); background: #263423; }
.level-number {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: #b9c7b5;
  background: #111912;
  font-size: 11px;
  font-weight: 800;
}
.level-row.active .level-number { color: #1b2815; background: var(--leaf); }
.level-copy { min-width: 0; }
.level-copy strong, .level-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.level-copy strong { font-size: 12px; }
.level-copy span { margin-top: 3px; color: var(--muted); font-size: 10px; }

.panel-footer {
  margin-top: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  border-top: 1px solid var(--line-soft);
}

.editor-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 1px;
  background: var(--line-soft);
}

.level-fields {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(220px, 1.25fr) 190px auto;
  gap: 14px;
  align-items: end;
}

label > span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
  color: #b9c4b6;
  font-size: 11px;
  font-weight: 700;
}

input[type="text"], input[type="number"], input[type="email"], input[type="password"] {
  width: 100%;
  height: 37px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #101711;
}

input[type="range"] { width: 100%; accent-color: var(--leaf); }
input[readonly] {
  color: #aab5a6;
  background: #182019;
  cursor: default;
}
.solution-field small { display: block; margin-top: 5px; color: #7f8c7c; font-size: 9px; }
.paired-inputs { gap: 7px; }
.paired-inputs input { min-width: 65px; }
.paired-inputs span { color: var(--muted); }
.level-field-actions { display: flex; gap: 7px; }

.stage-shell {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 62px minmax(0, 1fr) 35px;
}

.stage-toolbar {
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line-soft);
}
.stage-toolbar strong { display: block; margin-top: 4px; font-size: 13px; }
.stage-actions { gap: 10px; }
.counter { color: var(--muted); font-size: 11px; }
.clue-status {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clue-status.ready { color: var(--leaf-strong); }

.stage-viewport {
  min-width: 0;
  min-height: 0;
  padding: 24px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background-color: #0f1610;
  background-image: linear-gradient(#182019 1px, transparent 1px), linear-gradient(90deg, #182019 1px, transparent 1px);
  background-size: 24px 24px;
}

.stage {
  position: relative;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  border: 1px solid #5a685b;
  border-radius: 4px;
  background: var(--canvas);
  box-shadow: var(--shadow);
  user-select: none;
  touch-action: none;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: linear-gradient(45deg, rgba(255,255,255,.025) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.025) 75%), linear-gradient(45deg, rgba(255,255,255,.025) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.025) 75%);
  background-position: 0 0, 10px 10px;
  background-size: 20px 20px;
}

.empty-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--muted);
  text-align: center;
}
.empty-stage[hidden] { display: none; }
.empty-stage strong { color: var(--ink); font-size: 15px; }
.empty-stage span { max-width: 310px; font-size: 11px; line-height: 1.5; }
.empty-symbol {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  margin-bottom: 3px;
  border: 1px dashed #62715f;
  border-radius: 12px;
  color: var(--leaf);
  font-size: 24px;
}

.puzzle-image {
  position: absolute;
  transform-origin: center;
  cursor: grab;
  touch-action: none;
}
.puzzle-image:active { cursor: grabbing; }
.puzzle-image img { width: 100%; height: 100%; display: block; object-fit: fill; pointer-events: none; }
.puzzle-image.selected { outline: 2px solid var(--leaf); outline-offset: 2px; }
.resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  display: none;
  border: 2px solid #172018;
  border-radius: 50%;
  background: var(--leaf);
  cursor: nwse-resize;
}
.puzzle-image.selected .resize-handle { display: block; }

.stage-help {
  padding: 10px 18px 0;
  color: #839080;
  font-size: 10px;
  border-top: 1px solid var(--line-soft);
}

.no-selection { padding: 3px 18px 20px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.image-inspector { padding: 3px 18px 18px; overflow-y: auto; }
.image-inspector label { display: block; margin-bottom: 15px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-grid label { min-width: 0; }
.stacked-actions { display: grid; gap: 7px; margin-top: 5px; }
.format-note {
  margin: auto 14px 14px;
  padding: 13px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  color: var(--muted);
  background: #121a13;
  font-size: 10px;
  line-height: 1.5;
}
.format-note strong { color: #cfdbca; font-size: 11px; }
.format-note p { margin-top: 5px; }
.format-note code { color: var(--leaf); }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  max-width: 380px;
  padding: 11px 14px;
  border: 1px solid #5e7651;
  border-radius: 10px;
  color: #e9f4e3;
  background: #253322;
  box-shadow: var(--shadow);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 160ms ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-height: 700px) {
  .topbar { height: 64px; }
  .workspace { height: calc(100vh - 64px); }
  .level-fields { padding-top: 10px; padding-bottom: 10px; }
  .stage-toolbar { height: 52px; }
}
