  :root {
    --bg: #0f1115;
    --bg2: #181b21;
    --bg3: #222631;
    --card: #181b22;
    --card-border: #282d3a;
    --text: #f0f2f7;
    --muted: #959fad;
    --line: #242935;
    --accent: #ff5500;
    --accent-glow: rgba(255, 85, 0, 0.2);
    --good: #38bdf8;
    --chip: #20242e;
    --chip-on: #ff5500;
    --chip-on-text: #ffffff;
    --hover: rgba(255, 255, 255, 0.06);
    --radius: 12px;
  }
  [data-theme="light"] {
    --bg: #f8fafc;
    --bg2: #ffffff;
    --bg3: #e2e8f0;
    --card: #ffffff;
    --card-border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --accent: #ea580c;
    --accent-glow: rgba(234, 88, 12, 0.15);
    --good: #0284c7;
    --chip: #f1f5f9;
    --chip-on: #ea580c;
    --chip-on-text: #ffffff;
    --hover: rgba(0, 0, 0, 0.05);
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
  }

  /* Top Navigation Bar */
  .top-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 60px;
    background: var(--bg2);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
    gap: 16px;
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.5px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
  }
  .brand-badge {
    background: linear-gradient(135deg, #ff5500, #ff8800);
    color: #fff;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 800;
  }
  .search-wrap {
    flex: 0 1 560px;
    position: relative;
    display: flex;
    align-items: center;
  }
  .search-input {
    width: 100%;
    height: 40px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 0 45px 0 16px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
  }
  .search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
  }
  .search-kbd {
    position: absolute;
    right: 14px;
    background: var(--bg3);
    color: var(--muted);
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--line);
    pointer-events: none;
  }
  .top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .btn-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: 1px solid var(--line);
    color: var(--text);
    cursor: pointer;
    font-size: 15px;
    transition: all 0.15s;
  }
  .btn-icon:hover {
    background: var(--hover);
    border-color: var(--muted);
  }
  .pill-btn {
    height: 36px;
    padding: 0 14px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
    white-space: nowrap;
  }
  .pill-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
  .pill-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }

  /* Layout Container */
  .layout {
    display: flex;
    margin-top: 60px;
    min-height: calc(100vh - 60px);
  }

  /* Sidebar */
  .sidebar {
    width: 240px;
    background: var(--bg2);
    border-right: 1px solid var(--line);
    position: fixed;
    top: 60px; bottom: 0; left: 0;
    overflow-y: auto;
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    z-index: 90;
  }
  .nav-group {
    margin-bottom: 20px;
  }
  .nav-group-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 6px 12px;
  }
  .nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
  }
  .nav-item:hover {
    background: var(--hover);
  }
  .nav-item.active {
    background: var(--chip);
    color: var(--accent);
    font-weight: 700;
  }
  .nav-item .count {
    margin-left: auto;
    font-size: 11px;
    color: var(--muted);
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 10px;
  }

  /* Progress Card in Sidebar */
  .progress-card {
    background: linear-gradient(135deg, rgba(255,85,0,0.12), rgba(34,197,94,0.08));
    border: 1px solid rgba(255,85,0,0.25);
    border-radius: 10px;
    padding: 12px;
    margin: 0 4px 16px;
  }
  .progress-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11.5px;
    font-weight: 700;
    margin-bottom: 6px;
  }
  .progress-title {
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 5px;
  }
  .progress-val {
    color: #22c55e;
    font-family: monospace;
    font-weight: 800;
  }
  .progress-bar-bg {
    width: 100%;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 6px;
  }
  .progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff5500, #22c55e);
    border-radius: 3px;
    transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .progress-desc {
    font-size: 11px;
    color: var(--muted);
    text-align: right;
  }

  .sidebar-footer {
    font-size: 11px;
    color: var(--muted);
    padding: 12px;
    border-top: 1px solid var(--line);
    line-height: 1.5;
  }

  /* Main Workspace */
  .main-content {
    margin-left: 240px;
    flex: 1;
    padding: 20px 28px 60px;
    max-width: 1600px;
  }

  /* Sub Header Row (Chips + Sort Selection) */
  .sub-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
  }
  .sub-header-row .chips-bar {
    margin-bottom: 0;
    padding-bottom: 4px;
    flex: 1;
    min-width: 260px;
  }
  .sort-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }
  .sort-label {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--muted);
  }
  .sort-select {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 6px 14px;
    font-size: 12.5px;
    font-weight: 600;
    outline: none;
    cursor: pointer;
    transition: all 0.15s;
  }
  .sort-select:hover, .sort-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
  }

  /* Chips Header */
  .chips-bar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 14px;
    margin-bottom: 18px;
    scrollbar-width: none;
  }
  .chips-bar::-webkit-scrollbar { display: none; }
  .chip {
    padding: 7px 14px;
    background: var(--chip);
    border: 1px solid var(--line);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    user-select: none;
  }
  .chip:hover {
    background: var(--bg3);
    border-color: var(--muted);
  }
  .chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }

  /* Hero Info Bar */
  .hero-banner {
    background: linear-gradient(135deg, rgba(255,85,0,0.1), rgba(56,189,248,0.05));
    border: 1px solid rgba(255,85,0,0.25);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }
  .hero-title {
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .hero-desc {
    font-size: 12.5px;
    color: var(--muted);
    margin-top: 3px;
  }

  /* Video Grid */
  .video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 22px;
  }
  .video-card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
    position: relative;
  }
  .video-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
    border-color: var(--accent);
  }
  .video-card.selected {
    outline: 2px solid var(--accent);
  }
  .thumb-wrap {
    position: relative;
    width: 100%;
    padding-top: 56.25%; /* 16:9 ratio */
    background: #000;
    overflow: hidden;
  }
  .thumb-wrap img {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
  }
  .video-card:hover .thumb-wrap img {
    transform: scale(1.03);
  }
  .thumb-dur {
    position: absolute;
    bottom: 8px; right: 8px;
    background: rgba(0,0,0,0.8);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
  }
  .thumb-badge {
    position: absolute;
    top: 8px; left: 8px;
    background: rgba(0,0,0,0.75);
    color: #fb923c;
    border: 1px solid rgba(251,146,60,0.3);
    font-size: 10.5px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    backdrop-filter: blur(4px);
  }
  .btn-later-float {
    position: absolute;
    top: 8px; right: 8px;
    width: 30px; height: 30px;
    border-radius: 50%;
    background: rgba(0,0,0,0.7);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
  }
  .video-card:hover .btn-later-float {
    opacity: 1;
  }
  .btn-later-float:hover {
    background: var(--accent);
  }
  .btn-later-float.active {
    opacity: 1;
    background: var(--accent);
  }

  .thumb-badge-completed {
    position: absolute;
    bottom: 8px; left: 8px;
    background: rgba(34, 197, 94, 0.92);
    color: #fff;
    font-size: 10.5px;
    font-weight: 800;
    padding: 2px 7px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 3px;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    z-index: 2;
  }
  .video-card.is-completed {
    border-color: rgba(34, 197, 94, 0.45);
  }
  .video-card.is-completed:hover {
    border-color: #22c55e;
  }

  .card-body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    flex: 1;
  }
  .card-title {
    font-size: 14.5px;
    font-weight: 700;
    line-height: 1.4;
    color: var(--text);
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
  }
  .card-summary {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 10px;
    flex: 1;
  }
  .card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    border-top: 1px solid var(--line);
    padding-top: 8px;
    margin-top: auto;
  }
  .card-cat {
    color: var(--good);
    font-weight: 600;
  }
  .card-channel {
    cursor: pointer;
    transition: color 0.15s;
    user-select: none;
  }
  .card-channel:hover {
    color: var(--accent);
    text-decoration: underline;
  }
  .card-search-snippet {
    font-size: 11.5px;
    color: var(--text);
    background: rgba(255, 85, 0, 0.08);
    border-left: 2px solid var(--accent);
    padding: 5px 8px;
    margin-bottom: 8px;
    border-radius: 4px;
    line-height: 1.45;
    word-break: break-all;
  }
  .search-highlight {
    background: rgba(255, 85, 0, 0.32);
    color: #ff7700;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 800;
  }

  /* Queue Float Button on Card */
  .btn-queue-float {
    position: absolute;
    top: 8px; right: 44px;
    width: 30px; height: 30px;
    border-radius: 50%;
    background: rgba(0,0,0,0.7);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    font-size: 12px;
  }
  .video-card:hover .btn-queue-float,
  .btn-queue-float.active {
    opacity: 1;
  }
  .btn-queue-float:hover {
    background: var(--accent);
  }
  .btn-queue-float.active {
    background: var(--accent);
    color: #fff;
  }
  .queue-badge {
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 4px;
  }

  /* Duration Filter Group */
  .duration-filter-group {
    display: inline-flex;
    align-items: center;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 2px;
    gap: 2px;
    flex-shrink: 0;
  }
  .dur-chip {
    height: 30px;
    padding: 0 10px;
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 15px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
  }
  .dur-chip:hover {
    color: var(--text);
    background: var(--hover);
  }
  .dur-chip.active {
    background: var(--accent);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(255, 85, 0, 0.35);
  }

  /* Speaker Active Banner */
  .speaker-banner {
    display: none;
    margin-bottom: 18px;
    background: linear-gradient(135deg, rgba(255, 85, 0, 0.12), rgba(255, 136, 0, 0.06));
    border: 1px solid rgba(255, 85, 0, 0.35);
    border-radius: 12px;
    padding: 10px 16px;
  }
  .speaker-banner-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 13.5px;
    color: var(--text);
  }
  .speaker-banner-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }
  .speaker-icon {
    font-size: 20px;
    flex-shrink: 0;
  }
  .speaker-title {
    font-size: 13.5px;
    font-weight: 700;
  }
  .speaker-title strong {
    color: var(--accent);
  }
  .speaker-count {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 2px;
  }
  .btn-clear-speaker {
    height: 32px;
    padding: 0 14px;
    border-radius: 16px;
    border: 1px solid rgba(255, 85, 0, 0.4);
    background: rgba(255, 85, 0, 0.15);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
  }
  .btn-clear-speaker:hover {
    background: var(--accent);
    color: #fff;
  }

  /* Up Next Continuous Study Card */
  .up-next-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 16px;
    margin: 14px 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .up-next-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--muted);
  }
  .auto-play-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    color: var(--muted);
  }
  .auto-play-toggle input {
    cursor: pointer;
    accent-color: var(--accent);
  }
  .up-next-content {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.18s;
  }
  .up-next-content:hover {
    background: rgba(255, 85, 0, 0.08);
    border-color: rgba(255, 85, 0, 0.3);
  }
  .up-next-thumb {
    width: 96px;
    aspect-ratio: 16 / 9;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
  }
  .up-next-info {
    flex: 1;
    min-width: 0;
  }
  .up-next-title {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .up-next-meta {
    font-size: 11.5px;
    color: var(--muted);
    margin-top: 4px;
  }
  .btn-play-next {
    height: 36px;
    padding: 0 16px;
    border-radius: 18px;
    border: none;
    background: linear-gradient(135deg, #ff5500, #ff7700);
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 3px 10px rgba(255, 85, 0, 0.35);
    transition: all 0.18s;
  }
  .btn-play-next:hover {
    transform: translateY(-1px);
    filter: brightness(1.1);
  }

  /* Player Modal / Split View */
  .player-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(14px);
    z-index: 1000;
    padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    box-sizing: border-box;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
  }
  .player-modal.open {
    display: flex;
  }
  .player-box {
    background: var(--bg2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    width: 96vw;
    height: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px);
    max-width: 1480px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0,0,0,0.65);
    margin: auto;
  }

  /* Player Top Navigation Bar (Always Visible Return Header) */
  .player-nav-bar {
    height: 60px;
    background: rgba(22, 24, 30, 0.96);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    z-index: 30;
    gap: 12px;
    box-sizing: border-box;
  }
  .btn-player-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #ff5500, #ff7700);
    color: #ffffff;
    border: none;
    border-radius: 22px;
    height: 44px;
    padding: 0 20px;
    font-size: 14.5px;
    font-weight: 800;
    letter-spacing: -0.2px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(255, 85, 0, 0.4);
    transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    user-select: none;
    flex-shrink: 0;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
  }
  .btn-player-back:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(255, 85, 0, 0.52);
    filter: brightness(1.08);
  }
  .btn-player-back:active {
    transform: scale(0.96);
  }
  .back-icon {
    font-size: 18px;
    font-weight: 900;
    line-height: 1;
    display: inline-block;
    transition: transform 0.18s ease;
  }
  .btn-player-back:hover .back-icon {
    transform: translateX(-3px);
  }
  .back-label-short {
    display: none;
  }
  .back-label-full {
    display: inline;
  }
  .player-nav-title {
    font-size: 14.5px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    text-align: center;
    padding: 0 8px;
  }
  .player-nav-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
  }
  .view-mode-group {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 22px;
    padding: 3px;
    gap: 3px;
    flex-shrink: 0;
  }
  .nav-mode-btn {
    height: 38px;
    padding: 0 14px;
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 19px;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    -webkit-tap-highlight-color: transparent;
  }
  .nav-mode-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
  }
  .nav-mode-btn.active {
    background: linear-gradient(135deg, #ff5500, #ff7700);
    color: #ffffff;
    box-shadow: 0 2px 10px rgba(255, 85, 0, 0.35);
  }
  .btn-nav-complete {
    height: 44px;
    padding: 0 18px;
    border-radius: 22px;
    font-size: 14px;
    font-weight: 800;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
    transition: all 0.18s;
    -webkit-tap-highlight-color: transparent;
  }
  .btn-nav-complete:hover {
    border-color: #22c55e;
    color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
  }
  .btn-nav-complete.completed {
    background: rgba(34, 197, 94, 0.18);
    border-color: #22c55e;
    color: #22c55e;
    box-shadow: 0 0 14px rgba(34, 197, 94, 0.28);
  }
  .nav-sub-action {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.18s;
    -webkit-tap-highlight-color: transparent;
  }
  .nav-sub-action:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--accent);
  }
  .nav-sub-action.active {
    background: rgba(255, 85, 0, 0.15);
    border-color: var(--accent);
    color: var(--accent);
  }
  .btn-player-close {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: var(--muted);
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }
  .btn-player-close:hover {
    color: #fff;
    border-color: #ff5500;
    background: #ff5500;
  }
  .btn-player-close:active {
    transform: scale(0.92);
  }

  /* Theater Mode: Expand player to full width, hide side drawer */
  .player-box.theater-mode .player-side {
    display: none !important;
  }
  .player-box.theater-mode .player-main {
    flex: 1 1 100% !important;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
  }

  /* Reading Mode: Video becomes a compact companion player, notes take center stage */
  .player-box.reading-mode .player-split-body {
    flex-direction: column !important;
    overflow-y: auto;
  }
  .player-box.reading-mode .player-main {
    flex: none !important;
    position: sticky;
    top: 0;
    z-index: 20;
    background: #000;
    box-shadow: 0 6px 20px rgba(0,0,0,0.6);
  }
  .player-box.reading-mode .video-aspect-box {
    width: 320px;
    max-width: 80vw;
    margin: 0 auto;
  }
  .player-box.reading-mode .player-toolbar,
  .player-box.reading-mode .embed-fallback-hint {
    display: none !important;
  }
  .player-box.reading-mode .player-side {
    flex: 1 !important;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    border-left: none;
    padding: 24px 30px;
  }

  /* Interactive Timestamps (Click to Seek Video) */
  .time-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(56, 189, 248, 0.12);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.35);
    padding: 2px 8px;
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    margin: 0 3px;
    transition: all 0.15s;
    user-select: none;
    vertical-align: baseline;
  }
  .time-pill:hover {
    background: #38bdf8;
    color: #000;
    border-color: #38bdf8;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(56, 189, 248, 0.45);
  }
  .time-pill:active {
    transform: scale(0.95);
  }

  /* Interactive Checklist Items in Action Guide */
  .action-checkbox-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    margin: 4px 0;
    border-radius: 6px;
    background: rgba(255,255,255,0.03);
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
    font-size: 13.5px;
    line-height: 1.5;
  }
  .action-checkbox-item:hover {
    background: rgba(255,255,255,0.07);
  }
  .action-checkbox-item input[type="checkbox"] {
    margin-top: 3px;
    accent-color: #22c55e;
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex-shrink: 0;
  }
  .action-checkbox-item.checked span {
    text-decoration: line-through;
    color: var(--muted);
  }

  /* Lucky Shuffle Button */
  .lucky-btn {
    background: linear-gradient(135deg, rgba(168,85,247,0.15), rgba(236,72,153,0.15));
    border-color: rgba(168,85,247,0.35);
    color: #e879f9;
  }
  .lucky-btn:hover {
    border-color: #e879f9;
    color: #fff;
    box-shadow: 0 0 12px rgba(232, 121, 249, 0.4);
  }

  /* Completed Status Toggle in Toolbar */
  .pill-btn.completed {
    background: rgba(34, 197, 94, 0.2);
    border-color: #22c55e;
    color: #22c55e;
    font-weight: 700;
  }
  .pill-btn.completed:hover {
    background: #22c55e;
    color: #fff;
  }

  /* Split Body Container */
  .player-split-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .player-main {
    flex: 1.35;
    display: flex;
    flex-direction: column;
    background: #000;
    overflow-y: auto;
  }

  /* Fixed 16:9 Aspect Ratio Box - Eliminates distortion completely */
  .video-aspect-box {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    position: relative;
    flex-shrink: 0;
  }
  .video-aspect-box iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    display: block;
  }

  .embed-fallback-hint {
    background: #11141a;
    border-top: 1px solid var(--line);
    padding: 8px 16px;
    font-size: 11.5px;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }
  .embed-fallback-hint a {
    color: var(--accent);
    text-decoration: underline;
    font-weight: 600;
    white-space: nowrap;
  }
  .player-toolbar {
    background: var(--bg2);
    padding: 14px 20px;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .player-info-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 600px;
  }
  .player-info-meta {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
  }
  .player-actions {
    display: flex;
    gap: 8px;
  }

  /* AI Brain Takeaways Drawer */
  .player-side {
    flex: 1;
    background: var(--bg);
    border-left: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px 24px;
  }
  .side-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
  }
  .side-title {
    font-size: 15px;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
  }
  .btn-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
  }
  .btn-close:hover { color: var(--text); }

  /* Sticky Navigation Bar in Drawer */
  .side-sticky-bar {
    position: sticky;
    top: -20px;
    z-index: 20;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    padding: 8px 0 10px;
    margin: 0 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    backdrop-filter: blur(8px);
  }
  .anchor-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .anchor-tabs::-webkit-scrollbar { display: none; }
  .anchor-btn {
    padding: 4px 9px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
  }
  .anchor-btn:hover {
    color: var(--text);
    border-color: var(--accent);
  }
  .anchor-btn.active {
    background: var(--chip);
    color: var(--accent);
    border-color: var(--accent);
  }
  .font-size-controls {
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 2px 4px;
    flex-shrink: 0;
  }
  .font-btn {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 700;
    padding: 2px 5px;
    cursor: pointer;
    border-radius: 4px;
  }
  .font-btn:hover {
    color: var(--text);
    background: var(--hover);
  }
  mark.search-highlight {
    background: #f59e0b;
    color: #000;
    padding: 1px 3px;
    border-radius: 3px;
    font-weight: 700;
  }

  /* Markdown Content Styling for readability */
  .markdown-content {
    font-size: 14px;
    line-height: 1.75;
    color: var(--text);
  }
  .markdown-content h1, .markdown-content h2, .markdown-content h3 {
    margin: 20px 0 10px;
    color: var(--text);
    font-weight: 700;
  }
  .markdown-content h3 {
    font-size: 15.5px;
    border-left: 3px solid var(--accent);
    padding-left: 10px;
    margin-top: 18px;
  }
  .markdown-content h4 {
    font-size: 14px;
    color: var(--good);
    margin: 14px 0 6px;
  }
  .markdown-content p {
    margin-bottom: 12px;
  }
  .markdown-content ul, .markdown-content ol {
    margin: 10px 0 14px 20px;
  }
  .markdown-content li {
    margin-bottom: 6px;
  }
  .markdown-content strong {
    color: #fff;
    font-weight: 700;
  }
  [data-theme="light"] .markdown-content strong {
    color: #000;
  }
  .markdown-content blockquote {
    margin: 14px 0;
    padding: 10px 16px;
    background: var(--bg2);
    border-left: 3px solid var(--good);
    border-radius: 0 8px 8px 0;
    font-size: 13.5px;
    color: var(--muted);
  }
  .markdown-content code {
    background: var(--bg3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
    color: #fb923c;
  }
  .markdown-content pre {
    background: var(--bg2);
    padding: 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid var(--line);
  }
  .markdown-content pre code {
    background: none;
    padding: 0;
    color: inherit;
  }
  .markdown-content hr {
    border: 0;
    height: 1px;
    background: var(--line);
    margin: 20px 0;
  }

  /* Summary Box */
  .summary-callout {
    background: linear-gradient(135deg, rgba(255,85,0,0.08), rgba(56,189,248,0.05));
    border: 1px solid rgba(255,85,0,0.25);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 18px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
  }
  .summary-callout-title {
    font-size: 12px;
    font-weight: 800;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  /* Key Takeaways Cards */
  .takeaway-pill-card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 8px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    font-size: 13.5px;
    line-height: 1.55;
    transition: border-color 0.15s;
  }
  .takeaway-pill-card:hover {
    border-color: var(--accent);
  }
  .takeaway-num {
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    min-width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
  }

  .takeaways-box {
    margin-bottom: 18px;
  }
  .takeaways-box h4 {
    font-size: 13px;
    font-weight: 700;
    color: var(--good);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .deep-analysis-box {
    margin-bottom: 18px;
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 18px 20px;
  }
  .deep-analysis-box h4 {
    font-size: 13px;
    font-weight: 700;
    color: #fb923c;
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 8px;
  }

  .action-box {
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.25);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 18px;
  }
  .action-box h4 {
    color: var(--good);
    font-size: 13px;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(56, 189, 248, 0.2);
    padding-bottom: 8px;
  }

  /* Keyboard Shortcuts Help Modal */
  .help-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1200;
    align-items: center;
    justify-content: center;
  }
  .help-modal.open { display: flex; }
  .help-card {
    background: var(--bg2);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 24px 30px;
    width: 440px;
    max-width: 90vw;
  }
  .help-card h3 {
    margin-bottom: 16px;
    font-size: 17px;
  }
  .help-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
  }
  .help-table td {
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }
  kbd {
    background: var(--bg3);
    border: 1px solid var(--line);
    padding: 2px 7px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
  }

  /* Toast Notification */
  .toast {
    position: fixed;
    bottom: 24px; left: 50%;
    transform: translateX(-50%) translateY(50px);
    background: var(--accent);
    color: #fff;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s;
    z-index: 2000;
  }
  .toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }

  /* Safe Area & Mobile Support */
  :root {
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
  }

  /* Scrim for Drawer */
  .sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    z-index: 85;
    transition: opacity 0.25s;
  }
  .sidebar-scrim.open {
    display: block;
  }

  /* Hamburger button */
  .btn-hamburger {
    display: none;
    flex-shrink: 0;
    margin-right: 6px;
    font-size: 19px;
  }

  /* --- Responsive Rules for iPhone Duo (Unfolded 7.6" & Folded 5.4") & iPhone 12 --- */

  /* 1. Unfolded Inner Display & Medium Viewports (max-width: 1080px) */
  @media (max-width: 1080px) {
    .btn-hamburger { display: flex; }
    .brand .brand-text { display: none; } /* Hide 'AIOS 智庫' subtitle, keep bold CoachTube badge */
    .btn-icon[title*="鍵盤"] { display: none; } /* Hide keyboard help button on touch devices */
    .search-kbd { display: none; }

    .search-wrap {
      flex: 1;
      min-width: 160px;
    }
    
    /* Make sidebar a smooth slide-over drawer */
    .sidebar {
      transform: translateX(-100%);
      transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
      box-shadow: 6px 0 28px rgba(0,0,0,0.5);
      z-index: 95;
      width: 280px;
    }
    .sidebar.open {
      transform: translateX(0);
    }
    .main-content {
      margin-left: 0;
      padding: 16px 20px 40px;
      max-width: 100%;
    }

    /* 2 Columns on unfolded iPhone Duo screen (14:10 wide) without clipping */
    .video-grid {
      grid-template-columns: repeat(2, 1fr);
      gap: 16px;
    }

    /* Player modal on unfolded screen (Dual-screen split view!) */
    .player-box {
      width: 98vw;
      height: 100%;
      max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 20px);
      max-width: 1100px;
    }
    .player-split-body {
      flex-direction: row;
    }
    .player-main {
      flex: 1.15;
    }
    .player-side {
      flex: 1;
      padding: 16px;
    }
  }

  /* 1.5 Special ergonomic tuning for iPhone Duo in Portrait & Tablets (max-width: 860px) */
  @media (max-width: 860px) {
    .top-actions {
      gap: 6px;
    }
    .pill-btn {
      height: 38px;
      width: 38px;
      padding: 0;
      justify-content: center;
      border-radius: 50%;
    }
    .pill-btn .btn-text-part {
      display: none; /* Turn into sleek icon-only buttons (🎲, 🛡️, ⚡), saving space for search bar */
    }
    .search-input {
      font-size: 13.5px;
      padding: 0 16px;
    }

    /* Player Navigation Bar in Duo Portrait (720px): Clean, Spacious, Zero Squeeze */
    .player-nav-title {
      display: none !important; /* Hide title to give all space to generous action buttons */
    }
    .nav-sub-action {
      display: none !important; /* Like and Later are already in player-toolbar right below video */
    }
    .player-nav-bar {
      height: 60px;
      padding: 0 14px;
      gap: 10px;
    }
    .btn-player-back {
      height: 44px;
      padding: 0 18px;
    }
    .btn-nav-complete {
      height: 44px;
      padding: 0 16px;
      font-size: 14px;
    }
    .btn-player-close {
      width: 44px;
      height: 44px;
    }

    /* Portrait split stack: Video top, Notes bottom with independent smooth scrolling */
    .player-split-body {
      flex-direction: column;
      overflow-y: auto;
    }
    .player-main {
      flex: none;
      height: auto;
      overflow-y: visible;
    }
    .video-aspect-box {
      width: 100%;
      aspect-ratio: 16 / 9;
    }
    .player-side {
      flex: none;
      height: auto;
      overflow-y: visible;
      border-left: none;
      border-top: 1px solid var(--line);
      padding: 16px 16px calc(30px + var(--sab));
    }
  }

  /* 2. Compact Phone & iPhone 12 (max-width: 600px) — Viewport 390px */
  @media (max-width: 600px) {
    .top-bar {
      padding: 0 10px;
      gap: 8px;
      height: calc(56px + var(--sat));
      padding-top: var(--sat);
    }
    .brand-badge {
      font-size: 13px;
      padding: 4px 7px;
    }

    /* Search input flexible & roomy */
    .search-wrap {
      flex: 1;
      min-width: 0;
    }
    .search-input {
      height: 38px;
      font-size: 13px;
      padding: 0 12px;
      border-radius: 19px;
    }

    /* Compact Top Action Buttons (Icons Only on iPhone) */
    .top-actions {
      gap: 5px;
    }
    .btn-icon {
      width: 38px;
      height: 38px;
      font-size: 14.5px;
    }

    .main-content {
      padding: 12px 12px calc(40px + var(--sab));
    }
    .hero-banner {
      flex-direction: column;
      align-items: flex-start;
      padding: 12px 14px;
      gap: 10px;
    }
    .hero-banner button {
      width: 100%;
      justify-content: center;
    }

    /* Single column on iPhone screen (100% width, edge-to-edge clean cards) */
    .video-grid {
      grid-template-columns: 1fr;
      gap: 14px;
    }
    .video-card {
      border-radius: 12px;
    }
    .card-body {
      padding: 12px;
    }
    .card-title {
      font-size: 14.5px;
    }

    /* Player modal on iPhone 12: Fullscreen with Generous 44px Touch Targets */
    .player-modal {
      padding: 0;
    }
    .player-box {
      width: 100vw;
      height: 100dvh;
      max-height: 100dvh;
      border-radius: 0;
      border: none;
    }
    .player-nav-bar {
      height: calc(58px + var(--sat));
      padding-top: var(--sat);
      padding-left: 12px;
      padding-right: 12px;
      gap: 8px;
    }
    .btn-player-back {
      height: 44px;
      min-width: 44px;
      padding: 0 16px;
      font-size: 15px;
      font-weight: 800;
      border-radius: 22px;
    }
    .back-label-full {
      display: none !important;
    }
    .back-label-short {
      display: inline !important; /* Shows "← 返回" */
    }
    .view-mode-group {
      display: none !important; /* Stacked layout already gives 100% width video on iPhone 12 */
    }
    .btn-nav-complete {
      height: 44px;
      min-width: 44px;
      padding: 0 16px;
      font-size: 14.5px;
      font-weight: 800;
      border-radius: 22px;
    }
    .btn-player-close {
      width: 44px;
      height: 44px;
      min-width: 44px;
      font-size: 18px;
    }

    .player-toolbar {
      padding: 12px 14px;
    }
    .player-info-title {
      font-size: 15px;
      max-width: 260px;
    }
    .side-sticky-bar {
      top: 0;
      position: sticky;
      background: var(--bg);
      z-index: 10;
      padding: 6px 0 8px;
    }
  }

/* === iOS PWA Fullscreen Safe-Area Support === */
@supports (padding-top: env(safe-area-inset-top)) {
  .top-bar {
    padding-top: env(safe-area-inset-top);
    height: calc(56px + env(safe-area-inset-top));
  }
  .player-nav-bar {
    padding-top: max(8px, env(safe-area-inset-top));
  }
}

/* === Cross-Device Progress Sync Modal === */
.sync-modal-card {
  max-width: 560px;
  width: 92vw;
}
.sync-stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 16px;
}
.sync-stat-pill {
  background: rgba(255, 85, 0, 0.12);
  border: 1px solid rgba(255, 85, 0, 0.28);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 700;
}
.sync-section {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.sync-section h4 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--text);
}
.sync-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.sync-textarea {
  width: 100%;
  min-height: 86px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  resize: vertical;
  margin-bottom: 10px;
}
.sync-mode-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  font-size: 12.5px;
  color: var(--muted);
}
.sync-mode-row label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
