/* 不是熊猫：共享手机端适配层 */
.mobile-site-header,
.mobile-bottom-nav,
.mobile-nav-backdrop,
.mobile-nav-drawer,
.mobile-tier-filter-toggle,
.mobile-workbench-switcher {
  display: none;
}

@media (max-width: 900px) {
  :root {
    --mobile-page-gutter: 14px;
    --mobile-nav-height: 68px;
  }

  html {
    min-width: 0;
    overflow-x: hidden;
    scroll-padding-top: 72px;
    -webkit-text-size-adjust: 100%;
  }

  body {
    min-width: 0;
    overflow-x: hidden !important;
    padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    touch-action: manipulation;
  }

  body.mobile-menu-open {
    overflow: hidden !important;
  }

  body.tier-browse-page,
  body.tier-workbench-page {
    height: auto !important;
    min-height: 100%;
    overflow-y: auto !important;
    touch-action: pan-x pan-y;
  }

  .layout,
  .app {
    display: block !important;
    width: 100%;
    min-width: 0;
    height: auto !important;
    min-height: 100vh;
  }

  body.mobile-shell-ready > .layout,
  body.mobile-shell-ready > .app {
    min-height: calc(100vh - 58px);
  }

  .sidebar {
    display: none !important;
  }

  .main {
    width: 100%;
    min-width: 0;
    height: auto !important;
    min-height: calc(100vh - 58px);
    padding-right: var(--mobile-page-gutter) !important;
    padding-left: var(--mobile-page-gutter) !important;
    overflow: visible !important;
  }

  img,
  video,
  canvas,
  svg {
    max-width: 100%;
  }

  button,
  a,
  input,
  select,
  textarea {
    -webkit-tap-highlight-color: transparent;
  }

  button,
  select,
  input[type="button"],
  input[type="submit"] {
    min-height: 42px;
  }

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

  .mobile-site-header {
    position: sticky;
    top: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    height: 58px;
    padding: 7px 12px;
    border-bottom: 1px solid rgba(214, 158, 26, .22);
    background: rgba(255, 253, 241, .94);
    box-shadow: 0 5px 18px rgba(134, 88, 0, .08);
    backdrop-filter: blur(18px);
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: #3e2d0c;
    text-decoration: none;
  }

  .mobile-brand img {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    object-fit: contain;
    filter: drop-shadow(0 4px 7px rgba(183, 123, 0, .16));
  }

  .mobile-brand__copy {
    min-width: 0;
  }

  .mobile-brand__copy strong,
  .mobile-brand__copy span {
    display: block;
  }

  .mobile-brand__copy strong {
    font-size: .91rem;
    font-weight: 950;
    line-height: 1.1;
  }

  .mobile-brand__copy span {
    max-width: 210px;
    margin-top: 3px;
    overflow: hidden;
    color: #9b7b33;
    font-size: .67rem;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    min-height: 42px;
    flex: 0 0 42px;
    border: 1px solid rgba(217, 155, 10, .28);
    border-radius: 14px;
    color: #74550d;
    background: #fff9dc;
    cursor: pointer;
  }

  .mobile-menu-button .hd-icon {
    width: 23px;
    height: 23px;
  }

  .mobile-bottom-nav {
    position: fixed;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    z-index: 950;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    height: 60px;
    padding: 5px 4px;
    border: 1px solid rgba(209, 150, 13, .23);
    border-radius: 21px;
    background: rgba(255, 254, 246, .96);
    box-shadow: 0 13px 35px rgba(91, 58, 0, .17);
    backdrop-filter: blur(18px);
  }

  .mobile-bottom-nav a,
  .mobile-bottom-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 48px;
    padding: 3px 1px;
    border: 0;
    border-radius: 15px;
    color: #9b824a;
    background: transparent;
    font-size: .62rem;
    font-weight: 800;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
  }

  .mobile-bottom-nav a.active {
    color: #674900;
    background: linear-gradient(145deg, #fff2aa, #fff9dd);
    box-shadow: inset 0 0 0 1px rgba(226, 160, 0, .17);
  }

  .mobile-nav-icon,
  .mobile-bottom-nav .hd-icon {
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
  }

  .mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 970;
    display: block;
    visibility: hidden;
    opacity: 0;
    background: rgba(50, 34, 5, .36);
    backdrop-filter: blur(3px);
    transition: opacity .2s ease, visibility .2s ease;
  }

  .mobile-nav-backdrop.open {
    visibility: visible;
    opacity: 1;
  }

  .mobile-nav-drawer {
    position: fixed;
    right: 10px;
    bottom: calc(var(--mobile-nav-height) + 16px + env(safe-area-inset-bottom));
    left: 10px;
    z-index: 980;
    display: block;
    visibility: hidden;
    max-height: min(620px, calc(100vh - 104px));
    padding: 16px;
    overflow-y: auto;
    border: 1px solid rgba(213, 151, 10, .25);
    border-radius: 25px;
    background: #fffdf3;
    box-shadow: 0 22px 56px rgba(75, 47, 0, .24);
    opacity: 0;
    transform: translateY(18px) scale(.98);
    transition: opacity .2s ease, transform .2s ease, visibility .2s ease;
  }

  .mobile-nav-drawer.open {
    visibility: visible;
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  .mobile-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
  }

  .mobile-drawer-head strong {
    color: #46340e;
    font-size: 1rem;
  }

  .mobile-drawer-close {
    width: 40px;
    height: 40px;
    min-height: 40px;
    border: 1px solid rgba(214, 155, 16, .22);
    border-radius: 13px;
    color: #73540e;
    background: #fff8d7;
    cursor: pointer;
  }

  .mobile-drawer-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-drawer-grid a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    min-height: 78px;
    padding: 9px 5px;
    border: 1px solid rgba(214, 155, 16, .18);
    border-radius: 17px;
    color: #6f581f;
    background: #fffef9;
    font-size: .7rem;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
  }

  .mobile-drawer-grid a.active {
    color: #624500;
    border-color: rgba(220, 151, 0, .38);
    background: #fff4ba;
  }

  .mobile-table-scroll {
    width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-table-scroll > table {
    min-width: 720px;
  }

  /* 通用内容与标题 */
  .container {
    width: 100%;
    max-width: none !important;
    padding-right: var(--mobile-page-gutter) !important;
    padding-left: var(--mobile-page-gutter) !important;
  }

  .main > .page-title,
  .container > .page-title {
    margin: 16px 0 18px;
    font-size: clamp(1.35rem, 6vw, 1.75rem);
    line-height: 1.25;
  }

  .main > .topbar {
    position: static;
  }

  /* 首页 */
  .hero {
    gap: 10px !important;
    padding: 24px 4px 18px !important;
  }

  .hero-text {
    width: 100%;
    text-align: center;
  }

  .hero-text h1 {
    font-size: clamp(1.72rem, 8vw, 2.2rem) !important;
  }

  .hero-text .slogan {
    margin-bottom: 16px;
  }

  .hero-stats {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px !important;
    width: 100%;
  }

  .hero-stat {
    padding: 9px 4px;
    border: 1px solid rgba(215, 157, 24, .17);
    border-radius: 14px;
    background: rgba(255, 255, 255, .62);
  }

  .hero-stat .num {
    font-size: 1.28rem !important;
  }

  .hero-mascot img {
    height: 150px !important;
  }

  .quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 9px !important;
    padding: 0 0 18px !important;
  }

  .qa-card {
    min-height: 112px;
    padding: 14px 10px !important;
    border-radius: 15px !important;
  }

  .qa-card:first-child {
    grid-column: 1 / -1;
    min-height: 96px;
  }

  .qa-card .qa-icon {
    margin-bottom: 5px !important;
    font-size: 1.5rem !important;
  }

  .highlights {
    padding: 0 0 28px !important;
  }

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

  .hl-card .info {
    padding: 10px !important;
  }

  .status-note {
    align-items: flex-start !important;
    gap: 10px !important;
    margin: 0 0 18px !important;
    padding: 14px !important;
  }

  .status-note .badge {
    width: 36px !important;
    height: 36px !important;
    flex-basis: 36px;
  }

  .status-note .tag {
    display: none;
  }

  .editor-grid {
    grid-template-columns: 1fr !important;
  }

  .editor-card {
    padding: 12px !important;
  }

  .ai-rec {
    padding: 18px 14px !important;
  }

  /* 新番列表与筛选 */
  .filter-bar,
  .admin-filters,
  .filter-row {
    gap: 7px !important;
  }

  .filter-bar .search-box,
  .admin-filters input {
    flex: 1 0 100%;
    width: 100%;
    min-width: 0 !important;
  }

  .filter-chip,
  .fchip {
    flex: 1 1 auto;
    min-height: 40px;
    padding: 8px 12px !important;
  }

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

  .anime-card .info {
    padding: 10px !important;
  }

  /* 日历 */
  .day-tabs {
    margin-right: calc(var(--mobile-page-gutter) * -1) !important;
    margin-left: calc(var(--mobile-page-gutter) * -1) !important;
    padding: 2px var(--mobile-page-gutter) 8px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .day-tabs::-webkit-scrollbar {
    display: none;
  }

  .day-tab {
    min-width: 66px !important;
    padding: 9px 11px !important;
    scroll-snap-align: start;
  }

  .anime-line {
    display: grid !important;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 8px 11px !important;
    padding: 11px !important;
  }

  .anime-line .ainfo {
    align-self: center;
  }

  .anime-line .ameta {
    grid-column: 2;
    justify-content: flex-start;
    gap: 8px !important;
    flex-wrap: wrap;
  }

  .anime-line .atime {
    min-width: 0 !important;
    text-align: left !important;
  }

  /* 资讯 */
  .news-card {
    padding: 16px !important;
  }

  .news-card h3 {
    font-size: .95rem !important;
  }

  .news-card p {
    font-size: .82rem !important;
  }

  .news-side,
  .news-main {
    width: 100% !important;
  }

  /* 搜索 */
  .search-bar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px !important;
  }

  .search-bar input,
  .search-bar button {
    min-width: 0;
    padding: 12px 14px !important;
  }

  .result-card {
    gap: 12px !important;
    padding: 12px !important;
  }

  .result-card .rthumb {
    width: 70px !important;
    height: 98px !important;
  }

  .result-card .rtitle {
    font-size: .92rem !important;
  }

  /* 详情 */
  .detail {
    gap: 20px !important;
  }

  .detail-cover img {
    width: 164px !important;
  }

  .detail-info {
    width: 100%;
  }

  .detail-info h1 {
    font-size: 1.35rem !important;
    text-align: center;
  }

  .detail-info .jp-name,
  .detail-info .tag-row {
    text-align: center;
  }

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

  .meta-item {
    min-width: 0;
    padding: 10px !important;
  }

  .synopsis {
    padding: 16px !important;
  }

  .related-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* 后台 */
  .main > .topbar:not(.tier-page-topbar) {
    gap: 10px;
  }

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

  .stat-box {
    min-width: 0 !important;
    padding: 12px 8px !important;
  }

  .table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .table-wrap table {
    min-width: 760px;
  }

  .actions {
    flex-wrap: wrap;
  }

  .toast {
    right: 12px !important;
    bottom: calc(var(--mobile-nav-height) + 18px + env(safe-area-inset-bottom)) !important;
    left: 12px;
    text-align: center;
  }

  /* Tier 排行与排表工作台 */
  .app > .main {
    gap: 11px !important;
    padding-top: 12px !important;
    padding-bottom: 18px !important;
  }

  .app .header {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .app .crumb {
    display: none;
  }

  .app .title {
    font-size: clamp(1.24rem, 5.5vw, 1.55rem) !important;
    line-height: 1.25 !important;
  }

  .app .subtitle {
    display: none !important;
  }

  .mode-tabs {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px !important;
    width: 100%;
    padding: 5px !important;
  }

  .mode-tabs a,
  .mode-tabs button {
    min-width: 0;
    min-height: 40px;
    padding: 8px 7px !important;
    font-size: .78rem !important;
    text-align: center;
  }

  .app .topbar {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    padding: 10px !important;
    border-radius: 16px !important;
  }

  .mobile-tier-filter-toggle {
    grid-column: 1 / -1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid rgba(212, 153, 18, .25);
    border-radius: 12px;
    color: #71520c;
    background: linear-gradient(145deg, #fff7cb, #fffdf3);
    font-size: .78rem;
    font-weight: 900;
    cursor: pointer;
  }

  .mobile-tier-filter-toggle .hd-icon {
    width: 20px;
    height: 20px;
  }

  .app .topbar.mobile-tier-controls:not(.mobile-controls-open) > :not(.searchbox):not(#seasonFilter):not(.mobile-tier-filter-toggle) {
    display: none !important;
  }

  .app .topbar > .searchbox,
  .app .topbar > #seasonFilter {
    grid-column: 1 / -1;
  }

  .app .topbar .select,
  .app .topbar .btn,
  .app .topbar a.btn,
  .app .topbar .switch {
    width: 100%;
    min-width: 0 !important;
  }

  .app .topbar .switch {
    justify-content: center;
    min-height: 42px;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
  }

  .save-status {
    min-width: 0 !important;
    text-align: center !important;
  }

  .stats {
    display: flex !important;
    gap: 8px !important;
    margin-right: calc(var(--mobile-page-gutter) * -1);
    margin-left: calc(var(--mobile-page-gutter) * -1);
    padding: 0 var(--mobile-page-gutter) 5px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .stats::-webkit-scrollbar {
    display: none;
  }

  .stat {
    height: 60px !important;
    min-width: 126px;
    flex: 0 0 126px;
    padding: 10px 12px !important;
    scroll-snap-align: start;
  }

  .stat:last-child:nth-child(odd) {
    grid-column: auto;
  }

  .stat b {
    font-size: 1.25rem !important;
  }

  .stat i {
    font-size: 1.35rem !important;
  }

  .tier-workbench-page .mobile-workbench-switcher {
    position: sticky !important;
    top: 66px;
    z-index: 850 !important;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 6px;
    border: 1px solid rgba(212, 153, 18, .24);
    border-radius: 16px;
    background: rgba(255, 253, 241, .96);
    box-shadow: 0 8px 22px rgba(116, 78, 0, .1);
    backdrop-filter: blur(16px);
  }

  .mobile-workbench-switcher button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    min-height: 42px;
    padding: 8px 10px;
    border: 0;
    border-radius: 11px;
    color: #7f6938;
    background: transparent;
    font-size: .78rem;
    font-weight: 900;
    cursor: pointer;
  }

  .mobile-workbench-switcher button.active {
    color: #fff;
    background: linear-gradient(135deg, var(--purple), #9d63ee);
    box-shadow: 0 7px 16px rgba(124, 92, 240, .22);
  }

  .mobile-workbench-switcher small {
    color: inherit;
    font-size: .66rem;
    opacity: .82;
  }

  .workbench {
    display: flex !important;
    flex-direction: column;
    gap: 10px !important;
    min-height: 0;
  }

  .tier-browse-page .workbench {
    display: contents !important;
  }

  .tier-browse-page .tier-panel {
    order: 1;
  }

  .tier-browse-page .unranked-section {
    order: 2;
  }

  .tier-browse-page .info-panel {
    order: 3;
  }

  .panel {
    min-height: 0;
    border-radius: 17px !important;
  }

  .tier-panel,
  .pool-panel,
  .info-panel {
    width: 100%;
  }

  .panel-head {
    height: auto !important;
    min-height: 46px;
    gap: 8px;
    padding: 10px 12px !important;
  }

  .panel-head small {
    max-width: 54%;
    text-align: right;
    font-size: .64rem;
    line-height: 1.4;
  }

  .tier-lanes {
    max-height: none !important;
    padding: 8px !important;
    overflow: visible !important;
  }

  .tier-row {
    min-height: 90px !important;
    border-radius: 14px !important;
  }

  .tier-head {
    width: 70px !important;
    flex-direction: column;
    justify-content: center;
    gap: 1px !important;
    padding: 7px 4px !important;
  }

  .tier-letter {
    width: auto !important;
    font-size: 1.7rem !important;
    line-height: 1;
  }

  .tier-info {
    text-align: center;
  }

  .tier-info b {
    font-size: .65rem !important;
  }

  .tier-info span {
    display: none !important;
  }

  .tier-body {
    min-width: 0;
    padding: 8px !important;
    scroll-snap-type: x proximity;
  }

  .poster-card,
  .tier-body .poster-card {
    width: 50px !important;
    height: 68px !important;
    flex: 0 0 50px !important;
    scroll-snap-align: start;
  }

  .tier-row > .count,
  .tier-row > .tools {
    display: none !important;
  }

  .unranked-section {
    padding: 10px !important;
  }

  .unranked-head {
    flex-wrap: wrap;
    gap: 7px !important;
  }

  .unranked-head small {
    order: 3;
    width: 100%;
    margin-left: 0 !important;
  }

  .unranked-section.expanded {
    position: fixed !important;
    inset: 68px 8px calc(var(--mobile-nav-height) + 8px + env(safe-area-inset-bottom)) !important;
    z-index: 940 !important;
    overflow: auto !important;
  }

  .unranked-section.expanded .unranked-grid {
    grid-template-columns: repeat(auto-fill, 50px) !important;
    max-height: none !important;
  }

  .pool-controls {
    padding: 11px !important;
  }

  .pool-list {
    max-height: min(70vh, 650px) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .tier-workbench-page .workbench[data-mobile-view="tiers"] .pool-panel,
  .tier-workbench-page .workbench[data-mobile-view="pool"] .tier-panel {
    display: none !important;
  }

  .tier-workbench-page .workbench[data-mobile-view="tiers"] .tier-panel,
  .tier-workbench-page .workbench[data-mobile-view="pool"] .pool-panel {
    display: flex !important;
  }

  .tier-workbench-page .tier-panel,
  .tier-workbench-page .pool-panel {
    height: clamp(340px, calc(100vh - 190px), 680px);
    height: clamp(340px, calc(100dvh - 190px), 680px);
  }

  .tier-workbench-page .tier-lanes,
  .tier-workbench-page .pool-list {
    flex: 1 1 auto;
    max-height: none !important;
    overflow-y: auto !important;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }

  .tier-workbench-page .pool-panel .tip {
    display: none !important;
  }

  .pool-item {
    grid-template-columns: 20px 48px minmax(0, 1fr) !important;
    gap: 8px !important;
    padding: 8px !important;
  }

  .pool-item img {
    width: 48px !important;
    height: 64px !important;
  }

  .pool-actions {
    grid-column: 2 / -1;
    grid-template-columns: repeat(6, minmax(30px, 1fr)) !important;
    gap: 5px !important;
  }

  .assign {
    height: 36px !important;
    min-height: 36px !important;
  }

  .batch-btns {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .tip {
    margin: 8px !important;
  }
}

@media (max-width: 520px) {
  .mobile-brand__copy span {
    max-width: 170px;
  }

  .mobile-drawer-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .main {
    padding-top: 12px !important;
  }

  .hero {
    padding-top: 16px !important;
  }

  .hero-mascot img {
    height: 132px !important;
  }

  .section-title {
    margin-top: 18px !important;
  }

  .search-bar {
    grid-template-columns: 1fr !important;
  }

  .search-bar button {
    width: 100%;
  }

  .app .topbar {
    grid-template-columns: 1fr !important;
  }

  .app .topbar > * {
    grid-column: 1 !important;
  }

  .panel-head {
    align-items: flex-start !important;
    flex-direction: column;
  }

  .panel-head small {
    max-width: none;
    text-align: left;
  }
}

@media (max-width: 380px) {
  .mobile-brand__copy span {
    display: none;
  }

  .mobile-drawer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hl-grid,
  .anime-grid,
  .related-grid,
  .meta-grid {
    grid-template-columns: 1fr !important;
  }

  .quick-actions {
    grid-template-columns: 1fr !important;
  }

  .qa-card:first-child {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-nav-backdrop,
  .mobile-nav-drawer {
    transition: none !important;
  }
}
