/* Small Taipei: append after the existing viewport and bottom-sheet rules. */
#map:focus-visible::after {
  position: absolute;
  z-index: 3;
  inset: 3px;
  border: 3px solid #315c4a;
  box-shadow: inset 0 0 0 1px #f9f6eb;
  border-radius: 3px;
  pointer-events: none;
  content: "";
}

@media (max-width: 680px), (max-height: 510px) {
  :root {
    --tp-safe-top: max(8px, env(safe-area-inset-top, 0px));
    --tp-safe-right: max(8px, env(safe-area-inset-right, 0px));
    --tp-safe-bottom: max(6px, env(safe-area-inset-bottom, 0px));
    --tp-safe-left: max(8px, env(safe-area-inset-left, 0px));
    --tp-mini-width: clamp(75px, 24vw, 100px);
    --tp-bar-room: 60px;
  }

  .top {
    top: var(--tp-safe-top);
    left: var(--tp-safe-left);
    max-width: calc(100% - var(--tp-safe-left) - var(--tp-safe-right));
    padding: 3px 5px;
  }
  .brand,
  .top nav button {
    min-height: 44px;
  }
  .top nav {
    min-width: 0;
    max-width: 100%;
    padding-block: 1px;
    overscroll-behavior-inline: contain;
  }
  .top nav button {
    flex: 0 0 auto;
    min-width: 44px;
    padding-inline: 5px;
  }
  .top nav button:focus-visible {
    outline-offset: -3px;
  }

  .tools {
    top: calc(var(--tp-safe-top) + var(--tp-bar-room));
    right: var(--tp-safe-right);
    gap: 6px;
  }
  .tools button {
    width: 44px;
    height: 44px;
  }

  .status,
  .mini {
    bottom: calc(var(--tp-safe-bottom) + 12px);
  }
  .status {
    left: var(--tp-safe-left);
    max-width: calc(100% - var(--tp-safe-left) - var(--tp-safe-right) - var(--tp-mini-width) - 8px);
  }
  .mini {
    right: var(--tp-safe-right);
    width: var(--tp-mini-width);
  }
  .credits {
    bottom: var(--tp-safe-bottom);
    right: var(--tp-safe-right);
    max-width: calc(100% - var(--tp-safe-left) - var(--tp-safe-right));
    text-align: end;
  }

  body:not(.board-mode) .panel {
    left: var(--tp-safe-left);
    right: var(--tp-safe-right);
    bottom: calc(var(--tp-safe-bottom) + 12px);
  }
  .panel #close {
    flex: 0 0 44px;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 7px;
  }
  .panel #close:hover {
    background: #dcead9;
  }
  .panel .row,
  .panel .chip,
  .panel .toggle,
  .panel .projects-check,
  .panel .projects-tab,
  .panel .projects-record,
  .panel .projects-district {
    min-height: 44px;
  }
}

@media (max-width: 419px) {
  :root { --tp-bar-room: 104px; }
  .top { flex-direction: column; align-items: flex-start; }
}

@media (min-width: 420px) and (max-width: 680px) {
  .top { flex-wrap: nowrap; }
}

@media (max-height: 510px) {
  .tools { display: flex; }
  .tools > div { display: contents; }
  .tools div button:first-child,
  .tools div button:last-child { border-radius: 10px; }

  .mini { height: 60px; }
  #hint { display: none; }
  body:not(.board-mode) .panel {
    width: auto;
    top: auto;
    max-height: calc(100dvh - var(--tp-safe-top) - var(--tp-bar-room) - var(--tp-safe-bottom) - 12px);
  }
  body:not(.board-mode) .panel > header {
    align-items: center;
    padding: 3px 10px;
  }
  body:not(.board-mode) .panel > header .small { display: none; }
  body:not(.board-mode) .panel h1 { font-size: 1.35rem; }
  #panel-content { min-height: 0; }
  /* The bottom sheet replaces the floating controls on cramped displays. */
  .panel:not([hidden]) ~ .tools,
  .panel:not([hidden]) ~ .status,
  .panel:not([hidden]) ~ .mini { visibility: hidden; }
}

@media (max-width: 419px) and (max-height: 510px) {
  :root { --tp-bar-room: 89px; }
  .brand { min-height: 30px; }
}

@media (max-height: 250px) {
  .status { padding: 5px 7px; line-height: 1.18; }
}

@media (max-height: 210px) {
  .status,
  .mini { display: none; }
}

/* Keep TV mode's exit control behavior: the board itself has "Back to the map." */
.board-mode .panel #close { display: none; }
@media(max-height:520px), (max-width:420px) {
 .board-mode .board-qr{float:none;display:flex;align-items:center;gap:8px;margin:0 0 8px;text-align:left}
 .board-mode .board-qr img{height:48px;width:48px;margin:0}
 .board-mode .board-actions{display:flex;flex-wrap:wrap;gap:4px}
 .board-mode .board-actions .chip{margin:0;min-height:44px}
}
/* Proposed, append after mobile.css only if accepted. */
@media (max-width: 470px), (max-height: 380px) {
  .board-mode #panel-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-content: start;
    column-gap: 8px;
  }
  .board-mode #panel-content > div:has(> .chip) {
    display: flex;
    grid-column: 1 / -1;
    grid-row: 1;
    gap: 4px;
    margin: 8px 0 5px;
  }
  .board-mode #panel-content > div:has(> .chip) > .chip {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 4px 5px;
    margin: 0;
    font-size: .84rem;
    line-height: 1.18;
  }
  .board-mode #panel-content > p {
    grid-column: 1;
    grid-row: 2;
  }
  .board-mode .board-qr {
    float: none;
    grid-column: 2;
    grid-row: 2;
    margin: 5px 0;
  }
  .board-mode #board-arrivals {
    grid-column: 1 / -1;
    grid-row: 3;
  }
}

@media (max-height: 380px) {
  .board-mode .panel > header { padding-block: 8px; }
  .board-mode .panel > header .small { display: none; }
  .board-mode .panel h1 { font-size: clamp(1.55rem, 4vw, 2.2rem); }
  .board-mode .board-qr img { width: 52px; height: 52px; }
}

@media (max-width: 750px) {
  .board-mode .panel {
    inset: var(--tp-safe-top, 8px) var(--tp-safe-right, 8px) var(--tp-safe-bottom, 8px) var(--tp-safe-left, 8px);
    width: auto;
  }
}

body[data-chrome=dark] .panel #close:hover { background: #456359; }

@media (prefers-reduced-motion: reduce) {
  #effects,
  #hint { transition: none; }
}
.top nav [data-language-switch]{flex:0 0 auto;margin-inline-start:3px;border-inline-start:1px solid var(--line);font:650 .78rem system-ui,sans-serif;letter-spacing:.015em}
@media(max-width:680px){.top nav{min-inline-size:0;overflow-x:auto}.top nav [data-language-switch]{min-inline-size:44px;margin-inline-start:1px}}

/* Keep all primary map actions discoverable on narrow phones. The language
   switch stays on the brand row instead of behind the hidden nav scrollbar. */
@media (max-width: 419px) {
  .top {
    width: calc(100% - var(--tp-safe-left) - var(--tp-safe-right));
  }
  .top nav {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(7, minmax(44px, 1fr));
    gap: 0;
  }
  .top nav [data-panel] {
    min-width: 44px;
    white-space: normal;
    padding-inline: 2px;
    line-height: 1.1;
    font-size: .82rem;
  }
  .top nav [data-language-switch] {
    position: absolute;
    z-index: 1;
    inset-block-start: 2px;
    inset-inline-end: 5px;
    min-inline-size: 44px;
    min-block-size: 44px;
    border: 0;
    background: var(--glass);
  }
}
@media (max-width: 419px) and (max-height: 510px) {
  .top nav [data-language-switch] {
    inset-block-start: 0;
    min-height: 33px;
    min-block-size: 33px;
  }
}
