body {
  overscroll-behavior: none;
}

.mobile-controls {
  display: none;
}

.leaflet-map {
  touch-action: none;
}

.memory-drawer {
  overscroll-behavior: contain;
}

@media (max-width: 980px) {
  html,
  body {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    overflow: hidden;
  }

  .app-shell {
    display: block;
    width: 100%;
    height: 100dvh;
    margin: 0;
  }

  .startup-image {
    object-position: 50% center;
  }

  .startup-content {
    width: calc(100vw - 28px);
    padding: 22px 18px 20px;
    border-radius: 18px;
  }

  .startup-summary {
    max-width: 280px;
    line-height: 1.5;
  }

  .sidebar,
  .inspector {
    display: none;
  }

  .map-stage {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
    border: 0;
    border-radius: 0;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  }

  #campusTitle {
    font-size: 21px;
    line-height: 1.15;
  }

  .source-line {
    max-width: 55vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .toolbar {
    gap: 6px;
  }

  .toolbar #zoomIn,
  .toolbar #zoomOut,
  .toolbar #resetView {
    display: none;
  }

  .tool-button {
    min-width: 42px;
    min-height: 42px;
  }

  .theme-button,
  .auth-button {
    width: auto;
    max-width: 108px;
    padding: 0 10px;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-controls {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(110px, 0.8fr) minmax(170px, 1.2fr);
    gap: 8px;
  }

  .mobile-controls select,
  .mobile-search {
    min-width: 0;
    height: 42px;
  }

  .mobile-controls select,
  .mobile-search input {
    min-width: 0;
    border: 1px solid var(--line);
    color: var(--ink);
    background: rgba(5, 14, 27, 0.92);
  }

  .mobile-controls select {
    width: 100%;
    padding: 0 9px;
    border-radius: 9px;
  }

  .mobile-search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .mobile-search input {
    width: 100%;
    padding: 0 10px;
    border-radius: 9px 0 0 9px;
    outline: none;
  }

  .mobile-search button {
    padding: 0 12px;
    border: 0;
    border-radius: 0 9px 9px 0;
    color: #07111f;
    background: linear-gradient(135deg, var(--accent), #f0d58c);
    font-weight: 700;
  }

  .map-wrap,
  .leaflet-map {
    min-height: 0;
    height: 100%;
  }

  .map-badge {
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  .memory-guide {
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    max-width: calc(100% - 132px);
  }

  .memory-guide em {
    display: none;
  }

  .map-spotlight,
  .map-spotlight.is-pinned {
    background:
      radial-gradient(
        circle 135px at var(--spot-x) var(--spot-y),
        rgba(2, 7, 16, 0) 0 42%,
        rgba(2, 7, 16, 0.08) 60%,
        rgba(2, 7, 16, 0.24) 82%,
        rgba(2, 7, 16, 0.34) 100%
      );
  }

  .map-badge span:last-child,
  .campus-address-label {
    display: none;
  }

  .memory-drawer {
    position: absolute;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: min(62dvh, 620px);
    grid-template-rows: auto minmax(80px, 1fr) auto;
    padding: 14px 14px max(14px, env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 18px 18px 0 0;
    background: rgba(15, 28, 46, 0.98);
    backdrop-filter: none;
    touch-action: pan-y;
    transform-origin: bottom center;
  }

  .memory-drawer[data-state="opening"],
  .memory-drawer[data-state="closing"] {
    opacity: 0;
    transform: translateY(100%);
  }

  .memory-drawer[data-state="open"] {
    opacity: 1;
    transform: translateY(var(--drawer-drag-y, 0));
  }

  .memory-drawer.is-dragging {
    transition: none;
  }

  .memory-handle {
    width: 64px;
    height: 20px;
    display: grid;
    place-items: center;
    justify-self: center;
    margin: -10px 0 -5px;
    border: 0;
    padding: 0;
    background: transparent;
    touch-action: none;
  }

  .memory-handle span {
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 240, 203, 0.42);
    box-shadow: 0 0 10px rgba(88, 230, 255, 0.12);
  }

  .memory-list {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .memory-form textarea {
    max-height: 96px;
    resize: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .startup-image,
  .startup-loader span {
    animation: none;
  }

  .startup-screen,
  .app-shell,
  .startup-progress span {
    transition-duration: 0.01ms;
  }
}

@media (max-width: 620px) {
  .mobile-controls {
    grid-template-columns: 112px minmax(0, 1fr);
  }

  .feature-label,
  .road-label,
  .area-label {
    font-size: 10px;
  }
}

@media (max-width: 980px) {
  body.view-home {
    overflow: auto;
  }

  .home-screen {
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    align-content: start;
    gap: 16px;
    padding: max(72px, calc(env(safe-area-inset-top) + 58px)) 14px max(44px, env(safe-area-inset-bottom));
    overflow: auto;
  }

  .home-backdrop {
    position: fixed;
    object-position: 50% center;
  }

  .home-shade {
    position: fixed;
    background:
      linear-gradient(180deg, rgba(2, 8, 22, 0.54), rgba(2, 8, 22, 0.22) 44%, rgba(2, 8, 22, 0.72)),
      radial-gradient(circle at 50% 28%, rgba(38, 105, 255, 0.10), transparent 55%);
  }

  .home-hero {
    width: 100%;
    padding: 18px;
    border-radius: 20px;
  }

  .home-hero h1 {
    font-size: clamp(34px, 11vw, 50px);
  }

  .home-actions {
    top: max(12px, env(safe-area-inset-top));
    right: 12px;
  }

  .home-actions .tool-button {
    min-height: 38px;
    height: 38px;
  }

  .campus-home-panel {
    width: 100%;
    padding: 12px;
    border-radius: 22px;
  }

  .campus-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .campus-card {
    min-height: 128px;
    padding: 16px;
    border-radius: 18px;
  }

  .campus-card .campus-orb {
    width: 24px;
    height: 24px;
    margin-bottom: 14px;
  }

  .campus-card strong {
    font-size: 24px;
  }

  body.view-map .map-stage {
    width: 100%;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    grid-template-rows: auto minmax(0, 1fr);
  }

  body.view-map .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  }

  .back-home {
    min-width: 58px;
    padding: 0 9px;
  }

  .map-title-block {
    min-width: 0;
  }

  .map-title-block .source-line {
    max-width: 100%;
  }

  body.view-map #campusTitle {
    font-size: 19px;
  }

  .campus-switch {
    grid-column: 3;
    grid-row: 1;
    min-width: 88px;
    width: 88px;
    height: 38px;
    font-size: 12px;
  }

  .top-search {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .top-search input,
  .top-search button {
    height: 38px;
  }

  .toolbar {
    grid-column: 1 / -1;
    grid-row: 3;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .toolbar #zoomIn,
  .toolbar #zoomOut,
  .toolbar #resetView {
    display: none;
  }

  .top-key-places {
    grid-column: 1 / -1;
    grid-row: 4;
    margin-right: -10px;
  }

  .top-key-places .place-button {
    min-width: 96px;
    min-height: 32px;
    padding: 6px 9px;
  }

  .tool-popover {
    left: 0;
    right: auto;
    width: min(340px, calc(100vw - 20px));
  }

  .inspector {
    display: none;
  }

  body.view-map .memory-drawer {
    position: absolute;
    inset: 0;
    width: 100%;
    max-height: none;
    height: 100%;
    grid-template-rows: auto minmax(0, 1fr) auto;
    padding: max(14px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
    background: rgba(15, 28, 46, 0.99);
    transform-origin: bottom center;
  }

  body.view-map .memory-drawer[data-state="opening"],
  body.view-map .memory-drawer[data-state="closing"] {
    opacity: 0;
    transform: translateY(100%);
  }

  body.view-map .memory-drawer[data-state="open"] {
    opacity: 1;
    transform: translateY(var(--drawer-drag-y, 0));
  }

  body.view-map .memory-head h2 {
    font-size: 24px;
  }

  body.view-map .memory-list {
    min-height: 0;
  }

  body.view-map .memory-form textarea {
    min-height: 126px;
    max-height: 30dvh;
  }
}

@media (max-width: 980px) {
  body.view-home .home-screen {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    align-content: stretch;
    gap: 12px;
    padding: max(66px, calc(env(safe-area-inset-top) + 50px)) 12px max(38px, env(safe-area-inset-bottom));
  }

  body.view-home .home-hero {
    position: relative;
    top: auto;
    left: auto;
    width: 100%;
    z-index: 4;
  }

  .campus-home-panel {
    position: relative;
    inset: auto;
    z-index: 4;
    width: 100%;
    min-height: 0;
    pointer-events: auto;
  }

  .campus-grid {
    position: relative;
    inset: auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    pointer-events: auto;
  }

  .campus-card,
  .campus-card:hover {
    position: relative;
    left: auto;
    top: auto;
    width: auto;
    min-height: 132px;
    transform: none;
  }

  .campus-card::after {
    opacity: 1;
    transform: none;
  }

  .campus-card .pill {
    font-size: 11px;
  }
}

@media (max-width: 430px) {
  .campus-grid {
    gap: 8px;
  }

  .campus-card {
    min-height: 118px;
    padding: 12px;
  }

  .campus-card strong {
    font-size: 20px;
  }

  .campus-card > span:not(.campus-orb) {
    font-size: 11px;
  }
}
