/* Phone layout. Desktop rules are intentionally left unchanged. */
@media (max-width: 700px) {
  html { -webkit-text-size-adjust: 100%; }
  body { overflow-x: hidden; }
  .app { display: block; min-width: 0; }
  aside {
    position: sticky; top: 0; z-index: 30;
    display: flex; flex-wrap: nowrap; gap: 6px;
    padding: 8px 10px;
    overflow-x: auto; overscroll-behavior-x: contain;
    scrollbar-width: none; box-shadow: 0 2px 12px #0005;
  }
  aside::-webkit-scrollbar { display: none; }
  .brand { flex: 0 0 auto; font-size: 16px; margin: 0 8px 0 0; }
  aside .nav { flex: 0 0 auto; width: auto; min-height: 42px; padding: 8px 11px; margin: 0; font-size: 13px; }
  main { padding: 14px 10px 28px; min-width: 0; }
  .top { display: block; margin-bottom: 12px; }
  .top h1 { font-size: clamp(20px, 5vw, 25px); }
  .top .controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
  .top .controls > * { min-height: 42px; }
  button, select { touch-action: manipulation; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .stat { min-width: 0; padding: 9px 7px; }
  .stat small { display: block; font-size: 11px; line-height: 1.3; overflow-wrap: anywhere; }
  .stat b { font-size: clamp(18px, 5vw, 23px); }
  .layout { display: flex; flex-direction: column; gap: 12px; }
  .layout > .card:first-child { min-height: 0; display: block; }
  .toolbar { padding: 10px; align-items: stretch; }
  .toolbar .controls { width: 100%; display: flex; flex-wrap: wrap; }
  .toolbar .controls > * { min-height: 40px; }
  .map-scroll, .layout > .card:first-child > .map-scroll {
    width: 100%; height: min(58dvh, 600px); min-height: 300px;
    overflow: auto; overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y;
  }
  .map-inner { width: max-content; min-width: 100%; }
  .gridrow { width: max-content; min-width: 100%; grid-template-columns: 42px repeat(15, 42px); height: 42px; }
  .gridrow.header { height: 42px; }
  .gridrow .cell:not(.floor), .gridrow.header .cell:not(.floor) { min-width: 42px; font-size: 12px; }
  .gridrow .cell.floor { position: sticky; left: 0; z-index: 2; min-width: 42px; padding-left: 6px; background: #142a3c; }
  .gridrow.header .cell.floor { z-index: 6; }
  .gridrow .cell.editable { touch-action: manipulation; }
  .right { display: block; margin-top: 0; }
  .right .card { margin-bottom: 12px; }
  .panel { padding: 13px; }
  .auth-overlay { padding: 10px; align-items: center; }
  .auth-dialog { width: min(100%, 520px); max-height: calc(100dvh - 20px); overflow-y: auto; padding: 18px 15px; }
  .auth-dialog input:not([type="checkbox"]), .auth-dialog select { max-width: 100%; min-height: 44px; font-size: 16px; }
  .auth-dialog button { min-height: 44px; }
}

@media (max-width: 380px) {
  main { padding-inline: 7px; }
  .stat small { font-size: 10px; }
  .toolbar { padding: 8px; }
}

/* Compact expedition workspace: the map and its movement controls come first. */
.boss-deep-horror { color: #ff6d8d; }
.boss-lowland-horror { color: #e6a4ff; }
/* Mark the sticky floor number, not the whole row, so findings remain readable. */
#mapScroll .gridrow .cell.floor.floor-has-map { background: #8c2033; color: #fff !important; }
#mapScroll .gridrow .cell.floor.floor-has-chest { background: #7a5a17; color: #fff1a7 !important; }
#mapScroll .gridrow .cell.floor.floor-has-boss { background: #76375f; color: #ffe4f2 !important; }
.floor-find-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 8px 13px; border-top: 1px solid #294459; color: #a9bfd2; font-size: 12px; }
.floor-find-legend span { display: inline-flex; gap: 5px; align-items: center; }
.floor-find-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.floor-key-map { background: #d13a52; }
.floor-key-chest { background: #ddb035; }
.floor-key-boss { background: #c668a2; }
.map-actions-dropdown { position: relative; z-index: 20; }
.map-actions-dropdown > summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 38px; padding: 8px 12px;
  color: #def7f2; background: #103f40; border: 1px solid #16ae98;
  border-radius: 9px; cursor: pointer; list-style: none; user-select: none;
}
.map-actions-dropdown > summary::-webkit-details-marker { display: none; }
.map-actions-dropdown > summary::after { content: '⌄'; font-size: 17px; line-height: 1; }
.map-actions-dropdown[open] > summary::after { transform: rotate(180deg); }
.map-actions-menu {
  position: absolute; top: calc(100% + 5px); right: 0;
  display: grid; gap: 6px; min-width: 220px; max-width: min(300px, calc(100vw - 24px));
  padding: 9px; background: #10283b; border: 1px solid #31536b;
  border-radius: 10px; box-shadow: 0 12px 30px #0009;
}
.map-actions-menu > button { display: block; width: 100%; text-align: left; min-height: 38px; }
aside > .auth-button {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: -20px 10px 20px;
  text-align: left;
}
.map-reset-notice {
  padding: 10px 13px !important;
  border-top: 1px solid #294459;
}
@media (min-width: 701px) {
  .mobile-movement-slot { display: none; }
}
@media (max-width: 700px) {
  main { padding: 9px 9px 22px; }
  aside > .auth-button {
    flex: 0 0 auto;
    max-width: 125px;
    margin: 0 4px 0 0;
    padding: 7px 9px;
    font-size: 11px;
  }
  .top { margin-bottom: 7px; }
  .top h1 { font-size: 19px; line-height: 1.2; }
  .top .sub { font-size: 11px; margin-top: 2px; }
  .top .controls {
    display: flex; align-items: center; flex-wrap: wrap;
    width: 100%; gap: 6px; margin-top: 8px;
  }
  .top .controls label {
    display: inline-flex; align-items: center; flex: 0 0 auto;
    gap: 7px; margin: 0; font-size: 12px;
  }
  .top .controls select { min-width: 0; width: 122px; max-width: 44vw; height: 36px; padding: 6px 9px; font-size: 13px; }
  .top .controls .auth-button, .top .controls .pill {
    grid-column: auto; min-height: 34px; padding: 6px 9px;
    font-size: 11px; white-space: nowrap;
  }
  .map-tools {
    display: flex; flex-wrap: wrap; align-items: center;
    gap: 6px; margin: 0 0 9px;
  }
  .map-tools label { display: inline-flex; align-items: center; flex: 0 1 auto; gap: 6px; min-width: 0; font-size: 12px; }
  .map-tools label select { width: min(165px, 43vw); min-width: 0; max-width: 165px; height: 36px; padding: 5px 7px; font-size: 12px; }
  .map-tools .smallbtn { min-height: 35px; padding: 6px 9px; font-size: 11px; }
  .map-actions-dropdown > summary { min-height: 36px; padding: 7px 10px; font-size: 12px; }
  .map-actions-menu .smallbtn { min-height: 40px; font-size: 13px; }
  .map-tools #managePrivateMap, .map-tools #teamModeToggle { grid-column: auto; justify-self: auto; }
  .map-tools .map-access-panel, .map-tools #teamModeStatus { flex-basis: 100%; grid-column: auto; }

  #mapPage { display: flex; flex-direction: column; }
  #mapPage > .stats { order: 0; margin: 0 0 9px; }
  #mapPage > .layout { order: 1; }
  #mapPage > .labyrinth-status { order: 2; margin-top: 3px; }
  #mapPage .layout > .card:first-child { min-height: 0; }
  #mapPage .layout > .card > .toolbar { padding: 8px 10px; gap: 4px; }
  #mapPage .layout > .card > .toolbar > strong { font-size: 13px; line-height: 1.3; }
  .map-selected-summary { padding-top: 5px; }
  .map-selected-summary h3 { font-size: 11px; }
  .map-selected-summary #selectedInfo { font-size: 10px; line-height: 1.3; }
  .map-selected-summary .set-position { font-size: 10px; padding: 5px 7px; }
  #mapPage .layout > .card:first-child > .mobile-movement-slot { order: 2; display: block; }
  #mapPage .layout > .card:first-child > .map-scroll { order: 3; height: 59dvh; min-height: 300px; }
  #mapPage .layout > .card:first-child > .map-actions-row { order: 4; }
  #mapPage .layout > .card:first-child > .legend { order: 5; }
  #mapPage .layout > .card:first-child > .route-summary { order: 6; }
  #mapPage .layout > .card:first-child > .floor-find-legend { order: 7; }
  #mapPage .layout > .card:first-child > .map-reset-notice { order: 8; }
  .mobile-movement-slot .panel { padding: 6px 9px 7px; border-bottom: 1px solid #294459; }
  .mobile-movement-slot h3 { display: none; }
  .mobile-movement-slot .navigator-panel { padding: 9px 11px; }
  .mobile-movement-slot .navigator-panel h3 { display: block; font-size: 13px; margin: 0 0 6px; }
  .mobile-movement-slot .navigator-panel .formrow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; margin: 6px 0; }
  .mobile-movement-slot .navigator-panel .formrow label { min-width: 0; font-size: 11px; }
  .mobile-movement-slot .navigator-panel select { min-width: 110px; height: 34px; padding: 5px 7px; font-size: 12px; }
  .mobile-movement-slot .navigator-panel .muted { font-size: 11px; }
  .mobile-movement-slot .navigator-panel .notice { margin: 6px 0 0; padding: 7px; }
  #mapPage .right > .card:empty { display: none; }
  .mobile-movement-slot .action-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
  .mobile-movement-slot .action { min-height: 43px; padding: 3px 4px; font-size: 17px; border-radius: 7px; line-height: 1.1; }
  .mobile-movement-slot .action small { margin-top: 1px; font-size: 10px; }
  .mobile-movement-slot .formrow { margin: 5px 0 0; gap: 5px; }
  .mobile-movement-slot .smallbtn { padding: 5px 8px; font-size: 10px; min-height: 30px; }
  #mapScroll { overflow: auto; }
  #mapScroll .map-inner { width: max-content; min-width: 0; }
  #mapScroll .gridrow { width: max-content; min-width: 0; height: 36px; grid-template-columns: 35px repeat(15, 34px); }
  #mapScroll .gridrow.header { height: 35px; }
  #mapScroll .gridrow > .cell { min-width: 0; width: 100%; font-size: 11px; }
  #mapScroll .gridrow > .cell.floor { width: 35px; min-width: 35px; padding-left: 4px; font-size: 10px; }
  #mapScroll .gridrow.header > .cell:not(.floor) { font-size: 10px; }
  #mapScroll .cell .x { font-size: 16px; }
  #mapScroll .cell.route::after { inset: 2px; border-width: 2px; border-radius: 5px; }
  .stat { padding: 7px; }
  .stat small { min-height: 0; }
  .stat b { font-size: 19px; }
}
