/* En escritorio se conserva la distribución del panel lateral. */
.mobile-only,
#map-key > summary {
  display: none;
}
#map-key {
  min-width: 0;
}

@media (max-width: 760px), (max-width: 1000px) and (max-height: 500px) {
  body {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .map-wrap {
    grid-row: 1;
    height: 100%;
    min-height: 0;
    order: initial;
  }
  .panel {
    grid-row: 2;
    order: initial;
    min-height: 0;
    max-height: 48dvh;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 0 16px max(12px, env(safe-area-inset-bottom));
    border: 0;
    border-top: 1px solid var(--line);
    scrollbar-color: #aebccb var(--paper);
    scrollbar-width: thin;
  }
  .panel header {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 8px;
    min-height: 56px;
    padding: 4px 0;
    border: 0;
    background: var(--paper);
  }
  .panel h1 {
    margin: 0;
    font-size: 15px;
    letter-spacing: -0.03em;
  }
  .panel h1 span {
    display: inline;
    margin-left: 5px;
    font-size: 15px;
  }
  .panel .eyebrow {
    display: none;
  }
  #panel-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-shrink: 0;
    min-height: 44px;
    padding: 8px;
    border: 0;
    color: var(--green);
    background: transparent;
    font-size: 12px;
    font-weight: 600;
  }
  .panel[data-expanded="false"] #panel-toggle svg {
    transform: rotate(180deg);
  }
  .panel[data-expanded="false"] #route-form,
  .panel[data-expanded="false"] footer,
  .panel[data-expanded="false"] #route-note,
  .panel[data-expanded="false"] #remaining {
    display: none;
  }
  #mobile-hint {
    display: block;
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
  }
  #mobile-hint:empty {
    display: none;
  }
  .panel label {
    margin-top: 12px;
    margin-bottom: 7px;
  }
  .panel label strong {
    font-size: 13px;
  }
  button,
  input,
  select {
    min-height: 44px;
  }
  .panel input,
  .panel select {
    font-size: 16px;
  }
  .panel input {
    margin-bottom: 6px;
  }
  .panel .inline {
    margin-top: 0;
  }
  #calculate {
    margin-top: 12px;
    margin-bottom: 4px;
  }
  .panel footer {
    margin: 12px 0 0;
    font-size: 10px;
  }
  #result {
    margin-top: 10px;
    padding-top: 10px;
  }
  .panel[data-expanded="false"] #result {
    margin: 0;
    padding: 0;
    border: 0;
  }
  #status {
    font-size: 12px;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }
  #status strong {
    display: inline;
    font-size: 19px;
    margin-right: 6px;
  }
  .phase {
    font-size: 10px;
    margin-bottom: 4px;
  }
  #route-note {
    max-width: none;
  }
  #playback {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
  }
  #playback > .primary {
    flex: 1;
    width: auto;
    min-width: 0;
    margin: 0;
    padding: 10px;
    font-size: 12px;
  }
  #playback .inline {
    display: flex;
    gap: 6px;
    flex: 1;
  }
  #playback .inline > button {
    min-width: 44px;
    padding: 8px;
    font-size: 12px;
  }
  #playback .speed-label {
    margin: 0;
    font-size: 0;
  }
  #playback .speed-label select {
    width: 58px;
    min-height: 44px;
    font-size: 16px;
  }
  #playback progress {
    flex-basis: 100%;
    margin: 0;
    height: 3px;
  }
  #playback #remaining {
    flex-basis: 100%;
    margin: 0;
  }
  #pause {
    background: var(--green);
    color: var(--paper);
    border-color: var(--green);
  }
  .map-header {
    top: max(10px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    left: 12px;
  }
  .map-actions {
    gap: 8px;
  }
  .map-actions > button {
    min-height: 44px;
    font-size: 12px;
    padding: 10px 12px;
  }
  .zoom {
    top: max(70px, calc(env(safe-area-inset-top) + 60px));
    right: max(12px, env(safe-area-inset-right));
  }
  .zoom button {
    width: 44px;
    min-height: 44px;
  }
  #levels {
    top: max(168px, calc(env(safe-area-inset-top) + 158px));
    right: 12px;
  }
  #levels button {
    min-height: 44px;
  }
  .map-bottom {
    left: 12px;
    right: 12px;
    bottom: 32px;
    gap: 12px;
  }
  #map-key {
    position: relative;
    pointer-events: auto;
  }
  #map-key > summary {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 4px;
    background: var(--paper);
    color: var(--ink);
    font-size: 11px;
    cursor: pointer;
    list-style: none;
  }
  #map-key > summary::-webkit-details-marker {
    display: none;
  }
  #map-key[open] .legend {
    position: absolute;
    left: 0;
    bottom: 50px;
    display: grid;
    gap: 12px;
    width: max-content;
    max-width: calc(100vw - 24px);
    padding: 14px;
    font-size: 11px;
    background: var(--paper);
  }
  #scale {
    flex-shrink: 0;
  }
  .attribution {
    max-width: 100%;
    padding: 4px 6px;
    font-size: 8px;
  }
  :focus-visible {
    outline: 3px solid #167cc1;
    outline-offset: 2px;
  }
  ::selection {
    background: #cce2f7;
    color: #0d3b66;
  }
}

@media (max-width: 1000px) and (max-height: 500px) and (orientation: landscape) {
  body:has(.panel[data-expanded="true"]) {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-rows: minmax(0, 1fr);
  }
  body:has(.panel[data-expanded="true"]) .map-wrap {
    grid-column: 1;
    grid-row: 1;
  }
  .panel[data-expanded="true"] {
    grid-column: 2;
    grid-row: 1;
    max-height: 100dvh;
    border-top: 0;
    border-left: 1px solid var(--line);
  }
  .panel {
    max-height: 48dvh;
  }
  .panel header {
    min-height: 48px;
  }
  .panel[data-expanded="false"] #phase {
    display: none;
  }
  .panel[data-expanded="false"] #result {
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .panel[data-expanded="false"] #status {
    flex: 1;
  }
  .panel[data-expanded="false"] #playback {
    flex: 1;
    margin-top: 0;
  }
  .panel h1,
  .panel h1 span {
    font-size: 14px;
  }
}
