/* ===== V54 手機介面：320–430px 優先，平板沿用安全觸控規則 ===== */

.event-series-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-left: 6px;
  padding: 3px 8px;
  border: 1px solid rgba(73, 225, 238, .55);
  border-radius: 999px;
  background: rgba(73, 225, 238, .12);
  color: var(--cyan);
  font-size: 10px;
  font-weight: 900;
  line-height: 1.3;
  vertical-align: middle;
}

.event-series-badge.legacy {
  border-color: rgba(255, 167, 51, .6);
  background: rgba(255, 167, 51, .12);
  color: var(--amber);
}

.independent-event-count,
.independent-series-preview {
  margin: 9px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(73, 225, 238, .45);
  border-radius: 10px;
  background: rgba(73, 225, 238, .08);
  color: var(--cream);
  font-size: 12px;
  line-height: 1.55;
}

.admin-budget-grid .admin-break-even-card {
  border-color: rgba(73, 225, 238, .48);
  background: linear-gradient(145deg, rgba(73, 225, 238, .08), rgba(20, 25, 50, .86));
}

.admin-budget-grid .admin-break-even-card > span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.event-extra-details {
  margin-top: 12px;
  border: 1px solid var(--night-3);
  border-radius: 12px;
  background: rgba(15, 17, 34, .55);
  overflow: hidden;
}

.event-extra-details > summary {
  min-height: 44px;
  padding: 12px 14px;
  color: var(--cyan);
  font-weight: 900;
  cursor: pointer;
}

.event-extra-details-body {
  padding: 0 12px 12px;
}

@media (max-width: 760px) {
  :root {
    --mobile-safe-top: env(safe-area-inset-top, 0px);
    --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
    --mobile-header-total: calc(64px + var(--mobile-safe-top));
    --mobile-nav-height: 70px;
  }

  html {
    max-width: 100%;
    overflow-x: hidden;
    overflow-x: clip;
    scroll-padding-top: calc(var(--mobile-header-total) + 14px);
  }

  body {
    max-width: 100%;
    overflow-x: hidden;
    overflow-x: clip;
    background-attachment: scroll;
  }

  body:not(.admin-page) {
    padding-bottom: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom));
  }

  body.admin-page {
    padding-bottom: 0;
  }

  :where(main, section, article, form, fieldset, div, nav, header, footer) {
    min-width: 0;
  }

  :where(img, video, canvas, svg, table, input, select, textarea) {
    max-width: 100%;
  }

  :where(
    .btn,
    .link-btn,
    .auth-tab,
    .cal-nav,
    .cal-today,
    .cal-filter,
    .modal-close,
    .mobile-nav a,
    .admin-side-nav a,
    .admin-date-remove,
    .admin-prize-remove,
    .team-mode-btn
  ) {
    min-height:44px;
    touch-action: manipulation;
  }

  /* iPhone standalone / PWA 頂部安全區 */
  .topbar,
  .admin-topbar,
  .rewards-topbar,
  .market-topbar,
  .finance-topbar {
    min-height: var(--mobile-header-total);
    padding-top: calc(8px + var(--mobile-safe-top));
  }

  .topbar .top-actions {
    margin-left: auto;
  }

  .top-actions .btn {
    min-height: 44px;
  }

  /* DOM 已按實際閱讀順序排列，不再用 flex order 改變視覺次序。 */
  main#top {
    display: block;
  }

  /* 首屏：完整保留品牌圖，不裁走 Logo 文字。 */
  .hero {
    padding: 14px 12px 24px;
  }

  .hero-inner {
    width: 100%;
  }

  .hero-logo-frame {
    width: 100%;
    height: auto;
    aspect-ratio: 1200 / 669;
    margin: 0 auto 18px;
    border-radius: 16px;
  }

  .hero-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
  }

  .hero h1 {
    margin-bottom: 8px;
    font-size: clamp(34px, 10.5vw, 44px);
    line-height: 1.08;
  }

  .hero-sub {
    max-width: 36rem;
    font-size: 14px;
    line-height: 1.58;
  }

  .hero-cta {
    gap: 9px;
    margin: 16px 0 12px;
  }

  .hero-cta .btn {
    min-height: 48px;
    padding-inline: 10px;
  }

  .hero-badges {
    gap: 5px;
  }

  .hero-badges li {
    min-width: 0;
    min-height: 32px;
    overflow-wrap: anywhere;
  }

  /* 共用內容卡 */
  .section {
    width: 100%;
    max-width: 100%;
    padding: 26px 12px;
  }

  .section h2 {
    font-size: clamp(24px, 7vw, 28px);
  }

  .next-event,
  .next-empty,
  .points-panel,
  .points-table-wrap,
  .auth-card,
  .member-card,
  .panel,
  .cal-card {
    width: 100%;
    max-width: 100%;
  }

  .next-event,
  .next-empty {
    padding: 17px;
  }

  .next-event .ne-meta,
  .event-card .ev-meta,
  .modal .m-meta,
  .modal .m-desc {
    overflow-wrap: anywhere;
  }

  .next-event .btn,
  .event-card > .btn {
    width: 100%;
    min-height: 48px;
  }

  /* 活動卡：日期、資料、報名按鈕保持清楚三層。 */
  .event-list {
    width: 100%;
    gap: 12px;
  }

  .event-card {
    width: 100%;
    max-width: 100%;
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 11px;
    padding: 13px;
    overflow: hidden;
  }

  .event-card .ev-date {
    width: 64px;
  }

  .event-card .ev-main {
    min-width: 0;
  }

  .event-card-badges,
  .badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
  }

  .event-card h3 {
    font-size: 17px;
    line-height: 1.36;
  }

  .event-card .ev-meta {
    margin-block: 3px;
    font-size: 12px;
    line-height: 1.48;
  }

  .last-slots-badge {
    width: fit-content;
    max-width: 100%;
    white-space: normal;
  }

  /* 日曆：整個日期格負責選日，小圓點只提示有活動。 */
  .cal-card {
    margin-inline: 0;
    padding: 11px 7px 12px;
    overflow: hidden;
  }

  .cal-head {
    gap: 8px;
    padding-inline: 2px;
  }

  .cal-head > div {
    min-width: 0;
  }

  .cal-head h3 {
    font-size: 19px;
    white-space: nowrap;
  }

  .cal-nav {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
  }

  .cal-today {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 11px;
  }

  .cal-guide {
    max-width: 100%;
    margin-bottom: 9px;
    overscroll-behavior-inline: contain;
  }

  .cal-legend {
    max-width: 100%;
    margin-inline: 0;
    padding: 3px 1px 8px;
    scroll-snap-type: x proximity;
    overscroll-behavior-inline: contain;
  }

  .cal-filter {
    min-height: 44px;
    padding: 7px 11px;
    scroll-snap-align: start;
  }

  .cal-grid {
    width: 100%;
    gap: 2px;
  }

  .cal-week span {
    min-width: 0;
    font-size: 9px;
  }

  .cal-day {
    min-width: 0;
    min-height: 72px;
    padding: 2px;
    border-radius: 7px;
    cursor: pointer;
  }

  .cal-date-button {
    min-height: 44px;
    border-radius: 6px;
  }

  .cal-day .d {
    font-size: 12px;
  }

  .cal-events {
    min-height: 22px;
    pointer-events:none;
  }

  .cal-ev,
  .cal-more {
    pointer-events:none;
  }

  .cal-agenda-head {
    gap: 8px;
  }

  .cal-agenda-event {
    width: 100%;
    max-width: 100%;
    padding: 12px 11px;
  }

  .cal-agenda-event-main,
  .cal-agenda-action {
    min-width: 0;
  }

  .cal-agenda-event p,
  .cal-agenda-event h5 {
    overflow-wrap: anywhere;
  }

  .cal-agenda-action .btn {
    min-height: 48px;
  }

  /* 會員中心 */
  .auth-tabs {
    width: 100%;
  }

  .auth-tab {
    padding: 10px 8px;
  }

  .member-card-identity {
    min-width: 0;
  }

  .member-card .mc-top {
    gap: 8px;
  }

  .member-card .mc-no,
  .member-card .mc-email {
    overflow-wrap: anywhere;
  }

  .member-feedback-actions {
    width: 100%;
  }

  .member-feedback-actions .btn {
    min-height: 46px;
  }

  .reg-item-v33 > div:last-child {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .reg-item-v33 > div:last-child > .tag,
  .reg-item-v33 > div:last-child > .payment-hold-note {
    grid-column: 1 / -1;
  }

  .reg-item-v33 > div:last-child .btn {
    width: 100%;
    min-height: 44px;
    margin: 0;
    padding-inline: 7px;
  }

  /* 活動、付款及賽程彈窗改為安全的底部抽屜。 */
  .modal-mask {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    width: 100%;
    max-width: none;
    max-height: calc(100vh - var(--mobile-safe-top) - 8px);
    max-height: calc(100dvh - var(--mobile-safe-top) - 8px);
    padding: 18px 13px calc(18px + var(--mobile-safe-bottom));
    border-width: 3px 0 0;
    border-radius: 20px 20px 0 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .modal-close {
    position: sticky;
    top: 0;
    z-index: 5;
    float: right;
    width: 44px;
    height: 44px;
  }

  .modal h3 {
    padding-right: 48px;
    font-size: 21px;
    line-height: 1.32;
  }

  #eventModalBody,
  #payModalBody,
  #tourModalBody,
  #transferModalBody,
  #memberDeleteModalBody,
  #passwordModalBody,
  #adminPreviewBody,
  #adminConfirmBody {
    min-width: 0;
  }

  /* DOM 已把報名區放在獎品／長賽制之前，保持自然閱讀順序。 */
  #eventModalBody {
    display: block;
  }

  .event-extra-details > summary {
    position: sticky;
    top: 0;
  }

  .reg-summary {
    width: 100%;
    max-width: 100%;
    padding: 13px 12px;
  }

  .reg-summary .row {
    min-height: 44px;
    flex-wrap: wrap;
  }

  .reg-summary .btn-block {
    min-height: 48px;
  }

  .championship-public-board,
  .championship-public-sessions,
  .championship-public-sessions article,
  .championship-registration,
  .championship-slot-options,
  .championship-slot {
    min-width: 0;
    max-width: 100%;
  }

  .championship-public-board,
  .championship-slot {
    padding: 11px;
  }

  .championship-public-sessions small,
  .championship-slot small,
  .championship-slot em {
    overflow-wrap: anywhere;
  }

  .payment-destination,
  .payment-upload-block,
  .payment-hold-banner,
  .pending-payment-shortcut {
    max-width: 100%;
  }

  .payment-upload-block input[type="file"] {
    width: 100%;
    font-size: 14px;
  }

  .payment-qr-column {
    width: min(230px, 100%);
  }

  /* 手機底欄及意見按鈕 */
  .mobile-nav {
    height: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom));
    padding: 7px 6px calc(7px + var(--mobile-safe-bottom));
    gap: 2px;
  }

  .mobile-nav a {
    min-height: 54px;
    padding: 4px 2px;
    touch-action: manipulation;
  }

  .mobile-nav a > span {
    font-size: 20px;
  }

  .mobile-nav b {
    font-size: 10px;
  }

  .feedback-fab {
    right: 12px;
    bottom: calc(var(--mobile-nav-height) + 13px + var(--mobile-safe-bottom));
    width: 52px;
    min-width: 52px;
    height: 52px;
    min-height: 52px;
    padding: 0;
    border-radius: 50%;
  }

  .feedback-fab span {
    font-size: 20px;
  }

  .feedback-fab b {
    display: none;
  }

  .toast {
    bottom: calc(var(--mobile-nav-height) + 12px + var(--mobile-safe-bottom));
    width: min(90vw, 420px);
    padding: 12px 14px;
  }

  /* 管理員：保留完整功能，但在手機上改成可掃讀、可觸控。 */
  .admin-topbar {
    gap: 8px;
    padding-inline: 10px;
  }

  .admin-topbar .brand {
    min-width: 0;
  }

  .admin-topbar .brand-logo {
    width: 48px;
    height: 36px;
  }

  .admin-account {
    margin-left: auto;
  }

  .admin-account .btn {
    min-height: 44px;
    padding-inline: 10px;
  }

  .admin-app {
    width: 100%;
    max-width: 100%;
  }

  .admin-side-nav {
    top: var(--mobile-header-total);
    z-index: 50;
    width: 100%;
    max-width: 100%;
    height: auto;
    gap: 7px;
    padding: 8px 12px 10px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-padding-inline: 12px;
    scroll-snap-type: x proximity;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .admin-side-nav a {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 8px 13px;
    scroll-snap-align: start;
    white-space: nowrap;
  }

  .admin-main {
    width: 100%;
    max-width: 100%;
    padding: 0 10px 44px;
    overflow-x: hidden;
  }

  .admin-section {
    width: 100%;
    max-width: 100%;
    padding-block: 26px;
    scroll-margin-top: calc(var(--mobile-header-total) + 62px);
  }

  .admin-section-head,
  .panel-title-row,
  .admin-inline-heading,
  .event-day-head,
  .event-day-next,
  .registration-roster-summary,
  .registration-roster-card-head {
    min-width: 0;
    max-width: 100%;
  }

  .admin-main-actions,
  .event-draft-actions,
  .admin-form-grid,
  .planner-inputs,
  .admin-check-grid,
  .competition-mode-options,
  .admin-two-column,
  .offline-payment-fields,
  .grant-form,
  .registration-roster-filters,
  .registration-member-grid,
  .early-bird-admin-fields,
  .event-preview-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .event-draft-actions label,
  .field-wide,
  .registration-roster-filters .field-wide {
    grid-column: auto;
  }

  .admin-event-form,
  .admin-form-block,
  .event-draft-toolbar,
  .championship-session-card,
  .championship-final-card,
  .championship-plan-card {
    max-width: 100%;
  }

  .admin-event-form {
    padding: 10px;
  }

  .admin-form-block,
  .event-draft-toolbar,
  .championship-plan-card {
    padding: 13px 11px;
  }

  .admin-form-title {
    align-items: flex-start;
  }

  .admin-form-title > span {
    width: 38px;
    height: 38px;
  }

  .admin-date-row {
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
  }

  .admin-date-remove,
  .admin-prize-remove {
    width: 44px;
    height: 44px;
    padding: 0;
  }

  .admin-prize-row {
    grid-template-columns: minmax(0, 1fr) 88px 44px;
    gap: 7px;
  }

  .admin-prize-row label:first-child {
    grid-column: 1 / -1;
  }

  .admin-prize-row label:nth-child(2) {
    grid-column: 1 / 3;
  }

  .admin-publish-button {
    min-height: 52px;
    bottom: calc(10px + var(--mobile-safe-bottom));
  }

  .admin-stat-grid,
  .admin-budget-grid,
  .registration-roster-stats,
  .event-day-metrics,
  .closeout-checks {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-stat-grid article,
  .admin-budget-grid article,
  .registration-roster-stats article {
    min-width: 0;
    padding: 12px;
  }

  .admin-stat-grid strong,
  .admin-budget-grid strong,
  .registration-roster-stats strong {
    overflow-wrap: anywhere;
  }

  .admin-list-item,
  .admin-member-card,
  .registration-roster-card,
  .reward-product-item {
    width: 100%;
    max-width: 100%;
  }

  .admin-list-actions,
  .admin-member-actions,
  .reward-product-actions,
  .closeout-actions,
  .event-edit-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .admin-list-actions > :last-child:nth-child(odd),
  .admin-member-actions > :last-child:nth-child(odd),
  .reward-product-actions > :last-child:nth-child(odd),
  .closeout-actions > :last-child:nth-child(odd),
  .event-edit-actions > :last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .admin-list-actions .btn,
  .admin-list-actions a,
  .admin-member-actions .btn,
  .reward-product-actions .btn,
  .closeout-actions .btn,
  .event-edit-actions .btn {
    width: 100%;
    min-height: 44px;
    margin: 0;
    padding-inline: 7px;
  }

  .reward-product-info {
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 9px;
  }

  .reward-product-thumb {
    width: 56px;
    height: 56px;
  }

  .reward-product-title-row {
    flex-wrap: wrap;
  }

  .admin-pagination {
    max-width: 100%;
  }

  .admin-pagination-actions {
    width: 100%;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }

  .admin-pagination-actions .btn {
    min-height: 44px;
  }

  .bracket-tree,
  .whatsapp-preview pre,
  .points-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  .admin-gate {
    width: calc(100% - 24px);
    margin: 7vh auto;
    padding: 22px 17px;
  }
}

@media (max-width: 430px) {
  .cal-guide {
    display: none;
  }

  .hero-cta,
  .admin-main-actions,
  .event-draft-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .hero-cta .btn,
  .admin-main-actions .btn,
  .event-draft-actions .btn {
    width: 100%;
  }

  .member-feedback-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .championship-session-head,
  .championship-admin-stage {
    align-items: stretch;
    flex-direction: column;
  }

  .championship-session-head .btn,
  .championship-admin-stage .btn {
    width: 100%;
  }

  .registration-roster-filters,
  .registration-member-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 360px) {
  .brand-text strong,
  .admin-topbar .brand-text strong {
    font-size: 13px;
  }

  .top-actions .btn,
  .admin-account .btn {
    padding-inline: 8px;
    font-size: 11px;
  }

  .hero-badges,
  .admin-stat-grid,
  .admin-budget-grid,
  .registration-roster-stats,
  .event-day-metrics,
  .closeout-checks {
    grid-template-columns: minmax(0, 1fr);
  }

  .event-card {
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 9px;
    padding: 11px;
  }

  .event-card .ev-date {
    width: 58px;
  }

  .reg-item-v33 > div:last-child,
  .admin-list-actions,
  .admin-member-actions,
  .reward-product-actions,
  .closeout-actions,
  .event-edit-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .reg-item-v33 > div:last-child > *,
  .admin-list-actions > *,
  .admin-member-actions > *,
  .reward-product-actions > *,
  .closeout-actions > *,
  .event-edit-actions > * {
    grid-column: 1;
  }

  .member-card-identity {
    grid-template-columns: minmax(0, 1fr);
  }

  .member-qr {
    margin-inline: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-nav *,
  .admin-side-nav *,
  .feedback-fab {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
