:root {
    color-scheme: dark;
    --bg: #0b0d12;
    --surface: #131722;
    --panel: #181d2a;
    --panel-2: #212838;
    --text: #f7f8fb;
    --muted: #9aa3b5;
    --line: rgba(255, 255, 255, 0.12);
    --line-focus: rgba(255, 184, 77, 0.5);
    --accent: #ffb84d;
    --accent-hover: #ffa826;
    --accent-strong: #ff9f1c;
    --accent-subtle: rgba(255, 184, 77, 0.12);
    --danger: #ff6b6b;
    --danger-subtle: rgba(255, 107, 107, 0.15);
    --radius-lg: 22px;
    --radius-md: 14px;
    --radius-sm: 8px;
    font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

[hidden] {
    display: none !important;
}

html,
body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

body {
    min-height: 100dvh;
    overflow-x: hidden;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

.watch-app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(circle at 80% 0%, rgba(255, 184, 77, 0.1), transparent 36rem),
        radial-gradient(circle at 10% 90%, rgba(77, 140, 255, 0.06), transparent 30rem),
        var(--bg);
}

.topbar {
    min-height: 68px;
    padding: max(14px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) 12px max(22px, env(safe-area-inset-left));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    font-weight: 800;
    font-size: 19px;
    letter-spacing: -0.02em;
    user-select: none;
}

.brand-mark {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--accent);
    color: #171009;
    font-size: 13px;
    padding-left: 2px;
    box-shadow: 0 4px 14px rgba(255, 184, 77, 0.3);
}

.parent-button,
.text-button,
.close-button,
.fullscreen-button,
.icon-button,
.play-button,
.reorder-btn {
    border: 0;
    color: inherit;
    cursor: pointer;
    touch-action: manipulation;
}

.parent-button {
    width: 48px;
    height: 48px;
    min-height: 48px;
    min-width: 48px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    display: grid;
    place-items: center;
    transition: background 150ms ease, transform 100ms ease;
}

.parent-button:hover,
.parent-button:focus-visible {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.parent-button:active {
    transform: scale(0.94);
}

.parent-icon {
    font-size: 22px;
    line-height: 1;
    opacity: 0.9;
}

.viewer {
    width: min(1200px, 100%);
    margin: auto;
    padding: 0 max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
}

.video-stage {
    position: relative;
    aspect-ratio: 16 / 9;
    width: 100%;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: #000;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

#youtube-player,
iframe#youtube-player,
#youtube-player iframe,
.touch-layer,
.empty-state {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#youtube-player,
iframe#youtube-player,
#youtube-player iframe {
    z-index: 1;
    pointer-events: none !important;
    border: 0;
}

.touch-layer {
    z-index: 3;
    border: 0;
    padding: 0;
    background: transparent;
    color: #fff;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.play-prompt {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    min-width: 160px;
    padding: 16px 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-radius: 999px;
    background: rgba(10, 12, 17, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.01em;
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
}

.play-prompt[hidden] {
    display: none;
}

.play-triangle {
    width: 0;
    height: 0;
    border-top: 9px solid transparent;
    border-bottom: 9px solid transparent;
    border-left: 15px solid var(--accent);
}

.tap-feedback {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 76px;
    height: 76px;
    display: grid;
    place-items: center;
    transform: translate(-50%, -50%) scale(0.8);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 30px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
}

.tap-feedback.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.empty-state {
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    text-align: center;
    background: linear-gradient(145deg, #171c28, #0e1118);
}

.empty-state[hidden] {
    display: none;
}

.empty-icon {
    width: 68px;
    height: 68px;
    display: grid;
    place-items: center;
    margin-bottom: 16px;
    border: 2px dashed rgba(255, 184, 77, 0.35);
    border-radius: 20px;
    background: var(--accent-subtle);
    color: var(--accent);
    font-size: 34px;
}

.empty-state h1 {
    margin: 0 0 8px;
    font-size: clamp(22px, 3.5vw, 32px);
    font-weight: 800;
}

.empty-state p {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
    max-width: 360px;
    line-height: 1.45;
}

.controls {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 14px;
    padding: 20px 6px 0;
    width: 100%;
    box-sizing: border-box;
}

.controls.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.time {
    min-width: 42px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
    user-select: none;
    -webkit-user-select: none;
}

.seek-label {
    display: flex;
    align-items: center;
    min-width: 0;
    width: 100%;
}

.seek {
    --progress: 0%;
    width: 100%;
    min-width: 0;
    height: 36px;
    margin: 0;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    cursor: pointer;
    touch-action: pan-x;
}

.seek::-webkit-slider-runnable-track {
    height: 10px;
    border-radius: 99px;
    background: linear-gradient(to right, var(--accent) var(--progress), rgba(255, 255, 255, 0.18) var(--progress));
}

.seek::-webkit-slider-thumb {
    box-sizing: border-box;
    width: 26px;
    height: 26px;
    margin-top: -8px;
    appearance: none;
    -webkit-appearance: none;
    border: 3px solid var(--text);
    border-radius: 50%;
    background: var(--accent-strong);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    transition: transform 100ms ease;
}

.seek:active::-webkit-slider-thumb {
    transform: scale(1.15);
}

.seek::-moz-range-track {
    height: 10px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.18);
}

.seek::-moz-range-progress {
    height: 10px;
    border-radius: 99px;
    background: var(--accent);
}

.seek::-moz-range-thumb {
    box-sizing: border-box;
    width: 24px;
    height: 24px;
    border: 3px solid var(--text);
    border-radius: 50%;
    background: var(--accent-strong);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.seek:disabled {
    cursor: default;
    opacity: 0.4;
}

.fullscreen-button {
    position: relative;
    width: 46px;
    height: 46px;
    min-width: 46px;
    min-height: 46px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    border-radius: var(--radius-md);
    background: var(--panel-2);
    border: 1px solid var(--line);
    overflow: hidden;
    padding: 0;
    margin: 0;
    transition: background 150ms ease, transform 100ms ease;
}

.fullscreen-button:hover {
    background: rgba(255, 255, 255, 0.14);
}

.fullscreen-button:active {
    transform: scale(0.92);
}

.fullscreen-button svg {
    grid-area: 1 / 1;
    display: block;
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

.fullscreen-button svg[hidden],
.fullscreen-button svg.hidden {
    display: none !important;
}

.parent-dialog {
    width: min(780px, calc(100% - 24px));
    max-height: min(88dvh, 840px);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 26px;
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 34px 100px rgba(0, 0, 0, 0.65);
}

.parent-dialog::backdrop {
    background: rgba(3, 5, 8, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.dialog-card {
    position: relative;
    max-height: inherit;
    overflow-y: auto;
    padding: 32px 36px;
    -webkit-overflow-scrolling: touch;
}

.close-button {
    position: absolute;
    z-index: 2;
    top: 18px;
    right: 18px;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    font-size: 26px;
    line-height: 1;
    transition: background 150ms ease;
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.16);
}

.dialog-heading {
    max-width: 460px;
    margin: 12px auto;
    text-align: center;
}

.lock-icon {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    margin: 0 auto 18px;
    border: 1px solid rgba(255, 184, 77, 0.3);
    border-radius: 22px;
    background: var(--accent-subtle);
    font-size: 26px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 850;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.dialog-heading h2,
.editor-header h2 {
    margin: 0;
    font-size: clamp(24px, 4.5vw, 34px);
    letter-spacing: -0.03em;
    font-weight: 850;
}

.dialog-heading > p:last-child {
    margin: 10px 0 0;
    color: var(--muted);
    line-height: 1.5;
    font-size: 15px;
}

.pin-form {
    max-width: 360px;
    margin: 28px auto 8px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: #e2e6f0;
    font-size: 13px;
    font-weight: 750;
}

label span {
    color: var(--muted);
    font-weight: 500;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    height: 50px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    outline: 0;
    background: #0f121a;
    color: var(--text);
    font-size: 15px;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

input[type="text"]:focus,
input[type="password"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.pin-form input {
    text-align: center;
    font-size: 28px;
    letter-spacing: 0.3em;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.primary-button {
    min-height: 50px;
    padding: 0 22px;
    border: 0;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: #1b1308;
    cursor: pointer;
    font-weight: 850;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 150ms ease, transform 100ms ease;
    touch-action: manipulation;
}

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

.primary-button:active {
    transform: scale(0.97);
}

.pin-form .primary-button {
    width: 100%;
    margin-top: 14px;
}

.primary-button:disabled,
.icon-button:disabled,
.reorder-btn:disabled {
    cursor: wait;
    opacity: 0.5;
}

.form-message {
    min-height: 22px;
    margin: 10px 0 0;
    color: var(--danger);
    font-size: 13px;
    text-align: center;
    font-weight: 600;
}

.editor-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding-right: 48px;
}

.text-button {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    font-weight: 750;
    font-size: 13px;
    transition: background 150ms ease;
}

.text-button:hover {
    background: rgba(255, 255, 255, 0.15);
}

.editor-tabs {
    display: flex;
    gap: 6px;
    margin: 20px 0 16px;
    padding: 4px;
    border-radius: var(--radius-md);
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--line);
}

.tab-button {
    flex: 1;
    min-height: 44px;
    padding: 0 16px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    font-weight: 750;
    font-size: 15px;
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease;
    touch-action: manipulation;
}

.tab-button:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.tab-button.active,
.tab-button[aria-selected="true"] {
    background: var(--panel-2);
    color: var(--accent);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.tab-panel {
    animation: tabFadeIn 160ms ease;
}

.tab-panel[hidden] {
    display: none !important;
}

@keyframes tabFadeIn {
    from { opacity: 0; transform: translateY(3px); }
    to { opacity: 1; transform: translateY(0); }
}

#playlist-status-message {
    min-height: 22px;
    margin: 4px 0 10px;
    color: var(--accent);
    font-size: 13px;
    text-align: center;
    font-weight: 600;
}

.add-form {
    display: grid;
    grid-template-columns: 1.3fr 1fr auto;
    align-items: end;
    gap: 12px;
    margin-top: 14px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
}

.field {
    min-width: 0;
}

.import-form {
    grid-template-columns: minmax(0, 1fr) auto;
}

.import-help {
    margin: 10px 2px 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

.form-message.is-pending {
    color: var(--accent);
}

.add-button {
    white-space: nowrap;
}

.playlist-help {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin: 20px 2px 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    flex-wrap: wrap;
}

.playlist-meta {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.reorder-tip b {
    color: var(--text);
}

.shuffle-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    min-height: 44px;
    padding: 0 4px;
    touch-action: manipulation;
}

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

.shuffle-switch {
    position: relative;
    width: 44px;
    height: 26px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid var(--line);
    border-radius: 999px;
    transition: background 200ms ease, border-color 200ms ease;
    flex-shrink: 0;
}

.shuffle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1), background 200ms ease;
}

.shuffle-checkbox:checked + .shuffle-switch {
    background: var(--accent);
    border-color: var(--accent-strong);
}

.shuffle-checkbox:checked + .shuffle-switch::after {
    transform: translateX(18px);
    background: #171009;
}

.shuffle-checkbox:focus-visible + .shuffle-switch {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.shuffle-label {
    color: var(--text);
    font-size: 14px;
    font-weight: 750;
    white-space: nowrap;
}

.playlist {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.playlist-item {
    display: grid;
    grid-template-columns: 44px 116px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: 84px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.035);
    transition: opacity 120ms ease, transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.playlist-item:hover {
    background: rgba(255, 255, 255, 0.055);
}

.playlist-item.dragging {
    z-index: 10;
    opacity: 0.65;
    border-color: var(--accent);
    background: var(--panel-2);
    transform: scale(1.02);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
    pointer-events: none; /* Crucial for elementFromPoint during drag */
}

.drag-handle {
    width: 44px;
    height: 54px;
    display: grid;
    place-items: center;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: grab;
    font-size: 26px;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    border-radius: var(--radius-sm);
    transition: color 150ms ease, background 150ms ease;
}

.drag-handle:hover {
    color: var(--accent);
    background: var(--accent-subtle);
}

.drag-handle:active {
    cursor: grabbing;
}

.thumbnail {
    width: 116px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 10px;
    background: #08090d;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.video-info {
    min-width: 0;
    padding-right: 6px;
}

.video-title {
    overflow: hidden;
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.35;
}

.video-id {
    margin: 0;
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
}

.item-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-button,
.play-button,
.reorder-btn {
    height: 42px;
    padding: 0 12px;
    border-radius: var(--radius-md);
    background: var(--panel-2);
    border: 1px solid var(--line);
    font-weight: 750;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 150ms ease, transform 100ms ease;
}

.icon-button:hover,
.play-button:hover,
.reorder-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.icon-button:active,
.play-button:active,
.reorder-btn:active {
    transform: scale(0.94);
}

.play-button {
    color: var(--accent);
    min-width: 60px;
}

.reorder-btn {
    width: 38px;
    padding: 0;
    font-size: 12px;
    color: var(--muted);
}

.reorder-btn:hover {
    color: var(--text);
}

.icon-button.danger {
    color: var(--danger);
    background: var(--danger-subtle);
    border-color: rgba(255, 107, 107, 0.2);
}

.icon-button.danger:hover {
    background: rgba(255, 107, 107, 0.25);
}

.playlist-empty {
    margin: 24px 0 8px;
    padding: 36px 20px;
    border: 1px dashed var(--line);
    border-radius: 16px;
    color: var(--muted);
    text-align: center;
    font-size: 15px;
}

.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;
}

/* Body lock when viewer is in fallback fullscreen mode */
html.has-fullscreen-viewer,
body.has-fullscreen-viewer {
    overflow: hidden !important;
    overscroll-behavior: none !important;
    touch-action: none;
}

/* Fullscreen mode (native API and full-window fallback) */
.viewer:fullscreen,
.viewer:-webkit-full-screen,
.viewer.is-fullscreen {
    position: fixed;
    inset: 0;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    box-sizing: border-box;
    padding-top: max(12px, env(safe-area-inset-top, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #000;
    overflow: hidden;
}

.viewer:fullscreen .video-stage,
.viewer:-webkit-full-screen .video-stage,
.viewer.is-fullscreen .video-stage {
    width: 100%;
    max-height: calc(100vh - 84px);
    max-height: calc(100dvh - 84px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-width: min(100%, calc((100vh - 84px) * 16 / 9));
    max-width: min(100%, calc((100dvh - 84px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 16 / 9));
    aspect-ratio: 16 / 9;
    margin: auto auto 0;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}

.viewer:fullscreen .controls,
.viewer:-webkit-full-screen .controls,
.viewer.is-fullscreen .controls {
    width: 100%;
    max-width: min(1200px, 100%, calc((100vh - 84px) * 16 / 9));
    max-width: min(1200px, 100%, calc((100dvh - 84px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 16 / 9));
    margin: 8px auto auto;
    padding: 0 4px;
    flex-shrink: 0;
}

/* Responsive adjustments */
@media (max-width: 760px) {
    .topbar {
        min-height: 60px;
    }

    .viewer {
        padding-left: 10px;
        padding-right: 10px;
    }

    .dialog-card {
        padding: 26px 18px;
    }

    .add-form {
        grid-template-columns: 1fr;
    }

    .playlist-item {
        grid-template-columns: 36px 88px minmax(0, 1fr);
        gap: 10px;
    }

    .thumbnail {
        width: 88px;
    }

    .item-actions {
        grid-column: 2 / -1;
        justify-content: flex-end;
        padding-top: 4px;
    }
}

/* Mobile phones (portrait & landscape general adjustments) */
@media (max-width: 600px) {
    .controls {
        gap: 10px;
        padding: 14px 2px 0;
    }

    .time {
        min-width: 38px;
        font-size: 13px;
    }

    .seek::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
        margin-top: -6px;
        border-width: 3px;
    }

    .seek::-moz-range-thumb {
        width: 18px;
        height: 18px;
        border-width: 3px;
    }

    .fullscreen-button {
        width: 42px;
        height: 42px;
        min-width: 42px;
        min-height: 42px;
    }

    .fullscreen-button svg {
        width: 20px;
        height: 20px;
    }

    /* Mobile portrait fullscreen: Edge-to-edge video, clean controls below */
    .viewer:fullscreen,
    .viewer:-webkit-full-screen,
    .viewer.is-fullscreen {
        padding-left: 0;
        padding-right: 0;
        padding-top: max(8px, env(safe-area-inset-top, 0px));
        padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
        justify-content: center;
    }

    .viewer:fullscreen .video-stage,
    .viewer:-webkit-full-screen .video-stage,
    .viewer.is-fullscreen .video-stage {
        width: 100%;
        max-width: 100%;
        aspect-ratio: 16 / 9;
        border-radius: 0;
        box-shadow: none;
        margin: auto 0 0;
    }

    .viewer:fullscreen .controls,
    .viewer:-webkit-full-screen .controls,
    .viewer.is-fullscreen .controls {
        width: 100%;
        max-width: 100%;
        margin: 14px 0 auto;
        padding: 0 max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px));
        gap: 10px;
        box-sizing: border-box;
    }
}

/* Mobile landscape view (phones rotated sideways) */
@media (orientation: landscape) and (max-height: 650px) {
    .topbar {
        min-height: 48px;
        padding-top: max(4px, env(safe-area-inset-top));
        padding-bottom: 4px;
    }

    .viewer {
        width: min(1100px, calc((100dvh - 90px) * 16 / 9));
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }

    .controls {
        padding-top: 8px;
        gap: 10px;
    }

    .viewer:fullscreen,
    .viewer:-webkit-full-screen,
    .viewer.is-fullscreen {
        padding-top: max(4px, env(safe-area-inset-top, 0px));
        padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
        padding-left: max(16px, env(safe-area-inset-left, 0px));
        padding-right: max(16px, env(safe-area-inset-right, 0px));
        justify-content: center;
    }

    .viewer:fullscreen .video-stage,
    .viewer:-webkit-full-screen .video-stage,
    .viewer.is-fullscreen .video-stage {
        max-height: calc(100vh - 54px);
        max-height: calc(100dvh - 54px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        max-width: min(100%, calc((100vh - 54px) * 16 / 9));
        max-width: min(100%, calc((100dvh - 54px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 16 / 9));
        margin: auto auto 0;
        border-radius: var(--radius-sm);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
    }

    .viewer:fullscreen .controls,
    .viewer:-webkit-full-screen .controls,
    .viewer.is-fullscreen .controls {
        max-width: min(1200px, 100%, calc((100vh - 54px) * 16 / 9));
        max-width: min(1200px, 100%, calc((100dvh - 54px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 16 / 9));
        margin: 5px auto auto;
        gap: 10px;
        padding: 0 2px;
    }

    .viewer:fullscreen .time,
    .viewer.is-fullscreen .time {
        font-size: 13px;
        min-width: 38px;
    }

    .viewer:fullscreen .seek::-webkit-slider-thumb,
    .viewer.is-fullscreen .seek::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
        margin-top: -6px;
        border-width: 3px;
    }

    .viewer:fullscreen .seek::-moz-range-thumb,
    .viewer.is-fullscreen .seek::-moz-range-thumb {
        width: 18px;
        height: 18px;
        border-width: 3px;
    }

    .viewer:fullscreen .fullscreen-button,
    .viewer.is-fullscreen .fullscreen-button {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
    }

    .viewer:fullscreen .fullscreen-button svg,
    .viewer.is-fullscreen .fullscreen-button svg {
        width: 20px;
        height: 20px;
    }
}
