:root {
  --bg: #0f1115;
  --surface: #171b23;
  --surface-2: #202738;
  --line: #2f3850;
  --text: #f2f4f8;
  --muted: #a5b1c7;
  --accent: #ff8c3a;
  --accent-2: #2ec6ff;
  --danger: #ff5f7d;
  --ok: #1fd69e;
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 5%, rgba(255, 140, 58, 0.2), transparent 40%),
    radial-gradient(circle at 95% 20%, rgba(46, 198, 255, 0.2), transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

main {
  padding: 1rem;
  display: grid;
  gap: 0.9rem;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.hero {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  background: rgba(15, 17, 21, 0.82);
}

.hero h1 {
  font-size: 1.35rem;
}

.hero p {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.hero-right {
  display: grid;
  justify-items: end;
  gap: 0.35rem;
}

.render-mode-switch {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.42rem;
}

.render-mode-switch span {
  color: var(--muted);
  font-size: 0.82rem;
}

.render-mode-switch .mode-btn {
  padding: 0.34rem 0.58rem;
}

.render-mode-switch .mode-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.render-mode-hint {
  min-height: 1.1em;
  color: var(--muted);
  font-size: 0.77rem;
}

.render-mode-hint.error {
  color: var(--danger);
}

.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

.status.busy {
  border-color: var(--accent);
  color: var(--accent);
}

.status.error {
  border-color: var(--danger);
  color: var(--danger);
}

.status.ok {
  border-color: var(--ok);
  color: var(--ok);
}

.workspace {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 1rem;
  padding: 0;
}

.workspace.wizard-mode {
  grid-template-columns: 1fr;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}

.wizard-shell {
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(19, 23, 34, 0.92), rgba(15, 18, 28, 0.95));
  box-shadow: var(--shadow);
  padding: 0.75rem;
}

.wizard-head {
  display: grid;
  gap: 0.2rem;
}

.wizard-meta {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.45px;
}

.wizard-title {
  font-size: 1.05rem;
  color: #ffe2bd;
  font-weight: 700;
}

.wizard-nav {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 0.72rem;
}

.wizard-step-btn {
  border: 1px solid var(--line);
  background: rgba(13, 17, 27, 0.85);
  color: var(--muted);
  border-radius: 9px;
  padding: 0.5rem 0.45rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.wizard-step-btn:hover {
  border-color: rgba(255, 184, 82, 0.52);
}

.wizard-step-btn.done {
  color: #d9e6ff;
}

.wizard-step-btn.active {
  border-color: var(--accent-2);
  color: #cbf4ff;
  background: linear-gradient(180deg, rgba(17, 41, 58, 0.92), rgba(10, 24, 35, 0.92));
}

.wizard-controls {
  margin-top: 0.72rem;
  display: flex;
  justify-content: space-between;
  gap: 0.55rem;
}

.wizard-controls button {
  min-width: 150px;
}

.wizard-controls button:disabled {
  opacity: 0.5;
  cursor: default;
}

.panel {
  background: linear-gradient(180deg, rgba(32, 39, 56, 0.75), rgba(23, 27, 35, 0.95));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem;
  box-shadow: var(--shadow);
}

.preview-panel {
  position: sticky;
  top: 84px;
  align-self: start;
}

.workspace.wizard-mode .preview-panel {
  position: static;
  top: auto;
}

.panel.panel-empty {
  display: none;
}

details {
  border: 1px solid rgba(57, 69, 97, 0.72);
  border-radius: 10px;
  background: rgba(12, 16, 25, 0.72);
}

details + details {
  margin-top: 0.72rem;
}

summary {
  cursor: pointer;
  list-style: none;
  padding: 0.65rem 0.72rem;
  font-weight: 700;
  color: #ffdcae;
}

summary::-webkit-details-marker {
  display: none;
}

summary::before {
  content: "▸";
  margin-right: 0.45rem;
  color: var(--accent-2);
}

details[open] summary::before {
  content: "▾";
}

.details-body {
  padding: 0.1rem 0.72rem 0.75rem;
}

.wizard-hidden {
  display: none !important;
}

.content-mode-switch {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.72rem;
}

.content-mode-switch span {
  color: var(--muted);
  font-size: 0.82rem;
}

.mode-btn {
  border-radius: 999px;
  padding: 0.38rem 0.62rem;
  font-size: 0.8rem;
}

.mode-btn.active {
  border-color: var(--accent-2);
  color: #cbf4ff;
  background: rgba(15, 29, 43, 0.92);
}

.field-row {
  display: grid;
  gap: 0.38rem;
  margin-bottom: 0.72rem;
}

label {
  color: var(--muted);
  font-size: 0.86rem;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  background: rgba(14, 18, 27, 0.86);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 0.52rem 0.66rem;
}

textarea {
  resize: vertical;
}

button {
  border: 1px solid transparent;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #ffb852);
  color: #171717;
  font-weight: 700;
  padding: 0.56rem 0.8rem;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

button.full {
  width: 100%;
}

.actions.inline {
  display: flex;
  gap: 0.5rem;
  margin: 0.2rem 0 0.8rem;
}

.grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.grid.three {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
}

.grid.two.compact .field-row {
  margin-bottom: 0.45rem;
}

.grid.three.compact .field-row {
  margin-bottom: 0.45rem;
}

.question-list {
  display: grid;
  gap: 0.8rem;
}

.question-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(12, 16, 25, 0.82);
  padding: 0.65rem;
}

.question-card.active-question {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px rgba(46, 198, 255, 0.45);
}

.question-card h3 {
  font-size: 0.92rem;
  margin-bottom: 0.6rem;
}

.question-options {
  display: grid;
  gap: 0.45rem;
}

.option-line {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 0.35rem;
  align-items: center;
}

.option-line span {
  color: var(--muted);
  font-size: 0.85rem;
}

.question-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.58rem;
  gap: 0.6rem;
}

.question-actions select {
  width: auto;
}

.upload-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.upload-wrap.single {
  grid-template-columns: 1fr;
}

.upload-form {
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: rgba(12, 16, 25, 0.7);
  padding: 0.65rem;
  display: grid;
  gap: 0.5rem;
}

.upload-form label {
  color: var(--text);
}

.background-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  max-height: 490px;
  overflow: auto;
  padding-right: 0.2rem;
}

.overlay-grid {
  max-height: 380px;
}

.bg-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(10, 12, 20, 0.92);
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease;
}

.bg-card:hover {
  transform: translateY(-2px);
}

.bg-card.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 1px rgba(46, 198, 255, 0.45);
}

.bg-card img {
  width: 100%;
  display: block;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  background: #0b0f18;
}

.bg-meta {
  padding: 0.45rem 0.5rem 0.55rem;
}

.bg-name {
  font-size: 0.82rem;
  line-height: 1.25;
}

.bg-kind {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.45px;
}

.bg-cache-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 0.32rem;
  padding: 0.1rem 0.34rem;
  border-radius: 999px;
  font-size: 0.65rem;
  letter-spacing: 0.3px;
  border: 1px solid rgba(110, 221, 167, 0.65);
  color: #9be3bf;
  background: rgba(11, 42, 29, 0.72);
}

.hint {
  color: var(--muted);
  font-size: 0.84rem;
  margin-bottom: 0.72rem;
}

.layout-stage {
  width: min(100%, 345px);
  aspect-ratio: 9 / 16;
  margin: 0 auto 0.8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  position: relative;
  overflow: hidden;
  background: #0a0d13;
}

.layout-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 12%, rgba(255, 140, 58, 0.35), transparent 44%),
    radial-gradient(circle at 82% 18%, rgba(46, 198, 255, 0.27), transparent 46%),
    linear-gradient(160deg, #111624 0%, #1e2035 54%, #111623 100%);
}

.drag-item {
  position: absolute;
  z-index: 2;
  padding: 0.38rem 0.5rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(20, 23, 35, 0.82);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1.2;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: calc(100% - 14px);
  user-select: none;
  cursor: grab;
}

.drag-item.answer {
  border-color: rgba(31, 214, 158, 0.7);
  background: rgba(15, 33, 26, 0.86);
}

.drag-item.selected {
  border-color: rgba(46, 198, 255, 0.95);
  box-shadow: 0 0 0 1px rgba(46, 198, 255, 0.52);
  background: rgba(12, 36, 58, 0.86);
}

.drag-item.dragging {
  opacity: 0.85;
  cursor: grabbing;
}

.layout-editor-card {
  margin: 0.1rem 0 0.7rem;
  padding: 0.62rem;
  border: 1px solid rgba(63, 86, 128, 0.72);
  border-radius: 10px;
  background: rgba(8, 13, 24, 0.72);
}

.layout-slot-grid {
  margin-top: 0.1rem;
}

.layout-nudge {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
  margin: 0.15rem 0 0.62rem;
}

.layout-nudge button {
  padding: 0.44rem 0;
  line-height: 1;
}

.layout-actions-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.42rem;
}

.layout-actions-grid button:last-child {
  grid-column: 1 / -1;
}

.question-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.2rem 0 0.75rem;
}

.question-tab {
  border: 1px solid var(--line);
  background: rgba(11, 15, 22, 0.9);
  color: var(--text);
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  cursor: pointer;
}

.question-tab.active {
  border-color: var(--accent-2);
  color: #cbf4ff;
}

.coords {
  font-family: "Courier New", monospace;
  font-size: 0.76rem;
  color: var(--muted);
  background: rgba(11, 13, 20, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem;
  min-height: 72px;
  margin-top: 0.55rem;
  line-height: 1.35;
}

.render-btn {
  width: 100%;
  font-size: 1rem;
  padding: 0.8rem;
  margin-top: 0.35rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.2rem 0 0.55rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.checkbox-row input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent-2);
}

.result {
  margin-top: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem;
  background: rgba(11, 13, 20, 0.88);
}

.result.hidden {
  display: none;
}

.result video {
  width: 100%;
  max-height: 420px;
  border-radius: 8px;
  margin-top: 0.55rem;
  background: #000;
}

#resultLinks {
  margin-top: 0.55rem;
  display: grid;
  gap: 0.35rem;
}

#resultLinks a {
  color: var(--accent-2);
  text-decoration: none;
  word-break: break-all;
}

.history-list {
  display: grid;
  gap: 0.65rem;
  max-height: 390px;
  overflow: auto;
  padding-right: 0.2rem;
}

.history-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(11, 15, 22, 0.8);
  overflow: hidden;
}

.history-item img {
  width: 96px;
  height: 170px;
  object-fit: cover;
  background: #0a0d13;
}

.history-meta {
  padding: 0.52rem;
  display: grid;
  gap: 0.25rem;
}

.history-title {
  font-size: 0.84rem;
  color: #fff;
}

.history-sub {
  font-size: 0.76rem;
  color: var(--muted);
}

.history-links a {
  color: var(--accent-2);
  font-size: 0.78rem;
  text-decoration: none;
}

.history-links span {
  color: var(--muted);
  font-size: 0.76rem;
}

.history-actions {
  margin-top: 0.15rem;
}

.history-clone-btn {
  width: 100%;
  font-size: 0.78rem;
  padding: 0.38rem 0.5rem;
}

.empty-note {
  color: var(--muted);
  font-size: 0.84rem;
}

@media (max-width: 1200px) {
  main {
    padding: 0.85rem;
  }

  .wizard-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .hero {
    align-items: start;
    flex-direction: column;
  }

  .hero-right {
    width: 100%;
    justify-items: start;
  }

  .render-mode-switch {
    justify-content: flex-start;
  }

  main {
    padding: 0.65rem;
  }

  .wizard-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .wizard-controls {
    flex-direction: column;
  }

  .wizard-controls button {
    width: 100%;
  }

  .upload-wrap,
  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .background-grid {
    grid-template-columns: 1fr;
  }

  .history-item {
    grid-template-columns: 76px 1fr;
  }

  .history-item img {
    width: 76px;
    height: 136px;
  }

  .layout-actions-grid {
    grid-template-columns: 1fr;
  }

  .layout-actions-grid button:last-child {
    grid-column: auto;
  }
}
