:root {
  --bg-void: #05080c;
  --bg-panel: rgba(11, 17, 25, 0.82);
  --bg-inset: rgba(4, 8, 13, 0.7);
  --line: #243749;
  --line-hot: #4a7c9e;
  --fg: #d2dde7;
  --fg-dim: #7a8c9c;
  --accent-purple: #9a8ed6;
  --accent-cyan: #57cbde;
  --accent-chrome: #b9c8d6;
  --ease: 0.3s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  font: 12px/1.4 ui-monospace, monospace;
  color: var(--fg);
  background-color: var(--bg-void);
  background-image:
    radial-gradient(circle at 20% 10%, rgba(87, 203, 222, 0.1), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(154, 142, 214, 0.1), transparent 45%),
    radial-gradient(rgba(185, 200, 214, 0.16) 1px, transparent 1px);
  background-size: auto, auto, 14px 14px;
  overflow: hidden;
}

::selection {
  background: var(--accent-cyan);
  color: var(--bg-void);
}

#bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(87, 203, 222, 0.16), transparent 50%, rgba(154, 142, 214, 0.1));
}

#logo {
  position: relative;
  font-size: 22px;
  font-weight: normal;
  letter-spacing: 2px;
  color: var(--fg);
  text-shadow: 2px 0 var(--accent-purple), -2px 0 var(--accent-cyan);
}

#logo::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  color: var(--accent-purple);
  clip-path: inset(40% 0 35% 0);
  animation: tear 3.7s steps(1) infinite;
}

@keyframes tear {
  0%, 86% { transform: none; clip-path: inset(40% 0 35% 0); opacity: 0; }
  88% { transform: translateX(-5px); opacity: 1; }
  91% { transform: translateX(6px); clip-path: inset(10% 0 70% 0); opacity: 1; }
  94% { transform: translateX(-3px); clip-path: inset(65% 0 5% 0); opacity: 1; }
  97% { opacity: 0; }
}

.tag {
  color: var(--accent-chrome);
  margin-right: auto;
}

.group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border: 1px dotted var(--line);
}

.group label {
  color: var(--fg-dim);
}

button,
select,
input[type="text"],
textarea {
  font: inherit;
  color: var(--fg);
  background: var(--bg-inset);
  border: 1px solid var(--line);
  padding: 3px 7px;
  transition: transform var(--ease), border-color var(--ease), color var(--ease), background var(--ease), box-shadow var(--ease);
}

button {
  cursor: pointer;
  border-color: var(--line-hot) var(--line) var(--line) var(--line-hot);
}

button:hover {
  transform: translateY(-2px);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  box-shadow: 0 3px 0 rgba(87, 203, 222, 0.25);
}

button.on {
  color: var(--bg-void);
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

select:hover,
select:focus,
input[type="text"]:focus,
textarea:focus {
  border-color: var(--accent-purple);
  outline: none;
}

option,
optgroup {
  background: #0b1119;
  color: var(--fg);
}

.export button {
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  text-transform: uppercase;
  letter-spacing: 1px;
}

main {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr) 330px;
  gap: 10px;
  padding: 10px;
  min-height: 0;
}

.win {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 8px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  box-shadow: 4px 4px 0 rgba(87, 203, 222, 0.1), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  scrollbar-width: thin;
  scrollbar-color: var(--line-hot) transparent;
}

.win h2 {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0 -8px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: normal;
  letter-spacing: 2px;
  color: var(--bg-void);
  background:
    repeating-linear-gradient(90deg, transparent 0 3px, rgba(5, 8, 12, 0.25) 3px 4px),
    linear-gradient(90deg, var(--accent-cyan), var(--accent-chrome) 70%, #1a2a3a);
}

.win h2 span::before {
  content: "✦ ";
}

.win h2 em {
  font-style: normal;
  color: #12293a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tools select {
  flex: 1 1 110px;
  min-width: 0;
}

#layers {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 60px;
  padding: 3px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
}

.layer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 5px;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
}

.layer:hover {
  background: rgba(87, 203, 222, 0.08);
}

.layer.sel {
  background: rgba(87, 203, 222, 0.14);
  border-left-color: var(--accent-cyan);
}

.layer.off .name {
  color: var(--fg-dim);
  text-decoration: line-through;
}

.layer .eye {
  padding: 0 4px;
  border: none;
  background: none;
  color: var(--accent-cyan);
}

.layer .glyph {
  color: var(--accent-purple);
}

.layer .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer .count {
  color: var(--accent-chrome);
  font-size: 10px;
}

#props,
#fx {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 6px;
}

.row > span {
  color: var(--fg-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row > select,
.row > input[type="text"],
.row > textarea {
  grid-column: 2 / 4;
  min-width: 0;
}

.row > input[type="checkbox"],
.row > input[type="color"] {
  justify-self: start;
}

.row output {
  color: var(--accent-cyan);
  text-align: right;
  font-size: 11px;
}

textarea {
  resize: vertical;
  min-height: 44px;
}

input[type="range"] {
  appearance: none;
  width: 100%;
  min-width: 60px;
  height: 14px;
  background: transparent;
  cursor: ew-resize;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: linear-gradient(90deg, var(--accent-purple), var(--line));
  border: 1px solid var(--line);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: linear-gradient(90deg, var(--accent-purple), var(--line));
  border: 1px solid var(--line);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 8px;
  height: 14px;
  margin-top: -6px;
  background: var(--accent-chrome);
  border: 1px solid var(--bg-void);
}

input[type="range"]::-moz-range-thumb {
  width: 8px;
  height: 14px;
  background: var(--accent-chrome);
  border: 1px solid var(--bg-void);
  border-radius: 0;
}

input[type="checkbox"] {
  appearance: none;
  width: 13px;
  height: 13px;
  border: 1px solid var(--line-hot);
  background: var(--bg-inset);
  cursor: pointer;
}

input[type="checkbox"]:checked {
  background: var(--accent-cyan);
  box-shadow: inset 0 0 0 2px var(--bg-void);
}

input[type="color"] {
  width: 34px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--line-hot);
  background: none;
  cursor: pointer;
}

.card {
  border: 1px solid var(--line);
  background: var(--bg-inset);
  transition: border-color var(--ease), opacity var(--ease);
}

.card:hover {
  border-color: var(--line-hot);
}

.card.off {
  opacity: 0.5;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 5px;
  border-bottom: 1px dotted var(--line);
}

.card-head button {
  padding: 0 5px;
  border: none;
  background: none;
  box-shadow: none;
}

.card-head .card-name {
  flex: 1;
  text-align: left;
  color: var(--accent-purple);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 5px;
}

.empty {
  padding: 12px 6px;
  color: var(--fg-dim);
  text-align: center;
  border: 1px dotted var(--line);
}

#stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
  min-width: 0;
}

#frame {
  position: relative;
  aspect-ratio: 1;
  height: 100%;
  max-height: calc(100% - 100px);
  max-width: 100%;
  border: 1px solid var(--line-hot);
  box-shadow: 6px 6px 0 rgba(154, 142, 214, 0.18), -6px -6px 0 rgba(87, 203, 222, 0.12);
  background-color: #121a24;
  background-image: repeating-conic-gradient(#1b2531 0 25%, transparent 0 50%);
  background-size: 16px 16px;
}

#frame.drag {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px var(--accent-cyan);
}

#gl {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#ring {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle closest-side, transparent 99.4%, rgba(5, 8, 12, 0.82) 100%);
}

#hint {
  color: var(--fg-dim);
  font-size: 11px;
  text-align: center;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 12px;
  border-top: 1px solid var(--line);
  color: var(--accent-cyan);
  background: var(--bg-inset);
}

.stars {
  color: var(--accent-purple);
  animation: blink 1.4s steps(2) infinite;
}

@keyframes blink {
  50% { opacity: 0.35; }
}

@media (max-width: 1024px) {
  body {
    overflow: auto;
    height: auto;
  }

  main {
    grid-template-columns: 1fr;
  }

  #stage {
    order: -1;
  }

  #frame {
    height: auto;
    width: min(100%, 70vh);
    max-height: none;
  }

  .win {
    max-height: 70vh;
  }
}

@media (max-width: 480px) {
  #bar {
    gap: 6px;
  }

  .tag {
    display: none;
  }

  .row {
    grid-template-columns: 64px minmax(0, 1fr) 40px;
  }
}

@media (min-width: 1920px) {
  body {
    font-size: 14px;
  }

  main {
    grid-template-columns: 360px minmax(0, 1fr) 420px;
  }
}

@media (min-width: 2560px) {
  body {
    font-size: 16px;
  }

  main {
    grid-template-columns: 440px minmax(0, 1fr) 520px;
  }
}

@media (min-width: 3840px) {
  body {
    font-size: 22px;
  }

  main {
    grid-template-columns: 640px minmax(0, 1fr) 760px;
  }
}

@media (min-width: 6000px) {
  body {
    font-size: 32px;
  }

  main {
    grid-template-columns: 960px minmax(0, 1fr) 1100px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #logo::after,
  .stars {
    animation: none;
  }
}

#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#toolbar .group {
  background: var(--bg-panel);
}

#toolbar kbd {
  margin-left: 5px;
  color: var(--accent-cyan);
  font: inherit;
  font-size: 10px;
}

#toolbar button.on kbd {
  color: var(--bg-void);
}

#toolbar [hidden] {
  display: none;
}

#brush input[type="range"] {
  width: 70px;
}

#brush label {
  display: flex;
  align-items: center;
  gap: 4px;
}

#giz {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#gl.paint {
  cursor: crosshair;
}

#props h3 {
  margin-top: 6px;
  padding: 2px 4px;
  font-size: 11px;
  font-weight: normal;
  letter-spacing: 1px;
  color: var(--accent-cyan);
  border-bottom: 1px dotted var(--line-hot);
}

#props h3::before {
  content: "☆ ";
  color: var(--accent-purple);
}

#help {
  margin: auto;
  width: min(560px, 92vw);
  max-height: 86vh;
  color: var(--fg);
}

#help::backdrop {
  background: rgba(5, 8, 12, 0.7);
  backdrop-filter: blur(3px);
}

#keys {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 14px;
  padding: 6px 2px;
}

#keys dt {
  color: var(--accent-chrome);
  white-space: nowrap;
}

#keys dd {
  color: var(--fg-dim);
}

#help:not([open]) {
  display: none;
}
