:root {
  color-scheme: dark;
  --bg: #050b12;
  --panel: #091725;
  --panel-2: #0e2133;
  --line: #2b4358;
  --muted: #9dafc0;
  --text: #fffdf8;
  --red: #d5191b;
  --blue: #70bdff;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: var(--text);
}

.editor-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 24, 39, 0.97);
  backdrop-filter: blur(12px);
}

.editor-title {
  min-width: 0;
}

.editor-title h1 {
  margin: 0;
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.button,
.file-button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid #3b5870;
  border-radius: 6px;
  background: #10283c;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.button:hover,
.file-button:hover {
  border-color: #6e91ad;
  background: #16344d;
}

.button.primary {
  border-color: var(--red);
  background: var(--red);
}

.button.danger {
  color: #ffd8d8;
}

.file-button input {
  display: none;
}

.editor-shell {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.sidebar {
  position: sticky;
  top: 64px;
  align-self: start;
  max-height: calc(100vh - 64px);
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.panel-section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-section h2 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

.layer-list {
  display: grid;
  gap: 6px;
}

.layer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--panel-2);
}

.layer-row.selected {
  border-color: var(--red);
  box-shadow: 0 0 0 1px rgba(213, 25, 27, 0.24);
}

.layer-row.empty {
  opacity: 0.5;
}

.select-layer {
  min-width: 0;
  overflow: hidden;
  padding: 6px 7px;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-toggle {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid #365069;
  border-radius: 5px;
  background: #0a1b2a;
  cursor: pointer;
}

.icon-toggle[aria-pressed="false"] {
  color: #718395;
}

.property-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.property-grid label,
.opacity-control label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.property-grid input[type="number"] {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #365069;
  border-radius: 5px;
  outline: 0;
  background: #07131f;
  color: var(--text);
}

.property-grid input:focus {
  border-color: var(--blue);
}

.opacity-control {
  margin-top: 10px;
}

.opacity-control input {
  width: 100%;
  accent-color: var(--red);
}

.property-actions {
  display: flex;
  gap: 7px;
  margin-top: 11px;
}

.property-actions .button {
  flex: 1;
}

.selection-name {
  margin: 0 0 9px;
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  min-height: 20px;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.status.ok {
  color: #7ce4a5;
}

.status.error {
  color: #ff9b9b;
}

.workspace {
  min-width: 0;
  padding: 24px;
  overflow: auto;
  background:
    radial-gradient(circle at 50% 25%, rgba(34, 72, 100, 0.3), transparent 42%),
    #050b12;
}

.stage-wrap {
  width: min(540px, 100%);
  margin: 0 auto;
}

.stage-note {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 12px;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #17212b;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.66);
  touch-action: none;
  user-select: none;
}

.canvas-layer,
.selection-plane {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  will-change: transform;
}

.canvas-layer img {
  display: block;
  width: 100%;
  height: 100%;
  -webkit-user-drag: none;
  user-select: none;
}

.selection-plane {
  z-index: 1000;
}

.selection-box {
  position: absolute;
  border: 2px solid var(--red);
  background: rgba(213, 25, 27, 0.035);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.72) inset;
  pointer-events: auto;
  cursor: move;
}

.selection-box.locked {
  border-color: #718395;
  background: rgba(113, 131, 149, 0.05);
  cursor: not-allowed;
}

.drag-surface {
  position: absolute;
  inset: 0;
}

.handle {
  position: absolute;
  z-index: 2;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.55);
}

.handle.scale {
  cursor: nwse-resize;
}

.handle.nw {
  top: -8px;
  left: -8px;
}

.handle.ne {
  top: -8px;
  right: -8px;
  cursor: nesw-resize;
}

.handle.sw {
  bottom: -8px;
  left: -8px;
  cursor: nesw-resize;
}

.handle.se {
  right: -8px;
  bottom: -8px;
}

.rotate-stem {
  position: absolute;
  bottom: 100%;
  left: 50%;
  width: 2px;
  height: 28px;
  background: var(--red);
  transform: translateX(-50%);
}

.handle.rotate {
  bottom: calc(100% + 22px);
  left: calc(50% - 7px);
  cursor: grab;
}

.selection-box.locked .handle,
.selection-box.locked .rotate-stem {
  display: none;
}

.keyboard-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

@media (max-width: 800px) {
  .editor-header {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .editor-shell {
    display: flex;
    flex-direction: column;
  }

  .sidebar {
    position: static;
    order: 2;
    max-height: none;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .workspace {
    order: 1;
    padding: 16px;
  }
}
