/* Preact Audio Player Page — self-contained full-page styles (ap- prefix) */

/* ---- Full-Page Container ---- */
.ap-page {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    background: var(--ctrl-bg, #0a0a0a);
    color: var(--ctrl-text, #e5e5e5);
    font-family: 'Lora', Georgia, serif;
}

/* Song-themed gradient backdrop — uses shared .song-backdrop from presentation.css */

.ap-page > *:not(.song-backdrop) {
    position: relative;
    z-index: 1;
}

/* ---- Page Header ---- */
.ap-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    flex-shrink: 0;
    background: hsla(var(--song-hue, 220), var(--song-sat, 50%), 12%, 0.75);
    border-bottom: 1px solid hsla(var(--song-hue, 220), var(--song-sat, 50%), 25%, 0.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    backdrop-filter: blur(20px) saturate(1.4);
}

.ap-header-back {
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid var(--ctrl-border, #2a2a2a);
    border-radius: 8px;
    color: var(--ctrl-text, #e5e5e5);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.ap-header-back:active {
    background: var(--ctrl-border, #2a2a2a);
}

.ap-header-art {
    width: 36px;
    height: 36px;
    background: hsla(var(--song-hue, 220), var(--song-sat, 50%), 30%, 0.5);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.8rem;
    color: hsla(var(--song-hue, 220), var(--song-sat, 50%), 80%, 0.9);
}

.ap-header-text {
    flex: 1;
    min-width: 0;
}

.ap-header-title {
    font-size: 0.92rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.ap-header-artist {
    font-size: 0.75rem;
    color: var(--ctrl-text-muted, #8a8a8a);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
    margin-top: 1px;
}

.ap-header-loading {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    flex-shrink: 0;
}

.ap-header-menu {
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid var(--ctrl-border, #2a2a2a);
    border-radius: 8px;
    color: var(--ctrl-text, #e5e5e5);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.ap-header-menu:active {
    background: var(--ctrl-border, #2a2a2a);
}

.ap-header-cast {
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid var(--ctrl-border, #2a2a2a);
    border-radius: 8px;
    color: var(--ctrl-text, #e5e5e5);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.ap-header-cast.active {
    background: var(--ctrl-accent, #4a9eff);
    border-color: var(--ctrl-accent, #4a9eff);
    color: #fff;
}

.ap-header-cast:active {
    background: var(--ctrl-border, #2a2a2a);
}

.ap-header-btn {
    width: 36px;
    height: 36px;
    background: none;
    border: 1px solid var(--ctrl-border, #2a2a2a);
    border-radius: 8px;
    color: var(--ctrl-text, #e5e5e5);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.ap-header-btn:active {
    background: var(--ctrl-border, #2a2a2a);
}

/* ---- Live Bar (shown when casting) ---- */
.ap-live-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: hsla(120, 60%, 25%, 0.3);
    border-bottom: 1px solid hsla(120, 60%, 40%, 0.25);
    flex-shrink: 0;
    z-index: 1;
    position: relative;
}

.ap-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4caf50;
    animation: ap-live-pulse 2s ease-in-out infinite;
}

@keyframes ap-live-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.ap-live-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #4caf50;
}

.ap-live-pos {
    font-size: 0.75rem;
    opacity: 0.6;
    flex: 1;
}

.ap-live-actions {
    display: flex;
    gap: 4px;
}

.ap-live-btn {
    width: 32px;
    height: 32px;
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: var(--ctrl-text, #e5e5e5);
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.ap-live-btn.active {
    background: rgba(255,255,255,0.15);
    color: var(--ctrl-accent, #4a9eff);
}

/* ---- Track Badge (in header title) ---- */
.ap-track-badge {
    font-size: 0.6rem;
    font-weight: 600;
    opacity: 0.5;
    margin-left: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    vertical-align: middle;
}

/* ---- Lyrics Area ---- */
.ap-lyrics {
    flex: 1;
    overflow-y: auto;
    padding: 30vh 16px 20vh;
    -webkit-overflow-scrolling: touch;
}

.ap-chunk {
    padding: 14px 16px;
    border-left: 3px solid transparent;
    color: #f2f2f2;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    font-size: 1.575rem;
    line-height: 1.6;
    cursor: pointer;
    transition: opacity 0.25s, background 0.25s, border-color 0.25s,
                font-size 0.25s ease, padding 0.25s ease, letter-spacing 0.25s ease;
    -webkit-tap-highlight-color: transparent;
}

.ap-chunk.viewing {
    opacity: 1;
    color: #fff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
    font-size: 1.95rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    padding: 18px 16px;
    border-left-color: hsla(var(--song-hue, 220), var(--song-sat, 50%), 60%, 0.8);
}

.ap-chunk.dist-1 {
    opacity: 0.45;
}

.ap-chunk.dist-2 {
    opacity: 0.3;
}

.ap-chunk.dist-far {
    opacity: 0.18;
}

/* Larger screens: bump active chunk size */
@media (min-width: 600px) {
    .ap-chunk { font-size: 1.65rem; }
    .ap-chunk.viewing { font-size: 2.25rem; letter-spacing: 0.025em; }
}

/* Smart border fill for synced playback */
.ap-chunk.synced-active {
    border-image: linear-gradient(
        to bottom,
        hsla(var(--song-hue, 220), var(--song-sat, 50%), 65%, 0.9) var(--sync-progress, 0%),
        transparent var(--sync-progress, 0%)
    ) 1;
    border-left-width: 3px;
    border-left-style: solid;
}

.ap-chunk:active {
    background: rgba(255, 255, 255, 0.05);
}

.ap-chunk-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.ap-chunk-translation {
    font-size: 0.85em;
    font-style: italic;
    color: #8ab4f8;
    line-height: 1.5;
    margin-top: 4px;
}

.ap-lyrics-credits {
    text-align: center;
    font-size: 0.72rem;
    color: var(--ctrl-text-muted, #8a8a8a);
    opacity: 0.6;
    padding: 32px 0 16px;
}

/* ---- Empty Lyrics (no-lyrics "now playing" view) ---- */
.ap-lyrics-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px;
    gap: 12px;
}

.ap-lyrics-art {
    width: 120px;
    height: 120px;
    background: hsla(var(--song-hue, 220), var(--song-sat, 50%), 25%, 0.4);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: hsla(var(--song-hue, 220), var(--song-sat, 50%), 70%, 0.8);
    margin-bottom: 12px;
}

.ap-lyrics-now-playing {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ctrl-text-muted, #8a8a8a);
    font-weight: 600;
}

.ap-lyrics-title {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.3;
}

.ap-lyrics-artist {
    font-size: 0.95rem;
    color: var(--ctrl-text-muted, #8a8a8a);
}

/* ---- Transport Bar (bottom) ---- */
.ap-transport {
    flex-shrink: 0;
    padding: 8px 16px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    background: hsla(var(--song-hue, 220), var(--song-sat, 50%), 8%, 0.85);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    backdrop-filter: blur(20px) saturate(1.4);
    border-top: 1px solid hsla(var(--song-hue, 220), var(--song-sat, 50%), 25%, 0.2);
}

.ap-transport-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 4px;
}

.ap-transport-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ap-nav:disabled {
    opacity: 0.2;
    cursor: default;
}

.ap-nav:disabled:active {
    transform: none;
}

.ap-nav-spacer {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

/* ---- Seek Bar ---- */
.ap-seek-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 3px;
    position: relative;
    cursor: pointer;
    touch-action: none;
}

.ap-seek-bar::before {
    content: '';
    position: absolute;
    top: -10px;
    bottom: -10px;
    left: 0;
    right: 0;
}

.ap-seek-buffer {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    pointer-events: none;
}

.ap-seek-progress {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    background: #fff;
    border-radius: 3px;
    pointer-events: none;
}

.ap-seek-thumb {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    pointer-events: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
    opacity: 0;
    transition: opacity 0.15s;
}

.ap-seek-bar:hover .ap-seek-thumb,
.ap-seek-bar:active .ap-seek-thumb {
    opacity: 1;
}

@media (pointer: coarse) {
    .ap-seek-thumb { opacity: 1; }
    .ap-seek-bar { height: 8px; }
}

/* ---- Time ---- */
.ap-time {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
    font-family: 'Courier New', monospace;
    font-variant-numeric: tabular-nums;
    min-width: 36px;
}

/* ---- Buttons ---- */
.ap-btn {
    background: none;
    border: none;
    color: var(--ctrl-text, #e5e5e5);
    font-size: 1.05rem;
    cursor: pointer;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.ap-btn:active { transform: scale(0.93); }

.ap-btn:focus-visible {
    outline: 2px solid var(--ctrl-accent, #4a9eff);
    outline-offset: 2px;
}

.ap-play {
    background: #fff;
    color: #000;
    font-size: 1.15rem;
    width: 48px;
    height: 48px;
}

.ap-play:active {
    background: #d4d4d4;
}

.ap-loop {
    font-size: 0.88rem;
    opacity: 0.4;
}

.ap-loop.active {
    opacity: 1;
    color: var(--ctrl-accent, #4a9eff);
}

/* ---- Error ---- */
.ap-error {
    font-size: 0.75rem;
    color: var(--ctrl-red, #c44536);
    padding: 2px 16px 4px;
    text-align: center;
    flex-shrink: 0;
}

/* ---- State announcements (screen readers) ---- */
.ap-sr-live {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---- Track Menu (bottom sheet) ---- */
.ap-menu-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
}

.ap-menu {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 70vh;
    overflow-y: auto;
    background: var(--ctrl-surface, #141414);
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
    z-index: 201;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px));
    animation: ap-slide-up 0.2s ease-out;
}

@keyframes ap-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.ap-menu-info {
    padding: 14px 18px 8px;
}

.ap-menu-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ctrl-text, #e5e5e5);
    line-height: 1.3;
    word-break: break-word;
}

.ap-menu-detail {
    font-size: 0.78rem;
    color: var(--ctrl-text-muted, #8a8a8a);
    line-height: 1.3;
    margin-top: 2px;
}

.ap-menu-divider {
    height: 1px;
    background: var(--ctrl-border, #2a2a2a);
    margin: 4px 0;
}

.ap-menu-section {
    padding: 8px 18px 4px;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ctrl-text-muted, #8a8a8a);
    font-weight: 600;
}

.ap-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 18px;
    background: none;
    border: none;
    color: var(--ctrl-text, #e5e5e5);
    font-size: 0.88rem;
    font-family: 'Lora', Georgia, serif;
    cursor: pointer;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
}

.ap-menu-item:active {
    background: rgba(255,255,255,0.06);
}

.ap-menu-item i {
    width: 18px;
    text-align: center;
    font-size: 0.82rem;
    opacity: 0.6;
}

.ap-menu-check {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--ctrl-accent, #4a9eff);
}

.ap-menu-track.active {
    font-weight: 600;
    color: var(--ctrl-accent, #4a9eff);
}

.ap-menu-track.active i {
    opacity: 1;
    color: var(--ctrl-accent, #4a9eff);
}

.ap-menu-track-sub {
    font-size: 0.75rem;
    opacity: 0.55;
    font-weight: 400;
}

.ap-menu-danger {
    color: var(--ctrl-red, #c44536);
}

.ap-menu-danger i { opacity: 1; }

.ap-menu-font-scale {
    display: flex;
    align-items: center;
    cursor: default;
}

.ap-menu-font-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ap-menu-font-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.15);
    background: none;
    color: var(--ctrl-text, #e5e5e5);
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ap-menu-font-btn:active {
    background: rgba(255,255,255,0.1);
}

.ap-menu-font-value {
    font-size: 0.75rem;
    min-width: 36px;
    text-align: center;
    opacity: 0.7;
}

/* ---- Edit Form ---- */
.ap-edit {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
}

.ap-edit-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.ap-edit-field label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--ctrl-text-muted, #8a8a8a);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ap-edit-field input,
.ap-edit-field select {
    width: 100%;
    padding: 8px 10px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--ctrl-border, #2a2a2a);
    border-radius: 6px;
    color: var(--ctrl-text, #e5e5e5);
    font-size: 0.85rem;
    font-family: 'Lora', Georgia, serif;
    outline: none;
    box-sizing: border-box;
    -webkit-appearance: none;
}

.ap-edit-field input:focus,
.ap-edit-field select:focus {
    border-color: var(--ctrl-accent, #4a9eff);
    background: rgba(255,255,255,0.09);
}

.ap-edit-link {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
}

.ap-edit-link-text {
    flex: 1;
    font-size: 0.8rem;
    color: var(--ctrl-text, #e5e5e5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ap-btn-sm {
    background: none;
    border: none;
    color: var(--ctrl-accent, #4a9eff);
    cursor: pointer;
    padding: 4px 6px;
    font-size: 0.75rem;
    border-radius: 4px;
}

.ap-edit-search {
    margin-top: 4px;
}

.ap-edit-results {
    max-height: 120px;
    overflow-y: auto;
    margin-top: 4px;
    border-radius: 6px;
    border: 1px solid var(--ctrl-border, #2a2a2a);
}

.ap-edit-result {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--ctrl-text, #e5e5e5);
    background: none;
    border: none;
    text-align: left;
    font-family: 'Lora', Georgia, serif;
}

.ap-edit-result:active {
    background: rgba(255,255,255,0.06);
}

.ap-edit-result-sub {
    margin-left: auto;
    font-size: 0.7rem;
    opacity: 0.45;
}

.ap-btn-text {
    background: none;
    border: none;
    color: var(--ctrl-text-muted, #8a8a8a);
    font-size: 0.82rem;
    font-family: 'Lora', Georgia, serif;
    padding: 7px 14px;
    cursor: pointer;
    border-radius: 6px;
}

.ap-btn-text:active {
    background: rgba(255,255,255,0.06);
}

.ap-btn-primary {
    background: var(--ctrl-accent, #4a9eff);
    border: none;
    color: #fff;
    font-size: 0.82rem;
    font-family: 'Lora', Georgia, serif;
    font-weight: 600;
    padding: 7px 18px;
    border-radius: 6px;
    cursor: pointer;
}

.ap-btn-primary:active {
    background: #3a8aee;
}

/* ---- Sync Editor ---- */
.ap-sync {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ap-sync-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 12px;
    -webkit-overflow-scrolling: touch;
}

.ap-sync-chunk {
    padding: 10px 14px;
    margin-bottom: 4px;
    border-radius: 8px;
    opacity: 0.3;
    border-left: 3px solid transparent;
    transition: opacity 0.2s, border-color 0.2s;
}

.ap-sync-chunk.synced {
    opacity: 0.55;
    border-left-color: var(--ctrl-accent, #4a9eff);
}

.ap-sync-chunk.next {
    opacity: 1;
    border-left-color: #fff;
    background: rgba(255, 255, 255, 0.06);
}

.ap-sync-chunk-text {
    font-size: 1rem;
    line-height: 1.5;
    font-weight: 500;
}

.ap-sync-chunk.next .ap-sync-chunk-text {
    font-weight: 600;
}

.ap-sync-chunk-trans {
    font-size: 0.82rem;
    font-style: italic;
    color: var(--ctrl-text-muted, #8a8a8a);
    margin-top: 2px;
}

.ap-sync-badge {
    font-size: 0.68rem;
    color: var(--ctrl-accent, #4a9eff);
    margin-top: 4px;
    font-family: 'Courier New', monospace;
}

.ap-sync-toolbar {
    flex-shrink: 0;
    padding: 8px 16px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    background: hsla(var(--song-hue, 220), var(--song-sat, 50%), 8%, 0.9);
    border-top: 1px solid hsla(var(--song-hue, 220), var(--song-sat, 50%), 25%, 0.2);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
}

.ap-sync-toolbar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.ap-sync-progress {
    font-size: 0.78rem;
    color: var(--ctrl-text-muted, #8a8a8a);
    font-variant-numeric: tabular-nums;
}

.ap-sync-actions {
    display: flex;
    gap: 4px;
}

.ap-sync-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--ctrl-border, #2a2a2a);
    color: var(--ctrl-text, #e5e5e5);
    font-size: 0.78rem;
    font-family: 'Lora', Georgia, serif;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.ap-sync-btn:active {
    background: rgba(255, 255, 255, 0.14);
}

.ap-sync-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.ap-sync-mark {
    width: 100%;
    padding: 14px;
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--ctrl-accent, #4a9eff);
    border: none;
    color: #fff;
    border-radius: 10px;
    letter-spacing: 0.04em;
}

.ap-sync-mark:active {
    background: #3a8aee;
    transform: scale(0.97);
}

.ap-sync-save {
    width: 100%;
    padding: 14px;
    font-size: 0.95rem;
    font-weight: 600;
    background: #22c55e;
    border: none;
    color: #fff;
    border-radius: 10px;
}

.ap-sync-save:active {
    background: #16a34a;
}

.ap-sync-save:disabled {
    opacity: 0.6;
    cursor: wait;
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
    .ap-menu { animation: none; }
    .ap-btn { transition: none; }
    .ap-chunk { transition: none; }
    .ap-page::before,
    .ap-page::after { animation: none; }
}

/* ---- High contrast mode ---- */
@media (prefers-contrast: high) {
    .ap-page {
        border: 2px solid var(--ctrl-text, #e5e5e5);
    }
    .ap-seek-progress,
    .ap-play {
        outline: 1px solid var(--ctrl-text, #e5e5e5);
    }
}

/* ---- Mount container ---- */
#audio-player-page {
    display: none;
}
