/* Phone layouts are isolated from desktop tables and printable paper geometry. */
.reading-mobile-jump { display: none; }
@media screen and (max-width: 760px) {
  .topbar { height: 64px; }
  .topbar-inner { position: relative; width: 100%; height: 61px; padding: 7px 12px; flex-wrap: nowrap; gap: 8px; }
  .brand { flex: 1 1 auto; min-width: 0; gap: 7px; overflow: hidden; }
  .brand-logo { flex: 0 0 36px; width: 36px; height: 36px; }
  .brand-copy { min-width: 0; overflow: hidden; }
  .brand-copy strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
  .brand-copy small { font-size: 10px; }
  .btn.mobile-nav-toggle { display: inline-flex; order: 3; flex: 0 0 44px; width: 44px; min-width: 44px; height: 44px; padding: 0; }
  .user-menu { flex: 0 0 auto; order: 2; margin-left: 0; }
  .user-menu .user-name, .user-menu .btn span { display: none; }
  .user-menu .btn { width: 44px; min-width: 44px; height: 44px; padding: 0; }
  .topbar .nav { position: absolute; top: 61px; right: 0; left: 0; display: none; padding: 10px 12px; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); background: var(--brand-dark); border-bottom: 3px solid var(--gold); box-shadow: 0 10px 20px #29101330; overflow: visible; }
  .topbar.is-nav-open .nav { display: grid; }
  .topbar .nav a { min-width: 0; min-height: 44px; justify-content: flex-start; padding: 8px 12px; border: 1px solid #ffffff25; border-radius: 6px; font-size: 14px; }
  .app-shell { width: calc(100% - 24px); padding: 18px 0 36px; }
  .app-shell > *, .page-head > *, .panel, .panel-body, .field, .stack, .review-layout > * { min-width: 0; max-width: 100%; }
  .app-shell .page-head { flex-direction: column; align-items: stretch; gap: 14px; margin-bottom: 18px; }
  .app-shell h1 { font-size: 23px; line-height: 1.4; overflow-wrap: anywhere; }
  .page-head p { font-size: 13px; line-height: 1.6; overflow-wrap: anywhere; }
  .app-shell .page-actions { display: flex; flex-wrap: wrap; justify-content: flex-start; width: 100%; gap: 8px; margin-left: 0; }
  .app-shell .page-actions > *, .app-shell .reading-edit-actions > * { flex: 1 1 auto; }
  .app-shell .page-actions form { display: flex; margin: 0; }
  .app-shell .page-actions form .btn { width: 100%; }
  .app-shell .btn.btn { min-height: 44px; height: auto; padding: 9px 12px; font-size: 14px; line-height: 1.35; white-space: nowrap; }
  .app-shell .btn-icon { min-width: 44px; width: 44px; padding: 0; }
  .app-shell .panel-head { min-height: 48px; padding: 12px 14px; gap: 10px; flex-wrap: wrap; }
  .app-shell .panel-head h2 { font-size: 16px; }
  .app-shell .panel-body { padding: 14px; }
  .app-shell .input.input { min-width: 0; width: 100%; max-width: 100%; min-height: 44px; padding: 10px; font-size: 16px; line-height: 1.4; }
  .app-shell input.input, .app-shell select.input { height: 44px; }
  .app-shell textarea.input { resize: vertical; }
  .app-shell textarea.japanese-text { line-height: 1.8; }
  .app-shell textarea[name^="explanation_"] { min-height: 168px; }
  .app-shell .reading-form-grid, .app-shell .reading-meta-grid, .app-shell .group-meta-grid, .app-shell .form-row { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .app-shell .reading-filter { flex-wrap: wrap; gap: 10px; margin: 0; }
  .app-shell .reading-filter .input { flex: 1 1 100%; }
  .app-shell .reading-filter label { width: 100%; }
  .app-shell .reading-filter .btn { flex: 1 1 auto; }
  .app-shell .reading-question-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
  .app-shell .reading-question-head .choice-set { flex: 1 1 100%; width: 100%; max-width: none; }
  .app-shell .choice-set label { min-height: 44px; padding: 8px 0; font-size: 16px; }
  .app-shell .reading-edit-actions { display: flex; gap: 8px; width: 100%; }
  .app-shell .reading-edit-actions .btn { width: auto; min-height: 44px; }
  .app-shell .reading-marker-hint { flex-basis: 100%; margin: 2px 0 0; line-height: 1.6; }
  .app-shell .form-actions { flex-wrap: wrap; }
  .app-shell .form-actions .btn { width: 100%; }
  .app-shell .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .app-shell .metric { min-width: 0; padding: 13px; }
  .app-shell .metric strong { font-size: 26px; }

  .reading-task-list-page .reading-task-toolbar { display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; }
  .reading-task-list-page .reading-class-buttons { flex: 1 1 100%; width: 100%; gap: 8px; margin-bottom: 4px; }
  .reading-task-list-page .reading-task-toolbar > .btn { flex: 1 1 auto; }
  .reading-task-list-page .reading-task-toolbar #group-selection-form { display: contents; }
  .reading-task-list-page .reading-task-toolbar #create-training-group { flex: 1 1 auto; }
  .reading-task-list-page .reading-group-selector { width: 22px; height: 22px; vertical-align: middle; margin-right: 10px; }
  .app-shell .group-class-filters { flex-wrap: wrap; gap: 8px; }

  /* Keep one accessible set of controls; only their visual arrangement changes. */
  .app-shell .mobile-card-list { overflow: visible; background: transparent; border: 0; box-shadow: none; }
  .app-shell .mobile-card-list > .panel-head { margin-bottom: 10px; background: #fff; border: 1px solid var(--line); border-radius: 7px; }
  .app-shell table[data-mobile-cards] { display: block; width: 100%; min-width: 0; max-width: 100%; table-layout: auto; border: 0; }
  .app-shell table[data-mobile-cards] thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .app-shell table[data-mobile-cards] tbody { display: grid; gap: 12px; width: 100%; }
  .app-shell table[data-mobile-cards] tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 16px; margin: 0; width: 100%; min-width: 0; background: #fff; border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 2px 0 #ded9d740; }
  .app-shell table[data-mobile-cards] tbody td[data-label], .app-shell table[data-mobile-cards] tbody td[colspan] { display: block; width: auto; min-width: 0; height: auto; min-height: 0; padding: 0; border: 0; font-size: 14px; line-height: 1.5; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  .app-shell table[data-mobile-cards] td[data-label]::before { display: block; content: attr(data-label); margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 500; }
  .app-shell table[data-mobile-cards] td[data-mobile-field="title"] { grid-column: 1 / -1; font-size: 17px; font-weight: 750; }
  .app-shell table[data-mobile-cards] td[data-mobile-field="title"]::before, .app-shell table[data-mobile-cards] td[data-mobile-field="actions"]::before { display: none; }
  .app-shell table[data-mobile-cards] td[data-mobile-field="wide"], .app-shell table[data-mobile-cards] td[data-mobile-field="actions"], .app-shell table[data-mobile-cards] td[colspan] { grid-column: 1 / -1; }
  .app-shell table[data-mobile-cards] td[data-mobile-field="actions"] { padding-top: 12px; border-top: 1px solid #ece8e6; }
  .app-shell table[data-mobile-cards] td[colspan] { padding: 24px 0; text-align: center; }
  .app-shell table[data-mobile-cards] .reading-title { font-size: 17px; line-height: 1.5; }
  .app-shell table[data-mobile-cards] small { display: block; margin-top: 3px; font-weight: 400; font-size: 12px; line-height: 1.5; }
  .app-shell table[data-mobile-cards] .badge { font-size: 12px; padding: 4px 8px; }
  .app-shell table[data-mobile-cards] .reading-task-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; gap: 8px; }
  .app-shell table[data-mobile-cards] .reading-task-actions > *, .app-shell table[data-mobile-cards] .reading-task-actions form .btn { min-width: 0; width: 100%; margin: 0; }
  .app-shell table[data-mobile-cards] .reading-task-actions > form:last-child { grid-column: 1 / -1; }
  .app-shell table[data-mobile-cards] .reading-task-actions .btn { padding: 9px 4px; font-size: 13px; }
  .app-shell table[data-mobile-cards] .group-list-actions, .app-shell table[data-mobile-cards] .reading-record-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .app-shell table[data-mobile-cards] .group-list-actions > *, .app-shell table[data-mobile-cards] .reading-record-actions > * { flex: 1 1 auto; }
  .app-shell table[data-mobile-cards] .group-list-actions form .btn, .app-shell table[data-mobile-cards] .reading-record-actions form .btn { width: 100%; }
  .app-shell table[data-mobile-cards] time { font-size: 13px; white-space: normal; }
  .app-shell table[data-mobile-cards] pre { max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
  .app-shell table[data-mobile-cards] summary { min-height: 44px; padding: 10px 0; }

  .reading-task-page .reading-mobile-jump { display: flex; gap: 8px; margin: 0 0 14px; }
  .reading-task-page .reading-mobile-jump .btn { flex: 1; }
  .reading-task-page .reading-student-panel, .reading-task-page .reading-text-panel { scroll-margin-top: 78px; }
  .reading-task-page .reading-students-wrap { overflow: visible; padding: 12px; }
  .reading-task-page table[data-mobile-cards] tbody tr { box-shadow: none; padding: 12px; gap: 8px 12px; }
  .reading-task-page table[data-mobile-cards] td.col-student { grid-column: 1; grid-row: 1; }
  .reading-task-page table[data-mobile-cards] td.col-status { grid-column: 2; grid-row: 1; text-align: right; }
  .reading-task-page table[data-mobile-cards] td.col-status::before { display: none; }
  .reading-task-page table[data-mobile-cards] td.col-scan { grid-row: 2; }
  .reading-task-page table[data-mobile-cards] td.col-errors { grid-row: 2; }
  .reading-task-page table[data-mobile-cards] td.col-submitted { grid-column: 1 / -1; }
  .reading-task-page table[data-mobile-cards] td.col-submitted::before { display: inline; margin-right: 8px; }
  .reading-task-page table[data-mobile-cards] td.col-submitted time { display: inline; }
  .reading-task-page table[data-mobile-cards] td.col-student > strong, .reading-task-page table[data-mobile-cards] .student-name-link { font-size: 16px; overflow: visible; white-space: normal; }
  .reading-task-page table[data-mobile-cards] .reading-student-actions { justify-content: flex-start; gap: 8px; }
  .reading-task-page table[data-mobile-cards] .reading-student-actions .btn { flex: 1 1 auto; width: auto; min-width: 0; min-height: 44px; padding: 8px; }
  .reading-task-page table[data-mobile-cards] .reading-action-label { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip-path: none; white-space: normal; }
  .reading-group-task-page table[data-mobile-cards] tbody td[data-mobile-field="actions"] { display: flex; gap: 8px; }
  .reading-group-task-page table[data-mobile-cards] td[data-mobile-field="actions"] .btn { flex: 1; }
  .app-shell .group-reading-cards { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .app-shell .group-reading-card { gap: 6px; }
  .app-shell .group-reading-card a { display: inline-flex; align-items: center; min-height: 44px; }
  .app-shell .group-order-item { flex-wrap: wrap; gap: 12px; }
  .app-shell .group-order-item > div:first-of-type { flex: 1 1 100%; min-width: 0; overflow-wrap: anywhere; }
  .app-shell .group-order-actions { display: flex; width: 100%; gap: 8px; }
  .app-shell .group-order-actions .btn { flex: 1; }

  .app-shell .review-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .app-shell .scan-toolbar { padding: 10px; }
  .app-shell .scan-tabs { display: flex; flex-wrap: wrap; min-width: 0; gap: 4px; }
  .app-shell .scan-tabs button { min-height: 44px; padding: 8px 10px; }
  .app-shell .scan-image-wrap { max-height: 55vh; }
  .app-shell .review-answer-grid { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-auto-flow: row; grid-auto-columns: auto; gap: 10px; overflow: visible; }
  .app-shell .review-answer { min-width: 0; }
  .app-shell .review-answer .choice-set { width: 100%; max-width: none; }
  .app-shell .issue { overflow-wrap: anywhere; }
  .app-shell .issue svg { flex: 0 0 auto; }
  .reading-analysis-page .item-analysis-title-row { flex-wrap: wrap; justify-content: space-between; gap: 8px; }
  .reading-analysis-page .item-analysis-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .reading-analysis-page .item-analysis-metrics .metric { padding: 10px 8px; }
  .reading-analysis-page .item-analysis-metrics .metric-top { font-size: 11px; }
  .reading-analysis-page .item-analysis-metrics .metric-icon { display: none; }
  .reading-analysis-page .item-analysis-metrics .metric > strong { font-size: 21px; }
  .reading-analysis-page .item-analysis-header { display: flex; gap: 6px; padding: 10px; }
  .reading-analysis-page .item-analysis-header > span { display: none; }
  .reading-analysis-page .item-analysis-header .analysis-sort-link { display: flex; flex: 1; min-width: 0; min-height: 44px; padding: 8px 4px; font-size: 12px; }
  .reading-analysis-page .item-analysis-header .analysis-sort-link.is-centered { display: flex; }
  .reading-analysis-page .item-analysis-header .analysis-sort-link svg { display: none; }
  .reading-analysis-page .item-analysis-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "question accuracy" "responses responses" "discrimination discrimination" "detail detail"; gap: 12px; padding: 14px; }
  .reading-analysis-page .analysis-question { grid-area: question; }
  .reading-analysis-page .analysis-accuracy { grid-area: accuracy; }
  .reading-analysis-page .response-frequency { grid-area: responses; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; overflow: visible; contain: none; }
  .reading-analysis-page .response-option { grid-template-columns: minmax(0, 1fr); min-height: 78px; }
  .reading-analysis-page .response-option small { font-size: 11px; }
  .reading-analysis-page .analysis-discrimination { display: flex; grid-area: discrimination; gap: 8px; align-items: center; justify-content: flex-start; }
  .reading-analysis-page .analysis-discrimination::before { content: "区分度"; color: var(--muted); font-size: 12px; }
  .reading-analysis-page .item-response-detail { grid-area: detail; }
  .reading-analysis-page .item-response-detail-head { flex-wrap: wrap; }
  .reading-analysis-page .item-response-detail-head > div { flex-wrap: wrap; gap: 4px; }
  .reading-analysis-page .response-student-row { min-height: 44px; }
  .reading-overview-page .ro-controls .input, .reading-overview-page .ro-controls .btn { min-height: 44px; height: auto; font-size: 16px; }
  .reading-overview-page .ro-cell { font-size: 12px; }
  .reading-overview-page .ro-student-line strong { font-size: 13px; }
}
@media screen and (max-width: 359px) {
  .app-shell table[data-mobile-cards] tbody tr { padding: 12px; }
  .app-shell table[data-mobile-cards] .reading-task-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brand-copy strong { font-size: 12px; }
  .app-shell .page-actions .btn { padding: 9px 8px; }
}
