/* 手機版：保留所有功能，但改成單欄、可滑動與較大的觸控範圍。 */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 760px) {
  .app-shell,
  .workspace,
  .content,
  .panel,
  .table-panel,
  .roster-group-editor,
  .yjh-video-page {
    width: 100%;
    min-width: 0 !important;
    max-width: 100%;
  }

  .content {
    padding: 14px 10px calc(108px + env(safe-area-inset-bottom)) !important;
  }

  .topbar {
    position: sticky;
    z-index: 32;
    top: 0;
    min-height: 64px !important;
    padding: 9px 11px !important;
    gap: 8px !important;
    flex-wrap: wrap;
  }

  .topbar > div:first-child {
    min-width: 0;
    flex: 1 1 180px;
  }

  .topbar h1 {
    max-width: 46vw;
    overflow: hidden;
    font-size: 18px !important;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .yjh-topbar-logo {
    width: min(132px, 34vw) !important;
    height: 42px !important;
    object-fit: contain;
  }

  .top-actions {
    width: 100%;
    max-width: 100%;
    padding-bottom: 2px;
    gap: 7px !important;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .top-actions::-webkit-scrollbar,
  .main-nav::-webkit-scrollbar,
  .filter-tabs::-webkit-scrollbar,
  .team-tabs::-webkit-scrollbar {
    display: none;
  }

  .top-actions > button,
  .top-actions .ghost-button,
  .top-actions .primary-button {
    display: inline-flex !important;
    min-width: max-content;
    min-height: 40px;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    height: calc(82px + env(safe-area-inset-bottom)) !important;
    padding: 6px 6px env(safe-area-inset-bottom) !important;
    overflow: hidden;
  }

  .main-nav {
    display: flex !important;
    height: 76px;
    gap: 4px !important;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .main-nav > button,
  .main-nav > a,
  .main-nav .yjh-video-nav,
  .main-nav .yjh-data-nav {
    flex: 0 0 70px !important;
    width: 70px !important;
    min-width: 70px !important;
    min-height: 68px !important;
    padding: 4px 2px !important;
    scroll-snap-align: start;
    font-size: 9px !important;
    line-height: 1.2;
    text-align: center !important;
  }

  .main-nav button span,
  .main-nav a span {
    width: 25px !important;
    min-width: 25px !important;
    height: 25px !important;
  }

  button,
  a,
  select,
  input,
  textarea {
    touch-action: manipulation;
  }

  input,
  select,
  textarea {
    max-width: 100%;
    font-size: 16px !important;
  }

  .primary-button,
  .ghost-button,
  .event-picker,
  .filter-tabs button {
    min-height: 42px;
  }

  .welcome-row,
  .table-toolbar,
  .member-toolbar,
  .section-actions,
  .manager-heading,
  .roster-heading,
  .roster-template-bar,
  .roster-overview > header {
    align-items: stretch !important;
    flex-direction: column !important;
    gap: 9px !important;
  }

  .stats-grid,
  .management-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .stat-card {
    min-width: 0;
    padding: 11px !important;
  }

  .stat-card span,
  .stat-card small,
  .stat-card strong {
    overflow-wrap: anywhere;
  }

  .overview-grid,
  .settings-grid,
  .attendance-columns,
  .attendance-editor,
  .roster-detail-grid,
  .catalog-columns {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .event-row {
    grid-template-columns: 42px minmax(0, 1fr) 40px 12px !important;
    gap: 8px !important;
    padding: 11px 10px !important;
  }

  .event-main b,
  .event-main p,
  .todo-list b,
  .todo-list small,
  .member-name b,
  .member-name small {
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  .table-toolbar-actions,
  .roster-actions,
  .filter-tabs,
  .team-tabs {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
  }

  .search,
  .table-toolbar-actions .search,
  .member-toolbar .search,
  .event-picker {
    width: 100% !important;
    min-width: 0 !important;
  }

  .table-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    padding: 13px 11px !important;
    gap: 10px !important;
  }

  .member-field,
  .member-field select,
  .discord-ids-edit {
    min-width: 0 !important;
    width: 100%;
  }

  .attendance-controls > div,
  .attendance-controls > div:nth-child(2) {
    grid-template-columns: minmax(0, 1fr) !important;
    padding: 11px !important;
  }

  .attendance-controls > div > *,
  .attendance-controls > div:nth-child(2) > * {
    grid-column: 1 !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .event-hero {
    grid-template-columns: 44px minmax(0, 1fr) !important;
    gap: 9px !important;
    padding: 12px !important;
  }

  .event-hero > div:nth-child(2) {
    grid-column: 2 !important;
  }

  .event-hero .hero-count {
    grid-column: span 1;
    min-width: 0;
    padding: 9px 3px 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .attendance-cards {
    padding: 5px 9px 10px !important;
  }

  .attendance-cards > div {
    grid-template-columns: minmax(0, 1fr) minmax(88px, auto) 28px !important;
    gap: 6px !important;
    min-height: 54px !important;
  }

  .attendance-cards select {
    grid-area: auto !important;
    width: 100%;
    min-width: 88px;
  }

  .attendance-cards button {
    grid-area: auto !important;
    min-width: 28px;
  }

  .roster-group-editor {
    overflow: visible !important;
  }

  .roster-team-grid {
    display: flex !important;
    min-width: 0 !important;
    padding: 0 6px 8px;
    gap: 8px;
    overflow-x: auto !important;
    scroll-snap-type: x mandatory;
  }

  .roster-team-card {
    flex: 0 0 calc(100vw - 42px) !important;
    max-width: 420px;
    border: 1px solid #e7b6c9 !important;
    scroll-snap-align: center;
  }

  .roster-slot-editor {
    min-height: 104px !important;
  }

  .slot-fields,
  .slot-skills {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .slot-fields select,
  .slot-skills > select {
    width: 100%;
    min-height: 40px;
  }

  .yjh-video-toolbar,
  .yjh-video-date-grid,
  .yjh-video-list {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .yjh-video-toolbar {
    padding: 11px !important;
  }

  .yjh-video-toolbar select,
  .yjh-video-toolbar input,
  .yjh-video-toolbar button {
    width: 100%;
    min-width: 0;
    height: 44px !important;
  }

  .yjh-video-date-group > header {
    align-items: flex-start !important;
    flex-wrap: wrap;
    padding: 9px 10px !important;
  }

  .yjh-video-date-group > header h3 {
    font-size: 17px !important;
  }

  .yjh-video-card {
    width: calc(100% - 5px);
    padding: 12px !important;
    box-shadow: 4px 4px 0 #78dce1 !important;
  }

  .yjh-video-card header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .yjh-video-card header i {
    margin-left: 0 !important;
  }

  .yjh-video-links a,
  .yjh-discord-link {
    width: 100%;
    min-height: 40px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    overflow-wrap: anywhere;
  }

  .modal-backdrop,
  .account-admin-backdrop {
    align-items: end !important;
    padding: 6px !important;
  }

  .modal,
  .account-admin-modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: calc(100dvh - 12px) !important;
    height: auto !important;
    overflow-y: auto !important;
    border-radius: 17px 17px 8px 8px !important;
  }

  .account-admin-header,
  .account-admin-body {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .account-admin-row {
    grid-template-columns: 36px minmax(0, 1fr) auto !important;
    gap: 7px !important;
  }

  .account-admin-launcher {
    right: 10px !important;
    bottom: calc(90px + env(safe-area-inset-bottom)) !important;
  }

  .toast {
    top: 70px !important;
    right: 9px !important;
    left: 9px !important;
    max-width: calc(100% - 18px);
  }
}

@media (max-width: 390px) {
  .stats-grid,
  .management-stats {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .topbar h1 {
    max-width: 42vw;
  }

  .roster-team-card {
    flex-basis: calc(100vw - 34px) !important;
  }
}
