:root {
  --panel: rgba(20, 12, 12, 0.72);
  --line: rgba(255, 210, 180, 0.16);
  --text: #f6eae0;
  --dim: #c4ab9b;
  --accent: #e8743b;
  --accent2: #ffb37a;
  --water: #5cc8ff;
  --good: #8fd16a;
  --warn: #f2c14e;
  --bad: #ef5d4f;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #120b0b; color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
}
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
#view, #view canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

kbd {
  font: 11px ui-monospace, Consolas, monospace; color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.25); border-bottom-width: 2px; border-radius: 4px;
  padding: 0 5px; background: rgba(0, 0, 0, 0.35); margin-right: 2px;
}

/* ---------- HUD ---------- */
.hud-panel {
  position: fixed; background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); padding: 10px 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}
#hud { top: 14px; left: 14px; width: 270px; }
.clock { display: flex; gap: 8px; align-items: baseline; font-size: 16px; font-weight: 700; }
.clock .speed { margin-left: auto; font-size: 12px; color: var(--accent2); font-weight: 600; }
#weather { color: var(--dim); }
.subline { display: flex; justify-content: space-between; font-size: 12px; color: var(--dim); margin-bottom: 8px; }
.subline b { color: var(--text); }
#scan { color: var(--dim); font-size: 12px; }
#scan.ready { color: var(--good); }
.stats kbd { font-size: 9px; padding: 0 3px; }
#weather.storm { color: var(--warn); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin-bottom: 8px; }
.stats div { display: flex; flex-direction: column; }
.stats span, .tf-head span { color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; }
.stats b { font-size: 14px; font-weight: 600; }
.stats small { color: var(--good); font-weight: 400; font-size: 11px; }
.tf-head { display: flex; justify-content: space-between; margin-bottom: 3px; }
.bar { height: 6px; background: rgba(0, 0, 0, 0.45); border-radius: 4px; overflow: hidden; }
.bar.big { height: 8px; }
.bar > span { display: block; height: 100%; width: 0; background: var(--good); border-radius: 4px; transition: width 0.25s; }
#tfBar { background: linear-gradient(90deg, #c4502a, #e0a050, #8fd16a, #5cc8ff); }
.water > span { background: var(--water) !important; }
.health > span { background: #e06a8a !important; }

#crosshair {
  position: fixed; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; pointer-events: none;
  display: none;
}
#crosshair::before, #crosshair::after {
  content: ""; position: absolute; background: rgba(255, 255, 255, 0.9); box-shadow: 0 0 3px #000;
}
#crosshair::before { left: 10px; top: 3px; width: 2px; height: 16px; }
#crosshair::after { top: 10px; left: 3px; height: 2px; width: 16px; }
body.playing #crosshair { display: block; }

#target { right: 14px; top: 14px; width: 270px; }
#target.hidden { display: none; }
#target h3 { margin: 0; font-size: 16px; }
#target .sub { color: var(--dim); font-size: 12px; margin-bottom: 6px; }
#target .meter { margin: 5px 0; }
#target .meter .lbl { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); margin-bottom: 2px; }
#target .kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12px; margin-top: 6px; }
#target .kv span { color: var(--dim); }
#target .kv b { text-align: right; font-weight: 500; }
#target .status { margin-top: 8px; font-size: 12px; padding: 5px 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.3); }
#target .dist { position: absolute; top: 10px; right: 12px; font-size: 11px; color: var(--dim); }
#target .act { margin-top: 6px; font-size: 12px; color: var(--dim); }
.good { color: var(--good) !important; }
.warn { color: var(--warn) !important; }
.bad { color: var(--bad) !important; }

#hotbarWrap { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); text-align: center; }
#slotName { font-weight: 700; text-shadow: 0 1px 4px #000; margin-bottom: 6px; opacity: 0.9; }
#slotName.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { transform: scale(1.15); color: var(--accent2); } 100% { transform: scale(1); } }
#hotbar { display: flex; gap: 6px; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(6px); }
.slot {
  position: relative; width: 56px; height: 56px; border-radius: 9px; border: 2px solid transparent;
  background: rgba(0, 0, 0, 0.3); display: grid; place-items: center;
}
.slot canvas { width: 44px; height: 44px; }
.slot.active { border-color: var(--accent); background: rgba(232, 116, 59, 0.18); }
.slot kbd { position: absolute; top: 2px; left: 2px; font-size: 9px; padding: 0 3px; }
.slot .cost { position: absolute; bottom: 1px; right: 4px; font-size: 10px; color: var(--accent2); text-shadow: 0 1px 2px #000; }
.slot.broke .cost { color: var(--bad); }

#toasts { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(520px, 90vw); }
.toast {
  background: rgba(20, 12, 12, 0.85); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  padding: 7px 12px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  animation: tin 0.25s ease-out; transition: opacity 0.5s, transform 0.5s; color: var(--text) !important;
}
.toast.good { border-left-color: var(--good); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--bad); }
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- menu ---------- */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10, 5, 5, 0.55); padding: 16px; }
.overlay.hidden { display: none; }
.card {
  width: min(820px, 100%); max-height: 100%; overflow: auto; background: rgba(28, 17, 16, 0.92);
  border: 1px solid var(--line); border-radius: 16px; padding: 22px 26px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.logo { width: 46px; height: 46px; border-radius: 50%; flex: none; background: radial-gradient(circle at 35% 30%, #ffb37a, #c4502a 55%, #5a1d10); box-shadow: 0 0 22px rgba(232, 116, 59, 0.5); }
h1 { margin: 0; font-size: 26px; }
.tag { font-size: 12px; vertical-align: middle; background: var(--accent); color: #1a0d08; border-radius: 5px; padding: 1px 6px; margin-left: 4px; }
.brand p { margin: 2px 0 0; color: var(--dim); }
.card h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--dim); margin: 0 0 8px; }
.cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; margin: 18px 0; }
.cols ol { margin: 0; padding-left: 18px; }
.cols li { margin-bottom: 6px; }
.keys { border-collapse: collapse; font-size: 13px; }
.keys td { padding: 3px 10px 3px 0; color: var(--dim); }
.keys td:first-child { color: var(--text); white-space: nowrap; }

button, .btn {
  font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { background: rgba(255, 255, 255, 0.12); }
button.active { background: rgba(232, 116, 59, 0.3); border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a0d08; font-weight: 700; }
button.primary:hover { background: var(--accent2); }
button.big { width: 100%; padding: 12px; font-size: 16px; }
.menu-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.menu-row .spacer { flex: 1; }
.speeds { display: flex; gap: 6px; align-items: center; }
.speeds span { color: var(--dim); font-size: 12px; margin-right: 2px; }

@media (max-width: 720px) {
  .cols { grid-template-columns: 1fr; }
  #hud, #target { width: 220px; }
}

/* grove health */
.tf-head.grove { margin-top: 9px; }
.hbar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: rgba(0, 0, 0, 0.45); }
.hbar span { height: 100%; width: 0; transition: width 0.3s; }
.hg { background: var(--good); }
.hw { background: var(--warn); }
.hb { background: var(--bad); }
.hd { background: #6b625c; }
.hlegend { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 4px; font-size: 11px; color: var(--dim); }
.hlegend i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 4px; vertical-align: 0; }

/* ore tooltip + mining bar under the crosshair */
#tip {
  position: fixed; left: 50%; top: calc(50% + 22px); transform: translateX(-50%); pointer-events: none;
  background: rgba(20, 12, 12, 0.82); border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px;
  font-size: 13px; text-align: center; white-space: nowrap; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
#tip .val { color: #ffd166; font-weight: 700; }
#tip small { color: var(--dim); }
#tip kbd { font-size: 10px; }
#mine {
  position: fixed; left: 50%; top: calc(50% + 78px); transform: translateX(-50%); width: 160px; height: 8px;
  background: rgba(0, 0, 0, 0.55); border: 1px solid var(--line); border-radius: 5px; overflow: hidden; pointer-events: none;
}
#mine span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #e8743b, #ffd166); }
#tip.hidden, #mine.hidden { display: none; }

/* ice drills in the HUD */
.dlist { font-size: 11px; color: var(--dim); margin-top: 3px; display: flex; flex-direction: column; gap: 1px; }
.dlist b { color: var(--text); font-weight: 600; }
.dlist i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; }
.dlist .more { padding-left: 12px; }

/* weather station */
#wx { left: 14px; bottom: 14px; width: 300px; transition: border-color 0.4s, box-shadow 0.4s; }
.wx-head { display: flex; justify-content: space-between; align-items: center; }
.wx-head span { color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: rgba(143, 209, 106, 0.18); color: var(--good); letter-spacing: 0.04em; }
.pill.night { background: rgba(120, 140, 255, 0.18); color: #a9b8ff; }
.pill.dawn { background: rgba(255, 179, 122, 0.18); color: var(--accent2); }
.pill.warn { background: rgba(242, 193, 78, 0.2); color: var(--warn); }
.pill.storm { background: var(--bad); color: #1a0d08; animation: pulse 1s ease-in-out infinite alternate; }
.pill.frost { background: rgba(170, 225, 255, 0.2); color: #cdeeff; }
@keyframes pulse { from { opacity: 0.65; } to { opacity: 1; } }
#wx.storm { border-color: rgba(239, 93, 79, 0.7); box-shadow: 0 0 24px rgba(239, 93, 79, 0.35), 0 8px 28px rgba(0, 0, 0, 0.35); }
.wx-temp { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 2px; }
.wx-temp b { font-size: 26px; font-weight: 700; }
.wx-temp small { color: var(--dim); font-size: 11px; }
#wxChart { width: 100%; height: 35px; display: block; margin-bottom: 6px; }
.wx-grid { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 2px 8px; font-size: 11px; }
.wx-grid span { color: var(--dim); }
.wx-grid b { font-weight: 600; text-align: right; white-space: nowrap; }
.wx-fc { margin-top: 6px; font-size: 11.5px; color: var(--dim); border-top: 1px solid var(--line); padding-top: 5px; }
.wx-fc b { color: var(--text); font-weight: 600; }
@media (max-height: 700px) { #wxChart { display: none; } }
@media (max-width: 1200px) { #wx { bottom: 104px; } }

/* build stamp */
.ver { font-size: 13px; color: var(--dim); font-weight: 500; vertical-align: middle; }
#verStamp { position: fixed; right: 12px; bottom: 8px; font-size: 20px; color: rgba(225, 215, 208, 0.55); pointer-events: none; text-shadow: 0 1px 2px #000; }

/* rising "+X cr" when credits come in */
.floatcr { position: fixed; transform: translate(-50%, -50%); pointer-events: none; font-size: 22px; font-weight: 800;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.9), 0 2px 3px #000; animation: floatup 1.6s ease-out forwards; z-index: 5; }
.floatcr.big { font-size: 32px; }
@keyframes floatup {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  12% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  25% { transform: translate(-50%, -75%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -260%) scale(1); }
}

button.danger { color: #ffb3aa; border-color: rgba(239, 93, 79, 0.55); background: rgba(239, 93, 79, 0.12); }
button.danger:hover { background: rgba(239, 93, 79, 0.3); color: #fff; }

/* time speed on the HUD: a live indicator driven by T / Shift+T / P (the menu has clickable ones) */
.hudspeed { display: flex; align-items: center; gap: 4px; margin: 2px 0 6px; }
.hudspeed span { color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; margin-right: 2px; }
.hudspeed button { pointer-events: none; padding: 1px 7px; font-size: 11px; border-radius: 6px; font-family: ui-monospace, Consolas, monospace; }
.hudspeed button.active { background: var(--accent); border-color: var(--accent); color: #1a0d08; font-weight: 700; }
.hudspeed .hint { margin-left: auto; color: var(--dim); white-space: nowrap; }
.hudspeed kbd { font-size: 9px; padding: 0 3px; margin: 0; }

/* ---------- touch devices only (body.touch is set when there is no mouse) ---------- */
body.touch { touch-action: none; -webkit-user-select: none; -webkit-touch-callout: none; }
body.touch .hud-panel, body.touch #toasts { pointer-events: none; }
body.touch #hud { transform: scale(0.5); transform-origin: top left; top: 6px; left: 6px; }
body.touch #hlegend, body.touch #drillList, body.touch .hudspeed .hint { display: none; }
body.touch #target { transform: scale(0.5); transform-origin: top right; top: 6px; right: 6px; }
body.touch #wx { display: none; }
body.touch #toasts { transform: translateX(-50%) scale(0.72); transform-origin: top center; top: 52px; }
body.touch #hotbarWrap { transform: translateX(-50%) scale(0.58); transform-origin: top center; top: 4px; bottom: auto; }
body.touch #slotName { display: none; }
body.touch .slot kbd { display: none; }
body.touch #verStamp { display: none; }
body.touch #tip { top: calc(50% + 16px); font-size: 11px; }
#touchUI { display: none; }
body.touch.playing #touchUI { display: block; }
#tStick {
  position: fixed; left: 22px; bottom: 22px; width: 130px; height: 130px; border-radius: 50%; touch-action: none;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.14)); border: 2px solid rgba(255, 220, 190, 0.3);
}
#tKnob {
  position: absolute; left: 39px; top: 39px; width: 52px; height: 52px; border-radius: 50%; pointer-events: none;
  background: rgba(232, 116, 59, 0.55); border: 2px solid rgba(255, 200, 160, 0.7); box-shadow: 0 0 12px rgba(0, 0, 0, 0.4);
}
#tBtns { position: fixed; right: 16px; bottom: 18px; display: grid; grid-template-columns: repeat(3, auto); gap: 10px; align-items: end; justify-items: center; }
.tb {
  width: 62px; height: 62px; border-radius: 50%; padding: 0; touch-action: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1; color: #fff; background: rgba(20, 12, 12, 0.5); border: 2px solid rgba(255, 220, 190, 0.35);
}
.tb small { font-size: 9px; color: var(--dim); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.05em; }
.tb.small { width: 46px; height: 46px; font-size: 15px; }
.tb.big { width: 78px; height: 78px; font-size: 24px; background: rgba(232, 116, 59, 0.45); border-color: rgba(255, 200, 160, 0.7); }
.tb.on { background: rgba(232, 116, 59, 0.8); }
body.touch .card { padding: 14px 16px; }
body.touch .cols { display: none; }
@media (orientation: portrait) { body.touch #hud { transform: scale(0.42); } body.touch #target { display: none; } body.touch #hotbarWrap { top: auto; bottom: 170px; transform-origin: bottom center; transform: translateX(-50%) scale(0.52); } }
.touchhelp { color: var(--dim); font-size: 13px; margin: 10px 2px 0; }

/* ---- rain */
.pill.rain { background: rgba(110, 160, 255, 0.28); color: #d4e4ff; }
#wx.rain { border-color: rgba(120, 170, 255, 0.6); box-shadow: 0 0 24px rgba(110, 160, 255, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35); }

/* ---- tree advice in the target card */
#target .advice { margin-top: 6px; font-size: 12px; line-height: 1.35; color: #ffe2b8; }
#target .advice div { margin-top: 2px; }

/* ---- map (M) */
#map { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(84vh, 92vw); pointer-events: none;
  background: rgba(14, 8, 8, 0.82); border: 1px solid rgba(255, 220, 190, 0.25); border-radius: 18px; padding: 12px; box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6); }
#map.hidden { display: none; }
#mapCv { width: 100%; height: auto; display: block; aspect-ratio: 1; }
#mapStatus { text-align: center; font-size: 13px; margin-top: 8px; color: #f3e6dc; }
#map .maplegend { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; font-size: 12px; color: var(--dim); margin-top: 6px; }
#map .maplegend i, #mapStatus .mk { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
#map .ring, #mapStatus .mk { background: none; border: 2px solid; width: 8px; height: 8px; }
#map .crit, #mapStatus .mk.crit { border-color: #ff5046; }
#map .att, #mapStatus .mk.att { border-color: #ffc850; }
#mapStatus .mk.att { margin-left: 10px; }

/* ---- saved games */
details.saves { margin-top: 14px; border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 10px; }
details.saves summary { cursor: pointer; font-weight: 600; }
details.saves summary small { font-weight: 400; color: var(--dim); }
#slots { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.slotrow { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: rgba(0, 0, 0, 0.25); border-radius: 8px; }
.slotrow .n { width: 18px; text-align: center; color: var(--dim); font-weight: 600; }
.slotrow .info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.slotrow .info small { color: var(--dim); font-size: 11px; }
.slotrow .empty { color: var(--dim); font-style: italic; }
.slotrow button { padding: 4px 10px; font-size: 12px; }
.slotrow button.x { padding: 4px 8px; }
.slotrow button:disabled { opacity: 0.35; cursor: default; }

/* ---- two currencies */
.crmin { color: #ffd166; }
.crorg { color: #8ce27a; }
.slot .cost.org { color: #8ce27a; }
.slot.broke .cost.org { color: var(--bad); }
#hud .stats small { color: var(--dim); font-weight: 400; }
#tip .val.org { color: #8ce27a; }
#tip .bad { color: #ff7a6e; font-weight: 700; } #tip .warn { color: #ffc857; font-weight: 700; }
