:root {
  --ink: #20221f;
  --muted: #6c6f68;
  --line: #d9d8d0;
  --panel: #fbfaf5;
  --paper: #f4f1e7;
  --accent: #2f6f61;
  --accent-dark: #214e45;
  --warn: #9b5d24;
  --white: #fffefa;
  --shadow: 0 18px 48px rgba(42, 39, 30, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
  max-width: 100%;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 6px;
  font-size: 28px;
  line-height: 1;
  background: var(--panel);
}

.brand h1,
.brand p,
.step-head h2,
.step-head p,
.current-strip h2,
.topbar h2,
.topbar p,
.library-head h2 {
  margin: 0;
}

.brand h1 {
  font-size: 25px;
  letter-spacing: 0;
}

.brand p,
.eyebrow,
.status-line {
  color: var(--muted);
  font-size: 13px;
}

.library-head,
.topbar,
.topbar-actions,
.button-row,
.editor-toolbar,
.output-toolbar,
.editor-tool-groups,
.transpose-controls,
.lyric-shift-controls,
.segmented {
  display: flex;
  align-items: center;
}

.library-head,
.topbar,
.editor-toolbar,
.output-toolbar {
  justify-content: space-between;
  gap: 14px;
}

.editor-tool-groups {
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.lyric-shift-controls {
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  background: var(--white);
}

.lyric-shift-controls span {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.library-head h2 {
  font-size: 15px;
}

.library-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.library-item {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 10px;
  text-align: left;
  background: transparent;
  color: var(--ink);
}

.library-item:hover,
.library-item.active {
  background: var(--panel);
  border-color: var(--line);
}

.library-title {
  display: block;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.library-meta {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  width: min(1480px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 28px 38px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar {
  min-height: 54px;
}

.topbar h2 {
  font-size: clamp(24px, 3vw, 38px);
  letter-spacing: 0;
}

.topbar-actions,
.button-row {
  gap: 10px;
}

.current-strip {
  display: grid;
  grid-template-columns: minmax(180px, 0.5fr) minmax(0, 1.8fr);
  gap: 18px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ebe6d8;
}

.current-strip h2 {
  font-size: 24px;
}

.song-meta {
  display: grid;
  grid-template-columns: 1.4fr 1.2fr repeat(4, minmax(90px, 0.55fr));
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.field {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--white);
  outline: none;
}

.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 97, 0.16);
}

.textarea-small {
  min-height: 86px;
  resize: vertical;
}

.codebox {
  min-height: 310px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}

.codebox.tall {
  min-height: 410px;
}

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
}

.tab,
.segment {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 11px 14px;
  border-radius: 6px 6px 0 0;
}

.tab.active,
.segment.active {
  color: var(--ink);
  background: var(--panel);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.panel {
  display: none;
  animation: rise 180ms ease-out;
}

.active-panel {
  display: block;
}

.main-tabs {
  position: sticky;
  top: 0;
  z-index: 4;
  padding-top: 2px;
  background: var(--paper);
}

.wizard-head,
.song-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
  background: #ebe6d8;
}

.wizard-head h2,
.song-header h2,
.step-copy h3 {
  margin: 0;
}

.stepper {
  display: flex;
  gap: 8px;
}

.step-dot {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--muted);
  font-weight: 800;
}

.step-dot.active {
  background: var(--accent);
  color: var(--white);
}

.step-dot.done {
  color: var(--accent-dark);
  border-color: var(--accent);
}

.wizard-step {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  animation: rise 180ms ease-out;
}

.wizard-step.active-step {
  display: block;
}

.step-copy {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.step-label {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--white);
  font-weight: 800;
}

.step-copy p,
.helper-text {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(360px, 1.2fr);
  gap: 18px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.primary-button,
.ghost-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 38px;
  padding: 0 14px;
  background: var(--white);
  color: var(--ink);
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--white);
  font-weight: 750;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button:hover,
.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.full-width {
  width: 100%;
}

.status-line {
  min-height: 20px;
}

.source-preview {
  display: grid;
  gap: 8px;
}

.source-chip {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
}

.library-layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 18px;
}

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

.library-pane,
.library-workspace {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--panel);
}

.library-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 560px;
}

.library-pane.compact {
  min-height: auto;
  padding: 10px 12px;
}

.library-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.library-compact > div {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.library-compact .eyebrow {
  margin: 0;
  white-space: nowrap;
}

.library-compact strong {
  font-size: 17px;
  white-space: nowrap;
  overflow-wrap: anywhere;
}

.library-compact span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.library-management {
  display: grid;
  gap: 12px;
}

.library-compact[hidden],
.library-management[hidden] {
  display: none !important;
}

.library-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.song-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--white);
}

.edit-save-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #ebe6d8;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.song-facts {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  overflow-wrap: anywhere;
}

.fact-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.fact-tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--white);
  color: var(--ink);
  font-size: 13px;
}

.fact-tag b {
  color: var(--muted);
  font-weight: 650;
}

.quick-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--white);
  box-shadow: var(--shadow);
}

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

.preview-head h3 {
  margin: 0;
  font-size: 16px;
}

.structure-head {
  margin-top: 18px;
}

.detail-preview {
  max-height: 520px;
  margin: 0;
  padding: 16px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre-wrap;
  color: var(--ink);
  background: #fffefa;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
}

.sub-tabs {
  margin-bottom: 16px;
}

.sub-panel {
  display: none;
}

.active-sub-panel {
  display: block;
  animation: rise 160ms ease-out;
}

.structure-preview,
.section-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.edit-meta {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8f5ec;
}

.compact-editor {
  display: grid;
  gap: 14px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 0.86fr);
  gap: 14px;
  align-items: start;
}

.section-board {
  margin-top: 0;
}

.section-block {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  padding: 12px;
  text-align: left;
  display: grid;
  gap: 8px;
  transition:
    border-color 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.section-block:hover,
.section-block.active {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(42, 39, 30, 0.1);
}

.section-block strong,
.section-block span,
.section-block small {
  display: block;
}

.section-block span,
.section-block small {
  color: var(--muted);
  font-size: 13px;
}

.section-hit {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  display: grid;
  gap: 7px;
}

.block-actions {
  display: flex;
  gap: 6px;
}

.block-actions button {
  width: 32px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
}

.section-inspector {
  position: sticky;
  top: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8f5ec;
  display: grid;
  gap: 12px;
}

.section-text {
  min-height: 260px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
}

.lyric-aligner {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--white);
}

.lyric-align-board {
  display: grid;
  gap: 8px;
}

.bar-lyric-lanes {
  display: grid;
  gap: 8px;
}

.bar-lyric-lane {
  border: 1px dashed #c8c5b9;
  border-radius: 8px;
  padding: 9px;
  background: var(--white);
}

.bar-lyric-lane:hover {
  border-color: var(--accent);
  background: #f7fbf6;
}

.lane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

.lane-head strong {
  color: var(--ink);
  font-size: 13px;
}

.lyric-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 34px;
}

.lyric-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: #f8f5ec;
  color: var(--ink);
  font-size: 13px;
  cursor: grab;
}

.lyric-chip:active {
  cursor: grabbing;
}

.lyric-chip.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--white);
}

.lyric-chip.drop-before {
  box-shadow: -4px 0 0 var(--accent);
}

.raw-section-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--white);
}

.raw-section-editor summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.raw-section-editor[open] {
  display: grid;
  gap: 10px;
}

.raw-section-editor[open] summary {
  color: var(--ink);
}

.next-row {
  justify-content: flex-end;
  margin-top: 14px;
}

.section-editor {
  display: grid;
  gap: 16px;
  margin-top: 14px;
}

.section-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.section-head {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #f8f5ec;
}

.bars {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 58px minmax(120px, 0.6fr) minmax(180px, 1fr) 40px;
  gap: 8px;
  align-items: center;
}

.bar-index {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
}

.output-toolbar {
  margin-bottom: 12px;
}

.segmented {
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  background: var(--white);
}

.segment {
  border-radius: 5px;
  padding: 8px 12px;
}

.segment.active {
  border-radius: 5px;
}

.output-preview {
  min-height: 460px;
  margin: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre-wrap;
  color: var(--ink);
  background: var(--white);
  font-family: "SFMono-Regular", Consolas, monospace;
  line-height: 1.72;
}

.chord-card-preview[hidden],
.output-preview[hidden] {
  display: none;
}

.chord-card-preview {
  display: grid;
  place-items: start center;
}

.chord-card {
  width: min(100%, 1080px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.chord-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.chord-card-head p,
.chord-card-head h3 {
  margin: 0;
}

.chord-card-head p {
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

.chord-card-head h3 {
  font-size: clamp(28px, 4vw, 48px);
  overflow-wrap: anywhere;
}

.card-key {
  min-width: 70px;
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--accent);
  color: var(--white);
  text-align: center;
  font-size: 26px;
  font-weight: 900;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.card-tags span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  background: #f8f5ec;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.card-section-grid {
  display: grid;
  gap: 14px;
}

.card-section {
  display: grid;
  gap: 8px;
}

.card-section h4 {
  margin: 0;
  color: var(--accent-dark);
  font-size: 15px;
}

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

.card-bar {
  min-height: 62px;
  border-radius: 8px;
  padding: 8px 10px;
  background: #f8f5ec;
  display: grid;
  gap: 3px;
}

.card-bar b {
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
}

.card-bar span {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .current-strip,
  .song-meta,
  .two-column,
  .library-layout,
  .editor-grid,
  .wizard-head,
  .song-header {
    grid-template-columns: 1fr;
  }

  .wizard-head,
  .song-header {
    align-items: flex-start;
  }

  .library-compact > div {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  .section-inspector {
    position: static;
  }

  .bar-row {
    grid-template-columns: 48px 1fr;
  }

  .bar-row .field:nth-of-type(2),
  .bar-row .icon-button {
    grid-column: 2;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 14px 12px calc(28px + env(safe-area-inset-bottom));
    gap: 12px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 24px;
  }

  .brand h1 {
    font-size: 22px;
  }

  .brand p,
  .eyebrow,
  .status-line {
    font-size: 12px;
  }

  .tabs {
    gap: 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab,
  .segment {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 10px 12px;
  }

  .wizard-head,
  .song-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    margin-bottom: 12px;
  }

  .wizard-head h2,
  .song-header h2 {
    font-size: 22px;
  }

  .stepper {
    width: 100%;
    justify-content: space-between;
  }

  .step-dot {
    width: 34px;
    height: 34px;
  }

  .wizard-step,
  .library-pane,
  .library-workspace,
  .quick-preview,
  .section-inspector,
  .lyric-aligner,
  .edit-meta {
    padding: 12px;
  }

  .library-pane {
    min-height: auto;
  }

  .library-compact {
    align-items: flex-start;
  }

  .library-compact > div {
    display: grid;
    gap: 2px;
  }

  .library-compact strong,
  .library-compact span {
    white-space: normal;
  }

  .inline-grid,
  .song-meta {
    grid-template-columns: 1fr;
  }

  .field,
  .primary-button,
  .ghost-button,
  .icon-button {
    min-height: 44px;
    font-size: 16px;
  }

  .button-row,
  .preview-head,
  .editor-toolbar,
  .output-toolbar,
  .editor-tool-groups,
  .transpose-controls,
  .lyric-shift-controls {
    flex-wrap: wrap;
  }

  .button-row.next-row {
    justify-content: stretch;
  }

  .button-row.next-row > button,
  .preview-head > button,
  .edit-save-row > button {
    flex: 1 1 160px;
  }

  .editor-toolbar {
    align-items: stretch;
  }

  .editor-toolbar > button,
  .editor-tool-groups {
    width: 100%;
  }

  .editor-tool-groups,
  .lyric-shift-controls {
    justify-content: stretch;
  }

  .lyric-shift-controls > button {
    flex: 1 1 130px;
  }

  .structure-preview,
  .section-board {
    grid-template-columns: 1fr;
  }

  .section-block {
    min-height: 92px;
  }

  .preview-head {
    align-items: stretch;
  }

  .song-facts {
    text-align: left;
  }

  .detail-preview,
  .output-preview {
    max-height: 58vh;
    min-height: 300px;
    padding: 12px;
    font-size: 13px;
    line-height: 1.65;
  }

  .segmented {
    width: 100%;
    overflow-x: auto;
  }

  .segment {
    flex: 1 0 max-content;
    text-align: center;
  }

  .chord-card {
    border-radius: 8px;
    padding: 14px;
  }

  .chord-card-head {
    align-items: stretch;
  }

  .chord-card-head h3 {
    font-size: 28px;
  }

  .card-key {
    min-width: 58px;
    font-size: 22px;
  }

  .card-bars {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .workspace {
    padding-inline: 10px;
  }

  .main-tabs {
    margin-inline: -10px;
    padding-inline: 10px;
  }

  .topbar {
    min-height: 46px;
  }

  .brand h1 {
    font-size: 20px;
  }

  .wizard-step,
  .library-workspace,
  .quick-preview {
    box-shadow: none;
  }

  .step-copy {
    gap: 10px;
  }

  .step-label {
    width: 30px;
    height: 30px;
  }

  .codebox {
    min-height: 240px;
  }

  .codebox.tall {
    min-height: 320px;
  }

  .library-compact {
    gap: 10px;
  }

  .library-compact .ghost-button {
    flex: 0 0 auto;
    padding-inline: 12px;
  }

  .edit-save-row {
    flex-direction: column;
    align-items: stretch;
  }

  .section-head {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: 1fr;
  }

  .bar-row .field:nth-of-type(2),
  .bar-row .icon-button {
    grid-column: auto;
  }

  .bar-index {
    font-size: 12px;
  }

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

  .lyric-chip {
    min-height: 34px;
    padding: 7px 10px;
  }

  .fact-tag {
    font-size: 12px;
  }

  .detail-preview,
  .output-preview {
    max-height: 52vh;
    font-size: 12px;
  }
}
