.mobile-menu-button,
.mobile-menu-dialog { display: none; }

/* Phone layout: compact app shell, no document-level horizontal overflow. */
@media (max-width: 719px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    padding-bottom: env(safe-area-inset-bottom);
    -webkit-text-size-adjust: 100%;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 64px;
    padding: 0 14px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(14px);
  }

  .brand {
    flex: none;
    min-width: 0;
    font-size: 22px;
    white-space: nowrap;
    transform: none;
  }

  .top-actions {
    min-width: 0;
    justify-content: flex-end;
    gap: 4px;
    overflow: visible;
  }

  .top-actions #personalizeButton { display: none !important; }

  .top-actions #enrichButton,
  .top-actions #exportButton,
  .top-actions #importButton,
  .top-actions #personalizeButton {
    display: none !important;
  }

  .top-actions .mobile-menu-button {
    display: grid !important;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    background: transparent;
  }

  .top-actions .text-button,
  .top-actions #accountButton,
  .top-actions #personalizeButton {
    display: inline-flex !important;
    flex: 0 0 auto;
    width: auto;
    height: 40px !important;
    padding: 0 8px;
    white-space: nowrap;
    writing-mode: horizontal-tb;
    font-size: 12px;
  }

  .top-actions #addButton {
    flex: 0 0 auto;
    width: auto;
    height: 40px;
    padding: 0 12px;
    white-space: nowrap;
    writing-mode: horizontal-tb;
    font-size: 12px;
  }

  .top-actions #addButton .material-symbols-rounded { font-size: 18px; }

  .hero,
  .library {
    width: calc(100% - 28px);
    max-width: 100%;
    margin-inline: auto;
  }

  .hero {
    padding: 34px 0 24px;
  }

  .hero h1 {
    max-width: 100%;
    margin: 0;
    font-size: clamp(38px, 11.3vw, 52px);
    line-height: 1.12;
    letter-spacing: -.055em;
    overflow-wrap: break-word;
  }

  .stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
    margin-top: 24px;
    overflow: visible;
  }

  .stats div {
    min-width: 0 !important;
    width: auto;
    height: 66px;
    padding: 0 6px;
    gap: 5px;
    justify-content: center !important;
    text-align: center;
  }

  .stats strong { font-size: 23px; }
  .stats span { font-size: 10px; white-space: nowrap; }

  .controls {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    gap: 12px;
    margin-bottom: 16px;
    border-bottom: 0;
  }

  .search {
    order: 1;
    width: 100%;
    height: 48px;
  }

  .search input {
    width: 100%;
    min-width: 0;
    font-size: 16px;
  }

  .tabs {
    order: 2;
    width: calc(100vw - 14px);
    max-width: none;
    margin-right: -14px;
    padding-right: 14px;
    gap: 8px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: x proximity;
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 24px), transparent 100%);
  }

  .tab {
    flex: 0 0 auto;
    height: 38px;
    padding: 0 14px;
    scroll-snap-align: start;
    white-space: nowrap;
  }

  .show-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .show-card {
    width: 100%;
    min-width: 0;
    border-radius: 18px;
  }

  .poster-frame,
  .poster { border-radius: 17px 17px 0 0; }

  .card-content { padding: 11px 11px 12px !important; }
  .card-top { gap: 5px; }
  .card-top h3,
  .show-card h3 { font-size: 14px; }
  .badge { font-size: 9px; }
  .next-episode { padding-top: 8px !important; font-size: 11px; }
  .episode-name { font-size: 11px; }
  .progress-row { margin-top: 7px !important; gap: 7px; font-size: 9px; }

  .empty-state {
    width: calc(100% - 28px);
    padding: 44px 20px;
  }

  .site-footer {
    width: calc(100% - 28px);
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  dialog,
  #showDialog,
  .search-dialog,
  .personalize-dialog,
  .account-dialog {
    inset: auto 0 0 0;
    width: 100%;
    max-width: none;
    max-height: 92dvh;
    margin: 0;
    border-radius: 28px 28px 0 0;
    overscroll-behavior: contain;
  }

  html:has(dialog[open]),
  body:has(dialog[open]) {
    overflow: hidden;
    overscroll-behavior: none;
  }

  .mobile-menu-dialog[open] {
    display: block;
    padding: 0 18px calc(18px + env(safe-area-inset-bottom));
    background: var(--surface-container-high);
    height: auto;
    overflow: hidden;
    touch-action: none;
  }

  .mobile-menu-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 20px 2px 16px;
  }

  .mobile-menu-head p {
    margin: 0 0 4px;
    color: var(--primary);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: .09em;
  }

  .mobile-menu-head h2 {
    margin: 0;
    font-size: 25px;
    line-height: 1.2;
  }

  .mobile-menu-list {
    display: grid;
    gap: 7px;
  }

  .mobile-menu-list > button {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 68px;
    padding: 10px 14px;
    border: 0;
    border-radius: 18px;
    background: var(--surface-container-low);
    color: var(--on-surface);
    text-align: left;
  }

  .mobile-menu-list > button > .material-symbols-rounded {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--primary-container);
    color: var(--on-primary-container);
  }

  .mobile-menu-list > button > span:last-child { display: grid; gap: 2px; }
  .mobile-menu-list b { font-size: 14px; }
  .mobile-menu-list small { color: var(--on-surface-variant); font-size: 11px; }

  .account-dialog {
    padding: 0 20px calc(22px + env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  .account-head { padding-top: 20px; }
  .account-head h2 { font-size: 26px; }
  .account-intro { font-size: 14px; overflow-wrap: anywhere; }
  .login-form input { font-size: 16px; }

  #showDialog .dialog-fixed { padding-top: 8px; }
  #showDialog .dialog-head { padding: 12px 18px 14px; }
  #showDialog .dialog-head h2 { font-size: 23px; }
  #showDialog .season-tabs { padding-inline: 18px; }
  #showDialog .season-tabs button { height: 56px; }
  #showDialog .season-progress-row { padding-inline: 18px; }
  #showDialog .episode-list {
    max-height: calc(92dvh - 210px);
    margin-right: 3px;
    padding: 8px 8px calc(18px + env(safe-area-inset-bottom)) 10px;
  }
  #showDialog .episode { padding-inline: 8px; }
  #showDialog .episode { min-height: 94px; }
  #showDialog .episode-title { display: block; }
  #showDialog .episode-dates {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start;
    gap: 2px !important;
    white-space: nowrap;
    font-size: 11px;
    line-height: 1.35;
    min-height: calc(2.7em + 2px);
  }
  #showDialog .episode-dates span {
    display: flex !important;
    align-items: baseline;
  }
  #showDialog .episode-dates span + span::before { display: none !important; }
  #showDialog .episode-dates b {
    display: inline-block;
    min-width: 34px;
    margin-right: 4px;
  }

  .remote-search { margin-inline: 18px; }
  .remote-results { padding-inline: 18px; }

  .personalize-dialog[open] {
    display: block;
    height: 92dvh;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 390px) {
  .brand { font-size: 20px; }
  .top-actions #addButton { padding-inline: 10px; }
  .hero h1 { font-size: 38px; }
}

@media (max-width: 719px) {
  .top-actions #personalizeButton { display: none !important; }
  .top-actions #addButton {
    width: 96px;
    min-width: 96px;
    padding: 0 14px !important;
    justify-content: center;
    overflow: hidden;
    gap: 7px;
    color: var(--on-secondary-container);
    font-size: 12px !important;
  }
  .top-actions #addButton .material-symbols-rounded {
    display: grid;
    place-items: center;
    width: 18px;
    height: 18px;
    color: var(--on-secondary-container);
    line-height: 1;
  }
  .top-actions #addButton .add-button-label {
    display: inline-block;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
  }
  .top-actions #addButton::after { content: none !important; }
  .top-actions #accountButton {
    position: relative;
    width: 40px;
    min-width: 40px;
    padding: 0 !important;
    overflow: hidden;
    color: transparent;
    font-size: 0 !important;
  }
  .top-actions #accountButton::after {
    content: "person";
    display: grid;
    place-items: center;
    width: 100%;
    color: var(--on-surface-variant);
    font-family: "Material Symbols Rounded";
    font-size: 21px;
  }
  .top-actions #accountButton::before {
    position: absolute;
    top: 6px;
    right: 5px;
    width: 7px;
    height: 7px;
  }

  .site-footer {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    column-gap: 9px;
    row-gap: 10px;
  }
  .site-footer a,
  .site-footer > span {
    display: flex;
    align-items: center;
    min-height: 20px;
    margin: 0;
    line-height: 1.2;
  }
  .site-footer small {
    grid-column: 1 / -1;
    width: 100%;
    margin: 0;
    line-height: 1.55;
  }
}
