/* Keep the landscape header, content and navigation on the same spacing grid. */
@media (orientation: landscape) and (min-width: 700px) {
  body {
    --rail: 156px;
    --header: 48px;
    --gutter: clamp(16px, 2.4vw, 32px);
    padding: var(--header) 0 24px var(--rail);
  }
  html { scroll-padding-top: 64px; }
  .top { left: var(--rail); height: var(--header); padding: 0 var(--gutter); }
  .avatar { width: 30px; height: 30px; }
  .bottom-nav {
    width: var(--rail); padding: 60px 10px 12px; gap: 4px;
    overflow-y: auto; border-radius: 0;
  }
  .bottom-nav:before { top: 20px; left: 18px; font-size: 14px; }
  .bottom-nav button { min-height: 40px; flex-shrink: 0; padding: 0 10px; }
  .hero { margin: 0; padding: 28px var(--gutter); border-radius: 0; }
  .hero h1 { font-size: clamp(36px, 5vw, 64px); }
  .section { padding: 24px var(--gutter); }
  .section-head { align-items: center; gap: 16px; margin-bottom: 16px; }
  .section-head > div { min-width: 0; }
  .section-head > span { flex-shrink: 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 14px; }
  .card { min-width: 0; padding: 10px; }
  .cover { display: block; }
  .about { padding: 32px var(--gutter); }

  .tablet-detail { top: var(--header); left: 0; padding: 46px var(--gutter) 16px; overflow: hidden; }
  .detail-close { top: 10px; right: var(--gutter); width: 32px; height: 32px; z-index: 2; }
  .detail-layout {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 30%);
    align-items: stretch; gap: 18px; min-height: 0; padding-top: 0;
    height: 100%;
    max-width: 1440px; margin-inline: auto;
  }
  .detail-layout > * { min-width: 0; }
  .detail-info { display: none; }
  .detail-info img { display: block; width: 100%; max-width: 180px; }
  .detail-info h1 { font-size: clamp(18px, 2vw, 26px); line-height: 1.2; margin-top: 14px; overflow-wrap: anywhere; }
  .detail-info p { line-height: 1.5; }
  .detail-player-space {
    display: grid; grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto; gap: 12px; min-height: 0;
  }
  .detail-player-slot { grid-column: 1 / -1; max-width: none; min-height: 0; height: 100%; }
  .detail-player-slot > .youtube-stage { margin-top: 0; }
  .detail-player-slot > .youtube-stage:not(.force-fullscreen) {
    width: 100% !important; max-width: none !important;
    height: 100% !important; aspect-ratio: auto !important;
  }
  .detail-queue { grid-column: 2; grid-row: 1; padding: 14px; height: 100%; min-height: 0; max-height: none; }
  .detail-queue h3 { flex-shrink: 0; }
  .detail-queue > div { display: block; flex: 1; min-height: 0; overflow-y: auto; }
  .detail-song { min-height: 60px; gap: 10px; }
  .detail-song strong { font-size: 11px; }
  .detail-song small { font-size: 9px; }
  .detail-search { margin: 0; align-self: center; }
  .detail-note { display: none; }
  .detail-player-space > .mode-overlay { margin: 0 !important; padding: 4px !important; align-self: center; }
  .mode-overlay button { height: 36px !important; padding-inline: 16px !important; font-size: 10px !important; }
  .video-row { gap: 6px; flex-wrap: wrap; }
  .video-volume { width: 54px; }
  .record-mode.youtube-stage { left: var(--rail); width: calc(100% - var(--rail)); }

  /* An embedded MP3 player needs room for its controls, not a 16:9 video box. */
  .detail-player-slot > .youtube-stage.record-mode:not(.force-fullscreen) {
    position: relative !important; inset: auto !important;
    height: 100% !important; aspect-ratio: auto !important; max-width: none !important;
  }
  .record-mode .record-view {
    display: grid; grid-template-columns: minmax(80px, .8fr) minmax(0, 1.2fr);
    grid-template-rows: auto auto; align-content: center; align-items: center;
    gap: 12px 16px; padding: 44px 18px 18px;
  }
  .record-mode .record-disc { grid-row: 1 / 3; width: min(100%, 200px); margin: 0; justify-self: center; }
  .record-mode .record-copy { margin: 0; min-width: 0; }
  .record-mode .record-copy h2 { font-size: clamp(14px, 1.7vw, 22px); line-height: 1.25; overflow-wrap: anywhere; }
  .record-mode .record-copy p { font-size: 10px; }
  .record-mode .mobile-mp3 { width: 100%; min-width: 0; margin: 0; }
  .record-mode .lyrics-toggle {
    align-self: center; padding: 6px 14px; margin-bottom: 6px;
    border: 1px solid #ff1f6d77; border-radius: 18px;
    background: #ff1f6d18; color: #ff5c94; font-size: 10px;
  }
  .record-mode .lyrics-panel {
    display: none; position: absolute; z-index: 10; inset: 64px 18px 18px;
    padding: 18px; overflow-y: auto; border-radius: 12px;
    background: #10121bf2; color: #ececf2; white-space: pre-wrap;
    text-align: center; font-size: 13px; line-height: 1.7;
  }
  .record-mode .lyrics-panel.open { display: block; }
  .record-mode .mp3-main-controls { gap: 12px; margin: 4px 0; }
  .record-mode .mp3-actions { gap: 4px; flex-wrap: wrap; padding: 0; }
  .record-mode .mp3-wave { grid-template-columns: 28px minmax(0, 1fr) 28px; gap: 6px; }
  .record-mode .mp3-bars { min-width: 0; overflow: hidden; }
  .record-mode .record-source { top: 24px; right: 118px; }
  .record-mode .youtube-player { top: 10px; right: 12px; width: 90px; height: 50px; }
  .record-mode .mp3-queue { display: none; }
  .record-mode .mp3-queue.open { display: flex; width: min(300px, 100%); }
  .record-mode #mp3QueueClose { display: block; }
  .record-mode .record-close { top: 12px; left: 12px; width: 32px; height: 32px; }
  .record-mode.force-fullscreen .record-view { padding: 70px 32px 24px; }
  .record-mode.force-fullscreen .record-disc { width: min(48vh, 280px); }
  .record-mode.force-fullscreen .mobile-mp3 { max-width: 440px; justify-self: center; }
  body.record-open > .mode-overlay { top: 12px; left: 58px !important; }
}

@media (orientation: landscape) and (min-width: 700px) and (max-width: 1099px) {
  .detail-layout { grid-template-columns: minmax(0, 1fr) minmax(200px, 30%); gap: 14px; }
  .detail-queue { padding: 10px; }
  .detail-search { padding-left: 10px; }
  .detail-search input { font-size: 11px; }
  .detail-search button { padding-inline: 12px; font-size: 11px; }
}

@media (orientation: landscape) and (min-width: 700px) and (max-height: 500px) {
  body { --rail: 140px; --header: 44px; }
  .bottom-nav { padding-top: 48px; gap: 2px; }
  .bottom-nav:before { top: 16px; left: 16px; font-size: 12px; }
  .bottom-nav button { min-height: 36px; height: 36px; }
  .section { padding-block: 18px; }
  .tablet-detail { padding-top: 42px; padding-bottom: 12px; }
  .record-mode .record-copy h2 { font-size: 15px; }
  .record-mode .record-view { padding-top: 36px; padding-bottom: 12px; gap: 8px 14px; }
  .record-mode .mp3-main-controls .mp3-play { width: 46px; height: 46px; }
  .record-mode .mp3-actions button { width: 30px; height: 30px; }
  .detail-info img { max-width: 124px; }
  .detail-info h1 { font-size: 18px; }
  .detail-info p:last-child { font-size: 10px; }
}

/* Some Android TV launchers report a narrow CSS viewport. Keep desktop layout. */
html[data-android-tv] { zoom: .5; }
html[data-android-tv] body { min-width: 0; padding-left: 190px; padding-bottom: 20px; }
html[data-android-tv] header { position: relative; z-index: 20; overflow: visible; }
html[data-android-tv] header .brand { position: relative; z-index: 100; display: inline-flex; align-items: center; visibility: visible; opacity: 1; color: #fff; }
html[data-android-tv] header .brand img { position: relative; z-index: 31; display: block; visibility: visible; opacity: 1; }
html[data-android-tv] header .brand:focus-visible { outline: none; box-shadow: none; }
html[data-android-tv] #categoryNav { position: fixed; left: 8px; right: auto; top: 112px; bottom: 12px; z-index: 10; width: 148px; max-width: none; height: auto; margin: 0; display: flex; flex-direction: column; padding: 6px; gap: 5px; border-radius: 14px; overflow-y: auto; }
html[data-android-tv] #categoryNav button { min-height: 46px; width: 100%; flex: 0 0 auto; padding: 8px; gap: 9px; font-size: 12px; scroll-margin-block: 8px; }
html[data-android-tv] #categoryNav .icon { width: 30px; height: 30px; flex-shrink: 0; }
html[data-android-tv] #categoryNav .icon svg { width: 22px; height: 22px; }
html[data-android-tv] header { position: sticky; top: 0; z-index: 5; margin-left: -190px; height: 64px; padding: 0 20px; }
html[data-android-tv] header .brand { font-size: 22px; }
html[data-android-tv] header .brand img { width: 44px; height: 44px; }
html[data-android-tv] .hero { padding: 32px; }
html[data-android-tv] .section { padding: 20px 32px; }
html[data-android-tv] .artists { padding-left: 32px; }
html[data-android-tv] .grid { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: 210px; gap: 16px; overflow-x: auto; }
html[data-android-tv] .card img { border-radius: 12px; }
html[data-android-tv] .hero form { max-width: 640px; }
html[data-android-tv] button, html[data-android-tv] a { outline-offset: 3px; }
html[data-android-tv] button:focus-visible, html[data-android-tv] a:focus-visible, html[data-android-tv] input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--gold), 0 8px 20px #0008; }
html[data-android-tv] #categoryNav button:focus-visible { outline: none; border-radius: 12px; background: var(--theme-gradient); color: var(--gold); transform: translateX(3px); box-shadow: inset 0 0 0 2px var(--gold), 0 0 0 3px var(--gold), 0 8px 18px #0006; }
html[data-android-tv] #categoryNav button:focus-visible .icon { color: var(--gold); }
html[data-android-tv] #grid .card:focus-within, html[data-android-tv] #artists button:focus-visible, html[data-android-tv] .moods button:focus-visible { transform: translateY(-4px); outline: none; box-shadow: 0 0 0 3px var(--gold), 0 10px 22px #0008; }
html[data-android-tv] #grid .card, html[data-android-tv] #artists button, html[data-android-tv] .moods button { transition: transform .15s ease, box-shadow .15s ease; }
html[data-android-tv] .detail-layout { grid-template-columns: minmax(0, 1fr) minmax(220px, 30%); }
