/* ============ 归园 · 放逐小镇 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  background: #14181d;
  color: #e8dcc0;
  user-select: none;
  -webkit-user-select: none;
}
#game { position: absolute; inset: 0; display: block; cursor: default; }

#landscape-notice { display: none; }
@media (orientation: portrait) and (max-width: 600px) and (pointer: coarse) {
  #landscape-notice:not([hidden]) {
    position: fixed; inset: 0; z-index: 10001;
    display: grid; place-content: center; gap: 16px;
    padding: 32px; text-align: center;
    color: #e8dcc0; background: #202b29;
  }
  #landscape-notice strong { font-size: 24px; font-weight: 500; }
  #landscape-notice p { max-width: 320px; font-size: 14px; line-height: 1.8; }
  #continue-portrait, #play-landscape {
    justify-self: center; min-height: 44px; padding: 10px 24px;
    border: 1px solid #a8b99a; border-radius: 8px;
    background: #385b49; color: #fff5df; font: inherit; cursor: pointer;
  }
  #continue-portrait:focus-visible, #play-landscape:focus-visible { outline: 2px solid #fff5df; outline-offset: 4px; }
}

#hud { position: absolute; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }

/* ---- 顶栏 ---- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px;
  background: linear-gradient(rgba(24,18,10,0.92), rgba(24,18,10,0.78));
  border-bottom: 1px solid rgba(216,178,90,0.25);
  pointer-events: auto;
  font-size: 13px;
}
#res-row { display: flex; gap: 12px; }
.res { display: flex; align-items: center; gap: 4px; }
.res-icon { position: relative; width: 23px; height: 23px; display: inline-flex; align-items: center; justify-content: center; }
.res-icon img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.res b { color: #fff; font-weight: 600; min-width: 34px; }
.res i { font-style: normal; font-size: 11px; }
.res i.pos { color: #8fc866; }
.res i.neg { color: #e0705a; }
#date { color: #d8b25a; }
#pop small { color: #b8a888; }
.warn-txt { color: #e8a33d; }
#speed { display: flex; gap: 4px; margin-left: auto; }
#speed button, #sys button {
  background: rgba(60,48,30,0.6);
  border: 1px solid rgba(216,178,90,0.25);
  color: #e8dcc0;
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
  font-size: 13px;
}
#speed button.active { background: #6b5426; border-color: #d8b25a; color: #ffe9b0; }
#speed button:hover, #sys button:hover { border-color: #d8b25a; }
#sys { display: flex; gap: 4px; }

/* ---- 建造菜单 ---- */
#toolbar {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px;
  background: rgba(24,18,10,0.88);
  border: 1px solid rgba(216,178,90,0.25);
  border-radius: 10px;
  padding: 8px;
  pointer-events: auto;
}
.tb {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  min-width: 58px;
  background: rgba(60,48,30,0.5);
  border: 1px solid rgba(216,178,90,0.18);
  border-radius: 8px;
  color: #e8dcc0;
  padding: 5px 4px;
  cursor: pointer;
  font-size: 12px;
}
.tb:hover { border-color: #d8b25a; background: rgba(90,70,40,0.55); }
.tb.active { background: #6b5426; border-color: #ffd98a; color: #fff; }
.tb .ic { font-size: 18px; position: relative; display: inline-block; min-width: 22px; height: 22px; line-height: 22px; }
.tb .ic .icimg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; object-fit: contain; }
.tb .cost { font-size: 12px; color: #b8a888; display: flex; align-items: center; justify-content: center; gap: 3px; }
.res-cost { display: inline-flex; align-items: center; gap: 1px; white-space: nowrap; }
.res-cost .res-icon { width: 13px; height: 13px; font-size: 12px; flex: none; }
.tb.active .cost { color: #ffe9b0; }

/* ---- 信息面板 ---- */
#info {
  position: absolute; top: 52px; right: 12px;
  width: 250px;
  background: rgba(24,18,10,0.92);
  border: 1px solid rgba(216,178,90,0.25);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  pointer-events: auto;
  line-height: 1.6;
}
.info-head { display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: #ffd98a; margin-bottom: 4px; }
.info-head button { background: none; border: none; color: #b8a888; cursor: pointer; font-size: 13px; }
#info .row { margin: 2px 0; }
#info .desc { color: #b8a888; font-size: 11.5px; border-top: 1px dashed rgba(216,178,90,0.2); margin-top: 6px; padding-top: 6px; }
#info .danger {
  margin-top: 8px; width: 100%;
  background: rgba(140,50,40,0.5); border: 1px solid rgba(224,112,90,0.4);
  color: #f0b0a0; border-radius: 6px; padding: 4px; cursor: pointer;
}
#info .danger:hover { background: rgba(180,60,45,0.6); }

/* ---- 通知 ---- */
#toasts {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; flex-direction: column; gap: 6px;
  max-width: 380px;
}
.toast {
  background: rgba(24,18,10,0.92);
  border: 1px solid rgba(216,178,90,0.25);
  border-left: 3px solid #b8a888;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12.5px;
  animation: slidein 0.25s ease;
  transition: opacity 0.5s, transform 0.5s;
}
.toast.good { border-left-color: #8fc866; }
.toast.warn { border-left-color: #e8a33d; }
.toast.bad  { border-left-color: #e0705a; }
.toast.out { opacity: 0; transform: translateX(-12px); }
@keyframes slidein { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: none; } }

/* ---- 覆盖层 ---- */
.overlay {
  position: absolute; inset: 0;
  background: rgba(10,8,5,0.66);
  display: flex; align-items: center; justify-content: center;
  pointer-events: auto;
  z-index: 10;
}
.dialog {
  background: linear-gradient(rgba(38,30,18,0.98), rgba(28,22,12,0.98));
  border: 1px solid rgba(216,178,90,0.4);
  border-radius: 12px;
  padding: 26px 34px;
  max-width: 520px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6);
}
.dialog h2 { color: #ffd98a; margin-bottom: 12px; }
.dialog h2 small { font-size: 12px; color: #b8a888; font-weight: normal; margin-left: 8px; }
.dialog h3 { color: #d8b25a; font-size: 14px; margin: 12px 0 4px; }
.dialog p, .dialog li { font-size: 13px; line-height: 1.8; color: #ddd0b0; }
.dialog ul { padding-left: 20px; }
.dialog button {
  margin-top: 16px;
  background: #6b5426; border: 1px solid #d8b25a; color: #ffe9b0;
  border-radius: 8px; padding: 8px 26px; cursor: pointer; font-size: 14px;
}
.dialog button:hover { background: #7d622c; }
#over .dialog h2 { font-size: 22px; }
#over-text strong { color: #ffd98a; }

/* ---- 存档管理 ---- */
.sav-hint { font-size: 12px; color: #b8a888; margin-bottom: 10px; }
.save-row {
  display: flex; align-items: center; gap: 10px;
  background: rgba(60,48,30,0.4);
  border: 1px solid rgba(216,178,90,0.2);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 12.5px;
}
.save-row .sav-name { color: #ffd98a; min-width: 58px; }
.save-row .sav-info { flex: 1; color: #ddd0b0; line-height: 1.5; }
.save-row .sav-info small { display: block; color: #b8a888; font-size: 11px; }
.save-row button {
  background: rgba(107,84,38,0.7); border: 1px solid rgba(216,178,90,0.35);
  color: #ffe9b0; border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12px;
}
.save-row button:hover { background: #7d622c; }
.save-row button.del { background: rgba(120,50,40,0.5); border-color: rgba(224,112,90,0.35); color: #f0b0a0; }
.save-row button.del:hover { background: rgba(170,60,45,0.6); }
.save-empty { color: #b8a888; font-size: 13px; padding: 12px 4px; }
.save-actions { display: flex; gap: 10px; margin-top: 6px; }
.save-actions button {
  background: #6b5426; border: 1px solid #d8b25a; color: #ffe9b0;
  border-radius: 8px; padding: 6px 18px; cursor: pointer; font-size: 13px;
}
.save-actions button:hover { background: #7d622c; }
.save-actions button.clear-all {
  background: rgba(120,50,40,0.55); border-color: rgba(224,112,90,0.4); color: #f0b0a0;
}
.save-actions button.clear-all:hover { background: rgba(170,60,45,0.65); }
.save-actions button.plain {
  background: rgba(60,48,30,0.6); border-color: rgba(216,178,90,0.35); color: #ddd0b0;
}
.save-actions button.plain:hover { background: rgba(90,70,40,0.6); }

/* ---- 服务器存档区 + 存档文件导出/导入 ---- */
#server-saves { margin-top: 12px; border-top: 1px dashed rgba(216,178,90,0.25); padding-top: 10px; }
.server-saves-hint { color: #b8a888; font-size: 11.5px; line-height: 1.6; }
.server-saves-hint code { color: #ffd98a; background: rgba(60,48,30,0.6); border-radius: 4px; padding: 1px 5px; }
.server-saves-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 8px; color: #ffd98a; font-weight: bold; font-size: 13px;
}
.server-saves-head small { color: #b8a888; font-weight: normal; }
.server-save-new { display: flex; gap: 6px; }
.server-save-new input {
  width: 150px; background: rgba(30,24,14,0.8); border: 1px solid rgba(216,178,90,0.35);
  color: #ffe9b0; border-radius: 6px; padding: 4px 8px; font-size: 12px;
}
.server-save-new input:focus { outline: none; border-color: #d8b25a; }
.server-save-new button {
  background: #6b5426; border: 1px solid #d8b25a; color: #ffe9b0;
  border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12px; white-space: nowrap;
}
.server-save-new button:hover { background: #7d622c; }
.save-row.server { border-color: rgba(120,170,220,0.3); }
.save-row.server .sav-name { color: #a8d0f0; }
.file-io-row { display: flex; gap: 10px; margin-top: 10px; }
.file-io-row button {
  background: rgba(60,48,30,0.6); border: 1px solid rgba(216,178,90,0.35); color: #ddd0b0;
  border-radius: 8px; padding: 6px 14px; cursor: pointer; font-size: 12.5px;
}
.file-io-row button:hover { background: rgba(90,70,40,0.6); color: #ffe9b0; }

/* ---- 反馈 ---- */
#fb-text, #fb-fallback-text {
  width: 100%; display: block;
  min-height: 110px; resize: vertical;
  background: rgba(10,8,5,0.5);
  border: 1px solid rgba(216,178,90,0.3);
  border-radius: 6px;
  color: #e8dcc0; font: inherit; line-height: 1.6;
  padding: 8px 10px;
}
#fb-text:focus, #fb-name:focus { outline: none; border-color: #d8b25a; }
#fb .fb-hint { font-size: 12px; color: #b8a888; margin: 2px 0 10px; }
#fb-name, #fb-tag {
  padding: 5px 8px;
  background: rgba(10,8,5,0.5);
  border: 1px solid rgba(216,178,90,0.3);
  border-radius: 6px;
  color: #e8dcc0; font: inherit; font-size: 12.5px;
}
#fb-name { width: 140px; }
#fb-tag option { background: #241f16; color: #e8dcc0; }
.fb-row {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 8px 16px; margin-top: 8px;
  font-size: 12.5px; color: #ddd0b0;
}
.fb-row label { display: flex; align-items: center; gap: 6px; }
.fb-row input[type="checkbox"] { accent-color: #d8b25a; }
.fb-status { min-height: 18px; margin-top: 8px; font-size: 12px; color: #b8a888; }
.fb-status.err { color: #f0b0a0; }
#fb-fallback-text {
  min-height: 120px; margin-top: 8px; cursor: text;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px;
  user-select: text; -webkit-user-select: text;
}

.hidden { display: none !important; }

/* ---- 错误记录 ---- */
.err-pre {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.6;
  color: #f0b0a0;
  background: rgba(10,8,5,0.5);
  border: 1px solid rgba(224,112,90,0.3);
  border-radius: 8px;
  padding: 10px 12px;
  max-width: 460px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---- 护林小屋砍伐/补种开关 ---- */
.tog-row { display: flex; gap: 6px; }
.mini-tog {
  background: rgba(107,84,38,0.7); border: 1px solid rgba(216,178,90,0.35);
  color: #ffe9b0; border-radius: 6px; padding: 2px 9px; cursor: pointer; font-size: 11.5px;
}
.mini-tog:hover { background: #7d622c; }
.mini-tog.off { opacity: 0.5; border-style: dashed; }
.mini-tog.off:hover { opacity: 0.8; }

/* Compact windows keep every tool reachable without replacing the hand-painted palette. */
#toolbar { max-width: calc(100vw - 24px); overflow-x: auto; overflow-y: hidden; scrollbar-width: auto; scrollbar-color: #b79b64 #302619; }
.tb { flex: 0 0 auto; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid #ffe4a0; outline-offset: 2px; }
#topbar { flex-wrap: wrap; gap: 6px 14px; }
#res-row { flex-wrap: wrap; }
#survival-guide, #placement-info, #harvest-cancel { white-space: pre-line; background: rgba(24,18,10,.9); border: 1px solid rgba(216,178,90,.35); border-radius: 8px; padding: 7px 10px; font-size: 12px; line-height: 1.5; }
#survival-guide { position: absolute; left: 12px; top: 90px; width: min(450px, calc(100vw - 24px)); }
#placement-panel { position: absolute; left: 12px; bottom: 114px; width: min(450px, calc(100vw - 24px)); max-height: calc(100vh - 214px); overflow-y: auto; overscroll-behavior: contain; pointer-events: auto; scrollbar-color: #b79b64 #302619; }
#placement-info { border-left: 3px solid #a0c47a; }
#harvest-cancel { margin-bottom: 6px; white-space: normal; }
.harvest-cancel-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.harvest-cancel-buttons button { background: #5c412d; border: 1px solid #c29a70; border-radius: 6px; color: #ffe9ce; padding: 7px 4px; font: inherit; cursor: pointer; overflow-wrap: anywhere; }
.harvest-cancel-buttons button:hover:not([aria-disabled="true"]) { background: #75543a; border-color: #ffe4a0; }
.harvest-cancel-buttons button[aria-disabled="true"] { color: #b8aa99; border-color: #68594a; background: #342c23; cursor: default; }
#harvest-cancel-hint { margin-top: 6px; color: #c7b899; font-size: 11px; }
#harvest-cancel-status:not(:empty) { margin-top: 5px; color: #e5cd95; }
#placement-info[data-state="blocked"] { border-left-color: #e0705a; }
#placement-info[data-state="warning"] { border-left-color: #e8b350; }
#info { top: 90px; max-height: calc(100vh - 210px); overflow-y: auto; }
.dialog { max-height: calc(100vh - 24px); overflow-y: auto; max-width: min(620px, calc(100vw - 24px)); }
#toasts { bottom: 114px; pointer-events: none; }
#hud:has(#placement-info:not(.hidden)) #toasts { left: auto; right: 12px; max-width: max(220px, calc(100vw - 490px)); z-index: 3; }
@media (max-width: 1024px) { #survival-guide { width: min(440px, calc(100vw - 290px)); } #topbar { font-size: 12px; padding: 6px 10px; } #res-row { gap: 7px; } }
@media (max-width: 600px) { #survival-guide { top: 122px; width: calc(100vw - 24px); font-size: 11px; } #info { top: 208px; width: min(280px, calc(100vw - 24px)); max-height: calc(100vh - 325px); } #topbar { gap: 4px 8px; } #placement-panel { max-height: calc(100vh - 260px); } .dialog { padding: 18px; } }
@media (max-width: 600px) { #hud:has(#harvest-cancel:not(.hidden)) #survival-guide { display: none; } }
@media (max-height: 620px) { #hud:has(#placement-info:not(.hidden)) #survival-guide { display: none; } }

/* Production controls stay touch-sized and preserve their DOM/focus on updates. */
.production-goals-dialog { width: min(620px, calc(100vw - 24px)); box-sizing: border-box; }
.production-goal-row { border-top: 1px solid #6c583c; padding: 12px 0; }
.production-goal-row > label { display: flex; align-items: center; gap: 6px; font-weight: bold; color: #ffd98a; }
.production-goal-row p { margin: 6px 0; }
.goal-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.dialog .goal-controls button, #production-goals-close { min-height: 44px; min-width: 44px; margin: 0; padding: 8px 12px; }
.goal-controls input { width: 120px; min-height: 44px; box-sizing: border-box; border: 1px solid #9f8451; border-radius: 5px; padding: 8px; background: #231d16; color: #fff; font-size: 16px; }
.goal-controls input:focus-visible, .goal-controls button:focus-visible { outline: 3px solid #ffd98a; outline-offset: 2px; }
#sys #btn-production-goals { font-size: 13px; padding: 4px 8px; }
@media (max-width: 430px) {
  .production-goals-dialog { padding: 14px; }
  .goal-controls { gap: 6px; }
  .goal-controls input { width: 100px; flex: 1 1 80px; min-width: 70px; }
  .dialog .goal-controls .goal-inherit { flex-basis: 100%; }
}
#road-controls { background: rgba(24,18,10,.94); border: 1px solid #a0c47a; border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.5; }
#road-plan-status { white-space: pre-line; margin: 0 0 8px; }
#road-controls button { min-height: 44px; min-width: 100px; margin: 0 6px 4px 0; }
@media (max-width: 600px), (max-height: 620px) { #hud:has(#road-controls:not(.hidden)) #survival-guide { display: none; } }
#hud:has(#road-controls:not(.hidden)) #toasts { left: auto; right: 12px; max-width: max(220px, calc(100vw - 490px)); z-index: 3; }

#harvest-range-controls { background: rgba(24,18,10,.94); border: 1px solid #d5b16c; border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.5; margin-bottom: 6px; }
#harvest-range-status { white-space: pre-line; margin-bottom: 6px; }
#harvest-range-controls button { min-height: 44px; min-width: 100px; margin: 0 6px 4px 0; }

/* Grouped town management. Panels follow actual HUD/toolbar height as stocks grow. */
#hud { --hud-height: 86px; --toolbar-height: 151px; }
#res-row { flex: 1 1 100%; flex-wrap: wrap; gap: 5px 16px; }
.resource-group { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 11px; }
.food-resources { padding-right: 12px; border-right: 1px solid rgba(216,178,90,.3); }
.res { gap: 3px; white-space: nowrap; }
.res b { min-width: 22px; }
.res-label { color: #cabd9d; font-size: 11px; }
.res-total { padding: 3px 6px; border: 1px solid rgba(216,178,90,.38); border-radius: 6px; background: rgba(99,73,31,.35); }
.res-total .res-label { color: #ffe3a8; }
#date, #pop { white-space: nowrap; }
#pop { display: flex; align-items: center; flex-wrap: wrap; gap: 3px 5px; white-space: normal; }
.town-health { display: inline-block; color: #b9d3a7; border-left: 1px solid rgba(216,178,90,.3); padding-left: 8px; margin-left: 3px; font-size: 11px; white-space: nowrap; }
.town-health.warn-txt { color: #efb3a2; }
#toolbar { display: flex; flex-direction: column; gap: 6px; width: max-content; max-width: min(760px, calc(100vw - 24px)); overflow: visible; }
.toolbar-heading { display: flex; align-items: center; gap: 10px; min-height: 29px; }
#toolbar-path { flex: 1; color: #ead2a0; font-size: 12px; }
.toolbar-nav { min-height: 30px; border: 1px solid #8c7347; border-radius: 5px; padding: 4px 9px; background: #423320; color: #ffe7b1; font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; }
.toolbar-nav:hover { background: #614825; border-color: #d8b25a; }
#toolbar-cancel { border-color: #ae7250; color: #ffd2b8; }
.toolbar-items { display: flex; gap: 6px; width: 100%; max-width: 100%; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; padding: 2px; scrollbar-width: thin; scrollbar-color: #b79b64 #302619; }
#toolbar .tb { min-width: 88px; min-height: 72px; padding: 6px 7px; }
/* Equal top-level hit boxes; detail/cost stays in the second-level tools. */
#toolbar .tb-category {
  --category-card-width: 126px;
  flex: 0 0 var(--category-card-width);
  width: var(--category-card-width); min-width: var(--category-card-width); max-width: var(--category-card-width);
  height: 72px; min-height: 72px; max-height: 72px;
  box-sizing: border-box; padding: 8px 7px; gap: 5px; justify-content: center; overflow: hidden;
}
#toolbar .tb-category .ic { flex: 0 0 26px; width: 26px; min-width: 26px; height: 26px; line-height: 26px; font-size: 20px; text-align: center; }
#toolbar .tb-category .category-label { display: flex; align-items: center; justify-content: center; gap: 4px; max-width: 100%; min-width: 0; height: 18px; line-height: 18px; }
#toolbar .tb-category .lb { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#toolbar .tb-category .category-arrow { flex: none; }
#toolbar-state { color: #c6b79a; font-size: 11px; line-height: 1.5; min-height: 17px; max-width: 730px; }
#survival-guide { top: calc(var(--hud-height) + 10px); }
#info { top: calc(var(--hud-height) + 10px); width: 280px; max-height: calc(100vh - var(--hud-height) - var(--toolbar-height) - 46px); }
#placement-panel { bottom: calc(var(--toolbar-height) + 24px); max-height: calc(100vh - var(--hud-height) - var(--toolbar-height) - 48px); }
#toasts { bottom: calc(var(--toolbar-height) + 24px); }
.resource-output { display: flex; align-items: center; flex-wrap: wrap; gap: 3px; }
.resource-output .res-icon { width: 18px; height: 18px; }
@media (max-width: 760px) {
  #topbar { gap: 5px 10px; }
  #res-row { gap: 4px 10px; }
  .resource-group { gap: 4px 8px; }
  #speed { margin-left: 0; }
  #sys { margin-left: auto; }
  #survival-guide { width: min(420px, calc(100vw - 314px)); }
  #toolbar .tb-category { --category-card-width: 106px; }
}
@media (max-width: 600px) {
  #topbar { padding: 6px 8px; font-size: 11px; }
  .food-resources { padding-right: 0; border: 0; }
  .res-icon { width: 20px; height: 20px; }
  .res-label { font-size: 11px; }
  .res b { min-width: 18px; }
  .resource-group { gap: 3px 9px; }
  .materials-resources .res-label { display: none; }
  #pop small { font-size: 11px; }
  #speed button, #sys button { min-height: 30px; padding: 4px 7px; }
  #sys #btn-production-goals { font-size: 11px; }
  #toolbar { bottom: 6px; max-width: calc(100vw - 12px); padding: 6px; gap: 4px; }
  #toolbar-path { font-size: 11px; }
  .toolbar-heading { gap: 6px; }
  .toolbar-nav { min-height: 40px; padding: 5px 8px; }
  #toolbar .tb:not(.tb-category) { min-width: 86px; }
  #toolbar-state { max-width: calc(100vw - 30px); }
  #survival-guide { width: calc(100vw - 24px); font-size: 11px; }
  #info { width: min(300px, calc(100vw - 24px)); top: calc(var(--hud-height) + 10px); max-height: calc(100vh - var(--hud-height) - var(--toolbar-height) - 34px); }
  #hud:has(#info:not(.hidden)) #survival-guide { display: none; }
  #placement-panel { bottom: calc(var(--toolbar-height) + 16px); }
}

/* Compact real-economy controls in the selected-building panel. */
.economy-details { margin-top: 8px; padding-top: 5px; border-top: 1px solid rgba(216,178,90,.3); }
.resource-chain-details { margin-top: 8px; padding-top: 5px; border-top: 1px solid rgba(216,178,90,.3); }
.resource-chain-target { align-items: center; flex-wrap: wrap; }
.resource-chain-target > span { flex: 1 1 150px; }
.resource-chain-target .mini-tog { min-width: 32px; min-height: 32px; }
.economy-details p, .trade-inventory p { white-space: pre-line; }
.economy-form { margin: 9px 0; padding: 9px; background: rgba(77,59,31,.25); border: 1px solid rgba(216,178,90,.25); border-radius: 6px; }
.economy-form h3 { font-size: 12px; color: #ffd98a; margin-bottom: 6px; }
.economy-form label { display: block; color: #d8c5a0; margin-top: 5px; font-size: 11px; }
.economy-form select, .economy-form input { width: 100%; min-height: 34px; padding: 4px 6px; border: 1px solid #816940; border-radius: 4px; background: #282015; color: #f4e5c3; font: inherit; }
.economy-form select option { background: #282015; color: #f4e5c3; }
.economy-form button { min-height: 34px; margin-top: 7px; padding: 5px 8px; border: 1px solid #a98c4f; border-radius: 5px; background: #5b4525; color: #ffe4a0; font: inherit; cursor: pointer; }
.economy-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.economy-form button:disabled { opacity: .5; cursor: default; }
.economy-message { color: #e6ca85; margin-top: 6px; }
.trade-quote { border-left: 2px solid #c7a35b; padding-left: 7px; margin-top: 8px; color: #f4ddb0; }
.trade-inventory { margin: 6px 0; padding: 6px; border: 1px dashed #79643e; border-radius: 5px; }
.trade-inventory summary { cursor: pointer; color: #e5c88c; }
.trade-inventory p { padding-top: 6px; font-size: 11px; }
@media (max-width: 600px) { .economy-form select, .economy-form input, .economy-form button { min-height: 42px; font-size: 13px; } }

/* Town records and the explicit migration decision share one persistent panel. */
.townhall-details { margin-top: 7px; padding-top: 5px; border-top: 1px solid rgba(216,178,90,.3); }
.townhall-offer { border-color: #c69c4b; background: rgba(101,74,30,.3); }
.townhall-offer p { margin: 6px 0; white-space: pre-line; overflow-wrap: anywhere; }
.townhall-choice-note { color: #ffd59a; border-left: 2px solid #d4a35c; padding-left: 7px; }
.townhall-offer .economy-actions button { flex: 1 1 100px; }
.townhall-offer button:focus-visible, .townhall-ledger summary:focus-visible { outline: 2px solid #ffe4a0; outline-offset: 3px; }
.townhall-ledger { margin-top: 8px; padding-top: 6px; border-top: 1px dashed #79643e; }
.townhall-ledger summary { cursor: pointer; color: #e5c88c; }
.townhall-ledger p { margin: 6px 0; }
.townhall-ledger-rows { max-height: 180px; overflow-y: auto; white-space: pre-line; font-size: 11px; font-variant-numeric: tabular-nums; }
/* Flow facts share stable cells; disclosures and scroll/focus survive live refresh. */
.townledger-flows { overflow-wrap: anywhere; }
.townledger-flows details { margin-top: 9px; }
.townledger-flows summary { min-height: 28px; }
.townledger-table-wrap { overflow-x: auto; margin: 7px 0; scrollbar-color: #b79b64 #302619; }
.townledger-table-wrap:focus-visible { outline: 2px solid #ffe4a0; outline-offset: 2px; }
.townledger-table { width: 100%; border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; }
.townledger-table caption { text-align: left; color: #efd7a4; font-size: 12px; font-weight: bold; }
.townledger-table th, .townledger-table td { padding: 3px 4px; border-bottom: 1px solid rgba(216,178,90,.15); text-align: right; }
.townledger-table th:first-child { text-align: left; width: 30%; min-width: 52px; font-weight: normal; }
.townledger-table td { white-space: nowrap; }
.townledger-table thead th { color: #c8b891; font-weight: normal; }
.townledger-stock { color: #c8b891; }
.townledger-note { color: #c8b891; font-size: 11px; }
.townledger-today { margin-top: 10px; padding-top: 5px; border-top: 1px dashed #79643e; }
.townledger-today h3 { margin: 3px 0; font-size: 12px; color: #efd7a4; }

/* Food-first brewing controls stay mounted while stock and visitors change. */
.tavern-details, .citizen-leisure { margin-top: 7px; padding-top: 5px; border-top: 1px solid rgba(216,178,90,.3); }
.tavern-details p { overflow-wrap: anywhere; }
.tavern-reserve { margin: 8px 0; padding: 8px; border: 1px solid #987641; border-radius: 6px; background: rgba(97,70,29,.25); }
.tavern-actions { display: flex; gap: 8px; margin-top: 7px; }
.tavern-actions button { flex: 1; min-height: 36px; padding: 5px 9px; border: 1px solid #ad8d4d; border-radius: 5px; background: #594321; color: #ffe4a0; font: inherit; cursor: pointer; }
.tavern-actions button:hover { background: #75582b; }
.tavern-actions button:disabled { opacity: .45; cursor: default; }
.tavern-actions button:focus-visible { outline: 2px solid #ffe4a0; outline-offset: 3px; }
@media (max-width: 600px) { .tavern-actions button { min-height: 44px; } }

/* Tailor recipes and clothing facts keep their controls mounted across updates. */
.tailor-details, .citizen-clothing { margin-top: 7px; padding-top: 5px; border-top: 1px solid rgba(216,178,90,.3); }
.tailor-details p, .citizen-clothing .row { overflow-wrap: anywhere; }
.tailor-recipe select:focus-visible { outline: 2px solid #ffe4a0; outline-offset: 3px; }
.tailor-details [data-tailor="batches"] { white-space: pre-line; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) { .tailor-recipe select { min-height: 44px; } }
.farm-details { margin-top: 7px; padding-top: 5px; border-top: 1px solid rgba(216,178,90,.3); }
.farm-details p { overflow-wrap: anywhere; }
.farm-details [data-farm="current"], .farm-details [data-farm="choice"] { color: #f4ddb0; }
.farm-details [data-farm="progress"], .farm-details [data-farm="stock"] { font-variant-numeric: tabular-nums; }
.farm-crop select:focus-visible { outline: 2px solid #ffe4a0; outline-offset: 3px; }
.farm-crop select option:disabled { color: #ad9b7b; }
@media (max-width: 600px) { .farm-crop select { min-height: 44px; } }

.school-details,.student-details { border-top:1px solid #6d5a3c; margin-top:8px; padding-top:6px; }
.school-details [data-school="students"] { font-size:12px; overflow-wrap:anywhere; }
.school-leave-confirm { margin-top:8px; padding:8px; border:1px solid #af7256; }
.school-leave-confirm p { font-size:12px; }
.school-leave-confirm button { margin:4px 4px 0 0; }

/* Workforce facts update in place alongside the existing building controls. */
.workforce-details p { overflow-wrap: anywhere; }
.workforce-details [data-workforce] { font-variant-numeric: tabular-nums; }
.workforce-overview { margin-top: 7px; padding-top: 6px; border-top: 1px dashed #79643e; }
.workforce-overview summary { color: #e5c88c; cursor: pointer; }
.workforce-details input:focus-visible, .workforce-details button:focus-visible, .workforce-overview summary:focus-visible { outline: 2px solid #ffe4a0; outline-offset: 3px; }

/* Destructive home conversion has an explicit, persistent review step. */
.house-upgrade-materials { width: 100%; border-collapse: collapse; table-layout: fixed; margin: 10px 0 6px; font-variant-numeric: tabular-nums; }
.house-upgrade-materials caption { text-align: left; color: #e5c88c; font-weight: 700; margin-bottom: 6px; }
.house-upgrade-materials th, .house-upgrade-materials td { padding: 6px 4px; text-align: right; border-bottom: 1px solid rgba(216,178,90,.18); overflow-wrap: anywhere; }
.house-upgrade-materials thead th { color: #cbb990; font-size: .9em; font-weight: 400; }
.house-upgrade-materials th:first-child { text-align: left; }
.house-upgrade-materials td:last-child, .house-upgrade-materials thead th:last-child { color: #ffe4a0; background: rgba(216,178,90,.08); font-weight: 700; }
.house-upgrade-group { border-top: 1px solid rgba(216,178,90,.22); margin-top: 12px; padding-top: 10px; }
.house-upgrade-details h4 { margin: 0 0 5px; color: #e5c88c; font-size: 1em; }
.house-upgrade-details .house-upgrade-note { color: #cbb990; font-size: .9em; }
.house-upgrade-details .house-upgrade-warning { margin: 12px 0; }
.house-upgrade-warning h4:not(:first-child) { margin-top: 10px; }
.house-upgrade-secondary { margin: 10px 0; }
.house-upgrade-secondary summary { cursor: pointer; color: #cbb990; padding: 5px 0; }
.house-upgrade-secondary summary:focus-visible { outline: 2px solid #ffe4a0; outline-offset: 3px; }

.house-upgrade-details p { margin: 6px 0; overflow-wrap: anywhere; }
.house-upgrade-details [data-house-upgrade] { font-variant-numeric: tabular-nums; }
.house-upgrade-warning, .house-upgrade-confirm { padding: 8px; border-left: 2px solid #b97d57; background: rgba(120, 62, 32, .2); color: #ffd5b1; }
.house-upgrade-confirm { margin-top: 8px; border: 1px solid #af7256; border-radius: 5px; }
.house-upgrade-details button[aria-disabled="true"] { opacity: .55; cursor: default; }
.house-upgrade-details button:focus-visible { outline: 2px solid #ffe4a0; outline-offset: 3px; }
.house-upgrade-confirm .economy-actions button { flex: 1 1 120px; }
@media (max-width: 600px) { .house-upgrade-details button { min-height: 44px; } }

/* Farm rectangle preview shares the bounded placement panel, not a new menu. */
#farm-plan-controls, #pasture-plan-controls, #orchard-plan-controls, #cemetery-plan-controls { background: rgba(24,18,10,.94); border:1px solid #c1b371; border-radius:8px; padding:8px 10px; font-size:12px; line-height:1.5; }
#farm-plan-status, #pasture-plan-status, #orchard-plan-status, #cemetery-plan-status { white-space:pre-line; margin:0 0 8px; }
#farm-plan-controls button, #pasture-plan-controls button, #orchard-plan-controls button, #cemetery-plan-controls button { min-height:44px; min-width:100px; margin:0 6px 4px 0; }
@media (max-width:600px), (max-height:620px) { #hud:has(#farm-plan-controls:not(.hidden)) #survival-guide, #hud:has(#pasture-plan-controls:not(.hidden)) #survival-guide, #hud:has(#orchard-plan-controls:not(.hidden)) #survival-guide, #hud:has(#cemetery-plan-controls:not(.hidden)) #survival-guide { display:none; } }

/* Start choices use the established warm dialog and original resource icons. */
#new-game-settings { z-index: 11; }
.start-settings-dialog { width: min(660px, calc(100vw - 24px)); max-width: min(660px, calc(100vw - 24px)); box-sizing: border-box; }
.start-seed-row { display:flex; flex-wrap:wrap; gap:8px; align-items:end; }
.start-seed-row label { flex:1 1 180px; color:#eeddb7; font-size:13px; }
#new-game-seed { display:block; width:100%; min-height:44px; box-sizing:border-box; margin-top:5px; background:#1b170f; border:1px solid #b09556; border-radius:6px; color:#ffefc6; font:16px monospace; padding:8px; }
#new-game-settings button { min-height:44px; margin-top:8px; padding:8px 12px; }
.start-presets { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin:12px 0; }
.start-presets button { text-align:left; display:flex; flex-direction:column; gap:7px; background:#30291a; border-color:#776343; color:#e4d6b7; }
.start-presets button[aria-pressed="true"] { background:#4b4127; border:2px solid #d8b25a; }
.start-presets strong { font-size:15px; color:#ffde91; }
.start-presets span { font-size:12px; line-height:1.6; }
.start-presets img { width:20px; height:20px; object-fit:contain; vertical-align:middle; }
#new-game-summary, #new-game-confirm-summary { white-space:pre-line; }
#new-game-review { border:1px solid #b58c53; border-radius:8px; padding:10px 12px; margin-top:12px; background:rgba(110,62,28,.2); }
#new-game-confirm { background:#76532e; }
@media(max-width:480px) { .start-presets { grid-template-columns:1fr; } .start-settings-dialog { padding:16px; } .start-seed-row button { flex:1; } }

/* Construction delivery keeps material facts readable in the existing panel. */
.site-materials { white-space: pre-line; }

#meal-transition-notice:not([hidden]) { position:fixed; left:50%; transform:translateX(-50%); top:74px; z-index:12; max-width:700px; width:calc(100% - 32px); padding:10px 14px; border:1px solid #bb9c60; border-radius:8px; background:#fff1cd; color:#513b20; font-size:13px; line-height:1.5; pointer-events:none; }

/* Building inspector: a compact summary, then task-specific detail panes. */
#info:has(.building-detail-tabs) { width: min(352px, calc(100vw - 24px)); padding: 10px; font-size: 12px; line-height: 1.45; overscroll-behavior: contain; }
#info .building-status { padding: 7px 9px; margin: 7px 0; border-left: 3px solid #d8b25a; background: rgba(216,178,90,.08); overflow-wrap: anywhere; }
#info [data-building-activity] { color: #c6bda9; font-size: 11px; margin-bottom: 8px; }
.building-detail-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 6px 0 8px; border-bottom: 1px solid #5a4c32; }
.building-detail-tabs button, .building-quick-actions button { min-height: 36px; padding: 6px 8px; color: #e7dcc7; background: #30291e; border: 1px solid #665334; border-radius: 5px; font: inherit; cursor: pointer; }
.building-detail-tabs button[aria-pressed="true"] { color: #211b11; background: #d8b25a; border-color: #e8c674; font-weight: 650; }
#info .building-detail-tabs button:focus-visible, #info .building-quick-actions button:focus-visible, #info .building-help summary:focus-visible { outline: 2px solid #fff0b5; outline-offset: 2px; }
.building-detail-panel { padding-top: 9px; min-width: 0; overflow-wrap: anywhere; }
.building-detail-panel.hidden { display: none !important; }
.building-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin: 0 0 9px; }
.building-facts > div { padding: 7px 9px; border: 1px solid rgba(216,178,90,.16); border-radius: 5px; background: rgba(255,255,255,.025); }
.building-facts > div:last-child:nth-child(odd) { grid-column: 1 / -1; }
.building-facts dt { font-size: 11px; color: #b7aa91; }
.building-facts dd { margin: 3px 0 0; color: #f1e7d2; font-variant-numeric: tabular-nums; }
.building-quick-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px; }
.building-quick-actions button { flex: 1; }
#info .building-help { border-top: 1px solid rgba(216,178,90,.16); margin-top: 8px; padding-top: 6px; }
#info .building-help summary { color: #cfbd98; cursor: pointer; min-height: 28px; display: list-item; }
#info .building-detail-panel h3 { font-size: 12px; margin: 5px 0 7px; color: #e3c88d; }
#info .building-detail-panel .economy-form { margin: 7px 0; padding: 8px; }
#info .building-detail-panel .desc { font-size: 11px; line-height: 1.5; }
#info .building-detail-panel input, #info .building-detail-panel select { max-width: 100%; box-sizing: border-box; }
@media (max-width: 600px) {
  #info:has(.building-detail-tabs) { right: 8px; width: min(352px, calc(100vw - 16px)); box-sizing: border-box; }
  .building-detail-tabs button, .building-quick-actions button { min-height: 40px; }
}
#info .building-task { margin: 7px 0; border: 1px solid rgba(216,178,90,.22); border-radius: 5px; padding: 7px; }
#info .building-task > summary { cursor: pointer; min-height: 26px; color: #edd59e; font-weight: 600; }
#info .building-task[open] > summary { border-bottom: 1px solid rgba(216,178,90,.18); margin-bottom: 7px; }
#info .building-alert { color: #ffd194; background: #513520; border: 1px solid #a7783c; padding: 7px; border-radius: 5px; }
