  :root {
    --bg: #0b0d12;
    --panel: #121622;
    --panel2: #171c2b;
    --text: #e9ecf5;
    --muted: #a7afc7;
    --border: rgba(255,255,255,0.10);
    --accent: #6ea8fe;
    --accent2: #8bd3ff;
    --warn: #ffcc66;
    --ui-scale: 1;
    --sub-options-scale: 1;
  }

  * { box-sizing: border-box; }
  html, body {
    margin: 0; padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  }

  .app-shell {
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .app-header {
    padding: 1.5% 2% 1% 2%;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0));
  }

  .mode-pill {
    display: inline-block;
    margin-bottom: 0.55rem;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    border: 1px solid rgba(139, 211, 255, 0.36);
    background: rgba(110, 168, 254, 0.14);
    color: var(--accent2);
    font-size: calc(11px * var(--ui-scale));
    letter-spacing: 0.02em;
  }

  .app-title { font-size: calc(18px * var(--ui-scale)); font-weight: 650; letter-spacing: 0.2px; }
  .app-subtitle { margin-top: calc(6px * var(--ui-scale)); font-size: calc(13px * var(--ui-scale)); color: var(--muted); }

  .app-main {
    flex: 1;
    padding: 1.5%;
    display: flex;
    min-height: 0;
    overflow: hidden;
  }
  .app-footer {
    padding: 1% 1.5%;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: calc(12px * var(--ui-scale));
  }

  .view { display: none; width: 100%; min-height: 0; overflow: hidden; }
  .view-active { display: block; width: 100%; min-height: 100%; overflow: hidden; }
  #view-home.view-active {
    display: flex;
    width: 100%;
    height: 100%;
    min-height: 0;
    align-items: center;
    justify-content: center;
  }
  .grid-2 {
    display: flex;
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    align-items: center;
    justify-content: center;
  }
  #view-player.view-active { display: flex; flex-direction: column; min-height: 0; }

  /* Primary options grid */
  .primary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: clamp(0.5rem, 1.4vmin, 1.2rem);
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
  }

  .card {
    container-type: size;
    background: var(--panel);
    border: max(0.06rem, 0.12cqi) solid var(--border);
    border-radius: clamp(0.55rem, 1.2cqi, 1.2rem);
    padding: clamp(0.65rem, 4cqi, 1.8rem);
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    gap: clamp(0.4rem, 1.8cqi, 0.9rem);
    min-height: 0;
    cursor: pointer;
    transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
    user-select: none;
  }
  .card:hover { transform: translateY(-0.08em); border-color: rgba(255,255,255,0.18); background: var(--panel2); }
  .card-title {
    font-size: clamp(1rem, 8cqi, 2.1rem);
    line-height: 1.12;
    font-weight: 650;
    max-width: 100%;
  }
  .card-desc {
    margin-top: 0;
    font-size: clamp(0.76rem, 4.1cqi, 1.35rem);
    color: var(--muted);
    line-height: 1.3;
    max-width: 100%;
  }

  /* Buttons */
  .btn {
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    padding: 1% 1.4%;
    border-radius: calc(0.9vw * var(--ui-scale));
    cursor: pointer;
    font-size: calc(13px * var(--ui-scale));
  }
  .btn:hover { border-color: rgba(255,255,255,0.18); background: var(--panel2); }
  .btn:disabled { opacity: 0.45; cursor: not-allowed; }

  .btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
  }

  /* Player layout */
  .player-toolbar {
    display: flex;
    align-items: center;
    gap: 1.2%;
    margin: 0 0 1.2% 0;
    width: 100%;
  }

  .player-meta { display: flex; flex-direction: column; gap: 4px; }
  .player-title { font-weight: 650; font-size: calc(16px * var(--ui-scale)); }
  .player-status { font-size: calc(12px * var(--ui-scale)); color: var(--muted); }

  .player-layout {
    display: grid;
    gap: 1.2%;
    width: 100%;
    margin: 0;
    flex: 1;
    min-height: 0;
  }

  .player-layout--single {
    grid-template-columns: 1fr;
  }

  .player-layout--split {
    grid-template-columns: 58% 42%;
    align-items: stretch;
  }

  .video-pane {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: calc(1.2vw * var(--ui-scale));
    padding: 1.2%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 220ms ease, opacity 220ms ease;
  }

  .video-el {
    width: 100%;
    height: 100%;
    min-height: 0;
    border-radius: calc(0.9vw * var(--ui-scale));
    background: #000;
    object-fit: contain;
  }

  .video-hint {
    margin-top: 1%;
    font-size: calc(12px * var(--ui-scale));
    color: var(--muted);
  }

  .sub-pane {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: calc(1.2vw * var(--ui-scale));
    padding: 1.2%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    opacity: 1;
    transform: translateX(0);
    transition: transform 240ms ease, opacity 240ms ease;
  }
  .sub-pane--hidden { display: none; }

  .is-desktop .sub-pane {
    transform: translateX(10px);
    opacity: 0;
  }

  .is-desktop .player-layout--revealed .video-pane {
    transform: translateX(-8px);
  }

  .is-desktop .player-layout--revealed .sub-pane {
    transform: translateX(0);
    opacity: 1;
  }

  .sub-pane-title {
    font-size: calc(13px * var(--ui-scale));
    font-weight: 650;
    margin-bottom: calc(10px * var(--ui-scale));
    color: var(--muted);
  }

  .sub-options-list {
    display: flex;
    flex-direction: column;
    gap: 1%;
    flex: 1;
    min-height: 0;
    overflow: auto;
    font-size: calc(14px * var(--ui-scale) * var(--sub-options-scale));
  }

  .sub-options-list--fill .sub-option {
    flex: 1 1 0;
    min-height: 0;
  }

  .sub-option {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.75em;
    padding: 0.72em 0.9em;
    border-radius: 0.85em;
    border: max(0.06rem, 0.09em) solid var(--border);
    background: rgba(255,255,255,0.03);
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
  }

  .sub-option:hover {
    border-color: rgba(110,168,254,0.55);
    box-shadow: 0 0 0 0.14em rgba(110,168,254,0.08);
    background: rgba(110,168,254,0.06);
  }

  .sub-option-label {
    font-size: 1em;
    font-weight: 600;
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .sub-option-time {
    font-size: 0.79em;
    color: var(--muted);
    white-space: nowrap;
  }

  .sub-option .btn {
    font-size: 0.9em;
    padding: 0.55em 0.9em;
    border-radius: 0.7em;
    justify-self: end;
    white-space: nowrap;
  }

  .sub-option--active {
    border-color: rgba(110,168,254,0.75);
    box-shadow: 0 0 0 0.2em rgba(110,168,254,0.12);
    background: rgba(110,168,254,0.08);
  }

  .sub-option--locked .sub-option-label::after {
    content: " • locked";
    font-weight: 500;
    color: var(--warn);
    font-size: 0.86em;
  }

  .sub-pane-footnote {
    margin-top: 1%;
    font-size: calc(12px * var(--ui-scale));
    color: var(--muted);
  }

  .sub-context {
    margin-top: 1%;
    display: flex;
    flex-direction: column;
    gap: 0.6%;
  }

  .sub-context-label {
    font-size: calc(12px * var(--ui-scale));
    font-weight: 600;
    color: var(--muted);
  }

  .sub-context-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: calc(0.8vw * var(--ui-scale));
    padding: 1%;
    background: rgba(255,255,255,0.03);
    color: var(--text);
    font: inherit;
    resize: none;
    min-height: 12%;
  }

  .sub-context-input:focus {
    outline: none;
    border-color: rgba(110,168,254,0.65);
    box-shadow: 0 0 0 2px rgba(110,168,254,0.12);
  }

  .muted { color: var(--muted); }

  .is-mobile .primary-grid {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-rows: minmax(0, 1fr);
    width: min(96vw, 42rem);
    height: 100%;
    max-height: 100%;
    gap: clamp(0.4rem, 1.2vh, 0.85rem);
  }

  .is-mobile .player-layout--split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .is-mobile .sub-pane {
    transform: translateY(8px);
    opacity: 0;
  }

  .is-mobile .player-layout--revealed .sub-pane {
    transform: translateY(0);
    opacity: 1;
  }

  @media (pointer: coarse) and (orientation: portrait) {
    .primary-grid {
      grid-template-columns: 1fr;
      grid-template-rows: none;
      grid-auto-rows: minmax(0, 1fr);
      width: min(96vw, 42rem);
      height: 100%;
      max-height: 100%;
      gap: clamp(0.4rem, 1.2vh, 0.85rem);
    }

    .player-layout--split {
      grid-template-columns: 1fr;
      grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    }

    .sub-pane {
      transform: translateY(8px);
      opacity: 0;
    }

    .player-layout--revealed .sub-pane {
      transform: translateY(0);
      opacity: 1;
    }
  }

  @media (max-width: 43.75em) {
    .card, .video-pane, .sub-pane { border-radius: 4vw; }
    .btn { border-radius: 3vw; }
    .sub-context-input { border-radius: 3vw; }
  }
