:root {
    color-scheme: light;
    --ink: #242332;
    --muted: #747286;
    --line: #e5e2ed;
    --surface: rgba(255, 255, 255, .94);
    --accent: #7656d8;
    --accent-dark: #5e3fbd;
    --accent-soft: #eee9ff;
    --green: #2e9764;
    --red: #c74e5f;
    --shadow: 0 12px 34px rgba(47, 36, 82, .075);
}

* { box-sizing: border-box; }

html {
    min-height: 100%;
    background: #f6f5fb;
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
}

body {
    margin: 0;
    min-height: 100%;
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
    background:
        radial-gradient(circle at 0 0, rgba(138, 105, 229, .10), transparent 32rem),
        #f6f5fb;
    padding: env(safe-area-inset-top) 0 calc(90px + env(safe-area-inset-bottom));
}

button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.topbar {
    width: min(1180px, calc(100% - 32px));
    min-height: 82px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    gap: 14px;
}

.icon-button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: white;
    color: var(--ink);
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(38, 33, 55, .06);
}
.back-button { font: 400 36px/1 Georgia, serif; padding-bottom: 5px; }

.brand { min-width: 0; }
.eyebrow {
    display: block;
    color: var(--accent);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .16em;
    margin-bottom: 3px;
}
.brand h1 { margin: 0; font-size: 24px; line-height: 1.1; letter-spacing: -.03em; }
.brand h1 small { color: var(--muted); font-size: 15px; font-weight: 600; letter-spacing: 0; }
.version, .count-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 28px;
    padding: 0 11px;
    border: 1px solid #ddd8e9;
    border-radius: 999px;
    color: var(--muted);
    background: rgba(255,255,255,.7);
    font-size: 12px;
    font-weight: 800;
}

.workspace {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 290px;
    gap: 18px;
    align-items: start;
}
.editor-column { min-width: 0; display: grid; gap: 18px; }
.card {
    background: var(--surface);
    border: 1px solid rgba(218, 214, 229, .9);
    border-radius: 20px;
    box-shadow: var(--shadow);
}
.brief-card, .structure-card, .history-column { padding: 20px; }
.card-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}
.card-heading > div { display: flex; align-items: center; gap: 9px; }
.card-heading h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.step {
    color: var(--accent);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .09em;
}
.text-link { color: var(--accent-dark); font-size: 13px; font-weight: 700; text-decoration: none; }

.field { display: grid; gap: 7px; min-width: 0; }
.field > span { color: var(--muted); font-size: 11px; font-weight: 700; }
.field input, .field textarea, .field select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    outline: none;
    background: #faf9fc;
    color: var(--ink);
    padding: 10px 12px;
    font-size: 14px;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.field textarea { resize: vertical; min-height: 78px; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus,
.section-name:focus, .lyric-input:focus, .count-input:focus {
    border-color: #a38be9;
    background: white;
    box-shadow: 0 0 0 3px rgba(118, 86, 216, .11);
}
.title-field { margin-bottom: 12px; }
.compact-fields { margin-top: 12px; display: grid; grid-template-columns: 1fr 1fr 150px; gap: 10px; }

.hint { margin: -8px 0 15px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.ghost-button, .add-line-button {
    border: 1px solid #dcd5ef;
    border-radius: 10px;
    color: var(--accent-dark);
    background: #f9f7ff;
    font-size: 12px;
    font-weight: 750;
    padding: 8px 11px;
}
.song-section {
    overflow: hidden;
    margin-top: 12px;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: white;
}
.section-header {
    min-height: 43px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px 6px 14px;
    border-bottom: 1px solid var(--line);
    background: #faf9fc;
}
.section-name {
    min-width: 0;
    flex: 1;
    border: 1px solid transparent;
    border-radius: 8px;
    outline: none;
    background: transparent;
    color: var(--ink);
    padding: 6px 8px;
    font-size: 13px;
    font-weight: 800;
}
.small-icon-button {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #aaa5b5;
    font-size: 19px;
}
.small-icon-button:hover { color: var(--red); background: #fff0f2; }
.lines { padding: 4px 12px; }
.line-row {
    display: grid;
    grid-template-columns: 58px minmax(0,1fr) auto;
    gap: 9px;
    align-items: center;
    min-height: 48px;
    border-bottom: 1px solid #f0edf4;
}
.line-row:last-child { border-bottom: 0; }
.count-box { display: grid; grid-template-columns: auto 1fr; gap: 4px; align-items: center; color: var(--muted); font-size: 9px; }
.count-input {
    width: 36px;
    height: 31px;
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
    text-align: center;
    color: var(--accent-dark);
    background: #faf9fc;
    font-size: 13px;
    font-weight: 800;
    -moz-appearance: textfield;
}
.count-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.lyric-box { position: relative; min-width: 0; }
.lyric-input {
    width: 100%;
    height: 36px;
    border: 1px solid transparent;
    border-radius: 9px;
    outline: none;
    color: var(--ink);
    background: transparent;
    padding: 6px 54px 6px 8px;
    font-size: 14px;
}
.lyric-input:hover { background: #faf9fc; }
.line-meter {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: #aaa5b5;
    font-size: 10px;
    font-weight: 750;
    pointer-events: none;
}
.line-meter.is-valid { color: var(--green); }
.line-meter.is-over { color: var(--red); }
.line-tools { display: flex; gap: 3px; }
.line-tool {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #aaa5b5;
    font-size: 13px;
}
.line-tool:hover { color: var(--accent); background: var(--accent-soft); }
.line-tool svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.lock-button.is-active { color: var(--accent-dark); background: var(--accent-soft); }
.remove-line:hover { color: var(--red); background: #fff0f2; }
.add-line-button { margin: 8px 12px 12px; padding: 7px 10px; }

.dual-editor {
    display: grid;
    grid-template-columns: minmax(250px, .82fr) minmax(360px, 1.18fr);
    gap: 12px;
}
.lyric-panel {
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: #fff;
}
.panel-title {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 14px;
    border-bottom: 1px solid var(--line);
    background: #f7f5fb;
}
.panel-title strong { font-size: 13px; }
.panel-title span { color: var(--muted); font-size: 10px; }
.panel-scroll {
    height: min(52vh, 560px);
    min-height: 340px;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}
.dual-song-section + .dual-song-section { border-top: 8px solid #f6f5f9; }
.dual-section-header {
    height: 43px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px 6px 10px;
    border-bottom: 1px solid var(--line);
    background: #fbfafc;
}
.mirrored-title { padding-left: 18px; color: var(--ink); font-size: 13px; font-weight: 800; }
.dual-lines { padding: 4px 7px; }
.dual-line {
    height: 46px;
    display: grid;
    align-items: center;
    border-radius: 9px;
    transition: background .12s, box-shadow .12s;
}
.dual-line.is-corresponding { background: #f0ebff; box-shadow: inset 3px 0 var(--accent); }
.template-line { grid-template-columns: 30px minmax(0, 1fr) 30px; gap: 5px; padding: 0 7px; }
.content-line { grid-template-columns: minmax(0, 1fr) 88px; gap: 2px; padding: 0 4px 0 7px; }
.line-number { color: #aaa5b5; font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.pattern-input {
    width: 100%;
    min-width: 0;
    height: 34px;
    border: 0;
    border-radius: 8px;
    outline: none;
    background: transparent;
    color: var(--accent-dark);
    font: 750 15px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: .12em;
    padding: 6px 7px;
}
.pattern-input:focus, .dual-line:focus-within .lyric-input { background: rgba(255,255,255,.75); }
.target-count { color: var(--muted); font-size: 10px; font-weight: 800; text-align: center; }
.content-line .lyric-input { font-size: 14px; }
.content-line .line-tools { opacity: .35; transition: opacity .12s; }
.content-line:hover .line-tools, .content-line:focus-within .line-tools, .content-line.is-locked .lock-button { opacity: 1; }
.section-footer-note {
    height: 51px;
    display: flex;
    align-items: center;
    padding: 0 14px;
    color: #b2adba;
    font-size: 10px;
}

.free-dual-editor {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.free-panel {
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 15px;
    background: white;
}
.free-textarea, .placeholder-layer {
    width: 100%;
    height: min(54vh, 590px);
    min-height: 390px;
    margin: 0;
    border: 0;
    outline: none;
    padding: 18px 20px 28px;
    white-space: pre;
    overflow: auto;
    resize: none;
    tab-size: 4;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "PingFang SC", monospace;
    font-size: 16px;
    font-weight: 560;
    line-height: 1.85;
    letter-spacing: .045em;
    font-variant-east-asian: full-width;
}
.template-textarea {
    display: block;
    color: var(--accent-dark);
    background: #fdfcff;
}
.template-textarea:focus { box-shadow: inset 0 0 0 2px rgba(118, 86, 216, .18); }
.overlay-wrap { position: relative; height: min(54vh, 590px); min-height: 390px; background: #fff; }
.overlay-wrap .free-textarea { position: absolute; z-index: 2; inset: 0; height: 100%; background: transparent; color: transparent; -webkit-text-fill-color: transparent; caret-color: var(--accent-dark); }
.placeholder-layer {
    position: absolute;
    z-index: 1;
    inset: 0;
    height: 100%;
    color: #c5c1cb;
    background: #fff;
    pointer-events: none;
}
.lyric-draft-textarea, .placeholder-layer { letter-spacing: 0; }
.draft-render-line { display: block; height: 1.85em; white-space: nowrap; }
.draft-char { display: inline-block; width: 1em; color: var(--ink); text-align: center; }
.draft-char.is-placeholder { color: #c5c1cb; }
.draft-char.is-overflow { color: var(--red); font-weight: 750; }
.lyric-draft-textarea:focus { box-shadow: inset 0 0 0 2px rgba(118, 86, 216, .18); }
.lyric-draft-textarea.has-overflow { box-shadow: inset 0 0 0 2px rgba(199, 78, 95, .24); }

.history-column { position: sticky; top: 14px; max-height: calc(100vh - 130px); overflow: hidden; }
.history-heading { margin-bottom: 10px; }
.history-heading > div { display: block; }
.history-heading .step { display: block; margin-bottom: 3px; color: var(--muted); }
.history-list { overflow: auto; max-height: calc(100vh - 225px); padding-right: 3px; }
.history-item { display: grid; grid-template-columns: minmax(0,1fr) 30px; align-items: center; border-radius: 11px; }
.history-item:hover, .history-item.is-current { background: #f5f1ff; }
.history-link { min-width: 0; display: grid; gap: 3px; padding: 10px; text-decoration: none; color: var(--ink); }
.history-link strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.history-link span { color: var(--muted); font-size: 10px; }
.history-delete { width: 27px; height: 27px; border: 0; border-radius: 8px; background: transparent; color: #b7b2bf; font-size: 17px; }
.history-delete:hover { color: var(--red); background: #fff0f2; }
.empty-history { padding: 30px 10px; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.6; }

.notice { padding: 11px 14px; border-radius: 13px; font-size: 13px; line-height: 1.5; }
.notice-success { color: #466858; border: 1px solid #c9dfd1; background: #f1faf4; }
.notice-error { color: #9b4050; border: 1px solid #edc3ca; background: #fff2f4; }

.action-bar {
    position: fixed;
    z-index: 20;
    left: 50%;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: min(760px, calc(100% - 28px));
    min-height: 62px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 10px 9px 16px;
    border: 1px solid rgba(213, 208, 226, .9);
    border-radius: 18px;
    background: rgba(255,255,255,.9);
    box-shadow: 0 16px 45px rgba(45, 34, 76, .18);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}
.status-text { min-width: 0; overflow: hidden; color: var(--muted); font-size: 11px; white-space: nowrap; text-overflow: ellipsis; }
.action-buttons { display: flex; gap: 7px; }
.primary-button, .secondary-button {
    height: 42px;
    border-radius: 12px;
    padding: 0 16px;
    border: 0;
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}
.secondary-button { color: var(--ink); border: 1px solid var(--line); background: #faf9fc; }
.primary-button { min-width: 122px; color: white; background: linear-gradient(135deg, #835fe4, #6243c0); box-shadow: 0 8px 18px rgba(105, 72, 199, .25); }
.primary-button:disabled, .secondary-button:disabled { cursor: wait; opacity: .6; }
.spark { margin-right: 5px; }
.is-busy .spark { display: inline-block; animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.mobile-actions-space { display: none; }

@media (max-width: 820px) {
    body { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
    .topbar, .workspace { width: min(100% - 22px, 680px); }
    .topbar { min-height: 72px; grid-template-columns: 40px 1fr auto; gap: 10px; }
    .icon-button { width: 40px; height: 40px; }
    .brand h1 { font-size: 21px; }
    .brand h1 small { display: none; }
    .workspace { display: flex; flex-direction: column; gap: 12px; }
    .editor-column { width: 100%; gap: 12px; }
    .brief-card, .structure-card, .history-column { padding: 15px; border-radius: 17px; }
    .compact-fields { grid-template-columns: 1fr 1fr; }
    .compact-fields .field:last-child { grid-column: 1 / -1; }
    .history-column { order: 2; position: static; width: 100%; max-height: none; }
    .history-list { max-height: none; }
    .dual-editor { grid-template-columns: 1fr; }
    .free-dual-editor { grid-template-columns: 1fr; }
    .free-textarea, .placeholder-layer, .overlay-wrap { height: min(38vh, 390px); min-height: 250px; }
    .free-textarea, .placeholder-layer { padding: 15px 16px 24px; font-size: 15px; }
    .panel-scroll { height: min(38vh, 380px); min-height: 245px; }
    .content-line { grid-template-columns: minmax(0,1fr) 82px; }
    .line-tools { gap: 0; }
    .line-tool { width: 27px; }
    .action-bar { bottom: calc(7px + env(safe-area-inset-bottom)); min-height: 58px; padding: 7px; }
    .status-text { display: none; }
    .action-buttons { width: 100%; }
    .secondary-button { flex: 0 0 66px; padding: 0 10px; }
    .primary-button { flex: 1; }
}

@media (max-width: 390px) {
    .template-line { grid-template-columns: 25px minmax(0,1fr) 26px; }
    .content-line { grid-template-columns: minmax(0,1fr) 78px; }
    .lyric-input { font-size: 13px; padding-left: 5px; }
    .card-heading h2 { font-size: 16px; }
}
