* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #14110d;
  font-family: 'Courier New', monospace;
  color: #e7dcc9;
}

#game-root { position: fixed; inset: 0; overflow: hidden; }

#mine {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.hidden { display: none !important; }

/* ---- HUD ---- */
#hud {
  position: absolute;
  top: 0.9rem;
  left: 0.9rem;
  background: rgba(18, 16, 10, 0.78);
  border: 2px solid #4c5233;
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  font-size: 0.95rem;
  letter-spacing: 1px;
  line-height: 1.5;
  text-shadow: 0 1px 2px #000;
  pointer-events: auto;
  width: 13.5rem;
}

/* ---- Tab bar ---- */
.hud-tabs { display: flex; gap: 0.25rem; margin-bottom: 0.45rem; }
.hud-tab {
  flex: 1;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1;
  padding: 0.32rem 0;
  color: #cbb98a;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid #3c4228;
  border-radius: 5px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}
.hud-tab:hover { border-color: #8fbf55; transform: translateY(-1px); }
.hud-tab.active { border-color: #8fbf55; background: linear-gradient(180deg, #4d6a2a, #38501f); color: #f2e9cf; }

/* ---- Tab pages ---- */
.hud-page { display: none; flex-direction: column; gap: 0.12rem; max-height: 72vh; overflow: auto; }
.hud-page.active { display: flex; }
.hud-page-title {
  color: #93a35f;
  font-size: 0.68rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #3c4228;
}

/* ---- Industry grid ---- */
.hud-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.15rem 0.7rem; margin-top: 0.25rem; }
.hud-cell { display: flex; justify-content: space-between; align-items: baseline; gap: 0.3rem; }
.hud-cell span:last-child { color: #e0b070; font-weight: bold; font-size: 0.95rem; }

/* ---- Control-loop readouts ---- */
.ctl-row { display: flex; align-items: baseline; gap: 0.4rem; }
.ctl-val { color: #e8b25a; font-weight: bold; font-size: 0.9rem; }
.ctl-note { color: #8a7a63; font-size: 0.66rem; font-style: italic; margin-left: auto; text-align: right; }
.ctl-note.ok, .ctl-val.ok { color: #8fbf55; }
.ctl-note.bad, .ctl-val.bad { color: #e0685a; }
#ctl-weak-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #5c8f45, #8fbf55);
  transition: width 0.25s ease, background 0.4s ease;
}

.hud-row { display: flex; align-items: baseline; gap: 0.4rem; }
.hud-label { color: #93a35f; font-size: 0.72rem; min-width: 4.4rem; }
#depth-val, #pop-val, #dis-val { color: #e8b25a; font-weight: bold; font-size: 1.05rem; }
#cin-val { color: #e0685a; font-weight: bold; font-size: 1.05rem; }
#bux-val { color: #d69a5a; font-weight: bold; font-size: 1.05rem; }
.hud-unit { color: #7f8a55; font-size: 0.7rem; }

.hud-support { margin: 0.35rem 0 0.15rem; }
.sup-top { display: flex; justify-content: space-between; align-items: baseline; }
#sup-txt { color: #cbd39a; font-size: 0.8rem; font-weight: bold; }
.sup-bar {
  margin-top: 0.25rem;
  height: 0.55rem;
  background: rgba(0,0,0,0.5);
  border: 1px solid #3c4228;
  border-radius: 4px;
  overflow: hidden;
}
#sup-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #5c8f45, #8fbf55);
  transition: width 0.25s ease, background 0.4s ease;
}
#mule-txt { color: #d8b48a; font-size: 0.8rem; font-weight: bold; }
#mule-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8a5a2c, #c98a3a);
  transition: width 0.25s ease;
}
#wood-txt { color: #a7c98a; font-size: 0.8rem; font-weight: bold; }
#wood-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4a7040, #8fbf55);
  transition: width 0.25s ease;
}

#coin-val, #metal-val { color: #e8c25a; font-weight: bold; font-size: 1.05rem; }
#food-txt { color: #e8c25a; font-size: 0.8rem; font-weight: bold; }
#food-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #b8862c, #e8c25a);
  transition: width 0.25s ease, background 0.4s ease;
}

/* ---- Rachio-dominus HUD line ---- */
#ogre-hud {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid #4a3a52;
}
.ogre-name { color: #cba2e6; font-size: 0.82rem; font-weight: bold; letter-spacing: 0.5px; }
.ogre-skill { color: #e8b25a; font-size: 0.8rem; font-weight: bold; }

/* ---- Rachio-dominus picker ---- */
.ogre-picker { width: min(34rem, 94vw); border-color: #6a4c82; }
.ogre-list { display: flex; flex-direction: column; gap: 0.6rem; }
.ogre-card {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  text-align: left;
  width: 100%;
  padding: 0.7rem 0.9rem;
  font-family: inherit;
  color: #e7dcc9;
  background: rgba(0, 0, 0, 0.32);
  border: 2px solid #4a3a52;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}
.ogre-card:hover { border-color: #a06fd0; background: rgba(40, 30, 48, 0.65); transform: translateY(-1px); }
.ogre-card:active { transform: translateY(1px); }
.ogre-ico { font-size: 1.9rem; line-height: 1; flex: 0 0 auto; }
.ogre-info { display: flex; flex-direction: column; gap: 0.15rem; }
.ogre-cname { color: #d9bff0; font-weight: bold; letter-spacing: 1px; font-size: 0.98rem; }
.ogre-cskill { color: #e8b25a; font-size: 0.78rem; }
.ogre-cblurb { color: #8a7a63; font-size: 0.72rem; font-style: italic; line-height: 1.4; }

/* ---- Town action buttons ---- */
#town-btns {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: flex-end;
}
.town-btn {
  font-family: inherit;
  font-size: 0.82rem;
  letter-spacing: 1px;
  padding: 0.45rem 0.8rem;
  color: #ecdfc4;
  background: rgba(24, 21, 13, 0.82);
  border: 2px solid #4c5233;
  border-radius: 6px;
  cursor: pointer;
  text-shadow: 0 1px 2px #000;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.town-btn:hover { transform: translateY(-1px); border-color: #8fbf55; background: rgba(38, 33, 19, 0.92); }
.town-btn:active { transform: translateY(1px); }

/* ---- Panels (town hall / store) ---- */
.panel-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 7, 4, 0.55);
  z-index: 20;
}
.panel {
  width: min(30rem, 92vw);
  max-height: 88vh;
  overflow: auto;
  background: linear-gradient(180deg, #211d13, #16130c);
  border: 3px solid #4c5233;
  border-radius: 12px;
  box-shadow: 0 0 40px rgba(0,0,0,0.6), inset 0 0 30px rgba(0,0,0,0.4);
  color: #e7dcc9;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid #3c4228;
  color: #e8c25a;
  letter-spacing: 1px;
  font-size: 0.92rem;
}
.panel-x {
  font-family: inherit;
  font-size: 1.3rem;
  line-height: 1;
  color: #cbb98a;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 0.3rem;
}
.panel-x:hover { color: #e8b25a; }
.panel-body { padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }

.pol-group { display: flex; flex-direction: column; gap: 0.45rem; }
.pol-label { color: #93a35f; font-size: 0.74rem; letter-spacing: 1px; }
.pol-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.pol-btn {
  font-family: inherit;
  font-size: 0.82rem;
  letter-spacing: 1px;
  padding: 0.5rem 0.9rem;
  color: #e7dcc9;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid #3c4228;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.pol-btn.wide { width: 100%; text-align: left; }
.pol-btn:hover { border-color: #8fbf55; }
.pol-btn.active {
  border-color: #8fbf55;
  background: linear-gradient(180deg, #4d6a2a, #38501f);
  color: #f2e9cf;
}
.pol-hint { color: #8a7a63; font-size: 0.72rem; font-style: italic; line-height: 1.45; }

/* ---- Public-works build rows ---- */
.works-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  padding: 0.5rem 0.7rem;
  margin-bottom: 0.4rem;
  background: rgba(0,0,0,0.25);
  border: 1px solid #3c4228;
  border-radius: 6px;
}
.works-info { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.works-name { font-size: 0.84rem; color: #cbd39a; font-weight: bold; letter-spacing: 0.5px; }
.works-name .works-ico { margin-right: 0.35rem; }
.works-blurb { font-size: 0.7rem; color: #8a7a63; font-style: italic; line-height: 1.4; }
.works-built { color: #8fbf55; font-weight: bold; font-size: 0.8rem; white-space: nowrap; }
.works-row .pol-btn { white-space: nowrap; }
.pol-btn:disabled { opacity: 0.45; cursor: not-allowed; border-color: #3c4228; }

/* ---- Upkeep sliders ---- */
.slider-row { display: flex; align-items: center; gap: 0.6rem; }
.slider-name { color: #93a35f; font-size: 0.74rem; min-width: 5.6rem; letter-spacing: 0.5px; }
.slider-val { color: #e8b25a; font-size: 0.78rem; font-weight: bold; min-width: 2.6rem; text-align: right; }
.slider-row input[type="range"] {
  flex: 1;
  accent-color: #8fbf55;
  height: 0.4rem;
  cursor: pointer;
}

.store-stats {
  display: flex;
  gap: 0.8rem;
  justify-content: space-around;
  padding: 0.6rem;
  background: rgba(0,0,0,0.3);
  border: 1px solid #3c4228;
  border-radius: 6px;
}
.store-stats > div { display: flex; flex-direction: column; align-items: center; gap: 0.2rem; }
.ss-label { color: #93a35f; font-size: 0.68rem; letter-spacing: 1px; }
.ss-val { color: #e8c25a; font-weight: bold; font-size: 1.2rem; }
.trade-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.5rem 0.7rem;
  background: rgba(0,0,0,0.25);
  border: 1px solid #3c4228;
  border-radius: 6px;
}
.trade-txt { font-size: 0.82rem; color: #cbd39a; }
.trade-txt b { color: #e8b25a; }

/* ---- Smelter panel ---- */
.smelter-panel { border-color: #7a4a32; }
.reagent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.4rem 0.7rem;
  background: rgba(0,0,0,0.25);
  border: 1px solid #3c4228;
  border-radius: 6px;
}
.rg-txt { font-size: 0.8rem; color: #cbd39a; }
.rg-txt b { color: #e8b25a; }
.rg-f { color: #8fa0d0; font-size: 0.72rem; }
.recipe {
  font-size: 0.86rem;
  color: #e0b070;
  letter-spacing: 0.5px;
  padding: 0.32rem 0.55rem;
  background: rgba(0,0,0,0.28);
  border-left: 3px solid #a5623a;
  border-radius: 4px;
}
.recipe-need { font-size: 0.74rem; color: #b3a889; line-height: 1.45; }
.recipe-need b { color: #cbd39a; }
.recipe-need.warn { color: #d69a6a; font-style: italic; }

/* ---- Tech tree / resource-flow chart ---- */
.tech-panel { width: min(58rem, 95vw); border-color: #3f5a63; }
.tech-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.2rem;
  padding: 0.5rem 0.7rem;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid #3c4228;
  border-radius: 6px;
}
.tl-item { display: flex; align-items: center; gap: 0.4rem; font-size: 0.76rem; color: #cbd39a; }
.tl-dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; display: inline-block; }
.tl-dot.done { background: #7fbf55; box-shadow: 0 0 6px rgba(127, 191, 85, 0.6); }
.tl-dot.plan { background: transparent; border: 2px dashed #b89a54; }
.tl-hint { flex: 1 1 14rem; color: #8a7a63; font-size: 0.7rem; font-style: italic; line-height: 1.4; }

.tech-flow { display: flex; flex-direction: column; gap: 0.15rem; }
.tech-tier {
  border: 1px solid #34402c;
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  background: rgba(0, 0, 0, 0.22);
}
.tech-tier-title {
  color: #8fbfd0;
  font-size: 0.72rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}
.tech-nodes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.5rem;
}
.tech-node {
  border: 2px solid #3c4228;
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
  background: rgba(20, 26, 16, 0.6);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.tech-node.done { border-color: #4d6a2a; }
.tech-node.plan { border-style: dashed; border-color: #6a5a30; opacity: 0.82; }
.tn-head { display: flex; align-items: center; gap: 0.4rem; }
.tn-dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; flex: none; }
.tech-node.done .tn-dot { background: #7fbf55; box-shadow: 0 0 5px rgba(127, 191, 85, 0.6); }
.tech-node.plan .tn-dot { background: transparent; border: 2px dashed #b89a54; }
.tn-name { font-size: 0.8rem; font-weight: bold; color: #e2dcc5; line-height: 1.2; }
.tech-node.plan .tn-name { color: #d8c79a; }
.tn-note { font-size: 0.68rem; color: #93876c; font-style: italic; line-height: 1.35; }
.tn-to { font-size: 0.66rem; color: #7fa0b0; letter-spacing: 0.3px; }
.tech-arrow { text-align: center; color: #55663f; font-size: 0.9rem; line-height: 1; padding: 0.05rem 0; }

/* ---- Warning banner ---- */
#warn {
  position: absolute;
  top: 0.9rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(60, 18, 12, 0.86);
  border: 2px solid #a5352a;
  border-radius: 6px;
  padding: 0.4rem 0.9rem;
  font-size: 0.82rem;
  letter-spacing: 1px;
  color: #f0c2ab;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
  animation: pulseWarn 1.1s ease-in-out infinite;
}
@keyframes pulseWarn {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

/* ---- Legend ---- */
#legend {
  position: absolute;
  bottom: 0.9rem;
  left: 0.9rem;
  background: rgba(18, 16, 10, 0.74);
  border: 2px solid #3f4426;
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-size: 0.8rem;
  line-height: 1.55;
  max-width: 21rem;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
.leg-title { color: #9fd06a; letter-spacing: 2px; margin-bottom: 0.3rem; font-size: 0.8rem; }
.leg-line b { color: #cf9d63; }
.leg-hint { margin-top: 0.35rem; color: #8a7a63; font-size: 0.72rem; font-style: italic; }

/* ---- Menu ---- */
#menu {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 28%, rgba(64, 84, 44, 0.4), transparent 62%),
    linear-gradient(180deg, #26251a 0%, #15110b 100%);
  z-index: 10;
}
.menu-panel {
  text-align: center;
  padding: 2.2rem 2.6rem;
  max-width: 30rem;
  border: 3px solid #4c5233;
  border-radius: 12px;
  background: rgba(22, 19, 12, 0.88);
  box-shadow: 0 0 40px rgba(0,0,0,0.6), inset 0 0 30px rgba(0,0,0,0.4);
}
.menu-smoke { font-size: clamp(2.2rem, 8vw, 3.4rem); margin-bottom: 0.4rem; filter: hue-rotate(10deg); }
.menu-title {
  font-size: clamp(2.4rem, 8vw, 4.4rem);
  letter-spacing: 0.45rem;
  color: #e8b25a;
  text-shadow: 0 3px 0 #4d6a2a, 0 5px 8px rgba(0,0,0,0.6);
}
.menu-sub {
  margin-top: 0.25rem;
  color: #9fb073;
  letter-spacing: 3px;
  font-size: clamp(0.78rem, 2.4vw, 1.05rem);
}
.menu-blurb {
  margin: 1.1rem 0 0.4rem;
  color: #b3a889;
  font-size: 0.86rem;
  line-height: 1.55;
}
#play-btn {
  margin-top: 1.2rem;
  font-family: inherit;
  font-size: 1.4rem;
  letter-spacing: 4px;
  padding: 0.7rem 2.8rem;
  color: #16130c;
  background: linear-gradient(180deg, #e8b25a, #c98a3a);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 4px 0 #6a5a1e, 0 6px 12px rgba(0,0,0,0.5);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
#play-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #6a5a1e, 0 9px 16px rgba(0,0,0,0.55); }
#play-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #6a5a1e; }
.menu-controls {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.1rem;
  justify-content: center;
  color: #8a7a63;
  font-size: 0.8rem;
}
.menu-controls b { color: #cf9d63; }
