/* Hearthold UI. Canvas fills the screen; HUD, sheet, menu and toast overlay it. No page scroll. */
:root {
  --bg: #20301f;
  --panel: rgba(28, 36, 26, 0.94);
  --ink: #f3efe2;
  --muted: #b9b49f;
  --accent: #e0a020;
  --good: #3cbe6e;
  --danger: #c0392b;
  --line: rgba(255, 255, 255, 0.14);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: var(--bg); color: var(--ink);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* HUD */
#hud {
  position: fixed; top: 0; left: 0; right: 0;
  padding: calc(6px + var(--safe-t)) calc(8px + var(--safe-r)) 6px calc(8px + var(--safe-l));
  background: linear-gradient(var(--panel), rgba(28, 36, 26, 0.75));
  display: flex; flex-direction: column; gap: 4px;
}
.hud-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.clock { font-weight: 600; }
.version, .quick { color: var(--muted); font-size: 12px; }
.speeds, .hud-end { display: flex; gap: 4px; flex-shrink: 0; }
.hud-end { margin-left: auto; }
.quick { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
/* Phones: the stock summary drops to its own line under the buttons instead of wrapping
   word-by-word into a column and pushing the Menu button off screen. */
@media (max-width: 559px) {
  .hud-row.controls { flex-wrap: wrap; }
  .quick { order: 3; flex-basis: 100%; }
  .btn.plain { padding: 0 10px; }
}

/* Buttons: 44px minimum touch target */
.btn {
  min-height: 44px; min-width: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #3a4a33; color: var(--ink); font: inherit; font-weight: 600;
}
.btn:active { filter: brightness(1.25); }
.btn.on { background: var(--accent); color: #1b1608; }
.btn.primary { background: var(--good); color: #08210f; }
.btn.plain { background: transparent; }
.btn.speed { padding: 0 10px; }
.btn.danger { background: transparent; color: #ff8a7a; border: 1px dashed var(--danger); }
.btn[disabled] { opacity: 0.4; }

/* Sheet: bottom sheet on phones, side panel on wide screens */
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 58vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px calc(14px + var(--safe-r)) calc(12px + var(--safe-b)) calc(14px + var(--safe-l));
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.35);
}
#sheet.hidden, #menu.hidden { display: none; }
@media (min-width: 760px) {
  #sheet {
    left: auto; top: 96px; bottom: 0; width: 340px; max-height: none;
    border-radius: 16px 0 0 0; border-top: 0; border-left: 1px solid var(--line);
  }
}
h3 { margin: 0 0 8px; font-size: 17px; }
h4 { margin: 10px 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 4px 0 8px; }
.muted { color: var(--muted); font-weight: 400; }
.warn { color: #ffb347; }
.why { color: #ffb347; font-size: 13px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; align-items: center; }
.btn-row.close { justify-content: flex-end; }
.info .row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.build-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.build-row.blocked .build-text { opacity: 0.75; }
.chip { display: inline-block; margin: 2px 6px 2px 0; padding: 3px 8px; border-radius: 999px; background: #3a4a33; }
.danger-zone { margin-top: 28px; padding-top: 10px; border-top: 1px dashed var(--danger); }
details summary { padding: 10px 0; color: var(--muted); }

/* Menu + dialogs */
#menu {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.dialog { width: min(420px, 100%); padding: 18px; background: #263122; border: 1px solid var(--line); border-radius: 16px; }
.dialog hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.field { display: block; }
.seed { width: 8em; min-height: 40px; margin-left: 6px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); background: #141a12; color: var(--ink); font: inherit; -webkit-user-select: text; user-select: text; }

/* Toast */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--safe-b));
  max-width: min(90vw, 440px); padding: 10px 16px; border-radius: 12px;
  background: rgba(10, 12, 8, 0.92); color: var(--ink); text-align: center;
  opacity: 0; pointer-events: none; transition: opacity 0.18s;
}
#toast.show { opacity: 1; }

/* Step 4: HUD status row (people, morale, flags, stock), grouped build list, readiness */
.hud-row.status { flex-wrap: wrap; justify-content: flex-start; gap: 4px 6px; }
.hud-row.status .chip { margin: 0; padding: 2px 8px; font-size: 13px; white-space: nowrap; }
.hud-row.status .quick { margin-left: auto; }
.chip.hidden { display: none; }
button.chip.rivals { border: 0; color: inherit; font: inherit; cursor: pointer; background: #3d3a5c; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.6); }
.rival { padding: 8px 0; border-bottom: 1px solid var(--line); }
.rival-head { font-size: 16px; margin-bottom: 4px; }
.chip.flag { background: #7a2f1f; color: #ffd9b0; font-weight: 600; }
.chip.flag.cold { background: #1f4f8b; color: #d6ebff; }
.chip.morale { display: inline-flex; align-items: center; gap: 6px; }
.meter { display: inline-block; width: 44px; height: 8px; border-radius: 4px; background: rgba(0, 0, 0, 0.45); overflow: hidden; }
.meter .fill { display: block; height: 100%; background: var(--good); }
.meter .fill.mid { background: #e0a020; }
.meter .fill.low { background: #d9534f; }
.chip.morale.low b { color: #ff8a7a; }
.chip.morale.mid b { color: #ffd37a; }
/* Phones: the stock line keeps its own row, chips wrap instead of overflowing. */
@media (max-width: 559px) {
  .hud-row.status .quick { margin-left: 0; order: 9; flex-basis: 100%; }
}
@media (max-width: 340px) {
  .meter { width: 30px; }
  .hud-row.status .chip { padding: 2px 6px; font-size: 12px; }
  .btn.speed, .btn.plain { padding: 0 8px; }
  .speeds, .hud-end { gap: 2px; }
}
@media (min-width: 760px) {
  #sheet { top: 118px; }
}

.build-group { border-bottom: 1px solid var(--line); }
.build-group > summary { cursor: pointer; padding: 12px 0; font-weight: 600; color: var(--ink); min-height: 44px; }
.stock-overview details > summary { padding: 8px 0; }
.readiness .ready { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; }
.readiness .ready.ok b { color: var(--good); }
.readiness .ready.short b { color: #ffb347; }
.recipe { font-size: 13px; padding: 4px 0 6px; }
.bar.confirm h3 { color: #ffb3a7; }
.tool-chooser .btn { min-width: 0; padding: 0 10px; }
.crop-chooser { padding: 4px 0 8px; border-bottom: 1px solid var(--line); }
.crop-chooser h4 { margin: 4px 0 6px; }

/* Combat: attack and muster bars, garrison list, defeated rivals, the Under-attack chip */
/* (the muster bar shares the attack bar's stepper) */
.attack-bar .stepper, .muster-bar .stepper { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 4px 0 8px; }
.people-stepper { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 4px 0; }
.people-stepper .count { font-size: 18px; min-width: 64px; text-align: center; }
.attack-bar .stepper .count, .muster-bar .stepper .count { font-size: 20px; min-width: 72px; text-align: center; }
.attack-bar .strength.good { color: var(--good); }
.attack-bar .strength.bad { color: #ffb347; }
.garrison-list .row b { font-weight: 600; }
.chevrons { color: #e8c04a; letter-spacing: 1px; }
.rival.defeated { opacity: 0.6; }
button.chip.flag.attack { border: 0; font: inherit; cursor: pointer; background: #a3281b; color: #fff; animation: pulse-attack 1.4s ease-in-out infinite; }
@keyframes pulse-attack { 50% { background: #7a1d13; } }
