/* Load after style.css: one phone composition owns the responsive cascade.
   Desktop control nodes and presentation are retained. */
.mobile-disclosure > summary { cursor: pointer; }
.mobile-settings > summary, .mobile-account, .mobile-drawer-close,
.mobile-drawer-backdrop, .mobile-drawer-legend, .mobile-annotation-help { display: none; }
.mobile-settings, .mobile-settings-panel, .mobile-answer-tools { display: contents; }
.mobile-answer-tools > summary { display: none; }
.mobile-answer-tools[hidden] { display: none; }

/* The original middle-width stack was also overridden by late desktop rules. */
@media (min-width: 601px) and (max-width: 1080px) {
  main { grid-template-columns: minmax(0, 1fr); padding: 18px; }
  #live-stats { position: static; max-height: none; }
  #header-filter-slot { min-width: 0; max-width: 100%; }
  .filter-bar { flex-wrap: wrap; }
  .vocab-axis-freq { min-width: 0; max-width: 100%; box-sizing: border-box; overflow-x: auto; }
}

/* Side-by-side practice has two scroll areas. The page itself stays put, and
   the coverage heading belongs to the frame rather than the scrolling tiles. */
@media (min-width: 1081px) {
  body.practice-columns-active:not(.entry-active):not(.coverage-active) {
    display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
  }
  body.practice-columns-active:not(.entry-active):not(.coverage-active) > header,
  body.practice-columns-active:not(.entry-active):not(.coverage-active) > footer { flex: none; }
  body.practice-columns-active:not(.entry-active):not(.coverage-active) > main {
    flex: 1 1 0; min-height: 0; overflow: hidden; grid-template-rows: minmax(0, 1fr);
    padding-bottom: 12px;
  }
  body.practice-columns-active:not(.entry-active):not(.coverage-active) > main:has(> .load-failure-banner:not([hidden])) {
    grid-template-rows: auto minmax(0, 1fr);
  }
  body.practice-columns-active:not(.entry-active):not(.coverage-active) .load-failure-banner { margin: 0; }
  body.practice-columns-active:not(.entry-active):not(.coverage-active) > main > .content {
    min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable;
    padding-bottom: 44px; box-sizing: border-box;
  }
  body.practice-columns-active:not(.entry-active):not(.coverage-active) #live-stats {
    min-height: 0; max-height: none; height: 100%; position: static; overflow: hidden; padding: 0;
  }
  body.practice-columns-active:not(.entry-active):not(.coverage-active) #live-stats .live-header {
    position: static; flex: none; margin: 0; padding: 12px 15px 8px;
  }
  body.practice-columns-active:not(.entry-active):not(.coverage-active) #live-stats-scroll {
    flex: 1 1 0; min-height: 0; overflow: auto; padding: 12px 15px 40px;
    overscroll-behavior: contain; scrollbar-gutter: stable;
  }
  body.practice-columns-active:not(.entry-active):not(.coverage-active) #live-stats-content {
    overflow: visible; flex: none; padding-right: 0;
  }
}

@media (max-width: 600px) {
  :root {
    --phone-tabs-height: calc(62px + env(safe-area-inset-bottom, 0px));
    --phone-coverage-height: 48px;
    --phone-bottom: calc(var(--phone-tabs-height) + var(--phone-coverage-height));
  }
  html { scroll-padding-top: calc(var(--mobile-header-height, 110px) + 12px); }
  body { padding-bottom: var(--phone-bottom); overflow-x: clip; }
  body.entry-active, body.coverage-active { padding-bottom: var(--phone-tabs-height); }
  header { padding: 10px 14px 0; z-index: 30; }
  .header-row2 { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; }
  .brand-row { grid-column: 1; min-width: 0; }
  .brand-logo { transform: scale(.8); transform-origin: left center; margin-right: -4px; }
  .wordmark { font-size: 22px; }
  .tagline { grid-column: 1 / -1; margin: 0 0 8px; font-size: 12px; }
  body:not(.entry-active) .tagline { display: none; }
  nav#strand-nav { display: none; }
  .mobile-account { display: block; grid-column: 2; grid-row: 1; }
  .mobile-account > summary { display: block; font-size: 13px; padding: 11px 8px; min-height: 44px; box-sizing: border-box; color: var(--accent); }
  .mobile-account-panel { position: absolute; top: calc(100% + 4px); right: 12px; left: 12px; padding: 14px; background: var(--bg); border: 1px solid var(--line); box-shadow: 0 8px 24px #0002; max-height: calc(100dvh - 170px); overflow: auto; z-index: 80; }
  #identity-box { margin: 0 0 12px; width: 100%; min-width: 0; flex-wrap: wrap; white-space: normal; justify-content: flex-start; }
  #identity-box button, .mobile-feedback { min-height: 44px; padding: 8px 12px; font-size: 14px; }
  .mobile-feedback { display: block; background: transparent; border: 1px solid var(--line); border-radius: 3px; color: var(--ink); margin-bottom: 12px; }
  .mobile-info > summary { min-height: 44px; padding: 10px 0; box-sizing: border-box; font-size: 14px; }
  .mobile-info-panel { display: flex; flex-direction: column; gap: 10px; font-size: 13px; line-height: 1.5; }
  .mobile-info-panel #content-status { white-space: normal; overflow: visible; }
  .mobile-info-panel #content-status:not([hidden]), .mobile-info-panel #build-version:not([hidden]) { display: block; }
  .mobile-info-panel [hidden] { display: none !important; }
  .mobile-colour-key { margin-top: 12px; font-size: 12px; line-height: 1.7; }
  .mobile-info-panel #build-version, .mobile-info-panel #streak-host { margin: 0; }
  footer { display: none; }

  .mobile-settings { display: block; grid-column: 1 / -1; min-width: 0; }
  .mobile-settings[hidden], .mobile-account[hidden] { display: none; }
  .mobile-settings > summary { display: flex; flex-direction: column; gap: 3px; padding: 6px 25px 10px 0; min-height: 52px; box-sizing: border-box; position: relative; list-style: none; }
  .mobile-settings > summary::after { content: "⌄"; position: absolute; right: 2px; top: 13px; font-size: 20px; color: var(--accent); }
  .mobile-settings[open] > summary::after { content: "⌃"; }
  .mobile-settings-title { color: var(--accent); font-size: 12px; }
  .mobile-scope { font-size: 13px; line-height: 1.4; color: var(--ink); overflow-wrap: anywhere; }
  .mobile-settings-panel { display: block; padding: 4px 0 12px; max-height: 48dvh; overflow-y: auto; overscroll-behavior: contain; }
  #header-filter-slot { display: block; width: 100%; }
  .filter-bar, .filter-row.scope-strip { position: static; margin: 0; padding: 8px 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: 8px; }
  .filter-bar[hidden] { display: none; }
  .scope-lead { display: none; }
  .filter-chip.scope-chip { max-width: 100%; min-height: 44px; padding: 4px 9px; font-size: 14px; }
  .filter-chip.scope-chip select, .filter-chip.scope-chip strong { max-width: 100%; font-size: 14px; }
  .filter-chip select { min-height: 34px; max-width: 100%; font-size: 14px; }
  .filter-chip.level-boxes { display: flex; flex-wrap: wrap; }
  .filter-chip.level-boxes .level-toggle, .filter-chip .level-toggle { min-width: 40px; min-height: 40px; padding: 7px; font-size: 13px; }
  .scope-right { flex-wrap: wrap; gap: 8px; margin: 0; }
  .scope-setup, .scope-clear, .chip-x { min-height: 40px; font-size: 13px; }
  .scope-hint, .scope-legend, .filter-count, .session-score { font-size: 12px; line-height: 1.5; }
  #grammar-qtypes { width: auto; margin: 8px 0 0; padding: 10px; }

  main, body.strand-vocab-active main { display: block; width: 100%; box-sizing: border-box; padding: 14px; margin: 0; }
  main > .content, .strand, #grammar-host, #translation-host, #vocab-host { width: 100%; max-width: 100%; min-width: 0; }
  #vocab-body { display: block; height: auto; min-height: 0; }
  .qcard, #strand-grammar .qcard, #strand-translation .qcard, #vocab-host > .qcard { padding: 14px; margin: 0 0 12px; border-radius: 4px; max-height: none; min-height: 0; height: auto; overflow: visible; box-sizing: border-box; scroll-margin-top: calc(var(--mobile-header-height, 110px) + 12px); }
  #strand-grammar .qcard .prompt, #strand-translation .qcard .prompt, #strand-grammar .qcard .prompt .prompt-italian, #strand-grammar .qcard .prompt .prompt-english { font-size: 20px; line-height: 1.45; margin: 8px 0 14px; overflow-wrap: anywhere; }
  #vocab-host .qcard .prompt { font-size: 21px; line-height: 1.4; }
  .qcard .meta { font-size: 12px; line-height: 1.45; }
  .qcard input[type="text"], .qcard textarea { width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; font-size: 17px; padding: 12px; }
  .qcard textarea { min-height: 115px; resize: vertical; }
  .actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
  .actions > button:not(.secondary), #strand-grammar .actions button:not(.secondary), #strand-translation .actions button:not(.secondary) { flex: 0 0 100%; width: 100%; min-height: 48px; font-size: 16px; padding: 12px; }
  .actions > button.secondary, #strand-grammar .actions button.secondary, #strand-translation .actions button.secondary { min-height: 44px; font-size: 14px; padding: 9px 16px; margin-left: auto; }
  .actions .kbd-hint, .accent-bar .accent-hint { display: none; }
  .grammar-updated-hint { display: none; } /* phone coverage already has a working toggle */
  #strand-grammar .mcq-choice { width: 100%; min-height: 48px; font-size: 16px; line-height: 1.4; padding: 12px; }
  .multi-select-choice, .stress-choice, .gender-choice { min-height: 44px; }
  .vocab-help-bar { flex-wrap: wrap; justify-content: flex-start; font-size: 13px; margin: 10px 0; }
  .vocab-help-bar button { min-height: 40px; font-size: 14px; }
  .mobile-answer-tools { display: block; border-top: 1px solid var(--line); margin: 10px 0 0; }
  .mobile-answer-tools > summary { display: block; min-height: 44px; box-sizing: border-box; padding: 12px 0; font-size: 13px; color: var(--accent); }
  .mobile-answer-tools > summary::after { content: " +"; }
  .mobile-answer-tools[open] > summary::after { content: " −"; }
  .accent-bar { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
  .accent-bar button { min-width: 44px; min-height: 44px; font-size: 17px; padding: 8px; }
  .intent-bar { display: flex; flex-wrap: wrap; gap: 8px; font-size: 14px; margin: 8px 0; }
  .intent-bar select, .annotation-bar button { min-height: 44px; font-size: 14px; }
  .intent-why { flex-basis: 100%; font-size: 13px; }
  .annotation-bar { display: flex; flex-wrap: wrap; gap: 8px; }
  .mobile-annotation-help { display: block; font-size: 12px; color: var(--muted); line-height: 1.5; }
  .card-result, #vocab-host .card-result, .result, #strand-grammar .result, #strand-translation .result { max-height: none; overflow: visible; padding: 12px; font-size: 15px; line-height: 1.5; }
  .el-row { grid-template-columns: minmax(0, 1fr) 40px minmax(0, 1fr); gap: 6px; }
  .el-label { font-size: 13px; }
  .el-dots { min-width: 40px; min-height: 44px; line-height: 40px; }
  .el-row > .el-label { grid-column: 1; grid-row: 1; }
  .el-row > .el-evidence { grid-column: 3; grid-row: 1; }
  .el-reason { grid-column: 2; grid-row: 1; }
  .el-reason[open] { display: block; grid-column: 1 / -1; grid-row: 2; }
  .el-reason[open] .el-dots { width: auto; text-align: left; }
  .el-reason[open] .el-dots::after { content: " Hide explanation"; font-size: 13px; }
  .el-reason[open] .el-explanation { display: block; position: static; width: 100%; box-sizing: border-box; transform: none; margin: 3px 0; box-shadow: none; }
  .el-reason:not([open]) .el-explanation { display: none; }

  #mobile-tabs { height: var(--phone-tabs-height); box-sizing: border-box; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  #mobile-tabs button { min-height: 44px; }
  #pullup-bar { min-height: var(--phone-coverage-height); height: var(--phone-coverage-height); box-sizing: border-box; bottom: var(--phone-tabs-height); padding: 8px 14px; z-index: 61; }
  .pullup-hint { font-size: 12px; }
  .pullup-caret { margin-left: auto; }
  .mobile-mini-coverage:not([hidden]) { display: flex; flex: 1 1 auto; min-width: 60px; max-width: 165px; height: 8px; gap: 1px; margin: 0 8px; overflow: hidden; }
  .mobile-mini-coverage .vocab-cov-cell { flex: 1 1 0; min-width: 0; height: 8px; padding: 0; border: 0; }
  body.strand-vocab-active .pullup-hint, #pullup-bar.fired .mobile-mini-coverage { display: none; }
  body.pullup-open { overflow: hidden; }
  body.pullup-open #live-stats, body.pullup-open.strand-vocab-active #vocab-axes-host { top: auto; left: 0; right: 0; bottom: var(--phone-bottom); width: 100%; max-width: 100%; box-sizing: border-box; max-height: min(72dvh, calc(100dvh - var(--phone-bottom) - 24px)); overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 55px 14px 16px; border-radius: 12px 12px 0 0; z-index: 60; }
  body.pullup-open #live-stats .live-header { position: static; margin: 0 0 10px; padding: 0; }
  body.pullup-open.strand-vocab-active #vocab-axes-host > .vocab-axis { width: 100%; max-width: 100%; box-sizing: border-box; }
  .mobile-drawer-legend { display: block; font-size: 12px; line-height: 1.6; padding: 0 0 12px; }
  .mobile-drawer-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; border: 0; background: #1c1c1c55; z-index: 59; }
  .mobile-drawer-close:not([hidden]) { display: block; position: fixed; right: 14px; min-height: 40px; border: 1px solid var(--line); background: var(--bg); color: var(--accent); font: inherit; font-size: 14px; padding: 8px 12px; border-radius: 4px; z-index: 62; }
  .coverage-view { padding: 0; min-width: 0; }
  .analysis-header { gap: 8px; }
  .analysis-tabs, .analysis-switch { display: flex; flex-wrap: wrap; gap: 6px; }
  .analysis-tabs button, .analysis-switch button { min-height: 44px; font-size: 13px; padding: 8px 12px; }
  .analysis-section, .coverage-col { max-width: 100%; min-width: 0; }
  .pt-grid-wrap, .coverage-matrix-wrap, .cmp-wrap { max-width: 100%; overflow-x: auto; }
  .entry-gate-form { flex-wrap: wrap; }
  .entry-gate-form .identity-name, .entry-gate-form .identity-class { width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; min-height: 44px; }
  .entry-gate-form .identity-save { width: 100%; min-height: 48px; }
  #wk-fb-btn { display: none !important; }
  #wk-fb-panel { left: 14px !important; right: 14px !important; width: auto !important; max-width: none !important; bottom: calc(var(--phone-tabs-height) + 12px) !important; max-height: calc(100dvh - var(--phone-tabs-height) - 32px); overflow-y: auto; }
  body.mobile-keyboard-open { padding-bottom: 16px; }
  body.mobile-keyboard-open #mobile-tabs, body.mobile-keyboard-open #pullup-bar { display: none; }
  summary:focus-visible, button:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
}
