:root {
  --bg: #f4eee5;
  --panel: rgba(255, 252, 247, 0.9);
  --panel-strong: #fffaf5;
  --line: rgba(73, 56, 40, 0.1);
  --ink: #241d15;
  --muted: #6a5b4d;
  --accent: #9f2f23;
  --accent-strong: #7c241a;
  --accent-soft: rgba(159, 47, 35, 0.08);
  --shadow: 0 16px 42px rgba(61, 43, 26, 0.09);
  --radius: 22px;
  --font-sans: "PingFang SC", "Hiragino Sans GB", -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --font-serif: "Songti SC", "Iowan Old Style", serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at top right, rgba(159, 47, 35, 0.12), transparent 28%),
    radial-gradient(circle at left bottom, rgba(116, 138, 85, 0.15), transparent 26%),
    linear-gradient(180deg, #f8f2e9 0%, var(--bg) 100%);
}

button,
input,
textarea {
  font: inherit;
}

.shell {
  position: relative;
  min-height: 100vh;
  padding: 18px;
}

.portal-screen[hidden],
.workspace-shell[hidden] {
  display: none !important;
}

.shell-bg {
  position: fixed;
  inset: auto;
  pointer-events: none;
  border-radius: 999px;
  filter: blur(18px);
  opacity: 0.5;
}

.shell-bg-one {
  width: 180px;
  height: 180px;
  top: 48px;
  right: 48px;
  background: rgba(159, 47, 35, 0.12);
}

.shell-bg-two {
  width: 140px;
  height: 140px;
  bottom: 60px;
  left: 54px;
  background: rgba(116, 138, 85, 0.11);
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle,
.muted-note {
  color: var(--muted);
  line-height: 1.45;
  font-size: 13px;
}

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 14px;
}

.portal-screen {
  position: relative;
  z-index: 1;
  min-height: calc(100vh - 48px);
  display: grid;
  place-items: center;
}

.portal-card {
  width: min(500px, 100%);
  padding: 24px;
}

.portal-copy {
  margin-bottom: 16px;
}

.portal-copy h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(30px, 5vw, 42px);
  letter-spacing: -0.02em;
}

.portal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.portal-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.portal-status {
  margin: 12px 0 0;
}

.portal-status[data-kind="error"] {
  color: var(--accent-strong);
}

.portal-status[data-kind="success"] {
  color: #1e7a46;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.sidebar {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-create-button {
  width: 100%;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-card {
  padding: 14px 16px;
}

.step-card.is-locked {
  opacity: 0.46;
  filter: saturate(0.8);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.step-heading {
  display: flex;
  gap: 10px;
  align-items: center;
}

.section-head h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.step-index {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(159, 47, 35, 0.1);
  color: var(--accent);
  font-weight: 700;
  flex: 0 0 auto;
  font-size: 13px;
}

.step-state {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(73, 56, 40, 0.08);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.step-copy {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

input:not([type="range"]),
textarea {
  width: 100%;
  border: 1px solid rgba(73, 56, 40, 0.18);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

textarea {
  min-height: 132px;
  resize: vertical;
  line-height: 1.55;
}

input:not([type="range"]):focus,
textarea:focus {
  outline: 2px solid rgba(159, 47, 35, 0.18);
  border-color: rgba(159, 47, 35, 0.42);
}

.primary-button,
.ghost-button,
.danger-button {
  border: none;
  border-radius: 14px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease;
  font-size: 13px;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  font-weight: 700;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.58);
  color: var(--ink);
  border: 1px solid rgba(73, 56, 40, 0.12);
}

.ghost-button.danger-ghost {
  color: var(--accent-strong);
  border-color: rgba(159, 47, 35, 0.18);
  background: rgba(159, 47, 35, 0.06);
}

.danger-button {
  color: white;
  font-weight: 700;
  background: linear-gradient(135deg, #ba2c21, #8d2017);
}

.primary-button:hover,
.ghost-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.ghost-button:disabled,
.danger-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.stack {
  display: flex;
  flex-direction: column;
}

.gap-12 {
  gap: 12px;
}

.upload-box,
.publish-box {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.54);
  border: 1px dashed rgba(73, 56, 40, 0.18);
}

.publish-copy-preview {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(73, 56, 40, 0.12);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.publish-summary {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.publish-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.upload-input {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: white;
  color: var(--ink);
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid rgba(73, 56, 40, 0.14);
  cursor: pointer;
}

.upload-input.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.upload-trigger {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
}

.upload-input.is-disabled .upload-trigger {
  cursor: not-allowed;
}

.upload-input input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  pointer-events: none;
}

.config-grid-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px 86px;
  gap: 10px;
  margin-bottom: 6px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.config-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.config-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px 86px;
  gap: 10px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
  align-items: center;
}

.compact-input {
  padding: 10px 12px;
}

.style-editor {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

.style-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.style-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(73, 56, 40, 0.1);
}

.style-control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

.style-value {
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}

.range-input {
  width: 100%;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  background: transparent;
}

.range-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.style-preview-shell {
  padding: 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(73, 56, 40, 0.1);
}

.style-preview-paper {
  position: relative;
  min-height: 248px;
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(73, 56, 40, 0.1);
  background:
    linear-gradient(180deg, rgba(246, 240, 230, 0.9), rgba(255, 255, 255, 0.95)),
    white;
  --preview-opacity: 0.34;
  --preview-angle: 32deg;
  --preview-font-size: 34px;
  --preview-footer-size: 14px;
}

.style-preview-meta {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: rgba(73, 56, 40, 0.45);
}

.style-preview-content {
  position: absolute;
  left: 16px;
  top: 54px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: rgba(36, 29, 21, 0.72);
  font-size: 12px;
}

.style-preview-content p {
  margin: 0;
}

.style-preview-line,
.style-preview-footer {
  position: absolute;
  color: rgba(79, 84, 97, var(--preview-opacity));
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

.style-preview-line {
  left: 50%;
  transform: translateX(-50%) rotate(var(--preview-angle));
  transform-origin: center;
  font-size: var(--preview-font-size);
}

.style-preview-line-one {
  top: 52px;
}

.style-preview-line-two {
  top: 114px;
}

.style-preview-line-three {
  top: 176px;
}

.style-preview-footer {
  right: 14px;
  bottom: 12px;
  font-size: var(--preview-footer-size);
}

.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.generated-rail {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.generated-card {
  flex: 0 0 220px;
  padding: 14px;
  border-radius: 18px;
  background: var(--panel-strong);
  border: 1px solid rgba(73, 56, 40, 0.12);
}

.generated-card h4 {
  margin: 0 0 10px;
  font-size: 16px;
}

.project-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.project-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.project-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
}

.project-item.active {
  border-color: rgba(159, 47, 35, 0.42);
  background: rgba(159, 47, 35, 0.08);
}

.project-delete-button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}

.project-delete-button:hover {
  background: rgba(159, 47, 35, 0.08);
  color: var(--accent);
}

.project-delete-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.empty-state {
  padding: 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.32);
  color: var(--muted);
}

.flash {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  max-width: 360px;
  padding: 14px 18px;
  border-radius: 18px;
  color: white;
  background: rgba(36, 29, 21, 0.92);
  box-shadow: var(--shadow);
}

.flash[hidden],
.modal[hidden] {
  display: none !important;
}

.flash.error {
  background: rgba(159, 47, 35, 0.96);
}

.flash.success {
  background: rgba(30, 122, 70, 0.96);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(20, 16, 13, 0.56);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-dialog {
  width: min(1100px, 100%);
  height: min(85vh, 860px);
  background: white;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.modal-dialog-sm {
  width: min(460px, 100%);
  height: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(73, 56, 40, 0.12);
}

.modal-body {
  padding: 16px;
}

.modal-copy {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-status {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--accent-strong);
}

.modal-note {
  margin: -2px 0 0;
}

.preview-frame {
  width: 100%;
  height: calc(100% - 70px);
  border: 0;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions .ghost-button {
    flex: 1 1 180px;
  }

  .style-editor,
  .config-grid-head,
  .config-row {
    grid-template-columns: 1fr;
  }

  .style-preview-paper {
    min-height: 280px;
  }

  .style-preview-line {
    left: 18px;
    transform: rotate(var(--preview-angle));
    transform-origin: left center;
  }

  .portal-card {
    padding: 20px;
  }
}
