
:root {
    --bg: #000;
    --text: #e0e0e0;
    --muted: #8f8f8f;
    --dim: #888;
    --surface: #0a0a0a;
    --raised: #1a1a1a;
    --line: #262626;
    --radius: 8px;

}

:focus-visible {
    outline: 2px solid var(--text);
    outline-offset: 2px;
    border-radius: 4px;
}

input,
textarea,
button,
select {
    -webkit-appearance: none;
    appearance: none;
    font-size: 16px;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: calc(env(safe-area-inset-top) + 1rem);
}

#app {
    margin-inline: auto;
    width: min(960px, 100%);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: calc(env(safe-area-inset-bottom) + 1rem);
}

button {
    font-family: inherit;
    color: var(--text);
    background: var(--raised);
    border: 1px solid transparent;
    border-radius: var(--radius);
    min-height: 44px;
    padding: 0.5rem 1.1rem;
    font-size: 1rem;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    transition:
        background 0.12s ease-out,
        opacity 0.12s ease-out,
        transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

button:hover {
    background: #242424;
}
button:active {
    transform: scale(0.97);
    opacity: 0.85;
}
button:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

#setupView {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    width: 100%;
    min-width: 0;
    padding: clamp(1rem, 5vh, 3.5rem) clamp(1rem, 4vw, 2rem) 3rem;
    gap: 1rem;
}

#setupView > .app-header {
    width: min(100%, 720px);
    margin: 0 auto;
}

#setupControls {
    width: min(100%, 720px);
    margin-inline: auto;
}

.app-header {
    min-height: 44px;
    position: relative;
}

#setupControls {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
    align-items: stretch;
}

#setupControls #magnetInput {
    grid-column: 1 / -1;
}

#setupControls #streamBtn {
    grid-column: 1 / -1;
    width: 100%;
}

#setupControls #torrentFileBtn {
    grid-column: 1 / -1;
    width: 100%;
    background: transparent;
    border-color: var(--line);
    color: var(--muted);
}

#setupControls #torrentFileBtn:hover {
    color: var(--text);
    border-color: #555;
    background: transparent;
}

#setupControls #setupStatus {
    grid-column: 1 / -1;
}

#magnetInput {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
    font-size: 14px;
    line-height: 1.5;
    padding: 0.7rem 0.8rem;
    resize: vertical;
    min-height: 44px;
    transition: border-color 0.15s ease;
}

#magnetInput:focus,
#captionInput:focus {
    border-color: #555;
}

#setupView:not([hidden]) {
    animation: motion-fade-in 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

#setupView:not([hidden]) #setupControls {
    animation: motion-slide-up 0.4s cubic-bezier(0.32, 0.72, 0, 1) 0.14s both;
}

#setupView > #filePicker,
#setupView > #readiness,
#setupView > #savedVideos,
#setupView > #savedDownloads {
    margin-top: 0.75rem;
}

#playerView:not([hidden]) {
    animation: motion-fade-in 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

#captionBar:not([hidden]) {
    animation: motion-slide-up 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#captionPanel:not([hidden]) {
    animation: motion-scale-in 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.panel-message {
    animation: motion-fade-in 0.2s ease;
}

.caption-result {
    animation: motion-slide-up 0.22s cubic-bezier(0.4, 0, 0.2, 1) both;
}

.caption-result:nth-child(2) {
    animation-delay: 0.03s;
}
.caption-result:nth-child(3) {
    animation-delay: 0.06s;
}
.caption-result:nth-child(4) {
    animation-delay: 0.09s;
}
.caption-result:nth-child(5) {
    animation-delay: 0.12s;
}
.caption-result:nth-child(6) {
    animation-delay: 0.15s;
}
.caption-result:nth-child(n + 7) {
    animation-delay: 0.17s;
}

#streamBtn {
    background: #f5f5f5;
    color: #000;
    font-weight: 600;
}

#streamBtn:hover {
    background: #fff;
    transform: translateY(-1px);
}

.hint {
    margin-top: 1.25rem;
    text-align: center;
    font-size: 0.78rem;
    font-weight: 300;
    color: var(--muted);
    line-height: 1.6;
}

#setupStatus {
    min-height: 1.4em;
    text-align: left;
    font-size: 0.9rem;
    color: var(--dim);
    overflow-wrap: anywhere;
}

#setupStatus.error {
    color: #ff8080;
}

#playerView {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem 0.75rem 0;
    gap: 0.75rem;
}

.player-header {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    min-width: 0;
    padding-inline: 0.25rem;
}

.player-header button {
    min-height: 44px;
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
    flex-shrink: 0;
}

#torrentName {
    font-size: 0.9rem;
    color: var(--dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.player-hint {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 300;
    color: var(--muted);
}

.player-hint.error {
    color: #ff8080;
}

#playerWrap {
    position: relative;
    width: 100%;
    background: var(--bg);
}

#player {
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: calc(100dvh - 160px);
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
}

.art-video-player {
    background: #000 !important;
}
.art-video {
    border-radius: inherit;
}
.art-bottom {
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7)) !important;
}
.art-layer-mask {
    background: rgba(0, 0, 0, 0.55) !important;
}

::cue {
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
}

#statsOverlay {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 120;
    pointer-events: none;
    font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    line-height: 1.6;
    color: #eee;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 6px;
    padding: 6px 9px;
    white-space: pre;
}

#captionBar {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 64px;
    z-index: 120;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: rgba(0, 0, 0, 0.72);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px 10px;
}

#captionName {
    font-size: 0.8rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.caption-bar-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.caption-bar-controls button {
    min-height: 44px;
    padding: 0 0.8rem;
    font-size: 0.85rem;
    background: var(--raised);
}

#offsetValue {
    min-width: 3.6em;
    text-align: center;
    font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    color: var(--text);
}

#captionPanel {
    position: absolute;
    inset: 0;
    z-index: 130;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: auto;
    width: min(420px, calc(100% - 24px));
    height: fit-content;
    max-height: calc(100% - 32px);
    background: rgba(10, 10, 10, 0.97);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 1rem;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-head h2 {
    font-size: 1rem;
    font-weight: 600;
}

.panel-current {
    margin: 0;
    font-size: 0.85rem;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.panel-label {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 0.4rem;
}

.panel-search-row {
    display: flex;
    gap: 0.5rem;
}

#captionInput {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.5rem 0.75rem;
}

#captionInput::placeholder {
    color: var(--muted);
}

#captionSearchBtn {
    flex-shrink: 0;
}

.panel-results {
    overflow-y: auto;
    max-height: 46vh;
}

.panel-message {
    text-align: center;
    color: var(--dim);
    font-size: 0.88rem;
    padding: 1.25rem 0.5rem;
}

.panel-message.error {
    color: #ff8080;
}

.caption-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.caption-result {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border-radius: var(--radius);
    min-height: 44px;
    padding: 0.55rem 0.7rem;
}

.caption-result:hover {
    background: var(--raised);
}

.caption-result-title {
    display: block;
    font-size: 0.92rem;
    overflow-wrap: anywhere;
}

.caption-result-meta {
    display: block;
    margin-top: 2px;
    font-size: 0.75rem;
    color: var(--muted);
}

@media (max-width: 480px) {
    .app-title {
        display: block;
    }

    #setupView {
        padding: 1rem;
    }

    #setupControls {
        grid-template-columns: 1fr;
    }

    #setupControls #streamBtn,
    #setupControls #torrentFileBtn {
        grid-column: 1;
        width: 100%;
    }
    #playerView {
        padding: 0.75rem 0.5rem 0;
    }
    #captionPanel {
        inset-inline: 8px;
    }
}

@media (display-mode: standalone) {
    .player-header {
        min-height: 56px;
        padding-top: env(safe-area-inset-top, 0px);
    }
}

#authGate {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px 16px;
    text-align: center;
}

#authGate p {
    margin: 0;
    color: var(--muted);
}

#setupControls > * {
    min-width: 0;
}

#signOutBtn {
    width: 100%;
}

#setupStatus {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.recent-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}

.app-title {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.65rem;
    min-width: 0;
    text-align: center;
}

.app-header h1 {
    flex-shrink: 0;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--dim);
    cursor: pointer;
    padding: 10px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    min-height: 44px;
    min-width: 44px;
}

.icon-btn:hover {
    color: var(--text);
    background: var(--raised);
}

.icon-btn:active {
    color: #fff;
}

#settingsBtn {
    position: absolute;
    right: 0;
}

#settingsBtn svg,
#settingsClose svg {
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

#settingsBtn:hover svg {
    opacity: 1;
    transform: rotate(45deg);
}

#settingsBtn:active svg {
    transform: rotate(90deg);
}

#settingsClose:hover svg {
    transform: rotate(90deg);
}

#settingsClose:active svg {
    transform: rotate(180deg);
}

#filePicker,
#savedDownloads,
#savedVideos {
    width: min(100%, 720px);
    min-width: 0;
    margin-inline: auto;
}

#filePicker h2,
#savedDownloads h2,
#savedVideos h2 {
    margin: 0 0 10px;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--muted);
}

#fileList,
#savedDownloadsList {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-item,
.saved-download-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    text-align: left;
    background: var(--surface);
}

.file-item:hover,
.saved-download-item:hover {
    background: var(--raised);
}

.saved-download-row {
    display: flex;
    align-items: stretch;
    gap: 0.35rem;
}

.saved-download-row .saved-download-item {
    flex: 1;
    min-width: 0;
}

.saved-download-remove {
    flex: 0 0 44px;
    align-self: stretch;
}

.file-name,
.saved-download-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
}

.file-meta,
.saved-download-meta {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--muted);
    font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
}

.player-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding-inline: 0.25rem;
}

.player-actions button {
    min-height: 44px;
    padding: 0.35rem 0.9rem;
    font-size: 0.85rem;
}

#deleteBtn {
    color: #ff9999;
}

.choice-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.choice-btn {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    width: 100%;
    text-align: left;
}

.choice-btn-title {
    font-weight: 600;
}

.choice-btn-desc {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--muted);
}

.settings-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.2, 0, 0, 1);
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.settings-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.settings-box {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    width: calc(100% - 32px);
    max-width: 520px;
    max-height: 85vh;
    max-height: 85dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 1.25rem;
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    margin-bottom: 1rem;
    transform: translateY(calc(100% + env(safe-area-inset-bottom, 0px))) scale(0.92);
    transition: transform 0.4s cubic-bezier(0.2, 0, 0, 1);
}

.settings-overlay.visible .settings-box {
    transform: translateY(0) scale(1);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.75rem;
}

.settings-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.settings-option-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    color: var(--text);
    font-size: 0.92rem;
    padding: 0.65rem 0;
}

.settings-option-row > span {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.settings-account {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
    padding-top: 0.85rem;
    color: var(--text);
    font-size: 0.92rem;
}

.settings-account button {
    flex-shrink: 0;
    padding-inline: 0.8rem;
    font-size: 0.82rem;
}

.settings-option-row input {
    -webkit-appearance: none;
    appearance: none;
    width: 44px;
    height: 28px;
    min-height: 28px;
    border-radius: 14px;
    background: var(--raised);
    border: 1px solid var(--line);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    touch-action: manipulation;
    transition:
        background 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.settings-option-row input::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--dim);
    transition:
        transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#readiness {
    width: min(100%, 720px);
    min-width: 0;
    margin-inline: auto;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

#readiness h2 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--muted);
}

#readyProgress {
    width: 100%;
    height: 8px;
    appearance: none;
    -webkit-appearance: none;
    border: none;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.12);
}

#readyProgress::-webkit-progress-bar {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
}

#readyProgress::-webkit-progress-value {
    background: #e0e0e0;
    border-radius: 999px;
}

#readyProgress::-moz-progress-bar {
    background: #e0e0e0;
    border-radius: 999px;
}

#readyLine,
#readyStats {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text);
    overflow-wrap: anywhere;
}

#readyStats {
    display: none;
    color: var(--muted);
    font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
    font-size: 0.8rem;
}

body[data-tech="on"] #readyStats {
    display: block;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.readiness-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

#savedVideos {
    width: min(100%, 720px);
    min-width: 0;
    margin-inline: auto;
}

#savedVideos h2 {
    margin: 0 0 10px;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--muted);
}

#savedList {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.saved-item {
    margin: 0;
}

.saved-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.saved-open {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    text-align: left;
    padding: 10px 14px;
}

.saved-name {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.saved-meta {
    font-size: 0.8rem;
    color: var(--muted);
}

.saved-remove {
    flex-shrink: 0;
    min-width: 44px;
    padding: 0 0.8rem;
    font-size: 1.1rem;
    color: var(--dim);
    background: transparent;
    border: 1px solid var(--line);
}

.saved-remove:hover {
    background: var(--raised);
    color: var(--text);
}

#bufferOverlay {
    position: absolute;
    inset: 0;
    z-index: 110;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.35);
}

#bufferOverlay p {
    font-size: 0.9rem;
    color: #eee;
    background: rgba(0, 0, 0, 0.65);
    border-radius: 8px;
    padding: 0.6rem 1rem;
}

#techPanel {
    margin: 0 0.25rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
}

#techPanel summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    color: var(--muted);
    cursor: pointer;
}

#techBody {
    font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: 0.25rem 0 0.5rem;
}
