:root {
    --bg: #f6f2e8;
    --panel: #fffdfa;
    --ink: #2d2215;
    --accent: #c56b12;
    --line: #e2d7c4;
    --card-bg: #ffffff;
    --muted: #675843;
    --link: #14532d;
    --alert-bg: #e8f3e7;
    --alert-line: #c4ddc1;
    --focus: #1d4ed8;
}

body[data-theme="dark"] {
    --bg: #0f1318;
    --panel: #171d25;
    --ink: #e8edf5;
    --accent: #d78a2c;
    --line: #2e3946;
    --card-bg: #1c2530;
    --muted: #adbacb;
    --link: #8bd3ff;
    --alert-bg: #1d2a23;
    --alert-line: #335545;
}

body[data-theme="dark"] .topbar {
    background: #040404d9;
}

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

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Noto Sans", "Segoe UI", sans-serif;
    color: var(--ink);
    background: radial-gradient(circle at 20% 20%, #fff8ef 0 14%, transparent 15%), var(--bg);
    min-height: 100vh;
    line-height: 1.45;
}

.topbar {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--line);
    background: #ffffffd9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 40;
    backdrop-filter: blur(6px);
}

.brand {
    font-weight: 800;
    text-decoration: none;
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.brand-logo {
    height: 38px;
    width: auto;
    display: block;
    object-fit: contain;
}

.nav {
    display: flex;
    gap: 1rem;
    min-width: 0;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
}

.nav::-webkit-scrollbar {
    display: none;
}

.nav a {
    text-decoration: none;
    font-weight: 600;
    color: inherit;
}

.nav-item-with-badge {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.dashboard-menu {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.dashboard-menu-toggle {
    border: 0;
    background: transparent;
    color: inherit;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.menu-caret {
    font-size: 0.82rem;
}

.dashboard-menu-dropdown {
    position: absolute;
    top: calc(100% + 0.45rem);
    right: 0;
    min-width: 240px;
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(17, 24, 39, 0.16);
    padding: 0.45rem;
    display: none;
    z-index: 70;
}

.dashboard-menu-dropdown.open {
    display: grid;
    gap: 0.2rem;
}

.dashboard-menu-dropdown a {
    text-decoration: none;
    color: inherit;
    font-weight: 600;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
}

.dashboard-menu-dropdown form {
    margin: 0;
}

.dashboard-menu-dropdown .menu-action-btn {
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: inherit;
    font-weight: 600;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
    cursor: pointer;
}

.dashboard-menu-dropdown a:hover,
.dashboard-menu-dropdown .menu-action-btn:hover {
    background: color-mix(in srgb, var(--line) 45%, transparent);
}

.pending-alert-badge {
    position: absolute;
    top: -0.55rem;
    right: -0.85rem;
    min-width: 1.2rem;
    height: 1.2rem;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    align-items: center;
    justify-content: center;
    padding: 0 0.25rem;
    border: 2px solid #fff;
    line-height: 1;
    display: none;
}

main {
    width: min(1080px, 94vw);
    margin: 1.4rem auto;
    display: grid;
    gap: 1rem;
    padding-bottom: 1rem;
}

.site-footer {
    width: min(1080px, 94vw);
    margin: 0 auto 1.2rem;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1rem;
}

.btn {
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 9px;
    padding: 0.55rem 0.85rem;
    text-decoration: none;
    display: inline-block;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
    min-height: 40px;
    transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn.subtle {
    background: #4f5d4f;
}

.grid {
    display: grid;
    gap: 0.8rem;
}

.songs {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.song-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.9rem;
    background: var(--card-bg);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.song-card:hover {
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}

.song-card h3 {
    margin: 0 0 0.4rem;
}

.muted {
    color: var(--muted);
    font-size: 0.92rem;
}

.artist-link {
    color: var(--link);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.tuneeze-mark {
    color: #15803d;
    font-weight: 700;
    font-size: 0.9rem;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 0.58rem 0.65rem;
    font: inherit;
    background: #fff;
}

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

select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 0.58rem 0.65rem;
    background: #fff;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--focus) 70%, transparent);
    outline-offset: 1px;
}

.empty-state {
    border: 1px dashed var(--line);
    border-radius: 12px;
    padding: 1rem;
    background: color-mix(in srgb, var(--card-bg) 88%, #fff);
}

label {
    display: grid;
    gap: 0.3rem;
}

.form {
    display: grid;
    gap: 0.8rem;
}

.artist-input-wrap {
    position: relative;
    flex: 1;
}

.artist-input-field {
    width: 100%;
}

.artist-suggestions-box {
    position: absolute;
    inset: calc(100% + 0.2rem) 0 auto 0;
    z-index: 40;
    padding: 0.3rem;
    display: none;
    max-height: 220px;
    overflow: auto;
}

.row {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: center;
}

.topbar-right {
    display: flex;
    gap: 0.8rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.alert {
    padding: 0.7rem;
    border-radius: 10px;
    background: var(--alert-bg);
    border: 1px solid var(--alert-line);
}

.theme-toggle {
    min-width: 102px;
    text-align: center;
}

.compact-text {
    min-width: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.compact-actions {
    flex-shrink: 0;
    flex-wrap: nowrap;
}

.suggestion-item {
    width: 100%;
    text-align: left;
    margin: 0.15rem 0;
    background: #223128;
}

/* admin users */
.admin-users-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 980px;
}

.admin-users-table th,
.admin-users-table td {
    padding: 0.55rem 0.5rem;
    border-bottom: 1px solid rgba(140, 130, 115, 0.2);
    vertical-align: top;
}

.admin-users-table th {
    text-align: left;
    border-bottom-color: rgba(140, 130, 115, 0.35);
}

.admin-users-table .num-col {
    text-align: right;
    white-space: nowrap;
}

.admin-users-table .meta-col {
    white-space: nowrap;
}

.user-cell {
    display: grid;
    gap: 0.15rem;
    min-width: 210px;
}

.user-col {
    min-width: 210px;
}

.actions-cell {
    min-width: 170px;
    position: relative;
    overflow: visible;
}

.user-actions details > summary {
    list-style: none;
    cursor: pointer;
    font-weight: 700;
    color: #fff;
    background: #4f5d4f;
    border-radius: 8px;
    padding: 0.45rem 0.7rem;
    display: inline-block;
}

.user-actions details > summary::-webkit-details-marker {
    display: none;
}

.user-actions-panel {
    position: absolute;
    top: calc(100% + 0.45rem);
    right: 0;
    border: 1px solid rgba(140, 130, 115, 0.35);
    border-radius: 10px;
    padding: 0.55rem;
    display: grid;
    gap: 0.45rem;
    background: var(--card-bg);
    width: 280px;
    box-shadow: 0 12px 28px rgba(17, 24, 39, 0.18);
    z-index: 25;
}

.user-actions-panel form {
    display: grid;
    gap: 0.35rem;
    margin: 0;
}

.user-actions-panel .row {
    margin: 0;
}

/* user history pager */
.pager-summary {
    text-align: center;
    margin-bottom: 0.7rem;
}

.pager-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.35rem;
}

.pager-btn {
    border: 1px solid var(--line);
    background: var(--card-bg);
    color: var(--ink);
    border-radius: 8px;
    min-width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.75rem;
    text-decoration: none;
    font-weight: 600;
}

.pager-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* home page polish */
.home-hero {
    background:
        linear-gradient(140deg, color-mix(in srgb, var(--accent) 15%, transparent), transparent 45%),
        var(--panel);
}

.home-hero-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.home-hero-title {
    margin: 0;
    font-size: clamp(1.8rem, 2.4vw, 2.8rem);
    letter-spacing: -0.02em;
}

.home-hero-subtitle {
    margin: 0.45rem 0 0;
    font-size: 1.04rem;
}

.home-hero-btn {
    min-width: 190px;
    text-align: center;
}

.home-section {
    padding-top: 1.1rem;
}

.home-section-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.home-section-title {
    margin: 0;
    font-size: clamp(1.35rem, 1.8vw, 2rem);
}

.home-section-link {
    min-width: 84px;
    text-align: center;
}

.home-song-grid {
    margin-top: 1rem;
}

.home-song-card {
    display: grid;
    gap: 0.5rem;
    align-content: start;
}

.home-song-title {
    margin: 0;
    line-height: 1.25;
}

.home-song-artist {
    margin: 0;
}

.home-song-stats {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
    padding-top: 0.15rem;
}

/* profile pages */
.profile-panel {
    padding: 1.1rem;
}

.profile-header {
    justify-content: space-between;
    align-items: flex-start;
}

.profile-identity {
    align-items: center;
    gap: 0.9rem;
    flex-wrap: nowrap;
    min-width: 0;
}

.profile-avatar {
    width: clamp(76px, 9vw, 104px);
    height: clamp(76px, 9vw, 104px);
    border-radius: 999px;
    object-fit: cover;
    border: 1px solid var(--line);
    flex-shrink: 0;
    display: block;
    background: var(--card-bg);
}

/* fallback for legacy profile markup without classes */
.profile-panel .row > img,
.profile-panel .row > div > img {
    width: clamp(76px, 9vw, 104px);
    height: clamp(76px, 9vw, 104px);
    border-radius: 999px;
    object-fit: cover;
    border: 1px solid var(--line);
    flex-shrink: 0;
}

.profile-avatar-fallback {
    display: grid;
    place-items: center;
    font-weight: 700;
}

.profile-name {
    margin: 0;
    font-size: clamp(1.3rem, 2vw, 1.9rem);
    line-height: 1.25;
}

.profile-verified {
    font-size: 1rem;
}

.profile-reaction-stats {
    font-size: 0.95rem;
}

.profile-handle {
    margin: 0.2rem 0;
}

.profile-email {
    margin: 0;
    word-break: break-word;
}

.profile-actions {
    justify-content: flex-end;
}

.profile-songs-title {
    margin: 0;
}

.profile-search-form {
    margin-top: 1rem;
}

.profile-search-input {
    flex: 1;
    min-width: 220px;
}

.profile-songs-grid {
    margin-top: 1rem;
}

.profile-list-status {
    margin-top: 1rem;
}

.profile-list-sentinel {
    height: 1px;
}

.profile-edit-panel {
    max-width: 700px;
    margin: 0 auto;
}

.profile-edit-title {
    margin-top: 0;
}

.profile-edit-header {
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.profile-avatar-edit {
    width: 84px;
    height: 84px;
}

.profile-edit-label {
    margin: 0;
}

.profile-edit-url {
    margin: 0.2rem 0 0;
}

.field-error {
    color: #b42318;
}

@media (max-width: 720px) {
    .home-hero-btn {
        width: 100%;
    }

    .home-section-link {
        margin-left: auto;
    }

    .profile-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.9rem;
    }

    .profile-identity {
        flex-wrap: wrap;
    }

    .profile-actions {
        justify-content: flex-start;
    }
}

.pager-btn.disabled {
    opacity: 0.45;
    pointer-events: none;
}

/* song detail */
.line-block {
    display: grid;
    gap: 0.05rem;
}

.chord-line,
.lyric-line {
    line-height: 1.6;
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    white-space: pre;
    font-size: var(--lyrics-font-size, 12px);
}

[data-chord-line] {
    color: #111111;
    font-weight: 700;
}

body[data-theme="dark"] [data-chord-line] {
    color: #ffffff;
}

.section-line {
    color: #dc2626;
    font-weight: 700;
}

.lyrics-raw {
    margin: 0;
    line-height: 1.6;
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    white-space: pre;
    font-size: var(--lyrics-font-size, 12px);
}

.comment-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card-bg);
    padding: 0.75rem;
    display: grid;
    gap: 0.55rem;
}

.comment-card + .comment-card {
    margin-top: 0.7rem;
}

.comment-card.is-reply {
    margin-top: 0.6rem;
}

.comment-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.comment-body {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.comment-replies {
    display: grid;
    gap: 0.5rem;
    margin-left: 1rem;
    border-left: 2px solid var(--line);
    padding-left: 0.8rem;
}

.reply-form {
    display: none;
    margin-top: 0.2rem;
}

.reply-form.open {
    display: grid;
}

.tab-switcher {
    display: flex;
    gap: 0.55rem;
    flex-wrap: wrap;
}

.tab-btn {
    border: 1px solid var(--line);
    background: var(--card-bg);
    color: var(--ink);
    border-radius: 999px;
    padding: 0.38rem 0.8rem;
    font-weight: 700;
    cursor: pointer;
}

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

.note-viewer-wrap {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #8b8b8b;
    overflow: hidden;
}

.note-viewer-wrap.is-pdf {
    min-height: 86vh;
}

.note-pdf-frame {
    width: 100%;
    height: 86vh;
    border: 0;
    display: block;
    background: #8b8b8b;
}

.note-image {
    display: block;
    max-width: 100%;
    height: auto;
}

/* chord drag editor */
.drag-line-wrap {
    border: 1px solid #e2d7c4;
    border-radius: 10px;
    padding: 0.7rem;
    background: #fff;
    overflow-x: auto;
}

.drag-meta {
    font-size: 0.85rem;
    color: #675843;
    margin-bottom: 0.4rem;
}

.drag-canvas {
    position: relative;
    border: 1px dashed #d9cab3;
    border-radius: 8px;
    height: 2rem;
    background: #fffaf2;
    min-width: 420px;
}

.drag-lyric {
    margin-top: 0.35rem;
    white-space: pre;
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.95rem;
    color: #2d2215;
}

.drag-chord {
    position: absolute;
    top: 0.25rem;
    height: 1.4rem;
    line-height: 1.4rem;
    padding: 0 0.28rem;
    border-radius: 6px;
    background: #f59e0b;
    color: #fff;
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.85rem;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    cursor: grab;
    white-space: nowrap;
}

.drag-chord.is-dragging {
    cursor: grabbing;
    opacity: 0.85;
}

@media (max-width: 700px) {
    .topbar {
        position: static;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: flex-start;
        backdrop-filter: none;
    }

    .nav {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: nowrap;
        padding-bottom: 0.2rem;
    }

    .dashboard-menu-dropdown {
        position: static;
        min-width: 0;
        width: 100%;
        margin-top: 0.45rem;
    }

    .btn {
        padding: 0.62rem 0.9rem;
    }

    main {
        width: min(100%, 96vw);
        margin-top: 1rem;
    }

    .compact-top {
        display: grid !important;
        gap: 0.55rem;
    }

    .compact-text {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
    }

    .compact-actions {
        flex-wrap: wrap;
    }

    .note-viewer-wrap.is-pdf {
        min-height: 76vh;
    }

    .note-pdf-frame {
        height: 76vh;
    }
}
