:root {
  color-scheme: light dark;
  --ink: light-dark(#2a2018, #f4eadb);
  --muted: light-dark(#6f5f51, #bcae9b);
  --line: light-dark(#d9c6a8, #53483b);
  --surface: light-dark(#fffaf0, #181511);
  --surface-2: light-dark(#f6ead6, #241e18);
  --surface-3: light-dark(#efe0c8, #2c241d);
  --red: light-dark(#94291f, #ec7461);
  --gold: light-dark(#a86e0b, #efbd54);
  --blue: light-dark(#32617d, #7db3d6);
  --green: light-dark(#2f7256, #74c09a);
  --neutral: light-dark(#766657, #b7a693);
  --danger: light-dark(#9c251f, #ff8275);
  --shadow: light-dark(rgba(72, 42, 17, 0.12), rgba(0, 0, 0, 0.34));
  --focus: light-dark(#0b63ce, #7db8ff);
  font-family:
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 85% 0%, color-mix(in srgb, var(--red) 9%, transparent), transparent 34rem),
    var(--surface);
  color: var(--ink);
}

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

button,
a,
input,
textarea,
select {
  outline-color: var(--focus);
}

.shell,
.editor-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 48px;
}

.hero,
.editor-header {
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.hero-topline,
.section-title-row,
.editor-header,
.editor-section-heading,
.save-bar,
.layer-editor-heading,
.module-editor-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.kicker,
.section-eyebrow,
.detail-label {
  margin: 0 0 7px;
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-family: Georgia, "Songti SC", "STSong", serif;
  font-size: clamp(30px, 5vw, 48px);
  line-height: 1.12;
}

.subtitle {
  max-width: 850px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.revision-status,
.section-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.section-heading {
  margin: 28px 0 12px;
  font-size: 18px;
}

.core-loop {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--gold) 50%, var(--line));
  border-radius: 16px;
  background: color-mix(in srgb, var(--gold) 8%, var(--surface-2));
}

.core-step {
  position: relative;
  display: grid;
  min-height: 48px;
  place-items: center;
  padding: 8px 16px 8px 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.4;
}

.core-step:not(:last-child)::after {
  content: "›";
  position: absolute;
  top: 50%;
  right: -7px;
  translate: 0 -54%;
  color: var(--gold);
  font-size: 24px;
}

.layers {
  display: grid;
  gap: 10px;
}

.layer {
  --layer-color: var(--neutral);
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  gap: 12px;
}

.layer[data-color="red"] { --layer-color: var(--red); }
.layer[data-color="gold"] { --layer-color: var(--gold); }
.layer[data-color="blue"] { --layer-color: var(--blue); }
.layer[data-color="green"] { --layer-color: var(--green); }

.layer-label {
  display: flex;
  min-height: 100px;
  flex-direction: column;
  justify-content: center;
  padding: 14px;
  border-left: 4px solid var(--layer-color);
  border-radius: 12px;
  background: color-mix(in srgb, var(--layer-color) 10%, var(--surface-2));
}

.layer-index {
  color: var(--layer-color);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.13em;
}

.layer-title {
  margin-top: 5px;
  font-family: Georgia, "Songti SC", "STSong", serif;
  font-size: 18px;
  font-weight: 800;
}

.layer-note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
}

.modules {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 8px;
}

.module {
  --layer-color: inherit;
  min-width: 0;
  min-height: 100px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 150ms ease, transform 150ms ease, opacity 150ms ease;
}

.module:hover,
.module:focus-visible,
.module[aria-pressed="true"] {
  border-color: var(--layer-color);
  transform: translateY(-1px);
}

.module[aria-pressed="true"] {
  box-shadow: inset 0 0 0 1px var(--layer-color), 0 6px 16px var(--shadow);
}

.module.is-related:not([aria-pressed="true"]) {
  border-color: color-mix(in srgb, var(--gold) 70%, var(--line));
}

.module.is-dimmed {
  opacity: 0.42;
}

.module-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.module-title {
  font-size: 14px;
  font-weight: 800;
}

.module-badge {
  flex: none;
  padding: 2px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--layer-color) 13%, transparent);
  color: var(--layer-color);
  font-size: 10px;
  font-weight: 800;
}

.module-summary {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.module-detail {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 24px;
  margin-top: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}

.detail-heading h2 {
  margin: 0;
  font-size: 20px;
}

.detail-summary {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.detail-items {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 28px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.message {
  margin: 16px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
}

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

.message-success {
  border-color: var(--green);
  color: var(--green);
}

.editor-header {
  align-items: flex-start;
}

.quiet-link {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.quiet-link:hover {
  color: var(--ink);
  text-decoration: underline;
}

.editor-form {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.editor-section,
.layer-editor,
.module-editor {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-2) 90%, transparent);
}

.editor-section {
  padding: 18px;
}

.editor-section-heading h2,
.layer-editor-heading h3,
.module-editor-heading h4 {
  margin: 0;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-wide {
  grid-column: 1 / -1;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 11px;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  resize: vertical;
}

.layer-editors,
.module-editors {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.layer-editor {
  padding: 16px;
}

.layer-editor > summary {
  cursor: pointer;
  list-style-position: outside;
}

.layer-editor > .field-grid {
  margin-top: 14px;
}

.module-editor {
  padding: 14px;
  background: var(--surface);
}

.module-editor > summary {
  cursor: pointer;
  list-style-position: outside;
}

.module-editor > .field-grid {
  margin-top: 14px;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 13px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
}

.button:hover:not(:disabled) {
  border-color: var(--gold);
}

.button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.button-primary {
  border-color: var(--red);
  background: var(--red);
  color: light-dark(#fffaf0, #1b100d);
}

.button-secondary {
  border-color: var(--gold);
}

.button-danger {
  color: var(--danger);
}

.button-small {
  padding: 6px 9px;
  font-size: 11px;
}

.save-bar {
  position: sticky;
  bottom: 12px;
  z-index: 5;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: 0 10px 30px var(--shadow);
  backdrop-filter: blur(14px);
}

@media (max-width: 820px) {
  .core-loop {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .core-step:nth-child(3n)::after {
    display: none;
  }

  .layer {
    grid-template-columns: 122px minmax(0, 1fr);
  }

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

  .module-detail,
  .detail-items {
    grid-template-columns: 1fr;
  }

  .module-detail {
    gap: 12px;
  }
}

@media (max-width: 560px) {
  .shell,
  .editor-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 20px;
  }

  .hero-topline,
  .section-title-row,
  .editor-header,
  .editor-section-heading,
  .save-bar,
  .layer-editor-heading,
  .module-editor-heading {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .core-step:nth-child(3n)::after {
    display: block;
  }

  .core-step:nth-child(2n)::after {
    display: none;
  }

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

  .layer-label {
    min-height: 0;
  }

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

  .field-wide {
    grid-column: auto;
  }

  .save-bar {
    bottom: 6px;
  }

  .save-bar .button {
    width: 100%;
  }
}
