:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #12151d;
  --panel-raised: #181c26;
  --line: #2a3040;
  --line-soft: #202633;
  --text: #f3f5f8;
  --muted: #9199aa;
  --accent: #d8ff62;
  --accent-ink: #172000;
  --danger: #ff7c86;
  --success: #8ce6b2;
  --shadow: 0 22px 60px rgb(0 0 0 / 30%);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -8%, rgb(216 255 98 / 8%), transparent 28rem),
    radial-gradient(circle at 92% 12%, rgb(112 102 255 / 9%), transparent 32rem),
    var(--bg);
}

button,
select,
textarea {
  font: inherit;
}

button,
select {
  color: inherit;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(18px, 3vw, 42px);
  border-bottom: 1px solid var(--line-soft);
  background: rgb(11 13 18 / 78%);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--accent-ink);
  background: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 900;
  box-shadow: 0 0 28px rgb(216 255 98 / 20%);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
  letter-spacing: 0.02em;
}

.brand small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.runtime-status,
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.runtime-status i,
.live-pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f5bd57;
  box-shadow: 0 0 0 4px rgb(245 189 87 / 10%);
}

.runtime-status.ready i,
.live-pill i {
  background: var(--success);
  box-shadow: 0 0 0 4px rgb(140 230 178 / 10%);
}

.runtime-status.error i {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgb(255 124 134 / 10%);
}

.github-link {
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
}

.github-link:hover {
  color: var(--accent);
}

.workspace {
  width: min(1680px, 100%);
  min-height: calc(100vh - 132px);
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 14px;
  margin: 0 auto;
  padding: 18px clamp(12px, 2vw, 28px);
}

.panel {
  min-width: 0;
  min-height: 680px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgb(24 28 38 / 96%), rgb(16 19 27 / 96%));
  box-shadow: var(--shadow);
}

.panel-header {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line-soft);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-size: clamp(17px, 1.4vw, 21px);
  letter-spacing: -0.02em;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.select-wrap select,
.button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-raised);
  font-size: 12px;
  font-weight: 650;
}

.select-wrap select {
  max-width: 170px;
  padding: 0 28px 0 11px;
  cursor: pointer;
}

.button {
  padding: 0 12px;
  cursor: pointer;
}

.button:hover {
  border-color: #41495e;
  background: #202532;
}

.button-share {
  color: var(--accent-ink);
  border-color: var(--accent);
  background: var(--accent);
}

.button-share:hover {
  border-color: #e4ff91;
  background: #e4ff91;
}

.editor-wrap {
  min-height: 0;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  background: #0f1219;
}

.line-rail {
  border-right: 1px solid var(--line-soft);
  background:
    linear-gradient(90deg, transparent, rgb(255 255 255 / 1.5%)),
    #0c0f15;
}

#layout-editor {
  width: 100%;
  min-height: 100%;
  resize: none;
  padding: 22px;
  border: 0;
  outline: 0;
  color: #dbe1ec;
  background: transparent;
  caret-color: var(--accent);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.65;
  tab-size: 2;
}

.panel-footer {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 20px;
  border-top: 1px solid var(--line-soft);
  background: rgb(10 13 18 / 42%);
}

.message,
.selection {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.message.error {
  color: var(--danger);
}

.message.success {
  color: var(--success);
}

.live-pill {
  padding: 7px 10px;
  border: 1px solid rgb(140 230 178 / 18%);
  border-radius: 999px;
  color: var(--success);
  background: rgb(140 230 178 / 6%);
  font-weight: 700;
}

.preview-viewport {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #0d1016;
}

.preview-grid {
  position: absolute;
  inset: 0;
  opacity: 0.36;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(circle at center, black 15%, transparent 86%);
}

.preview-surface {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  transition:
    transform 180ms ease,
    left 180ms ease,
    top 180ms ease;
}

.layout-node {
  position: absolute;
  overflow: visible;
  outline: 1px solid var(--node-color);
  outline-offset: -1px;
  background: color-mix(in srgb, var(--node-color) 12%, transparent);
  cursor: pointer;
  transition:
    background 120ms ease,
    outline-color 120ms ease;
}

.layout-node:hover,
.layout-node.selected {
  z-index: 5;
  outline-width: 2px;
  background: color-mix(in srgb, var(--node-color) 22%, transparent);
}

.layout-label {
  position: absolute;
  top: 5px;
  left: 6px;
  z-index: 20;
  max-width: calc(100% - 12px);
  overflow: hidden;
  color: color-mix(in srgb, var(--node-color) 78%, white);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 750;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 1px 4px #080a0f;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 7px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty-state.hidden {
  display: none;
}

.empty-state strong {
  color: var(--text);
  font-size: 14px;
}

.empty-state span:last-child {
  max-width: 300px;
  font-size: 12px;
  line-height: 1.5;
}

.empty-icon {
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 34px;
}

.metrics {
  display: flex;
  gap: clamp(14px, 2vw, 30px);
  margin: 0;
}

.metrics div {
  display: grid;
  gap: 2px;
}

.metrics dt {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.metrics dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 750;
}

.selection {
  max-width: 48%;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-footer {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 2px clamp(18px, 3vw, 42px) 20px;
  color: #747d90;
  font-size: 11px;
}

.page-footer p {
  margin: 0;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: 620px;
  }

  .preview-panel {
    min-height: 720px;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
  }

  .runtime-status {
    display: none;
  }

  .workspace {
    padding: 10px;
  }

  .panel {
    min-height: 660px;
    border-radius: 14px;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
    min-height: 122px;
  }

  .controls {
    width: 100%;
  }

  .select-wrap {
    flex: 1;
  }

  .select-wrap select {
    width: 100%;
    max-width: none;
  }

  .line-rail {
    display: none;
  }

  .editor-wrap {
    grid-template-columns: 1fr;
  }

  #layout-editor {
    padding: 18px;
    font-size: 12px;
  }

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

  .button-share {
    width: 100%;
  }

  .preview-footer {
    min-height: 104px;
  }

  .selection {
    max-width: 100%;
    text-align: left;
  }

  .page-footer {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
