:root {
  --ink: #17212b;
  --muted: #68727c;
  --line: #dce2e7;
  --surface: #ffffff;
  --canvas-bg: #edf0f3;
  --accent: #7557a6;
  --accent-deep: #5d3f8d;
  --accent-soft: #f1ebf8;
  --shadow: 0 18px 50px rgba(25, 35, 45, .12);
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: #f5f6f7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button, label, summary { -webkit-tap-highlight-color: transparent; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 0 28px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.25rem;
  letter-spacing: .02em;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: white;
  background: var(--accent);
  border-radius: 50%;
}

.topbar-actions { display: flex; align-items: center; gap: 18px; }

.status { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .83rem; }
.status i { width: 7px; height: 7px; background: #53a578; border-radius: 50%; box-shadow: 0 0 0 4px rgba(83,165,120,.14); }

.button {
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}

.button-primary { color: white; background: var(--accent); box-shadow: 0 8px 22px rgba(117,87,166,.2); }
.button-primary:hover { background: var(--accent-deep); }

.editor-shell {
  display: grid;
  grid-template-columns: minmax(360px, 470px) minmax(540px, 1fr);
  min-height: calc(100vh - 68px);
}

.controls {
  padding: 38px 34px 70px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.controls-heading { max-width: 390px; margin: 0 auto 28px; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-weight: 800; font-size: .73rem; letter-spacing: .16em; text-transform: uppercase; }
.controls-heading h1 { margin: 0; font: 400 clamp(1.75rem, 3vw, 2.3rem)/1.08 Georgia, "Times New Roman", serif; }
.controls-heading > p:last-child { margin: 11px 0 0; color: var(--muted); line-height: 1.55; }

.step-list { max-width: 390px; margin: 0 auto; }
.panel { border-top: 1px solid var(--line); }
.panel:last-child { border-bottom: 1px solid var(--line); }
.panel summary { display: flex; align-items: center; justify-content: space-between; min-height: 64px; cursor: pointer; list-style: none; font-weight: 750; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary span { display: flex; align-items: center; gap: 11px; }
.panel summary b { display: grid; width: 25px; height: 25px; place-items: center; color: var(--accent); background: var(--accent-soft); border-radius: 50%; font-size: .76rem; }
.panel summary i { width: 9px; height: 9px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); transition: transform .2s ease; }
.panel[open] summary i { transform: rotate(225deg); }
.panel-body { display: grid; gap: 17px; padding: 0 0 25px 36px; }

.field, .field-group { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.field > span, .field-group legend { color: #39444f; font-size: .84rem; font-weight: 700; }
.field input, .field select {
  width: 100%;
  min-height: 45px;
  padding: 0 13px;
  color: var(--ink);
  background: #fbfcfd;
  border: 1px solid #cfd7dd;
  border-radius: 9px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(117,87,166,.12); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { margin: -6px 0 0; color: var(--muted); font-size: .76rem; line-height: 1.45; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; background: #f0f2f4; border-radius: 10px; }
.segmented input, .shape-grid input, .swatches input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: grid; min-height: 37px; place-items: center; cursor: pointer; border-radius: 7px; color: var(--muted); font-size: .84rem; }
.segmented input:checked + span { color: var(--accent-deep); background: white; box-shadow: 0 2px 8px rgba(22,32,42,.09); font-weight: 700; }

.swatches { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.swatches label { position: relative; display: grid; width: 31px; height: 31px; place-items: center; cursor: pointer; }
.swatches label span { display: block; width: 27px; height: 27px; background: var(--swatch); border: 1px solid rgba(0,0,0,.13); border-radius: 50%; }
.swatches input:checked + span { outline: 2px solid var(--accent); outline-offset: 3px; }
.swatches .custom-color { overflow: hidden; border: 1px dashed #9aa4ad; border-radius: 50%; color: var(--muted); }
.swatches .custom-color input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; pointer-events: auto; }

.shape-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.shape-grid label span { display: grid; min-height: 76px; place-items: center; align-content: center; gap: 6px; cursor: pointer; color: var(--muted); border: 1px solid #d8dee3; border-radius: 9px; font-size: .73rem; }
.shape-grid input:checked + span { color: var(--accent-deep); border-color: var(--accent); background: var(--accent-soft); }
.shape { display: block; color: currentColor; }
.shape.circle { width: 27px; height: 27px; border: 1.5px solid currentColor; border-radius: 50%; }
.shape.heart { font: 28px/1 Georgia, serif; }
.shape.compass { font: 29px/1 Georgia, serif; }

.switch-list { display: grid; gap: 2px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; min-height: 38px; color: #39444f; font-size: .87rem; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; }
.switch-row i { position: relative; width: 38px; height: 22px; background: #cbd2d8; border-radius: 100px; transition: .2s ease; }
.switch-row i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: white; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.25); transition: .2s ease; }
.switch-row input:checked + i { background: var(--accent); }
.switch-row input:checked + i::after { transform: translateX(16px); }

.file-field { position: relative; }
.file-field input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-field em { display: grid; min-height: 45px; place-items: center; color: var(--accent-deep); background: var(--accent-soft); border: 1px dashed #aa98c7; border-radius: 9px; cursor: pointer; font-style: normal; font-weight: 700; font-size: .84rem; }

.preview-area { position: relative; min-width: 0; padding: 25px 34px 45px; background: var(--canvas-bg); }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; max-width: 770px; margin: 0 auto 18px; color: var(--muted); font-size: .8rem; }
.preview-toolbar > div:first-child { display: flex; align-items: center; gap: 11px; }
.preview-label { color: var(--ink); font-weight: 800; }
.zoom-control { display: flex; align-items: center; overflow: hidden; background: white; border: 1px solid #d8dee3; border-radius: 8px; }
.zoom-control button { width: 34px; height: 32px; border: 0; background: white; cursor: pointer; color: var(--ink); }
.zoom-control output { min-width: 48px; text-align: center; color: var(--muted); font-size: .75rem; }

.canvas-stage { display: grid; min-height: calc(100vh - 170px); place-items: start center; overflow: auto; padding: 0 20px 35px; }
.canvas-wrap { width: min(100%, 720px); transition: width .2s ease; }
#posterCanvas { display: block; width: 100%; height: auto; background: #071727; box-shadow: var(--shadow); }
.mobile-actions { max-width: 720px; margin: 18px auto 0; text-align: center; }
.mobile-actions .button { width: 100%; }
.mobile-actions p { margin: 10px 0 0; color: var(--muted); font-size: .73rem; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 30; max-width: 310px; padding: 12px 16px; color: white; background: #202a34; border-radius: 9px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s ease; font-size: .84rem; }
.toast.show { opacity: 1; transform: translateY(0); }

.celestial-host {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 820px;
  height: 820px;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
}

#celestial-map {
  width: 820px !important;
  height: 820px !important;
}

@media (max-width: 980px) {
  .editor-shell { grid-template-columns: minmax(330px, 400px) minmax(410px, 1fr); }
  .controls { padding-inline: 24px; }
  .preview-area { padding-inline: 20px; }
}

@media (max-width: 780px) {
  .topbar { padding: 0 17px; }
  .status, #downloadTop { display: none; }
  .editor-shell { display: flex; flex-direction: column; }
  .controls { order: 2; border: 0; padding: 31px 20px 50px; }
  .preview-area { order: 1; padding: 17px 12px 26px; }
  .canvas-stage { min-height: 0; padding: 0 5px 18px; overflow: visible; }
  .canvas-wrap { max-width: 510px; }
  .preview-toolbar { padding-inline: 5px; }
  .controls-heading, .step-list { max-width: 510px; }
}

@media (max-width: 430px) {
  .brand { font-size: 1.05rem; }
  .brand-mark { width: 31px; height: 31px; }
  .controls { padding-inline: 16px; }
  .panel-body { padding-left: 0; }
  .field-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
