#town {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #151b18;
}
#town-map {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}
.town-bar,
.town-actions {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #f9ecd1;
  pointer-events: none;
}
.town-bar {
  top: max(12px, env(safe-area-inset-top));
  left: 18px;
  right: 18px;
}
.town-name,
.town-bar > div:last-child,
.town-actions button,
.town-actions > span {
  background: #16201ded;
  border: 1px solid #a18a60b0;
  box-shadow: 0 2px 10px #0005;
}
.town-name {
  padding: 7px 17px;
}
.town-name small {
  display: block;
  font:
    900 10px Cinzel,
    Georgia,
    serif;
  letter-spacing: 0.28em;
  color: #d0b679;
}
.town-name strong {
  font: 700 23px var(--serif);
}
.town-bar > div:last-child {
  display: flex;
  align-items: center;
}
.town-bar #town-character {
  padding: 2px 4px;
}
.town-bar button,
.town-actions button {
  pointer-events: auto;
  border: 0;
  color: #f1e6ce;
  background: transparent;
  padding: 10px;
  font: 600 14px var(--serif);
}
.town-bar button:hover,
.town-actions button:hover,
.map-label:hover {
  color: white;
  background: #504634;
}
.town-actions {
  left: 18px;
  right: 18px;
  bottom: max(16px, env(safe-area-inset-bottom));
  justify-content: flex-start;
}
.town-actions > span,
.town-actions button {
  padding: 10px 13px;
  pointer-events: auto;
  background: #19221eed;
  border: 1px solid var(--rule);
  font-size: 13px;
}
.town-actions #town-expedition {
  margin-left: auto;
  background: #4c4029;
  border-color: #c3a064;
}
.map-label {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  font-size: 14px;
  white-space: nowrap;
  letter-spacing: 0.05em;
  color: #ffebbb;
  border: 1px solid #b59a63bd;
  background: #1d2521eb;
  padding: 8px 14px;
  box-shadow: 0 2px 6px #0007;
  cursor: pointer;
  touch-action: manipulation;
}
/* Invisible margin so a near miss still lands on the name plate. */
.map-label:before {
  content: "";
  position: absolute;
  inset: -10px -12px -14px;
}
.map-label:after {
  content: "";
  position: absolute;
  left: calc(50% - 4px);
  bottom: -5px;
  width: 7px;
  height: 7px;
  background: #222b22;
  border-right: 1px solid #b59a63;
  border-bottom: 1px solid #b59a63;
  transform: rotate(45deg);
}
#adventure-dialog.wide-panel {
  width: min(790px, calc(100vw - 26px));
}
.stage-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}
.stage-card {
  display: flex;
  align-items: center;
  min-width: 0;
  text-align: left;
  border: 1px solid #8f7e51;
  background: #2c3229;
  padding: 0;
  color: #eee3c9;
  overflow: hidden;
}
.stage-card img {
  width: 38%;
  height: 70px;
  object-fit: cover;
}
.stage-card > span {
  padding: 6px 9px;
}
.stage-card b,
.stage-card small {
  display: block;
}
.stage-card b {
  font: 700 18px var(--serif);
  margin-bottom: 4px;
}
.stage-card small,
.board-summary {
  color: #cdc5b1;
  font-size: 12px;
}
.stage-card.locked {
  opacity: 0.71;
  cursor: default;
}
.stage-card.locked img {
  filter: saturate(0.45);
}
.stage-card:not(:disabled):hover {
  border-color: #efcd8b;
  background: #464232;
}
.stage-banner {
  display: block;
  width: 100%;
  max-height: 158px;
  object-fit: cover;
  border: 1px solid var(--rule);
}
.facility-row {
  display: block;
  width: 100%;
  background: #282d27;
  border: 1px solid var(--rule);
  color: var(--ivory);
  margin: 8px 0 0;
  padding: 10px;
  font: 600 15px var(--serif);
}
.difficulty-select {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 15px 0;
}
.difficulty-select select {
  background: #272e28;
  color: var(--ivory);
  border: 1px solid var(--rule);
  padding: 6px 15px;
}
#run-chest {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  border: 1px solid #c2a466;
  background: #322d21ea;
  color: #ffdf94;
  padding: 9px 12px;
  font-size: 13px;
}
#run-chest:disabled {
  opacity: 0.78;
  cursor: default;
}
#run-chest span {
  font-size: 11px;
}
#chain {
  position: absolute;
  top: 83px;
  right: 19px;
  color: #ffe7a5;
  font: bold clamp(16px, 2vw, 27px) var(--serif);
  text-shadow: 0 1px 4px #211604;
  pointer-events: none;
}
.hub-content .primary {
  margin-top: 11px;
}
.reward-lines {
  font-size: 13px;
  line-height: 1.6;
  color: var(--gold);
  margin: 8px 0;
}
.battle-hint {
  color: #c5b690;
}
@media (max-width: 620px) {
  .stage-list {
    grid-template-columns: 1fr;
  }
  .stage-card img {
    height: 48px;
    width: 29%;
  }
  .stage-card b {
    font-size: 15px;
  }
  .stage-card small {
    font-size: 11px;
  }
  .town-name {
    padding: 5px 9px;
  }
  .town-name strong {
    font-size: 18px;
  }
  .town-bar button {
    padding: 8px 5px;
    white-space: nowrap;
    font-size: 12px;
  }
  .town-bar,
  .town-actions {
    left: 8px;
    right: 8px;
    gap: 4px;
  }
  .town-actions > span,
  .town-actions button {
    font-size: 11px;
    padding: 7px;
  }
  .map-label {
    font-size: 12px;
    padding: 7px 10px;
  }
  #run-chest {
    bottom: 49px;
    padding: 5px 8px;
    font-size: 11px;
  }
  #chain {
    top: 59px;
    right: 9px;
  }
}

/* Points waiting to be spent: a dot on the character button. */
#town-character {
  position: relative;
}
#town-character.has-points::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e24a3b;
  border: 1px solid #ffd9c9;
}

/* 排行榜入口：金色字，城鎮頂端列、首頁選單、遠征地圖最上方 */
.town-bar button.rank-button,
.masthead nav button.rank-button {
  color: #ffd36a;
  font-weight: 700;
}
.town-bar button.rank-button::before,
.masthead nav button.rank-button::before,
.rank-links .rank-button::before {
  content: "♛ ";
}
.rank-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 4px;
}
.rank-links .facility-row {
  margin: 8px 0 0;
}
.facility-row.rank-button {
  color: #ffd36a;
  border-color: #c9a24f;
  background: linear-gradient(#3a3324, #282d27);
}
.facility-row.rank-button:hover {
  color: #fff3c9;
  background: #504634;
}
@media (max-width: 740px) {
  .rank-links {
    grid-template-columns: 1fr;
    gap: 0;
  }
}

/* 首頁選單在手機寬度會比畫面寬（加排行榜之前就有 394px），窄螢幕改成可換行 */
@media (max-width: 740px) {
  .masthead {
    height: auto;
    min-height: 82px;
    gap: 6px;
  }
  .masthead nav {
    flex: 1;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 2px;
  }
}
