.icon-library { position: absolute; overflow: hidden; }
#map-hud {
  --hud-surface: #102027f2;
  --hud-edge: #446369;
  --hud-text: #ecf3ef;
  --hud-muted: #bacdc5;
  --hud-active: #a3e8b5;
  --hud-top: max(12px, env(safe-area-inset-top));
  --hud-left: max(12px, env(safe-area-inset-left));
  --hud-right: max(12px, env(safe-area-inset-right));
  --hud-bottom: max(12px, env(safe-area-inset-bottom));
  position: absolute;
  inset: 0;
  color: var(--hud-text);
  font: 14px system-ui, sans-serif;
  pointer-events: none;
}
#map-top {
  position: absolute;
  top: var(--hud-top);
  left: var(--hud-left);
  right: var(--hud-right);
  display: grid;
  gap: 8px;
}
#map-top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
#map-info {
  display: grid;
  gap: 2px;
  padding: 8px 12px;
  min-width: 0;
  overflow-wrap: anywhere;
}
#map-info strong { font-size: 15px; }
#map-info span { font-size: 12px; color: var(--hud-muted); }
#map-utilities { flex: none; }
.map-card {
  position: relative;
  box-sizing: border-box;
  width: min(282px, calc(100% - 64px));
  max-height: min(330px, 45dvh);
  padding: 11px 12px;
  border: 1px solid var(--hud-edge);
  border-radius: 8px;
  background: var(--hud-surface);
  box-shadow: 0 5px 20px #0005;
  overflow: auto;
  pointer-events: auto;
}
.map-card h2 { margin: 0 40px 4px 0; font-size: 14px; }
.map-card p { margin: 0; color: var(--hud-muted); font-size: 12px; line-height: 1.4; }
#map-tip p { padding-right: 26px; }
.map-close {
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--hud-text);
  font: 22px system-ui, sans-serif;
  cursor: pointer;
}
#build-palette {
  display: grid;
  grid-template-columns: repeat(auto-fit, 44px);
  width: min(246px, 100%);
}
#housing-palette {
  box-sizing: border-box;
  width: min(328px, 100%);
  padding: 8px;
  overflow: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
}
#housing-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}
#housing-palette button {
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--hud-edge);
  border-radius: 6px;
  color: var(--hud-text);
  background: #263b41;
  font: inherit;
  cursor: pointer;
}
#housing-tabs button {
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 4px 2px;
  font-size: 13px;
  font-weight: 650;
}
#housing-tabs button[aria-selected="true"] {
  border-color: var(--hud-active);
  background: var(--hud-active);
  color: #14261b;
}
.housing-lock { font-size: 11px; font-weight: 500; }
.housing-milestone {
  margin: 8px 2px 0;
  color: var(--hud-text);
  font-size: 12px;
  line-height: 1.4;
}
.housing-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 92px), 1fr));
  gap: 6px;
  margin-top: 8px;
}
.housing-options button {
  display: grid;
  gap: 3px;
  align-content: center;
  justify-items: start;
  padding: 8px;
  text-align: left;
  overflow-wrap: anywhere;
}
.housing-options small { color: var(--hud-muted); font-size: 11px; }
.housing-options small span { display: block; }
#housing-palette button:disabled { opacity: .65; cursor: default; }
#housing-palette :is(button, [role="tabpanel"]):focus-visible {
  outline: 2px solid var(--hud-active);
  outline-offset: 2px;
}
.map-dialog {
  color: #ecf3ef;
  background: #102027;
  border: 1px solid #446369;
  border-radius: 10px;
  box-shadow: 0 10px 42px #0009;
  box-sizing: border-box;
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 16px;
  font: 14px system-ui, sans-serif;
}
.map-dialog::backdrop { background: #071019a8; }
.map-dialog header, .map-dialog nav, .map-dialog footer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.map-dialog header { justify-content: space-between; margin-bottom: 12px; }
.map-dialog h1, .map-dialog h2 { margin: 0; }
.map-dialog h1 { font-size: 20px; }
.map-dialog h2 { margin-top: 14px; font-size: 16px; }
.map-dialog p { line-height: 1.5; }
.map-dialog :is(button, select) {
  min-height: 44px;
  padding: 5px 10px;
  color: inherit;
  border: 1px solid #446369;
  border-radius: 6px;
  background: #233941;
  color-scheme: dark;
  font: inherit;
  cursor: pointer;
}
.map-dialog button:disabled { opacity: .48; cursor: default; }
.map-dialog :is(button, select, input):focus-visible, .map-close:focus-visible {
  outline: 2px solid #a3e8b5;
  outline-offset: 2px;
}
.map-dialog select { max-width: 100%; }
.map-dialog footer { margin-top: 14px; padding-top: 12px; border-top: 1px solid #446369; }
.map-stat-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 8px;
  margin: 9px 0;
  font-size: 13px;
}
.map-stat-list dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
#entry-tip { margin: 12px 0 0; font-size: 13px; line-height: 1.4; color: #bacdc5; }
#map-bottom {
  position: absolute;
  bottom: var(--hud-bottom);
  left: var(--hud-left);
  right: var(--hud-right);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.map-tray {
  border: 1px solid var(--hud-edge);
  border-radius: 10px;
  background: var(--hud-surface);
  box-shadow: 0 5px 20px #0005;
}
.icon-tray {
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 4px;
  width: max-content;
  max-width: 100%;
  pointer-events: auto;
}
.map-icon {
  box-sizing: border-box;
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--hud-text);
  border: 1px solid transparent;
  border-radius: 6px;
  background: #263b41;
  cursor: pointer;
  touch-action: manipulation;
}
.map-icon svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.map-icon:is([aria-pressed="true"], [aria-expanded="true"]) { background: var(--hud-active); color: #14261b; }
.map-icon:hover { border-color: #b1d6b9; }
.map-icon:disabled { opacity: .46; cursor: wait; }
.map-icon:focus-visible, #atlas-panel :is(button, select):focus-visible { outline: 2px solid #a3e8b5; outline-offset: 2px; }
#map-hud [hidden] { display: none; }
#map-zoom {
  position: absolute;
  right: 0;
  bottom: 70px;
  flex-direction: column;
}
#map-message {
  box-sizing: border-box;
  display: flex;
  gap: 8px;
  align-items: center;
  width: max-content;
  max-width: min(460px, 100%);
  padding: 7px 10px;
  margin: 0;
  border-radius: 6px;
  background: var(--hud-surface);
  text-align: center;
  font-size: 13px;
}
#cancel-tool {
  flex: none;
  min-height: 44px;
  padding: 4px 10px;
  border: 1px solid var(--hud-edge);
  border-radius: 6px;
  color: var(--hud-text);
  background: #263b41;
  font: inherit;
  cursor: pointer;
  pointer-events: auto;
}
#atlas-panel {
  position: absolute;
  box-sizing: border-box;
  width: min(360px, calc(100vw - 24px));
  max-height: min(220px, 40dvh);
  overflow: auto;
  left: var(--hud-left);
  bottom: calc(var(--hud-bottom) + 62px);
  padding: 11px 12px;
  background: var(--hud-surface);
  border: 1px solid var(--hud-edge);
  border-radius: 10px;
  pointer-events: auto;
}
#atlas-panel h1 { margin: 0; font-size: 18px; }
#atlas-panel p { margin: 4px 0 8px; color: var(--hud-muted); font-size: 12px; }
.atlas-picker, #atlas-links { display: flex; gap: 5px; flex-wrap: wrap; }
#atlas-panel :is(button, select) {
  box-sizing: border-box;
  min-height: 44px;
  padding: 4px 7px;
  color: var(--hud-text);
  border: 1px solid var(--hud-edge);
  border-radius: 6px;
  font: inherit;
  background: #233941;
  color-scheme: dark;
  cursor: pointer;
}
#atlas-panel .atlas-primary { background: var(--hud-active); color: #14261b; font-weight: 650; }
#atlas-panel button:disabled { opacity: .6; }
#atlas-links { margin-top: 7px; }
#atlas-links button { font-size: 12px; }
#atlas-links small { display: block; margin-top: 2px; color: var(--hud-muted); }
#atlas-legend { display: flex; gap: 14px; margin-bottom: 0 !important; }
#atlas-legend span::before {
  content: '';
  display: inline-block;
  border-top: 2px solid #ffc157;
  width: 15px;
  margin: 0 5px 3px 0;
}
#atlas-legend span + span::before { border-top: 2px dashed #64d5fd; }
@media (max-width: 600px) {
  #atlas-panel { left: 50%; transform: translateX(-50%); }
}
@media (max-width: 380px) {
  #map-zoom { bottom: calc(100% + 12px); }
}
@media (min-width: 381px) and (max-width: 560px), (max-width: 380px) and (max-height: 480px) {
  #map-bottom > :is(#map-message, #land-picker, #housing-palette, #build-palette, #service-palette) {
    max-width: calc(100% - 64px);
    margin-right: 64px;
  }
}
@media (max-width: 380px) and (max-height: 480px) {
  #map-zoom { bottom: 70px; }
}
@media (max-width: 560px) and (max-height: 400px) {
  #map-hud:has(#land-picker:not([hidden]), #housing-palette:not([hidden]), #build-palette:not([hidden]), #service-palette:not([hidden])) #map-tip {
    display: none;
  }
}
@media (max-height: 480px) {
  #housing-palette { max-height: 43dvh; }
  #map-bottom:has(#map-message:not([hidden])) #housing-palette { max-height: 30dvh; }
  #build-palette {
    max-height: 106px;
    overflow: auto;
  }
  .map-card { max-height: 24dvh; }
  #atlas-panel { max-height: 28dvh; }
}

#map-layers {
  justify-self: end;
  display: grid;
  padding: 3px 10px;
  pointer-events: auto;
}
#map-layers label {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
#map-layers input { accent-color: var(--hud-active); }
#housing-design-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
#housing-design, #inspector-upgrade {
  color: var(--hud-text);
  background: #233941;
  color-scheme: dark;
  border: 1px solid var(--hud-edge);
  border-radius: 6px;
  min-height: 44px;
  padding: 5px 10px;
  font: inherit;
}
#inspector-upgrade { margin-top: 8px; cursor: pointer; }
#inspector-upgrade:disabled { opacity: .6; cursor: default; }
.goods-quote:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  margin: 12px 0;
}
.goods-quote label { display: grid; gap: 4px; }
.goods-quote input {
  box-sizing: border-box;
  width: 106px;
  min-height: 44px;
  padding: 5px 9px;
  color: inherit;
  background: #233941;
  border: 1px solid #446369;
  border-radius: 6px;
  font: inherit;
  color-scheme: dark;
}
#goods-offers article { margin-top: 12px; padding-top: 3px; border-top: 1px solid #446369; }
#goods-offers article > button { margin: 0 6px 4px 0; }

#building-inspector:has(#commute-details:not([hidden])) { max-height: min(510px, 58dvh); }
#inspector-commute, #commute-fit, #commute-choice {
  min-height: 44px;
  border: 1px solid var(--hud-edge);
  border-radius: 6px;
  padding: 5px 9px;
  color: inherit;
  color-scheme: dark;
  background: #233941;
  font: inherit;
}
#inspector-commute { margin-top: 8px; cursor: pointer; }
#commute-details { border-top: 1px solid var(--hud-edge); margin-top: 8px; padding-top: 8px; }
#commute-route { display: grid; gap: 5px; margin-top: 6px; }
#commute-choice { width: 100%; min-width: 0; }
.commute-actions, .commute-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.commute-actions { justify-content: space-between; }
.commute-legend { font-size: 11px; }
.commute-legend span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 3px;
  margin: 0 4px 2px 0;
  background: #ffd266;
}
.commute-legend span + span::before { background: #3ee0ff; }
#commute-fit { cursor: pointer; }

#economy-panel { width: min(560px, calc(100vw - 24px)); }
.economy-history {
  --history-produced: #8ce5ad;
  --history-consumed: #8ed8ff;
  --history-shortfall: #ffbb8e;
  margin: 14px 0;
  border-top: 1px solid #446369;
  color: #ecf3ef;
}
.economy-history h3 { margin: 12px 0 4px; font-size: 14px; }
.economy-history p, .economy-history figcaption { margin: 4px 0 8px; color: #bacdc5; font-size: 12px; }
.economy-history-figure { margin: 8px 0 0; }
.economy-history-key {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0 0 4px;
  padding: 0;
  list-style: none;
  font-size: 12px;
}
.economy-history-key li { display: flex; align-items: center; gap: 6px; }
.economy-history-key li::before { content: ""; width: 15px; }
.history-produced::before { border-top: 2px solid var(--history-produced); }
.history-consumed::before { border-top: 2px dashed var(--history-consumed); }
.history-shortfall::before { border-top: 2px dotted var(--history-shortfall); }
#economy-history-chart {
  display: block;
  width: 100%;
  height: clamp(128px, 24dvh, 200px);
  border-radius: 6px;
  background: #0b1920;
}
.economy-history-stock {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0;
  font-size: 12px;
}
.economy-history-stock dt { color: #bacdc5; }
.economy-history-stock dd { margin: 2px 0 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.economy-history summary { padding: 8px 0; cursor: pointer; }
.economy-history :is(summary, .economy-history-table):focus-visible { outline: 2px solid #a3e8b5; outline-offset: 2px; }
.economy-history-table { max-height: 200px; overflow: auto; }
.economy-history-table table { width: 100%; border-collapse: collapse; font-size: 12px; white-space: nowrap; }
.economy-history-table :is(th, td) { padding: 4px; text-align: right; font-variant-numeric: tabular-nums; }
.economy-history-table :is(th, td):first-child { text-align: left; }
.economy-history-table th { position: sticky; top: 0; background: #233941; }
.economy-history-table tbody tr:nth-child(even) { background: #15272f; }
