:root {
  --bg: #0a0d18;
  --panel: #121626;
  --panel-2: #0e1220;
  --line: #262b40;
  --line-2: #33395a;
  --text: #e6e8f2;
  --muted: #9097b0;
  --dim: #6b7290;
  --accent: #7c83f6;
  --accent-2: #3aa6e0;
  --sel: #232a5a;
  --sel-line: #4a52a8;
  --radius: 10px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-image: linear-gradient(rgba(124, 131, 246, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 131, 246, 0.04) 1px, transparent 1px);
  background-size: 32px 32px;
}

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

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

/* ---------- top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 13, 24, 0.8);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.logo {
  display: block;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  box-shadow: 0 4px 14px rgba(70, 90, 220, 0.35);
}

.gh {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}

.gh:hover {
  border-color: var(--accent);
}

/* ---------- layout */

.app {
  flex: 1;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  margin: 24px auto;
  width: min(1240px, calc(100% - 32px));
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background: var(--panel-2);
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px 22px 24px;
  overflow-y: auto;
  max-height: calc(100vh - 140px);
}

.panel {
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}

.panel section + section {
  margin-top: 22px;
}

h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.lbl {
  display: block;
  margin: 12px 0 7px;
  color: var(--text);
}

small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--dim);
}

/* segmented buttons */

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}

.seg button {
  padding: 7px 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.seg button:hover {
  color: var(--text);
}

.seg button[aria-pressed='true'] {
  background: var(--sel);
  border-color: var(--sel-line);
  color: var(--text);
  font-weight: 600;
}

/* sliders */

.slider {
  margin-top: 14px;
}

.slider label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.slider output {
  font-size: 11px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.slider.disabled {
  opacity: 0.4;
  pointer-events: none;
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 6px 0 0;
  background: transparent;
  --p: 50%;
}

input[type='range']::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) var(--p), #3a3f55 var(--p));
}

input[type='range']::-moz-range-track {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) var(--p), #3a3f55 var(--p));
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5px;
  border-radius: 50%;
  background: #8b91ff;
  border: 2px solid #c9ccff;
}

input[type='range']::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #8b91ff;
  border: 2px solid #c9ccff;
}

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

/* colors */

.colors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 18px;
}

.color {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

input[type='color'] {
  width: 38px;
  height: 30px;
  padding: 4px;
  border: 1px solid var(--line-2);
  border-radius: 7px;
  background: var(--panel-2);
  cursor: pointer;
}

input[type='color']::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type='color']::-webkit-color-swatch {
  border: 1px solid rgba(0, 0, 0, 0.4);
  border-radius: 3px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  user-select: none;
}

.check.box {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  margin-top: 14px;
}

.checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checks .check.box {
  margin: 0;
}

input[type='checkbox'] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
}

.gridcolor {
  margin-top: 14px;
}

.gridcolor.disabled,
.check.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.seg.modes {
  grid-auto-flow: row;
  grid-template-columns: 1fr 1fr;
}

.legend {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.legend i {
  display: inline-block;
  width: 14px;
  height: 3px;
  margin: 0 6px 2px 10px;
  vertical-align: middle;
  border-radius: 2px;
}

.previewtools .check {
  font-size: 12px;
  margin-right: 4px;
}

[hidden] {
  display: none !important;
}

.presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.presets button {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 6px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}

.presets button:hover {
  border-color: var(--line-2);
  color: var(--text);
}

.presets button[aria-pressed='true'] {
  border-color: var(--sel-line);
  background: var(--sel);
  color: var(--text);
  font-weight: 600;
}

.presets canvas {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #0b0f1d;
  box-shadow: none;
}

.presets span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seed {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  font-variant-numeric: tabular-nums;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.btn.wide {
  grid-column: 1 / -1;
}

.actions.secondary {
  margin-top: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
}

.btn.primary {
  border-color: transparent;
  background: linear-gradient(90deg, #6457e8, #3aa6e0);
  color: #fff;
}

.btn.primary:hover {
  filter: brightness(1.1);
}

.btn.small {
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 500;
}

/* ---------- stage */

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 600px;
}

.stagebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  font: 12px/1.4 ui-monospace, 'Cascadia Code', Consolas, monospace;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

.tabs button {
  padding: 4px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.tabs button[aria-selected='true'] {
  background: var(--sel);
  color: var(--text);
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-height: 0;
}

.view[hidden] {
  display: none;
}

canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  max-width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

#sheet,
#preview {
  background: repeating-conic-gradient(#2a2f45 0% 25%, #1f2336 0% 50%) 0 0 / 16px 16px;
}

#preview {
  cursor: crosshair;
  touch-action: none;
}

.previewtools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.hint {
  font-size: 12px;
  color: var(--dim);
  margin-right: 8px;
}

.busy {
  position: absolute;
  right: 16px;
  bottom: 12px;
  font: 11px ui-monospace, Consolas, monospace;
  color: var(--muted);
}

.foot {
  text-align: center;
  font-size: 12px;
  color: var(--dim);
  padding: 0 16px 20px;
}

/* ---------- small screens */

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    width: calc(100% - 32px);
  }
  .panel {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .stage {
    min-height: 420px;
  }
  .stagebar {
    flex-wrap: wrap;
  }
  .topbar {
    padding: 12px 16px;
  }
}
