* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #f5f5f7;
    --bg-text: #1d1d1f;
    --surface: rgba(0, 0, 0, 0.06);
    --surface-hover: rgba(0, 0, 0, 0.1);
    --surface-text: #6e6e73;
    --primary: #1DB954;
    --primary-hover: #169c46;
    --primary-text: #fff;
    --error-bg: rgba(255, 59, 48, 0.12);
    --error-text: #ff3b30;
    --border: rgba(0, 0, 0, 0.1);
    --shadow: rgba(0, 0, 0, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
    --font: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
}

.dark-mode {
    --bg: #1a1a1e;
    --bg-text: #f5f5f7;
    --surface: rgba(255, 255, 255, 0.08);
    --surface-hover: rgba(255, 255, 255, 0.14);
    --surface-text: #98989d;
    --primary: #1DB954;
    --primary-hover: #22d65e;
    --primary-text: #fff;
    --error-bg: rgba(255, 59, 48, 0.2);
    --error-text: #ff453a;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--bg-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
}

[contenteditable] {
    outline: none;
}

/* ---- Layout ---- */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 2rem 1rem;
}

/* ---- Screen ---- */
.screen {
    width: 100%;
    max-width: 800px;
    opacity: 1;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    transform: translateY(12px);
}

.screen-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

header {
    position: relative;
    text-align: center;
    width: 100%;
    margin-bottom: 1.5rem;
}

h1 {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

h2 {
    font-size: 1.4rem;
    font-weight: 700;
}

.subtitle {
    color: var(--surface-text);
    font-size: 0.95rem;
    margin-top: 0.25rem;
}

.nav-btn {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    background: var(--surface);
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.4rem;
    color: var(--bg-text);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background: var(--surface-hover);
}

.btn-selectall {
    position: absolute;
    top: 50%;
    right: 3.2rem;
    transform: translateY(-50%);
    background: var(--primary);
    color: var(--primary-text);
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.9rem;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-family: var(--font);
    white-space: nowrap;
}

.btn-selectall:hover {
    background: var(--primary-hover);
}

.nav-btn.right {
    left: auto;
    right: 0;
}

/* ---- Search Screen ---- */
.tab-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tab-btn {
    padding: 0.6rem 1.4rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--surface-text);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
}

.tab-btn:hover {
    background: var(--surface-hover);
}

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

.tab-panel {
    display: none;
    width: 100%;
    max-width: 420px;
}

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

.tab-panel form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.input-surface {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--bg-text);
    font-size: 0.95rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}

.input-surface:focus {
    border-color: var(--primary);
    background: var(--bg);
}

.btn-primary {
    padding: 0.85rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: var(--primary-text);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    font-family: var(--font);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---- Status & Error ---- */
.status-bar {
    width: 100%;
    max-width: 420px;
    min-height: 1.5rem;
    margin-top: 1rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--surface-text);
    position: relative;
    overflow: hidden;
    transition: all 0.3s;
}

.status-bar.loading::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: var(--primary);
    animation: loading-bar 1.2s ease-in-out infinite;
}

@keyframes loading-bar {
    0% { width: 0; left: 0; }
    50% { width: 60%; left: 20%; }
    100% { width: 0; left: 100%; }
}

.error-bar {
    width: 100%;
    max-width: 420px;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--error-bg);
    color: var(--error-text);
    font-size: 0.85rem;
    text-align: center;
    margin-top: 0.75rem;
    transition: all 0.3s;
}

.error-bar.hidden {
    padding: 0;
    margin-top: 0;
    font-size: 0;
    opacity: 0;
}

/* ---- Song Grid ---- */
.song-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    width: 100%;
    padding: 1rem 0;
}

.song-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 0.75rem;
    cursor: pointer;
    transition: transform 0.2s var(--ease), background 0.2s;
    overflow: hidden;
}

.song-card:hover {
    background: var(--surface-hover);
    transform: translateY(-3px);
}

.song-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--surface);
    display: block;
}

.song-card .name {
    font-weight: 700;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.song-card .artist {
    font-size: 0.78rem;
    color: var(--surface-text);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Song Info (screen 3) ---- */
.song-info {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 0.75rem;
    width: 100%;
    max-width: 500px;
    margin-bottom: 1rem;
}

.song-info-cover {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--surface);
}

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

.song-info-name {
    font-weight: 700;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.song-info-artist {
    font-size: 0.8rem;
    color: var(--surface-text);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Lines Grid ---- */
.lines-grid {
    width: 100%;
    max-width: 500px;
    padding-bottom: 5rem;
}

.line-item {
    padding: 0.85rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--surface);
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s var(--ease);
    user-select: none;
}

.line-item:hover {
    background: var(--surface-hover);
    transform: scale(1.03);
}

.line-item.selected {
    background: var(--primary);
    color: var(--primary-text);
}

/* ---- FAB ---- */
.fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    background: var(--primary);
    color: var(--primary-text);
    border: none;
    box-shadow: 0 4px 16px var(--shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s var(--ease);
    z-index: 100;
}

.fab.hidden {
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

.fab:hover {
    transform: scale(1.1);
}

/* ---- Poster Preview Screen ---- */
.poster-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
}

.poster-preview {
    display: flex;
    justify-content: center;
    width: 100%;
    min-height: 200px;
}

.poster {
    display: flex;
    flex-direction: column;
    padding: 1.2rem 1rem 0.8rem;
    border-radius: 20px;
    background: #1DB954;
    color: rgba(0, 0, 0, 0.92);
    transform-origin: top center;
    transition: all 0.3s ease;
}

.poster.light-text {
    color: rgba(255, 255, 255, 0.95);
}

.poster-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding-bottom: 1rem;
}

.poster-cover {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    object-fit: cover;
    background: rgba(0,0,0,0.1);
}

.poster-meta {
    flex: 1;
    min-width: 0;
}

.poster-title {
    font-size: 0.95rem;
    font-weight: 800;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.poster-artist {
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0.65;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.poster-lyrics {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 2;
    padding-bottom: 0.5rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.poster-lyrics ruby rt {
    font-size: 0.55em;
    font-weight: 400;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
}

.poster.light-text .poster-lyrics rt {
    color: rgba(255, 255, 255, 0.7);
}

/* ---- Furigana ---- */
.furigana-switch {
    width: 100%;
    max-width: 500px;
    padding: 0.5rem 0;
}

.furigana-switch.hidden {
    display: none;
}

.line-item ruby rt {
    font-size: 0.6em;
    font-weight: 400;
    line-height: 1;
}

/* ---- Controls ---- */
.poster-controls {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem 0;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group > label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--surface-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.color-picker-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
}

.color-swatch:hover {
    transform: scale(1.15);
}

.color-swatch.active {
    border-color: var(--bg-text);
}

.custom-color-wrap {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.3rem;
}

.custom-color-wrap input[type="color"] {
    width: 0;
    height: 0;
    padding: 0;
    border: none;
    position: absolute;
}

.custom-color-wrap label {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--surface-text);
    transition: transform 0.2s;
}

.custom-color-wrap label:hover {
    transform: scale(1.15);
}

.switch-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    user-select: none;
}

.switch-row span {
    font-size: 0.9rem;
    font-weight: 500;
}

.switch {
    width: 44px;
    height: 24px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    position: relative;
    transition: background 0.25s;
    flex-shrink: 0;
}

.switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--surface-text);
    transition: all 0.25s var(--ease);
}

.switch-row.on .switch {
    background: var(--primary);
    border-color: var(--primary);
}

.switch-row.on .switch::after {
    left: 22px;
    background: #fff;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.slider-row input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--surface);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    transition: transform 0.15s;
}

.slider-row input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.slider-row input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
}

#width-display {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--primary);
    min-width: 48px;
    text-align: right;
}

select.input-surface {
    cursor: pointer;
}

/* ---- Footer ---- */
footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
    font-size: 0.85rem;
    color: var(--surface-text);
}

#theme-toggle {
    background: var(--surface);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--bg-text);
    transition: background 0.2s;
}

#theme-toggle:hover {
    background: var(--surface-hover);
}

/* ---- Responsive ---- */
@media (min-width: 768px) {
    .poster-layout {
        flex-direction: row;
        align-items: flex-start;
    }
    .poster-preview {
        flex: 1;
        position: sticky;
        top: 2rem;
    }
    .poster-controls {
        max-width: 280px;
    }
    .song-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 480px) {
    h1 { font-size: 1.6rem; }
    .song-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .song-card {
        padding: 0.5rem;
    }
}
