*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
}

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

a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line-soft);
  background: var(--elevated);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 6px 12px;
}

button:hover {
  border-color: var(--rust);
  background: var(--rust-soft);
}

button.ghost {
  background: transparent;
}

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.top h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--rust-bright);
}

.top .tag {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.top .spacer {
  flex: 1;
}

.top .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dim);
}

.top .status-dot.ok {
  background: var(--ok);
  box-shadow: 0 0 8px rgba(106, 184, 122, 0.5);
}

.top .status-dot.err {
  background: var(--error);
  box-shadow: 0 0 8px rgba(224, 90, 90, 0.5);
}

.layout {
  display: grid;
  grid-template-columns: 200px 1fr 340px;
  height: calc(100% - var(--header-h));
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}

.sidebar-head {
  padding: 12px 14px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.gallery {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--elevated);
  text-align: left;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.preset-btn:hover,
.preset-btn.active {
  border-color: var(--rust);
  box-shadow: inset 0 0 0 1px var(--rust-soft);
}

.preset-btn canvas {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 4px;
  display: block;
  background: #000;
}

.preset-btn span {
  font-size: 12px;
  font-weight: 500;
}

.controls {
  border-top: 1px solid var(--line);
  padding: 12px 14px 16px;
}

.control {
  margin-bottom: 14px;
}

.control:last-child {
  margin-bottom: 0;
}

.control label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.control label output {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--rust-bright);
}

.control input[type="range"] {
  width: 100%;
  accent-color: var(--rust);
  height: 4px;
}

.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(196, 92, 42, 0.08), transparent 60%),
    var(--bg);
  overflow: hidden;
}

#preview {
  display: block;
  width: min(100%, 960px);
  height: auto;
  max-height: 100%;
  aspect-ratio: 16 / 10;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
}

.error-overlay {
  position: absolute;
  inset: 16px;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 24px;
  pointer-events: none;
}

.error-overlay.visible {
  display: flex;
}

.error-box {
  max-width: 560px;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid rgba(224, 90, 90, 0.45);
  border-radius: var(--radius);
  background: var(--error-bg);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.error-box h2 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--error);
}

.error-box pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: #f0c0c0;
  max-height: 200px;
  overflow-y: auto;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

#fragment {
  flex: 1;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 14px;
  border: none;
  resize: none;
  background: var(--bg);
  color: #d4cfc6;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  tab-size: 2;
  outline: none;
}

#fragment:focus {
  box-shadow: inset 0 0 0 1px var(--rust-soft);
}

.editor-foot {
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--dim);
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 160px 1fr 280px;
  }
}
