/* Dedicated mobile layout. Loaded after app.css, only below 820px. */
@media (max-width: 820px) {
  :root {
    --header-h: 58px;
    --radius: 14px;
    --radius-sm: 10px;
  }

  html {
    min-height: 100%;
    scroll-padding-top: calc(var(--header-h) + env(safe-area-inset-top) + 10px);
    -webkit-text-size-adjust: 100%;
  }

  body {
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
    font-size: 14px;
    line-height: 1.6;
    overscroll-behavior-y: none;
  }

  .site-header {
    padding-top: env(safe-area-inset-top);
    background: rgba(7, 8, 15, 0.94);
  }
  .header-inner {
    height: var(--header-h);
    padding: 0 12px;
    gap: 8px;
  }
  .brand { gap: 8px; min-width: 0; }
  .brand-mark { width: 31px; height: 31px; border-radius: 0; background: none; box-shadow: none; }
  .brand-mark svg { width: 25px; height: 25px; }
  .brand-name { font-size: 0.9rem; letter-spacing: 0.04em; }
  .brand-sub { display: none; }
  .brand-text { min-width: 0; }
  .brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .header-actions { gap: 6px; margin-left: auto; }
  .header-actions > .btn.btn-ghost { display: none; }
  .header-actions .btn { min-height: 36px; padding: 7px 11px; font-size: 0.78rem; }
  .nav-toggle { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; }
  .user-chip { padding: 4px 7px 4px 4px; gap: 5px; }
  .user-chip .avatar { width: 26px; height: 26px; }
  .user-chip .who { display: none; }
  #logout-btn { padding: 7px 8px; font-size: 0.72rem; }

  .nav {
    position: fixed;
    top: calc(var(--header-h) + env(safe-area-inset-top) + 8px);
    left: 12px;
    right: 12px;
    bottom: auto;
    max-height: calc(100dvh - var(--header-h) - env(safe-area-inset-top) - 24px);
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--line-strong);
    border-radius: 14px;
    background: rgba(12, 14, 25, 0.98);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    transform: translateY(-8px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 45;
  }
  .nav.open { transform: translateY(0); opacity: 1; visibility: visible; pointer-events: auto; }
  .nav a { padding: 12px 14px; border-radius: 9px; font-size: 0.92rem; }
  .nav a.active { background: rgba(124, 92, 255, 0.22); }

  .view {
    padding: 18px 14px calc(44px + env(safe-area-inset-bottom));
    min-height: calc(100dvh - var(--header-h) - env(safe-area-inset-top));
  }
  .card { padding: 14px; border-radius: 14px; }
  .card h1, .view h1 { font-size: clamp(1.55rem, 7.5vw, 2rem); }
  h2 { font-size: 1.3rem; }
  h3 { font-size: 1.05rem; }
  p { font-size: 0.92rem; }
  .tiny { font-size: 0.72rem; }
  .dim { font-size: 0.78rem; }

  .btn { min-height: 42px; padding: 9px 13px; border-radius: 10px; font-size: 0.86rem; }
  .btn-sm { min-height: 36px; padding: 7px 10px; font-size: 0.78rem; }
  .btn-row { flex-wrap: wrap; gap: 8px; }
  .input, .select, .textarea { font-size: 16px; min-height: 42px; }
  .field label { font-size: 0.8rem; }
  .form-row { gap: 10px; }

  .hero { padding: 24px 0 10px; }
  .hero h1 { font-size: clamp(2rem, 10vw, 3rem); }
  .hero p { font-size: 0.93rem; }
  .hero-actions { gap: 8px; }
  .hero-meta { gap: 18px; flex-wrap: wrap; }
  .hero-stat b { font-size: 1.45rem; }
  .section-head { gap: 8px; flex-wrap: wrap; }
  .section-head h2 { margin-bottom: 0; }

  .split, .grid-2, .grid-3, .grid-4 { gap: 12px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; }
  .table { min-width: 620px; }
  .table th, .table td { padding: 8px 7px; font-size: 0.75rem; }
  .cover-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 9px; }

  .game-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
    margin: 12px 0 14px;
    padding-bottom: 0;
  }
  .game-tab { padding: 11px 12px; border-radius: 11px; min-width: 0; }
  .game-tab b { font-size: 0.9rem; }
  .game-tab span { font-size: 0.72rem; line-height: 1.45; }
  .game-layout { grid-template-columns: 1fr; gap: 12px; }
  .game-stage { min-height: 0; padding: 12px; }
  .game-stage .card-head { gap: 8px; }
  .game-stage .card-head h2 { font-size: 1.15rem; }
  .game-stat { gap: 8px; font-size: 0.72rem; }
  .game-stat b { font-size: 0.95rem; }
  .game-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 0; }
  .game-settings label { font-size: 0.76rem; gap: 5px; }
  .game-settings .select { min-height: 36px; font-size: 14px; }
  .game-settings .tiny { grid-column: 1 / -1; }
  .game-area { flex: none; height: clamp(300px, 56dvh, 520px); min-height: 0; margin-top: 10px; border-radius: 11px; }
  .piano-time { top: 9px; font-size: 1.65rem; }
  .piano-cps { top: 10px; right: 9px; font-size: 0.68rem; }
  .game-stage .btn-row.mt-2 { margin-top: 10px !important; }

  .game-stage:fullscreen {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    padding: calc(env(safe-area-inset-top) + 10px) 10px calc(env(safe-area-inset-bottom) + 10px);
    border-radius: 0;
  }
  .game-stage:fullscreen .game-area { flex: 1; height: auto; min-height: 0; margin-top: 8px; }
  .game-stage:fullscreen .game-settings { margin-top: 6px; }

  .bp-page { padding: 14px 0; }
  .bp-head { gap: 10px; }
  .bp-head h1 { font-size: 1.45rem; }
  .bp-head .btn-row { gap: 6px; }
  .bp-body { padding: 12px; }
  .bp-maps-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .bp-map { min-height: 0; }
  .bp-map img, .bp-map .bp-cover { aspect-ratio: 16 / 9; }
  .bp-map-meta b { font-size: 0.72rem; }
  .bp-team h2 { font-size: 1.2rem; }
  .bp-history { margin-top: 10px; }
  .bp-obs-panel .input { min-width: 0; }

  .admin-shell { gap: 12px; }
  .admin-nav { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 4px; scrollbar-width: none; }
  .admin-nav::-webkit-scrollbar { display: none; }
  .admin-nav a { flex: 0 0 auto; padding: 8px 10px; font-size: 0.76rem; }
  .admin-nav .group-label { display: none; }
  .admin-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .admin-head h1 { font-size: 1.3rem; }
  .admin-content { min-width: 0; }
  .admin-content .card { overflow-x: auto; }

  .auth-shell { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .auth-form { padding: 22px 18px; }

  .footer-inner { padding: 24px 14px calc(24px + env(safe-area-inset-bottom)); gap: 14px; flex-direction: column; align-items: flex-start; }
  .footer-inner nav { display: flex; flex-wrap: wrap; gap: 12px; }

  .modal-backdrop { padding: 10px; align-items: flex-end; }
  .modal { max-height: calc(100dvh - 20px); border-radius: 14px; }
  .toast-stack { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .toast { min-width: 0; width: 100%; }

  .score-rks { font-size: 2.4rem !important; }
  .b27-wrap { min-height: 100px; }
  .series-line { flex-wrap: wrap; }
  .bp-result { gap: 4px; }
}

@media (max-width: 420px) {
  .brand-name { max-width: 96px; }
  .game-settings { grid-template-columns: 1fr; }
  .game-settings .tiny { grid-column: auto; }
  .bp-maps-grid { grid-template-columns: 1fr; }
  .cover-grid { grid-template-columns: 1fr !important; }
  .hero h1 { font-size: 2rem; }
}

/* keep the logout action reachable in the compact header */
@media (max-width: 820px) {
  .header-actions > #logout-btn { display: inline-flex; }
}
