/* ==========================================================================
   Responsive & 390px Mobile Bottom-Sheet Layout (<= 800px)
   ========================================================================== */

@media (max-width: 1200px) {
  .shortcuts-hint {
    display: none;
  }

  #region-bar {
    max-width: calc(100% - 310px);
  }
}

@media (max-width: 800px) {
  #topbar {
    padding: 0 10px;
    gap: 6px;
  }

  .topbar-left {
    gap: 4px;
  }

  .topbar-nav,
  .top-progress-btn,
  #btn-perf-mode,
  .brand-sub {
    display: none;
  }

  #btn-mobile-sidebar,
  #btn-mobile-search {
    display: inline-flex;
  }

  .brand-title {
    font-size: 13px;
    white-space: nowrap;
  }

  html[lang="en"] .brand-title {
    font-size: 12px;
  }

  #workspace-root {
    padding-bottom: var(--mobile-nav-h);
  }

  /* Sidebar as Slide-over Drawer on Mobile */
  #sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: var(--mobile-nav-h);
    width: min(86vw, 324px);
    margin-left: 0 !important;
    transform: translateX(-102%);
    transition: transform 230ms var(--ease-out);
    box-shadow: var(--shadow-lg);
  }

  #sidebar.mobile-open {
    transform: translateX(0);
  }

  #btn-toggle-sidebar {
    display: none;
  }

  /* Top Region Bar on Mobile */
  #region-bar {
    top: 8px;
    left: 8px;
    right: 8px;
    max-width: none !important;
    padding: 3px;
    -webkit-mask-image: none !important;
    mask-image: none !important;
    transition: opacity 180ms, transform 180ms;
  }

  /* Auto-hide floating top bars when mobile Bottom Sheet is open */
  #map-stage.mobile-sheet-open #region-bar,
  #map-stage.mobile-sheet-open #map-top-right,
  #map-stage.sheet-expanded #region-bar {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
  }

  /* Compact Top-Right Layer Dock on Mobile */
  #map-top-right {
    top: 52px;
    right: 10px !important;
    gap: 4px;
    transition: opacity 180ms, transform 180ms;
  }

  #map-top-right .glass-dock {
    padding: 2px;
  }

  #map-top-right .dock-btn {
    height: 28px;
    padding: 0 7px;
    font-size: 11.5px;
  }

  .map-region-label {
    font-size: 10.5px;
    padding: 2px 8px;
    letter-spacing: 0.04em;
  }

  #map-options-popover {
    top: 90px;
    right: 10px !important;
    width: min(260px, calc(100vw - 20px));
  }

  #map-bottom-right {
    right: 10px !important;
    bottom: 12px;
  }

  #map-banners {
    top: 90px;
    width: calc(100% - 16px);
  }

  #map-statusbar {
    padding: 0 8px;
    font-size: 11px;
  }

  .statusbar-center {
    display: none;
  }

  /* 3-Stage Height-Driven Bottom Sheet (#detail-sheet) on Mobile
     Height snaps keep .detail-sticky-bar ALWAYS pinned above bottom nav! */
  #detail-sheet {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: var(--mobile-nav-h);
    width: 100%;
    height: 50dvh;
    max-height: calc(100dvh - var(--topbar-h) - var(--mobile-nav-h) - 8px);
    min-height: 186px;
    border-left: 0;
    border-top: 1px solid var(--border-strong);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: 0 -10px 32px rgba(4, 8, 14, 0.72);
    transform: none;
    transition: height 230ms var(--ease-out);
    will-change: height;
  }

  #detail-sheet.dragging {
    transition: none;
  }

  #detail-sheet.sheet-peek {
    height: 196px;
  }

  #detail-sheet.sheet-half {
    height: 50dvh;
  }

  #detail-sheet.sheet-full {
    height: calc(100dvh - var(--topbar-h) - var(--mobile-nav-h) - 8px);
  }

  .detail-hero {
    aspect-ratio: auto;
    height: 112px;
    max-height: 112px;
  }

  .detail-head {
    padding: 10px 14px 10px;
  }

  .detail-title {
    font-size: 15.5px;
  }

  .detail-body {
    padding: 12px 14px 18px;
    gap: 11px;
  }

  .detail-sticky-bar {
    padding: 8px 12px;
  }

  .sheet-drag-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 0 6px;
    cursor: grab;
    touch-action: none;
    flex-shrink: 0;
  }

  .sheet-drag-bar {
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: var(--border-strong);
  }

  /* Swipe labels on mobile */
  .swipe-corner-label {
    bottom: 58px;
    font-size: 11px;
    padding: 4px 9px;
  }

  .swipe-corner-label.is-right {
    right: 52px !important;
  }

  #swipe-toolbar {
    bottom: 10px;
  }

  /* Mobile Bottom 4-Tab Bar */
  #mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--mobile-nav-h);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--bg-bay);
    border-top: 1px solid var(--border-tide);
    z-index: var(--z-topbar);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 500;
    color: var(--ink-haze);
    white-space: nowrap;
  }

  .mobile-nav-btn .ic {
    width: 19px;
    height: 19px;
  }

  .mobile-nav-btn.active {
    color: var(--accent-flamingo);
    font-weight: 650;
  }

  /* Database Subtabs right-edge fade mask on mobile */
  .db-subtabs-wrap::after {
    content: "";
    position: absolute;
    top: 1px;
    right: 1px;
    bottom: 1px;
    width: 28px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    background: linear-gradient(90deg, transparent, var(--surface-asphalt));
    pointer-events: none;
  }

  .workspace-inner,
  .quiz-shell {
    padding: 14px 12px 32px;
  }

  .db-grid {
    grid-template-columns: 1fr;
  }

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

  .progress-hero-grid,
  .breakdown-columns,
  .tier-legend-grid {
    grid-template-columns: 1fr;
  }

  #toast {
    bottom: calc(var(--mobile-nav-h) + 12px);
  }
}

@media (max-width: 420px) {
  .dock-btn .dock-label-hide-xs {
    display: none;
  }

  .quiz-options-grid {
    grid-template-columns: 1fr;
  }
}
