:root {
    --bg: #f6f7fb;
    --card: #ffffff;
    --text: #1e2430;
    --muted: #64748b;
    --muted-soft: #687184;
    --primary: #3056d3;
    --secondary: #64748b;
    --danger: #b42318;
    --success: #13795b;
    --border: #dfe5f0;
    --input-border: #cbd5e1;
    --shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

h1,
h2,
h3 {
    margin-top: 0;
    line-height: 1.2;
}

label {
    display: block;
    font-weight: 600;
}

input,
textarea,
select {
    width: 100%;
    max-width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--input-border);
    margin-top: 6px;
    margin-bottom: 14px;
    font: inherit;
}

textarea {
    min-height: 280px;
    resize: vertical;
}

input[type="checkbox"] {
    width: auto;
    margin: 0 8px 0 0;
}

input[type="file"] {
    padding: 10px;
    background: #fff;
}

button,
.link,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 14px;
    border-radius: 10px;
    text-decoration: none;
    border: 0;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    width: auto;
    max-width: 100%;
    min-height: 40px;
    white-space: nowrap;
}

.link.secondary,
.btn.secondary {
    background: var(--secondary);
}

.btn.danger {
    background: var(--danger);
}

.success {
    color: var(--success);
    margin-bottom: 12px;
}

.error {
    color: var(--danger);
    margin-bottom: 12px;
}

.muted {
    color: var(--muted);
    line-height: 1.5;
}

.muted2 {
    color: var(--muted);
    line-height: 1.5;
    padding-left: 25px;
}

.wrap {
    width: min(100%, 960px);
    margin: 0 auto;
    padding: 24px 16px 32px;
}

.page-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.page-brand img {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: 12px;
}

.page-brand strong {
    font-size: 16px;
}

.card {
    background: var(--card);
    padding: 24px;
    border-radius: 18px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.top-actions,
.actions,
.danger-zone-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.top-actions,
.danger-zone-actions {
    margin-bottom: 16px;
}

.top-actions > *,
.actions > * {
    flex: 0 0 auto;
}

.site-footer {
    padding: 18px 16px 26px;
    color: var(--muted-soft);
}

.site-footer-inner {
    max-width: 1100px;
    margin: 0 auto;
    text-align: center;
    font-size: 14px;
    line-height: 1.6;
}

.site-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.site-footer a:hover {
    text-decoration: underline;
}

/* Home */
.home-header {
    background: linear-gradient(180deg, #e9effc, var(--bg));
    color: var(--text);
    padding: 24px 16px;
}

.header-bar {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}

.header-copy {
    min-width: 0;
    flex: 1 1 320px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.header-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    flex: 0 0 auto;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.12);
    padding: 8px;
}

.header-text {
    min-width: 0;
}

.header-copy h1 {
    margin: 0;
    font-size: 1.2rem;
}

.header-copy p {
    margin: 0;
    opacity: 0.92;
    line-height: 1.5;
}

.header-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
}

.login-action {
    margin-left: auto;
}

.home-main {
    max-width: 1100px;
    margin: 24px auto;
    padding: 0 16px 40px;
}

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
    overflow: hidden;
}

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: #f8faff;
}

.tab-btn {
    flex: 1;
    background: transparent;
    color: var(--muted-soft);
    border-radius: 0;
    padding: 16px 14px;
    font-weight: 700;
    min-width: 0;
}

.tab-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    margin-left: 6px;
    padding: 0 8px;
    border-radius: 999px;
    background: #e8eefc;
    color: var(--muted);
    font-size: 13px;
    line-height: 1;
}

.tab-btn.active {
    color: var(--primary);
    background: #fff;
}

.tab-btn.active .tab-count {
    background: rgba(37, 99, 235, 0.12);
    color: var(--primary);
}

.tab-content {
    display: none;
    padding: 22px;
}

.tab-content.active {
    display: block;
}

.search {
    width: 100%;
    max-width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 18px;
    font-size: 14px;
}

.list {
    display: grid;
    gap: 12px;
}

.item-link {
    display: flex;
    align-items: center;
    gap: 16px;
    text-decoration: none;
    color: inherit;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    background: #fbfcff;
    min-width: 0;
    transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.item-link:hover {
    border-color: #bfd0ff;
    transform: translateY(-2px);
    background: #fff;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.thumb {
    width: 72px;
    height: 72px;
    border-radius: 16px;
    object-fit: cover;
    flex: 0 0 72px;
    border: 1px solid var(--border);
    background: #eef2ff;
}

.content {
    min-width: 0;
}

.title {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 6px;
    line-height: 1.3;
    word-break: break-word;
}

.meta {
    color: var(--muted-soft);
    line-height: 1.5;
    word-break: break-word;
}

.empty {
    color: var(--muted-soft);
    font-style: italic;
    margin: 0;
}

.hidden {
    display: none !important;
}

.flash {
    margin: 0 0 18px;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid #cfe8d8;
    background: #ecfdf3;
    color: #166534;
    line-height: 1.45;
}

.flash.error {
    border-color: #f3c9c9;
    background: #fef2f2;
    color: var(--danger);
}

/* Forms */
.form-page .wrap {
    max-width: 840px;
}

.form-page .muted {
    margin-top: -6px;
    margin-bottom: 14px;
    font-size: 14px;
}

.field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.inline-help-link {
    min-height: 0;
    padding: 0;
    background: transparent;
    color: var(--primary);
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
}

.inline-help-link:hover {
    text-decoration: underline;
}

.overlay-open {
    overflow: hidden;
}

.help-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    grid-template-rows: auto 1fr;
    background: var(--bg);
}

.help-overlay.active {
    display: grid;
}

.help-overlay-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: #fff;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

.help-overlay-close {
    background: var(--secondary);
}

.help-overlay-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: var(--bg);
}

.create-songsheet-page .wrap,
.songsheet-page .wrap {
    max-width: 940px;
}

.song-search {
    margin: 8px 0 6px;
}

.song-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin: 12px 0 16px;
}

.song-option {
    border: 1px solid #dbe2f0;
    padding: 12px;
    border-radius: 12px;
    background: #f8fafc;
    display: block;
    min-width: 0;
}

.song-option.hidden {
    display: none;
}

.result-note,
.image-note {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.result-note {
    margin-top: -4px;
    margin-bottom: 10px;
}

.image-note {
    margin-top: -8px;
    margin-bottom: 16px;
}

.song-option strong,
.song-option span {
    word-break: break-word;
}

/* Login */
.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 16px;
}

.login-page .card {
    width: min(100%, 430px);
}

.login-logo {
    width: 84px;
    height: 84px;
    object-fit: contain;
    display: block;
    margin: 0 auto 16px;
}

.login-page .card h1,
.login-page .card .muted {
    text-align: center;
}

.login-page .actions {
    gap: 10px;
    align-items: center;
    margin-top: 6px;
}

/* Songsheet view */
.hero-image {
    width: 100%;
    max-width: 280px;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: #eef2ff;
    margin-bottom: 18px;
}

.songsheet-page .meta {
    margin-bottom: 20px;
}

.song-info {
    flex: 1;
    min-width: 0;
}

.song-info strong,
.song-info span {
    word-break: break-word;
}

.song-link-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 12px;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
    min-width: 0;
    cursor: pointer;
}

.song-link-card:hover {
    background: #eef2ff;
    border-color: #c7d2fe;
    transform: translateY(-1px);
}

/* Song view */
.song-page .wrap {
    max-width: 900px;
}

.song-page .top-actions {
    margin-bottom: 16px;
}

.song-page .meta {
    margin-bottom: 10px;
}

.song-links {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 20px;
}

.song-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border-radius: 10px;
    text-decoration: none;
    background: #eef2ff;
    color: #1e3a8a;
    border: 1px solid #c7d2fe;
    min-width: 0;
    word-break: break-word;
}

.lyrics {
    line-height: 1.6;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    overflow-wrap: anywhere;
}

.markdown {
    line-height: 1.7;
    font-size: 16px;
}

.markdown p {
    margin: 0 0 10px;
}

.markdown strong {
    font-weight: 700;
}

.markdown em {
    font-style: italic;
}

.chord {
    display: inline-block;
    color: var(--primary);
    font-weight: 700;
    font-size: 0.95em;
    margin-right: 4px;
}

.lyrics.chords {
    font-family: monospace;
    white-space: pre-wrap;
    line-height: 1.6;
    font-size: 16px;
    background: #f8fafc;
    padding: 18px;
    border-radius: 14px;
    overflow-x: auto;
    color: #111;
}

.chord-row {
    margin-bottom: 8px;
    font-family: "Courier New", monospace;
    overflow-x: auto;
}

.chord-line {
    color: var(--primary);
    font-weight: 700;
    white-space: pre;
    line-height: 1.2;
}

.lyric-line {
    white-space: pre;
    line-height: 1.4;
}

.markdown-block {
    margin-bottom: 12px;
}

.hide-chords .chord-line {
    display: none;
}

#toggleChords {
    margin-bottom: 14px;
}

.chord-toggle-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--input-border);
    transition: 0.25s;
    border-radius: 28px;
}

.slider::before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    top: 3px;
    background-color: #fff;
    transition: 0.25s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary);
}

input:checked + .slider::before {
    transform: translateX(24px);
}

.toggle-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.transpose-controls {
    display: none;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

/* Edit songsheet */
.edit-songsheet-page .wrap {
    max-width: 1100px;
}

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

.image-preview {
    width: 100%;
    max-width: 220px;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: #eef2ff;
    display: block;
    margin-bottom: 14px;
}

.library-search {
    margin-bottom: 12px;
}

.song-library,
.selected-list {
    display: grid;
    gap: 12px;
}

.edit-songsheet-page .song-option,
.selected-item {
    border: 1px solid var(--border);
    background: #f8fafc;
    border-radius: 14px;
    padding: 14px;
    min-width: 0;
}

.edit-songsheet-page .song-option label {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    cursor: pointer;
}

.selected-item strong,
.selected-item span {
    word-break: break-word;
}

.selected-item {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
    cursor: grab;
}

.selected-item.dragging {
    opacity: 0.55;
    transform: scale(0.99);
}

.selected-main {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    min-width: 0;
    flex: 1;
}

.drag-handle {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid var(--input-border);
    background: #fff;
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex: 0 0 auto;
}

.selected-content {
    min-width: 0;
}

.selected-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.selected-controls button {
    background: var(--secondary);
    padding: 10px 12px;
}

.drop-target {
    border: 2px dashed #93c5fd;
    background: #eff6ff;
}

.empty-note {
    color: var(--muted);
    font-style: italic;
    margin: 0;
}

.danger-zone {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

.remove-image {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -4px 0 14px;
}

.section-heading-spaced {
    margin-top: 24px;
}

.actions-spaced {
    margin-top: 20px;
}

/* Disclaimer */
.disclaimer-page .wrap {
    max-width: 860px;
}

.disclaimer-title {
    margin-top: 18px;
}

.disclaimer-page .muted {
    color: var(--muted-soft);
    line-height: 1.7;
}

/* Help */
.help-page .wrap {
    max-width: 900px;
}

.help-content {
    margin-top: 18px;
}

.help-tabs {
    display: flex;
    gap: 8px;
    margin-top: 18px;
    border-bottom: 1px solid var(--border);
}

.help-tab-btn {
    border-radius: 10px 10px 0 0;
    background: transparent;
    color: var(--muted);
    min-height: 42px;
}

.help-tab-btn.active {
    background: #eef2ff;
    color: var(--primary);
}

.help-tab-panel {
    display: none;
}

.help-tab-panel.active {
    display: block;
}

.help-reference-text {
    margin: 18px 0 0;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
    color: var(--text);
    white-space: pre-wrap;
    overflow-x: auto;
    font-family: "Courier New", monospace;
    font-size: 14px;
    line-height: 1.6;
}

.help-content h1,
.help-content h2,
.help-content h3,
.help-content h4 {
    margin: 24px 0 12px;
}

.help-content h1:first-child,
.help-content h2:first-child,
.help-content h3:first-child,
.help-content h4:first-child {
    margin-top: 0;
}

.help-content hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

.help-content blockquote {
    margin: 14px 0;
    padding: 10px 14px;
    border-left: 4px solid var(--primary);
    background: #f8fafc;
    color: var(--muted);
}

.help-content code {
    padding: 2px 5px;
    border-radius: 6px;
    background: #eef2ff;
    color: #1e3a8a;
    font-family: "Courier New", monospace;
    font-size: 0.95em;
}

.help-content pre {
    overflow-x: auto;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #f8fafc;
}

.help-content pre code {
    padding: 0;
    background: transparent;
    color: inherit;
}

.help-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0;
    overflow-wrap: anywhere;
}

.help-content th,
.help-content td {
    padding: 10px;
    border: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.help-content th {
    background: #f8fafc;
}

.help-content img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    border: 1px solid var(--border);
}

@media (hover: none) {
    .item-link:hover {
        transform: none;
        box-shadow: none;
    }
}

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

@media (max-width: 700px) {
    .wrap {
        padding: 16px 12px 24px;
    }

    .card {
        padding: 18px;
        border-radius: 16px;
    }

    textarea {
        min-height: 220px;
    }

    .home-header {
        padding: 20px 14px;
    }

    .header-copy {
        align-items: center;
    }

    .header-logo {
        width: 56px;
        height: 56px;
        border-radius: 14px;
    }

    .home-main {
        margin: 18px auto;
        padding: 0 12px 28px;
    }

    .panel {
        border-radius: 16px;
    }

    .tab-content {
        padding: 16px;
    }

    .item-link {
        padding: 14px;
        gap: 12px;
    }

    .thumb {
        width: 60px;
        height: 60px;
        flex-basis: 60px;
        border-radius: 14px;
    }

    .title {
        font-size: 16px;
    }

    .header-actions {
        width: 100%;
    }

    .header-actions .btn {
        text-align: center;
    }
}

@media (max-width: 640px) {
    .song-link-card {
        align-items: flex-start;
    }

    .hero-image {
        max-width: 100%;
    }
}

@media (max-width: 560px) {
    .selected-item {
        flex-direction: column;
    }

    .selected-main,
    .selected-controls {
        width: 100%;
    }

    .selected-controls button,
    .top-actions > *,
    .actions > * {
        flex: 0 0 auto;
    }
}

@media (max-width: 520px) {
    .song-picker {
        grid-template-columns: 1fr;
    }

    .song-links a {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .tabs {
        flex-direction: row;
    }

    .tab-btn {
        padding: 14px 10px;
        font-size: 14px;
    }

    .item-link {
        align-items: flex-start;
    }
}
