:root {
    color-scheme: light;
    --bg: #f7f7f4;
    --panel: #ffffff;
    --panel-soft: #f1f3f5;
    --text: #171717;
    --muted: #646970;
    --line: #ddded9;
    --strong-line: #c8cac4;
    --accent: #d92d20;
    --accent-dark: #b42318;
    --blue: #2563eb;
    --green: #14825d;
    --field: #ffffff;
    --shadow: 0 14px 34px rgba(23, 23, 23, 0.08);
    --focus: rgba(217, 45, 32, 0.18);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button, input, select {
    font: inherit;
}

button {
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
}

button:disabled {
    cursor: wait;
    opacity: 0.62;
}

input, select {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    color: var(--text);
    outline: none;
}

input:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--focus);
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
    gap: 22px;
    width: min(1480px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    padding: 22px;
}

.search-panel,
.watch-panel {
    min-width: 0;
}

.search-panel {
    position: sticky;
    top: 22px;
    align-self: start;
    max-height: calc(100vh - 44px);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.brand-row,
.search-box,
.search-meta {
    padding: 18px;
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--line);
}

h1, h2, h3, p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: 1.22rem;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 10px;
    font-size: clamp(1.45rem, 2.2vw, 2.2rem);
    line-height: 1.2;
    letter-spacing: 0;
}

h3 {
    margin-bottom: 0;
    font-size: 1.02rem;
}

label,
.small-label {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 750;
}

.merge-link,
.text-button,
.ready-link {
    color: var(--blue);
    font-weight: 750;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

.text-button {
    width: auto;
    min-height: auto;
    padding: 0;
    background: transparent;
}

.search-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 86px;
    gap: 9px;
}

.search-controls input {
    width: 100%;
    padding: 10px 12px;
}

.search-controls button,
#downloadButton {
    background: var(--accent);
    color: #fff;
    min-height: 42px;
    padding: 0 14px;
}

.search-controls button:hover,
#downloadButton:hover {
    background: var(--accent-dark);
}

.search-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.88rem;
}

.results-list,
.compact-list,
.comments-list {
    display: grid;
    gap: 10px;
}

.results-list {
    padding: 0 12px 14px;
}

.result-card,
.compact-card {
    display: grid;
    grid-template-columns: 128px minmax(0, 1fr);
    gap: 12px;
    width: 100%;
    min-height: 88px;
    padding: 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    text-align: left;
}

.result-card:hover,
.compact-card:hover,
.result-card.active {
    border-color: var(--strong-line);
    background: var(--panel-soft);
}

.thumb {
    position: relative;
    overflow: hidden;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 6px;
    background: #e5e7eb;
}

.thumb img,
.player-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.duration-pill {
    position: absolute;
    right: 5px;
    bottom: 5px;
    padding: 2px 6px;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 800;
}

.result-title,
.compact-title {
    display: -webkit-box;
    overflow: hidden;
    margin: 0 0 5px;
    font-size: 0.94rem;
    line-height: 1.35;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.result-meta,
.meta-line,
.note,
.status-line,
.global-status {
    color: var(--muted);
    font-size: 0.9rem;
}

.kind-pill,
.chip {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 2px 7px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 0.73rem;
    font-weight: 800;
}

.watch-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.mobile-watch-nav {
    display: none;
}

.empty-state {
    display: grid;
    min-height: calc(100vh - 46px);
    align-content: center;
    padding: 42px;
}

.empty-state p {
    max-width: 580px;
    color: var(--muted);
}

.video-workspace {
    padding: 18px;
}

.video-head {
    display: grid;
    grid-template-columns: minmax(280px, 48%) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.player-thumb {
    overflow: hidden;
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    background: #111827;
}

.video-summary {
    min-width: 0;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.channel-button {
    width: auto;
    margin-top: 14px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    background: var(--panel-soft);
    color: var(--text);
    text-align: left;
}

.tabs {
    display: flex;
    gap: 6px;
    margin: 20px 0 18px;
    border-bottom: 1px solid var(--line);
}

.tab,
.segment {
    width: auto;
    background: transparent;
    color: var(--muted);
}

.tab {
    min-height: 42px;
    padding: 0 14px;
    border-bottom: 3px solid transparent;
    border-radius: 0;
}

.tab.active {
    border-color: var(--accent);
    color: var(--text);
}

.tab-panel {
    min-height: 240px;
}

.grid-two {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 14px;
}

.form-group select {
    width: 100%;
    padding: 9px 10px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin: 14px 0;
}

.info-tile {
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
}

.info-tile span {
    display: block;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 750;
}

.info-tile strong {
    display: block;
    overflow-wrap: anywhere;
    font-size: 0.92rem;
}

.download-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 14px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff7ed;
}

#estimatedSize {
    font-size: 1.22rem;
    font-variant-numeric: tabular-nums;
}

#downloadButton {
    width: auto;
    min-width: 150px;
}

.progress-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 10px;
    align-items: center;
    margin: 12px 0;
}

progress {
    width: 100%;
    height: 10px;
    overflow: hidden;
    border: 0;
    border-radius: 999px;
    background: #e5e7eb;
}

progress::-webkit-progress-bar {
    background: #e5e7eb;
    border-radius: 999px;
}

progress::-webkit-progress-value {
    background: var(--green);
    border-radius: 999px;
}

progress::-moz-progress-bar {
    background: var(--green);
}

.description-box {
    white-space: pre-wrap;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
    overflow-wrap: anywhere;
}

.collection-panel {
    margin-top: 16px;
}

.collection-header {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.collection-header img {
    width: 72px;
    height: 72px;
    border-radius: 8px;
    object-fit: cover;
    background: #e5e7eb;
}

.row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.segmented {
    display: inline-flex;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.segment {
    min-height: 36px;
    padding: 0 12px;
    border-radius: 0;
}

.segment.active {
    background: var(--text);
    color: #fff;
}

.comment-card {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
}

.comment-author {
    display: flex;
    gap: 9px;
    align-items: center;
    margin-bottom: 8px;
    font-weight: 800;
}

.comment-author img {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: #e5e7eb;
}

.comment-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.comment-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.82rem;
}

.error {
    color: var(--accent-dark) !important;
}

[hidden] {
    display: none !important;
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
        padding: 14px;
    }

    .search-panel {
        position: static;
        max-height: none;
    }

    .empty-state {
        min-height: 300px;
    }

    .video-head,
    .grid-two {
        grid-template-columns: 1fr;
    }

    .info-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    body.mobile-watch-open {
        overflow: hidden;
    }

    .app-shell {
        padding: 0;
        min-height: 100vh;
    }

    .search-panel,
    .watch-panel {
        border-right: 0;
        border-left: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .search-panel {
        min-height: 100vh;
    }

    .watch-panel {
        position: fixed;
        inset: 0;
        z-index: 20;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        background: var(--panel);
        pointer-events: none;
        transform: translateX(100%);
        transition: transform 0.2s ease;
    }

    body.mobile-watch-open .watch-panel {
        pointer-events: auto;
        transform: translateX(0);
    }

    .mobile-watch-nav {
        display: grid;
        grid-template-columns: 72px minmax(0, 1fr) 72px;
        gap: 8px;
        align-items: center;
        flex: 0 0 auto;
        min-height: 52px;
        padding: max(8px, env(safe-area-inset-top)) 10px 8px;
        border-bottom: 1px solid var(--line);
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(12px);
    }

    .mobile-nav-button {
        min-height: 36px;
        padding: 0 10px;
        border: 1px solid var(--line);
        background: var(--panel-soft);
        color: var(--text);
        font-size: 0.9rem;
    }

    .mobile-nav-title {
        overflow: hidden;
        color: var(--muted);
        font-size: 0.86rem;
        font-weight: 800;
        text-align: center;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .video-workspace,
    .empty-state {
        overflow: auto;
        flex: 1 1 auto;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
    }

    .search-controls,
    .result-card,
    .compact-card {
        grid-template-columns: 1fr;
    }

    .video-workspace,
    .empty-state {
        padding: 14px;
    }

    .tabs {
        overflow-x: auto;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }

    .download-bar {
        align-items: stretch;
        flex-direction: column;
    }

    #downloadButton {
        width: 100%;
    }
}
