/**
 * 手机端专用样式（≤767px）
 * 底部导航、迷你播放条、触控与安全区
 */

:root {
  --mobile-nav-h: 3.35rem;
  --mobile-mini-h: 3.1rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-chrome-h: calc(var(--mobile-nav-h) + var(--safe-bottom));
  --bg-image-mobile: url("/images/bg-castle-mobile.jpg");
}

/* 桌面默认隐藏手机专用 UI */
.mobile-bottom-nav,
.mobile-mini-player {
  display: none;
}

.app-topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.mobile-room-chip {
  flex-shrink: 0;
  max-width: 42%;
  padding: 0.2rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(201, 160, 255, 0.2);
  border: 1px solid rgba(201, 160, 255, 0.35);
  color: var(--accent2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 767px) {
  html {
    -webkit-text-size-adjust: 100%;
  }

  body {
    -webkit-tap-highlight-color: transparent;
    background-color: #1e1228;
    background-image: none;
    background-attachment: scroll;
  }

  /* 手机端：完整显示城堡，略偏右、偏下，避免 cover 裁切主体 */
  body.is-mobile {
    position: relative;
    background-color: #1a1028;
    background-image: linear-gradient(
      180deg,
      rgba(22, 12, 36, 0.88) 0%,
      rgba(28, 16, 44, 0.45) 28%,
      rgba(28, 16, 44, 0.15) 55%,
      rgba(18, 10, 30, 0.65) 100%
    );
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-attachment: scroll;
  }

  body.is-mobile::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    pointer-events: none;
    background-image: var(--bg-image-mobile);
    background-repeat: no-repeat;
    background-size: contain;
    background-position: 58% 72%;
    filter: blur(7px);
    transform: scale(1.06);
  }

  /* 蒙版：压暗 + 轻模糊，突出前景内容 */
  body.is-mobile::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    background: linear-gradient(
        180deg,
        rgba(18, 10, 30, 0.72) 0%,
        rgba(22, 12, 36, 0.5) 35%,
        rgba(22, 12, 36, 0.38) 58%,
        rgba(12, 6, 22, 0.68) 100%
      ),
      linear-gradient(
        90deg,
        rgba(14, 8, 24, 0.55) 0%,
        rgba(14, 8, 24, 0.2) 22%,
        rgba(14, 8, 24, 0.2) 78%,
        rgba(14, 8, 24, 0.45) 100%
      );
  }

  body.is-mobile .card {
    background: rgba(36, 22, 54, 0.88);
    border-color: rgba(200, 170, 235, 0.22);
    box-shadow: 0 6px 24px rgba(12, 6, 22, 0.35);
    backdrop-filter: blur(10px) saturate(1.05);
    -webkit-backdrop-filter: blur(10px) saturate(1.05);
  }

  body.is-mobile .hub-card,
  body.is-mobile .player.compact-card {
    background: rgba(40, 24, 60, 0.9);
  }

  body.is-mobile {
    padding-bottom: calc(var(--mobile-chrome-h) + 0.35rem);
  }

  body.is-mobile.has-mobile-mini {
    padding-bottom: calc(
      var(--mobile-chrome-h) + var(--mobile-mini-h) + 0.35rem
    );
  }

  .app-shell {
    position: relative;
    z-index: 0;
    flex-direction: column;
    gap: 0;
    padding: calc(0.65rem + var(--safe-top)) 0.65rem 0.5rem;
    max-width: none;
  }

  .content-row {
    flex-direction: column;
    gap: 0;
    width: 100%;
  }

  /* 按底部导航切换主区域 */
  body.is-mobile[data-mobile-page="play"] .sidebar,
  body.is-mobile[data-mobile-page="play"] .room-panel,
  body.is-mobile[data-mobile-page="discover"] .sidebar,
  body.is-mobile[data-mobile-page="discover"] .room-panel,
  body.is-mobile[data-mobile-page="comments"] .sidebar,
  body.is-mobile[data-mobile-page="comments"] .room-panel,
  body.is-mobile[data-mobile-page="room"] .sidebar,
  body.is-mobile[data-mobile-page="room"] .main-col,
  body.is-mobile[data-mobile-page="me"] .main-col,
  body.is-mobile[data-mobile-page="me"] .room-panel {
    display: none !important;
  }

  body.is-mobile[data-mobile-page="play"] .main-col,
  body.is-mobile[data-mobile-page="discover"] .main-col,
  body.is-mobile[data-mobile-page="comments"] .main-col {
    display: block !important;
    width: 100%;
  }

  body.is-mobile[data-mobile-page="room"] .room-panel {
    display: flex !important;
    flex-direction: column;
    width: 100%;
    position: static;
    margin-top: 0;
    padding: 0.85rem 0.9rem;
    min-height: calc(100dvh - var(--mobile-chrome-h) - 4rem);
  }

  body.is-mobile[data-mobile-page="me"] .sidebar {
    display: block !important;
    width: 100%;
    position: static;
    margin: 0;
    padding: 0.85rem 0.9rem;
  }

  .main-view-tabs {
    display: none;
  }

  .app-topbar h1 {
    font-size: 1.2rem;
    margin: 0;
  }

  .app-topbar {
    margin-bottom: 0.15rem;
  }

  .wrap {
    padding: 0 0 0.25rem;
  }

  .card {
    margin-top: 0.55rem;
    padding: 0.85rem 0.9rem;
    border-radius: 12px;
  }

  .compact-card {
    padding: 0.75rem 0.85rem;
    margin-top: 0.5rem;
  }

  /* 触控：至少 44px 可点区域 */
  button,
  .view-tab,
  .hub-tab,
  .room-panel-tab,
  .playlist-tab,
  .search-mode-tabs .tab,
  .mobile-nav-item {
    min-height: 2.75rem;
  }

  input,
  input[type="search"] {
    font-size: 16px;
    min-height: 2.75rem;
  }

  .room-bar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .room-bar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    width: 100%;
  }

  .room-bar-actions button {
    width: 100%;
  }

  .now {
    font-size: 0.95rem;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
  }

  .transport {
    gap: 0.85rem;
    margin-bottom: 0.65rem;
  }

  .transport-side {
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0.5rem;
    font-size: 1.15rem;
  }

  .toggle-play {
    width: 3.65rem;
    height: 3.65rem;
  }

  .player-meta-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .volume-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    min-width: 0;
  }

  .vol-slider {
    flex: 1;
    max-width: none;
    min-width: 0;
  }

  .volume-pct {
    flex-shrink: 0;
    min-width: 2.85rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  .play-mode-tabs {
    margin-left: 0;
    width: 100%;
  }

  .play-mode-tabs .tab {
    flex: 1;
    min-height: 2.5rem;
  }

  #seekBar.slider {
    display: block;
    width: 100%;
    height: 40px;
    margin: 0.15rem 0 0.35rem;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }

  input[type="range"].slider {
    height: 40px;
    padding: 0;
  }

  input[type="range"].slider::-webkit-slider-runnable-track {
    height: 8px;
    border-radius: 4px;
  }

  input[type="range"].slider::-webkit-slider-thumb {
    width: 22px;
    height: 22px;
    margin-top: -7px;
  }

  input[type="range"].slider::-moz-range-track {
    height: 8px;
    border-radius: 4px;
  }

  input[type="range"].slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
  }

  /* 进房后隐藏「进入 / 新建」，仅保留房间号展示 */
  body.is-mobile.room-joined .room-bar-actions {
    display: none !important;
  }

  body.is-mobile.room-joined #roomInput {
    flex: 1;
    opacity: 0.92;
    pointer-events: none;
  }

  .mobile-room-chip {
    cursor: pointer;
    border: none;
    font: inherit;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-room-chip:active {
    background: rgba(201, 160, 255, 0.32);
  }

  .stat-track-list .stat-track-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    padding: 0.55rem 0.35rem;
  }

  .stat-track-list .stat-track-row .row-actions,
  .stat-track-list .stat-track-row > button {
    align-self: flex-end;
    min-height: 2.4rem;
    min-width: 3.5rem;
  }

  .queue-peek-row {
    flex-wrap: wrap;
  }

  .queue-peek-row .btn-chip {
    flex: 1 1 auto;
    min-height: 2.5rem;
  }

  .search-row {
    flex-direction: column;
    align-items: stretch;
  }

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

  .search-type-tabs .tab {
    min-width: 0;
    flex: 1 1 calc(50% - 0.2rem);
  }

  .search-results li,
  .playlist-list li,
  .queue li {
    padding: 0.55rem 0.2rem;
    font-size: 0.88rem;
    align-items: flex-start;
  }

  /* 歌单行：小彦 / 我的 / 搜索歌单 — 操作按钮换行展示 */
  .playlist-list li.playlist-row,
  .search-results li.playlist-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
    padding: 0.65rem 0.35rem;
    border-radius: 10px;
    background: rgba(32, 18, 50, 0.45);
    border-bottom: 1px solid rgba(200, 170, 235, 0.12);
    margin-bottom: 0.35rem;
  }

  .playlist-list li.playlist-row.active {
    background: rgba(201, 160, 255, 0.14);
    border-color: rgba(201, 160, 255, 0.28);
  }

  .playlist-list li.playlist-row .meta,
  .search-results li.playlist-row .meta {
    width: 100%;
    min-width: 0;
  }

  .playlist-list li.playlist-row .row-actions,
  .search-results li.playlist-row .row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
    flex-shrink: 0;
  }

  .playlist-list li.playlist-row .row-actions button,
  .search-results li.playlist-row .row-actions button {
    flex: 1 1 calc(33.333% - 0.3rem);
    min-width: 4.5rem;
    min-height: 2.5rem;
    padding: 0.4rem 0.35rem !important;
    font-size: 0.76rem !important;
    white-space: nowrap;
  }

  .search-results .row-actions button,
  .queue li .queue-actions button,
  #roomPlaylistTracks .row-actions button {
    min-height: 2.35rem;
    padding: 0.35rem 0.55rem;
    font-size: 0.78rem;
  }

  #roomPlaylistTracks li.playlist-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    padding: 0.55rem 0.35rem;
    border-radius: 10px;
    background: rgba(32, 18, 50, 0.4);
    margin-bottom: 0.3rem;
  }

  #roomPlaylistTracks .row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
  }

  #roomPlaylistTracks .row-actions button,
  #roomFavoritesList .row-actions button {
    flex: 1 1 calc(33.333% - 0.3rem);
    min-width: 4rem;
  }

  #roomFavoritesList li.playlist-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    padding: 0.55rem 0.35rem;
    border-radius: 10px;
    background: rgba(32, 18, 50, 0.4);
    margin-bottom: 0.3rem;
  }

  #roomFavoritesList .row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
  }

  .playlist-tabs .playlist-tab {
    flex: 1 1 calc(33.333% - 0.25rem);
    min-width: 3.5rem;
    font-size: 0.8rem;
    padding: 0.35rem 0.3rem;
  }

  .playlist-detail {
    margin-top: 0.65rem;
    padding: 0.75rem;
    border-radius: 12px;
    background: rgba(28, 16, 44, 0.75);
    border: 1px solid rgba(200, 170, 235, 0.18);
  }

  .playlist-detail-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .playlist-detail-actions .btn-bar-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
  }

  .playlist-detail-actions .btn-bar-group button,
  .playlist-detail-actions > .btn-chip {
    width: 100%;
    min-height: 2.5rem;
  }

  .xiaoyan-comments-list {
    max-height: none;
  }

  .xiaoyan-comment-row .row-actions button {
    min-height: 2.5rem;
    min-width: 3.25rem;
  }

  .room-pl-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .room-pl-names {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.35rem;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
  }

  .room-pl-name {
    flex: 0 0 auto;
    max-width: 8rem;
  }

  .hub-card {
    margin-top: 0.45rem;
  }

  .compact-footer {
    font-size: 0.72rem;
    padding-bottom: 0.25rem;
  }

  .app-modal {
    padding: 0.75rem;
    padding-bottom: calc(0.75rem + var(--safe-bottom));
    align-items: flex-end;
  }

  .app-modal-panel {
    width: 100%;
    max-height: 85dvh;
    overflow-y: auto;
    border-radius: 14px 14px 0 0;
  }

  .app-modal-panel--room {
    width: 100%;
  }

  .btn-bar--modal {
    flex-direction: column;
  }

  .btn-bar--modal .btn-chip {
    width: 100%;
    min-height: 2.75rem;
  }

  /* 迷你播放条（非播放页时显示） */
  .mobile-mini-player {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--mobile-nav-h) + var(--safe-bottom));
    z-index: 900;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.65rem;
    background: rgba(30, 18, 48, 0.97);
    border-top: 1px solid rgba(200, 170, 235, 0.22);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 -4px 20px rgba(15, 8, 28, 0.35);
  }

  .mobile-mini-player.hidden {
    display: none !important;
  }

  .mobile-mini-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.1rem;
    padding: 0.35rem 0.25rem;
    border: none;
    background: transparent;
    color: var(--text);
    box-shadow: none;
    text-align: left;
    cursor: pointer;
    min-height: 2.5rem;
  }

  .mobile-mini-title {
    font-size: 0.88rem;
    font-weight: 600;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-mini-sub {
    font-size: 0.72rem;
    color: var(--muted);
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-mini-toggle {
    flex-shrink: 0;
    width: 2.65rem;
    height: 2.65rem;
    border-radius: 50%;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    box-shadow: 0 2px 10px var(--glow);
  }

  /* 底部导航 */
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 950;
    height: calc(var(--mobile-nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(24, 14, 38, 0.96);
    border-top: 1px solid rgba(200, 170, 235, 0.2);
    box-shadow: 0 -6px 28px rgba(8, 4, 16, 0.45);
    backdrop-filter: blur(16px) saturate(1.1);
    -webkit-backdrop-filter: blur(16px) saturate(1.1);
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.12rem;
    padding: 0.25rem 0.15rem;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    min-height: var(--mobile-nav-h);
  }

  .mobile-nav-item.active {
    color: var(--accent2);
    background: rgba(201, 160, 255, 0.12);
  }

  .mobile-nav-icon {
    font-size: 1.05rem;
    line-height: 1;
  }

  .mobile-nav-label {
    line-height: 1.1;
  }

  .app-toast {
    bottom: calc(var(--mobile-chrome-h) + 0.65rem);
  }

  body.is-mobile.has-mobile-mini .app-toast {
    bottom: calc(var(--mobile-chrome-h) + var(--mobile-mini-h) + 0.65rem);
  }
}

@media (max-width: 767px) and (max-height: 500px) and (orientation: landscape) {
  .mobile-bottom-nav .mobile-nav-label {
    display: none;
  }

  :root {
    --mobile-nav-h: 2.75rem;
  }
}
