:root {
  color-scheme: dark;
  --page: #0c0d1c;
  --panel: #18162c;
  --ink: #f6f1ff;
  --muted: #c2b8db;
  --line: #423661;
  --purple: #b99aff;
  --gold: #ffe098;
  --shadow: #080817;
  --gutter: clamp(10px, 2vw, 30px);
  font: 16px/1.45 ui-rounded, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-height: 100dvh;
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background:
    radial-gradient(ellipse at 14% 0%, #292045 0%, transparent 46%),
    radial-gradient(ellipse at 88% 0%, #142942 0%, transparent 42%),
    var(--page);
  color: var(--ink);
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .62; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--purple); outline-offset: 2px; }
button svg { width: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.masthead {
  min-height: 100px;
  padding: 12px var(--gutter) 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.brand { display: flex; align-items: center; gap: clamp(8px, 1.4vw, 16px); }
.brand-mark {
  width: clamp(42px, 6vw, 63px);
  height: clamp(42px, 6vw, 63px);
  padding: 7px;
  flex: none;
  border-radius: 22px;
  background: #5934a6;
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.8;
  transform: rotate(-8deg);
  box-shadow: 0 4px #2a1959;
}
.satellite { fill: var(--gold); }
.brand strong { display: block; font-size: clamp(23px, 3.8vw, 41px); font-weight: 900; line-height: 1.14; }
.brand div span { display: block; margin-top: 4px; color: var(--muted); font-size: clamp(12px, 1.4vw, 16px); font-weight: 650; }
.masthead-actions, .preview-pagination { display: flex; align-items: center; gap: 9px; }
.view-button {
  min-height: 48px;
  padding: 8px clamp(10px, 2vw, 21px);
  border: 2px solid #b58638;
  border-radius: 15px;
  color: var(--gold);
  background: #493216;
  box-shadow: 0 4px #211608;
  font-size: clamp(14px, 1.7vw, 17px);
  font-weight: 850;
  white-space: nowrap;
}
.view-button:hover:not(:disabled) { background: #644519; }
.view-button[aria-pressed="true"] {
  border-color: #9971d6;
  color: #f0dfff;
  background: #3b265d;
  box-shadow: 0 4px #211534;
}
.view-button[aria-pressed="true"]:hover { background: #523477; }

.workspace, .preview { width: 100%; padding: 0 var(--gutter) var(--gutter); min-width: 0; }
.workspace {
  display: grid;
  grid-template-areas: "catalog board settings";
  grid-template-columns: minmax(198px, 18%) minmax(0, 1fr) minmax(206px, 20%);
  gap: clamp(10px, 1.5vw, 22px);
  min-height: 580px;
}
.catalog { grid-area: catalog; min-width: 0; display: flex; flex-direction: column; }
.sidebar { grid-area: settings; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.board {
  grid-area: board;
  position: relative;
  isolation: isolate;
  min-width: 0;
  min-height: 520px;
  overflow: hidden;
  border: 3px solid #6f54a8;
  border-radius: 27px;
  background: radial-gradient(ellipse at 51% 43%, #342965 0%, #171b43 56%, #0d1029 100%);
  color: #fff;
  box-shadow: 0 5px var(--shadow);
}
.viewport { position: absolute; inset: 0; cursor: grab; }
.viewport:active { cursor: grabbing; }
.viewport canvas { display: block; width: 100%; height: 100%; }
.object-label, .stage-hint { position: absolute; pointer-events: none; }
.object-label { inset: clamp(12px, 2vw, 24px) 16px auto clamp(12px, 2vw, 24px); }
.object-label p {
  display: inline-block;
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: #493216;
  color: var(--gold);
  font-size: 13px;
  font-weight: 850;
}
.object-label h1 { margin: 5px 0 0; font-size: clamp(26px, 3.6vw, 51px); line-height: 1.15; font-weight: 900; }
.stage-hint {
  bottom: 15px;
  left: clamp(12px, 2vw, 24px);
  right: 12px;
  color: #e8e1ff;
  font-size: clamp(12px, 1.15vw, 15px);
  font-weight: 650;
}
.stage-hint br { display: none; }
.message {
  position: absolute;
  top: 50%;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 28px);
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 10px 15px;
  border-radius: 12px;
  background: #31266a;
  color: #fff;
  text-align: center;
  pointer-events: none;
}
.message:empty { display: none; }

.panel {
  padding: clamp(11px, 1.3vw, 18px);
  border: 2px solid var(--line);
  border-radius: 23px;
  background: var(--panel);
  box-shadow: 0 4px var(--shadow);
}
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 12px; }
.panel-title h2 { display: flex; align-items: center; gap: 7px; margin: 0; font-size: clamp(17px, 1.55vw, 22px); font-weight: 850; }
.count-badge { padding: 4px 8px; border-radius: 999px; background: #32234f; color: #dec8ff; font-size: 13px; font-weight: 800; white-space: nowrap; }
.planet-list { display: grid; align-content: start; gap: 8px; overflow: auto; }
.planet-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  text-align: left;
  gap: 9px;
  width: 100%;
  min-height: 65px;
  padding: 5px 8px;
  border: 2px solid #483762;
  border-radius: 16px;
  background: #241c37;
  color: var(--ink);
}
.planet-card:nth-child(3n + 2) { background: #192a40; border-color: #324e6a; }
.planet-card:nth-child(3n) { background: #302133; border-color: #57394f; }
.planet-card:hover, .planet-card[aria-pressed="true"] { border-color: var(--purple); }
.planet-card[aria-pressed="true"] { background: #3e2b64; }
.planet-card:focus-visible { outline-offset: -4px; }
.planet-card strong { font-size: clamp(14px, 1.15vw, 17px); line-height: 1.25; overflow-wrap: anywhere; }
.planet-thumb { display: block; width: clamp(42px, 4vw, 58px); aspect-ratio: 1; }

.controls { border-color: #345773; background: #17273c; }
.interior { border-color: #613952; background: #2b1a30; }
.panel-icon {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 11px;
  background: #244963;
  color: #b9edff;
  font-size: 23px;
  line-height: 1;
}
.interior .panel-icon { background: #502849; color: #ffc2e3; }
.control-row, .speed {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  color: #dae5fa;
  font-weight: 700;
}
.control-row { min-height: 55px; margin-bottom: 6px; }
.switch {
  width: 62px;
  height: 44px;
  padding: 5px;
  border: 2px solid #8e7eae;
  border-radius: 999px;
  background: #2f2943;
}
.switch::before { content: ""; display: block; width: 27px; height: 27px; border-radius: 50%; background: #ad9cc9; }
.switch[aria-checked="true"] { background: #603bb8; border-color: #a383f0; }
.switch[aria-checked="true"]::before { transform: translateX(20px); background: #fff; }
.speed output { padding: 2px 7px; border-radius: 8px; color: #e1ccff; background: #382958; }
.speed input { grid-column: 1 / -1; width: 100%; min-height: 44px; margin: -5px 0 5px; accent-color: var(--purple); cursor: pointer; }
.reset {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  width: 100%;
  min-height: 48px;
  padding: 7px;
  border: 2px solid #4b7898;
  border-radius: 14px;
  color: #d1edff;
  background: #213952;
  font-weight: 800;
}
.reset:hover:not(:disabled) { background: #2b4c6a; }
.interior .reset { border-color: #a15a87; color: #ffd0e9; background: #4b2545; }
.interior .reset:hover, .interior .reset[aria-expanded="true"] { background: #653356; }
.layer-list { display: grid; gap: 8px; padding: 0; margin: 13px 0 0; list-style: none; }
.layer-list li { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; }
.layer-swatch { width: 13px; height: 13px; flex: none; border: 1px solid #37205355; border-radius: 4px; }
.layer-note { margin: 11px 0 0; color: var(--muted); font-size: 14px; }

.preview-heading { display: flex; justify-content: space-between; align-items: end; gap: 10px; margin-bottom: 13px; }
.preview-heading h1 { margin: 0; font-size: clamp(25px, 3vw, 35px); font-weight: 900; }
.preview-heading p { margin: 2px 0 0; color: var(--muted); font-weight: 650; }
.preview-stage { position: relative; isolation: isolate; }
.preview-stage > canvas { position: absolute; inset: 0; z-index: 1; display: block; width: 100%; height: 100%; pointer-events: none; }
.preview-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(6px, 1vw, 12px); }
.preview-card {
  --tile-ink: #e6d5ff;
  --tile-label: #382751;
  --tile-line: #624d86;
  position: relative;
  min-width: 0;
  height: clamp(96px, calc((100svh - 220px) / 4), 260px);
  padding: 0;
  border: 2px solid var(--tile-line);
  border-radius: clamp(11px, 1.6vw, 22px);
  background: radial-gradient(ellipse at 50% 40%, #31295e, #141831 82%);
  color: var(--tile-ink);
  box-shadow: 0 3px var(--shadow);
}
.preview-card:nth-child(4n + 2) { --tile-label: #203a51; --tile-ink: #c6edff; --tile-line: #426c8d; }
.preview-card:nth-child(4n + 3) { --tile-label: #44331d; --tile-ink: #ffe6ac; --tile-line: #7d6138; }
.preview-card:nth-child(4n + 4) { --tile-label: #45273e; --tile-ink: #ffd4ec; --tile-line: #784f72; }
.preview-card:hover, .preview-card:focus-visible { border-color: var(--purple); }
.preview-card span {
  position: absolute;
  inset: auto -1px -1px;
  z-index: 2;
  display: grid;
  place-items: center;
  min-height: 31px;
  padding: 3px;
  border-radius: 0 0 clamp(9px, 1.5vw, 19px) clamp(9px, 1.5vw, 19px);
  background: var(--tile-label);
  font-size: clamp(11px, 1.2vw, 16px);
  font-weight: 850;
  line-height: 1.12;
  overflow-wrap: anywhere;
}
.preview-card.empty { border-style: dashed; border-color: #58456f; background: #1a172d; box-shadow: none; }

@media (width > 900px) {
  .planet-list { flex: 1; min-height: 0; contain: size; }
}

@media (max-width: 900px) {
  .workspace { grid-template-areas: "board board" "catalog settings"; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board { min-height: clamp(365px, 59svh, 570px); }
  .planet-list { max-height: 410px; }
}

@media (max-width: 510px) {
  .masthead { min-height: 78px; }
  .brand-mark { border-radius: 15px; }
  .workspace { grid-template-areas: "board" "catalog" "settings"; grid-template-columns: minmax(0, 1fr); }
  .board { min-height: clamp(320px, 51svh, 430px); }
  .planet-list { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 230px; }
  .planet-card { min-height: 55px; padding: 4px; gap: 5px; }
  .planet-thumb { width: 38px; }
  .stage-hint span { display: none; }
  .stage-hint br { display: initial; }
  .preview-heading p { font-size: 14px; }
}
