:root {
  color-scheme: dark;
  --bg: #11110f;
  --panel: #181816;
  --panel-raised: #1f1f1c;
  --surface: #252521;
  --surface-hover: #2d2d28;
  --text: #f2efe7;
  --muted: #9a988f;
  --faint: #6d6b64;
  --line: #373730;
  --line-strong: #555249;
  --accent: #cbff45;
  --accent-ink: #16190c;
  --danger: #ff705f;
  --paper: #e9e0cf;
  --red: #95170e;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  font-size: 13px;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: inherit;
}

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

.app-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 58px;
  flex: 0 0 58px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: #151513;
  position: relative;
  z-index: 10;
}

.brand,
.top-actions,
.document-meta,
.zoom-control,
.stage-label,
.section-heading,
.field-row,
.inspector-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  font-family: Georgia, serif;
  font-size: 19px;
  line-height: 1;
  color: var(--accent);
}

.brand-divider {
  width: 1px;
  height: 18px;
  background: var(--line-strong);
}

.brand-name {
  color: #d5d1c8;
  font-size: 12px;
  text-transform: uppercase;
}

.document-meta {
  gap: 10px;
}

.project-name {
  width: 180px;
  border: 0;
  border-bottom: 1px solid transparent;
  padding: 5px 4px;
  background: transparent;
  color: var(--text);
  text-align: center;
  font-weight: 600;
}

.project-name:hover,
.project-name:focus {
  border-bottom-color: var(--line-strong);
}

.save-state {
  color: var(--faint);
  font-size: 11px;
  min-width: 54px;
}

.top-actions {
  justify-content: flex-end;
  gap: 6px;
}

.editor-layout {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 254px minmax(420px, 1fr) 294px;
}

.left-panel,
.right-panel {
  min-height: 0;
  overflow-y: auto;
  background: var(--panel);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.left-panel {
  border-right: 1px solid var(--line);
}

.right-panel {
  border-left: 1px solid var(--line);
}

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

.compact-section {
  padding-bottom: 10px;
}

.section-heading {
  justify-content: space-between;
  gap: 12px;
  min-height: 24px;
  margin-bottom: 11px;
}

.section-heading h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: #cfccc3;
}

.section-heading > span {
  color: var(--faint);
  font-family: "Courier New", monospace;
  font-size: 10px;
}

.template-list,
.preset-list,
.layer-list,
.project-actions,
.inspector-form {
  display: grid;
  gap: 8px;
}

.template-card,
.preset-card,
.layer-row {
  position: relative;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-raised);
  transition: border-color 150ms ease, background 150ms ease;
}

.template-card:hover,
.preset-card:hover,
.layer-row:hover {
  background: var(--surface);
  border-color: var(--line-strong);
}

.template-card.is-active,
.preset-card.is-active,
.layer-row.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.template-card {
  min-height: 65px;
  padding: 7px;
  display: grid;
  grid-template-columns: 72px 1fr 18px;
  align-items: center;
  gap: 9px;
  text-align: left;
  cursor: pointer;
}

.template-thumb {
  width: 72px;
  height: 48px;
  display: block;
  border-radius: 3px;
  background-color: #222;
  background-position: center;
  background-size: cover;
}

.crimson-thumb {
  background-image: url("./assets/crimson-club-clean.png");
}

.archive-thumb {
  background-image: url("./assets/archive-collage-clean.png");
}

.template-copy,
.preset-card > span:last-child {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.template-copy strong,
.preset-card strong {
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-copy small,
.preset-card small {
  color: var(--muted);
  font-size: 10px;
}

.template-check {
  opacity: 0;
  color: var(--accent);
  font-size: 14px;
}

.template-card.is-active .template-check {
  opacity: 1;
}

.preset-card {
  min-height: 48px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: center;
  text-align: left;
  cursor: pointer;
}

.ratio-icon {
  display: block;
  border: 1px solid var(--muted);
  background: #141412;
  justify-self: center;
}

.ratio-portrait { width: 13px; height: 23px; }
.ratio-four-three { width: 22px; height: 17px; }
.ratio-wide { width: 24px; height: 14px; }
.ratio-banner { width: 25px; height: 10px; }

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.primary-button,
.tool-button,
.outline-button,
.danger-button,
.text-row-button,
.text-button,
.icon-button {
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease, opacity 150ms ease;
}

.primary-button {
  height: 34px;
  padding: 0 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 750;
}

.primary-button:hover {
  background: #ddff82;
}

.tool-button,
.outline-button,
.danger-button {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: #d7d3ca;
}

.tool-button {
  height: 32px;
  padding: 0 10px;
  font-size: 11px;
}

.tool-button:hover,
.tool-button.is-active {
  background: var(--surface);
  color: var(--text);
  border-color: #77736a;
}

.tool-button.is-active::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}

.outline-button,
.danger-button {
  min-height: 34px;
  padding: 7px 9px;
  font-size: 11px;
}

.outline-button:hover {
  background: var(--surface-hover);
}

.danger-button {
  color: #ff9a8d;
  border-color: #6b3933;
}

.danger-button:hover {
  background: #3d211e;
}

.text-button,
.text-row-button {
  background: transparent;
  color: var(--muted);
}

.text-button {
  padding: 3px 0;
  font-size: 10px;
}

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

.text-row-button {
  width: 100%;
  padding: 5px 0;
  text-align: left;
  font-size: 11px;
}

.icon-button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #c8c4ba;
  font-size: 18px;
  line-height: 1;
}

.icon-button:hover:not(:disabled) {
  background: var(--surface);
}

.icon-button:disabled {
  opacity: 0.28;
  cursor: default;
}

.stage-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 46px minmax(0, 1fr) 30px;
  background: #0c0c0b;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: #141412;
}

.stage-label {
  gap: 9px;
}

.stage-label > span {
  font-weight: 650;
}

.stage-label small {
  color: var(--muted);
}

.zoom-control {
  gap: 3px;
}

.zoom-control > span {
  width: 46px;
  text-align: center;
  color: var(--muted);
  font-family: "Courier New", monospace;
  font-size: 10px;
}

.stage {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background-color: #0e0e0d;
  background-image:
    linear-gradient(#171714 1px, transparent 1px),
    linear-gradient(90deg, #171714 1px, transparent 1px);
  background-size: 24px 24px;
}

.canvas-wrap {
  flex: 0 0 auto;
  position: relative;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.08);
  line-height: 0;
}

#coverCanvas {
  display: block;
  max-width: none;
  background: #1c1b18;
  cursor: default;
  touch-action: none;
}

#coverCanvas.is-dragging {
  cursor: grabbing;
}

.inline-text-editor {
  position: absolute;
  z-index: 4;
  min-width: 96px;
  min-height: 42px;
  margin: 0;
  padding: 5px 7px;
  overflow: hidden;
  resize: none;
  border: 1px solid var(--accent);
  border-radius: 2px;
  outline: 2px solid rgba(203, 255, 69, 0.2);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.38);
  letter-spacing: 0;
  white-space: pre-wrap;
}

.inline-text-editor[hidden] {
  display: none;
}

.stage-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-top: 1px solid var(--line);
  background: #141412;
  color: var(--faint);
  font-size: 10px;
  text-align: center;
}

.empty-inspector {
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 20px;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  text-align: center;
}

.empty-glyph {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  font-family: Georgia, serif;
  font-size: 18px;
}

.empty-inspector strong {
  font-size: 12px;
}

.empty-inspector p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.field-row {
  gap: 8px;
}

.field-row > .field {
  flex: 1 1 0;
  min-width: 0;
}

.three-cols {
  align-items: flex-end;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  color: var(--muted);
  font-size: 10px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #121211;
  color: var(--text);
}

.field input,
.field select {
  height: 32px;
  padding: 0 8px;
}

.field textarea {
  min-height: 76px;
  resize: vertical;
  padding: 8px;
  line-height: 1.45;
}

.field input:hover,
.field textarea:hover,
.field select:hover,
.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--line-strong);
}

.color-field input[type="color"] {
  padding: 4px;
}

.range-field > span {
  display: flex;
  justify-content: space-between;
}

.range-field output {
  color: #d3cfc4;
  font-family: "Courier New", monospace;
}

.range-field input[type="range"] {
  height: 18px;
  padding: 0;
  border: 0;
  accent-color: var(--accent);
}

.inspector-actions {
  gap: 8px;
  margin-top: 3px;
}

.inspector-actions > button {
  flex: 1;
}

.layers-section {
  padding-bottom: 24px;
}

.layer-row {
  min-height: 40px;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 7px;
  padding: 5px 6px;
  cursor: pointer;
}

.layer-visibility,
.layer-order-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.layer-visibility {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  font-size: 10px;
}

.layer-visibility:hover,
.layer-order-button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.layer-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
  text-align: left;
}

.layer-copy strong,
.layer-copy small {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.layer-copy strong {
  font-size: 11px;
  font-weight: 600;
}

.layer-copy small {
  color: var(--faint);
  font-size: 9px;
}

.layer-order {
  display: flex;
}

.layer-order-button {
  width: 22px;
  height: 25px;
  padding: 0;
  border-radius: 3px;
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 30;
  transform: translate(-50%, 12px);
  min-width: 180px;
  max-width: min(90vw, 420px);
  padding: 10px 14px;
  border: 1px solid #555249;
  border-radius: 5px;
  background: #24231f;
  color: var(--text);
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.45);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1060px) {
  .editor-layout {
    grid-template-columns: 220px minmax(360px, 1fr) 260px;
  }

  .document-meta {
    display: none;
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }
}

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

  .app-shell {
    min-height: 100%;
    height: auto;
  }

  .topbar {
    position: sticky;
    top: 0;
    grid-template-columns: 1fr auto;
  }

  .brand-name,
  #safeZoneBtn {
    display: none;
  }

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

  .left-panel,
  .right-panel {
    overflow: visible;
    border: 0;
  }

  .left-panel {
    order: 2;
  }

  .right-panel {
    order: 3;
  }

  .stage-panel {
    order: 1;
    min-height: 65vh;
    grid-template-rows: 46px minmax(420px, 65vh) 30px;
  }

  .template-list,
  .preset-list {
    grid-template-columns: 1fr 1fr;
  }

  .stage {
    padding: 20px;
  }

  .project-name,
  .save-state {
    display: none;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding: 0 9px;
  }

  .top-actions {
    gap: 2px;
  }

  .primary-button {
    padding: 0 10px;
  }

  .template-list,
  .preset-list {
    grid-template-columns: 1fr;
  }

  .stage-panel {
    min-height: 58vh;
    grid-template-rows: 46px minmax(340px, 58vh) 34px;
  }

  .stage-toolbar {
    padding: 0 8px;
  }

  .stage-label small,
  .stage-hint {
    font-size: 9px;
  }

  .zoom-control .tool-button {
    display: none;
  }
}
