html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1a0e08;
  font-family: system-ui, sans-serif;
  color: #f4e6dc;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

.box {
  position: fixed;
  padding: 10px 14px;
  background: rgba(20, 10, 6, 0.82);
  border: 1px solid rgba(255, 200, 160, 0.3);
  border-radius: 8px;
  font-size: 13px;
  box-sizing: border-box;
}

h1 { margin: 0 0 8px; font-size: 14px; letter-spacing: 0.5px; }
hr { border: 0; border-top: 1px solid rgba(255, 200, 160, 0.2); margin: 8px 0; }
button {
  font: inherit;
  color: #f4e6dc;
  background: #8a3b2a;
  border: 1px solid rgba(255, 200, 160, 0.4);
  border-radius: 5px;
  padding: 3px 9px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #a84b33; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

/* HUD */
#hud { top: 12px; left: 12px; width: min(290px, 30vw); max-height: calc(100vh - 24px); overflow-y: auto; }
.res {
  display: grid;
  grid-template-columns: 10px 22px 1fr auto;
  grid-template-areas: "dot icon name val" ". . rate left";
  column-gap: 4px;
  padding: 3px 0;
}
.res .dot { grid-area: dot; width: 8px; height: 8px; border-radius: 50%; align-self: center; background: #4caf50; }
.res.warn .dot { background: #f2c94c; }
.res.crit .dot { background: #ff4d4d; animation: blink 0.8s infinite; }
.ricon { grid-area: icon; }
.rname { grid-area: name; }
.rval { grid-area: val; font-weight: bold; text-align: right; font-variant-numeric: tabular-nums; }
.rrate { grid-area: rate; font-size: 12px; font-variant-numeric: tabular-nums; }
.rrate.pos { color: #7ee08a; }
.rrate.neg { color: #ff8a7a; }
.rleft { grid-area: left; font-size: 12px; text-align: right; }
.res.warn .rleft { color: #f2c94c; }
.res.crit .rleft { color: #ff4d4d; font-weight: bold; }
.res.crit { background: rgba(255, 60, 60, 0.12); border-radius: 4px; }
@keyframes blink { 50% { opacity: 0.2; } }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.kv span:last-child { text-align: right; }
.bar { height: 8px; background: rgba(255, 255, 255, 0.12); border-radius: 4px; overflow: hidden; margin: 3px 0 2px; }
#roster { margin: 4px 0 2px; }
.crew-row { display: grid; grid-template-columns: 74px 1fr 30px; gap: 6px; align-items: center; font-size: 12px; }
.crew-row .cname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crew-row .cval { text-align: right; }
.crew-row .bar { position: relative; margin: 2px 0; }
.crew-row .fill { height: 100%; background: #4caf50; transition: width 0.2s; }
.crew-row .fill.warn { background: #f2c94c; }
.crew-row .fill.crit { background: #ff4d4d; }
/* the share of maximum health lost to radiation dose, at the bar's right end */
.crew-row .lost { position: absolute; top: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(135deg, rgba(255, 120, 80, 0.55) 0 2px, rgba(0, 0, 0, 0.35) 2px 4px); }
.crew-more { font-size: 11px; opacity: 0.75; }
.warn-text { color: #f2c94c; }
.crit-text { color: #ff6b5a; font-weight: bold; }
#power-note { font-size: 12px; }
#goal { font-size: 12px; line-height: 1.5; }
.small { font-size: 11px; opacity: 0.8; margin-bottom: 2px; }
.effect { margin-top: 6px; padding: 3px 6px; background: rgba(255, 120, 60, 0.2); border-radius: 4px; font-size: 12px; }
.help { margin-top: 8px; font-size: 11px; opacity: 0.6; line-height: 1.5; }

/* Clock */
#clockbox { top: 12px; right: 12px; width: 190px; }
.clockrow { display: flex; justify-content: space-between; }
#clock { font-variant-numeric: tabular-nums; font-weight: bold; }
.sky {
  position: relative;
  height: 40px;
  margin: 6px 0;
  border-bottom: 1px solid rgba(255, 200, 160, 0.4);
  overflow: hidden;
}
#sun { position: absolute; transform: translate(-50%, 50%); transition: left 0.2s linear, bottom 0.2s linear; }
#speed { font-size: 11px; opacity: 0.7; margin-top: 4px; }

/* Side panel */
#panel { top: 164px; right: 12px; width: 320px; max-height: calc(100vh - 304px); overflow-y: auto; }
.ptitle { font-weight: bold; font-size: 15px; display: flex; justify-content: space-between; align-items: center; }
.close { background: none; border: none; padding: 0 4px; }
.sub { opacity: 0.7; font-size: 12px; margin: 2px 0 8px; }
.opt { padding: 6px 0; border-top: 1px solid rgba(255, 200, 160, 0.15); }
.opt.blocked b { opacity: 0.6; }
.orow { display: flex; gap: 6px; align-items: center; }
.orow b { flex: 1; }
.whybtn { background: #2e5a7a; }
.whybtn:hover { background: #3b7099 !important; }
.ocost { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.blk { color: #ff8a7a; }
.bonus { font-size: 12px; color: #f2c94c; margin-top: 2px; }
.why {
  margin-top: 6px;
  padding: 6px 8px;
  background: rgba(46, 90, 122, 0.35);
  border-left: 3px solid #7fc8ff;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.45;
}
.actions { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }

/* Watney messages */
#messages {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-30%);
  width: min(520px, 60vw);
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}
.msg {
  padding: 6px 10px;
  background: rgba(20, 10, 6, 0.85);
  border: 1px solid rgba(255, 200, 160, 0.3);
  border-radius: 6px;
  font-size: 13px;
}
.msg:not(:first-child) { opacity: 0.55; }
.msg.bad { border-color: rgba(255, 90, 70, 0.7); }
.msg.good { border-color: rgba(120, 220, 140, 0.6); }
.msg.tip { border-color: rgba(255, 210, 122, 0.8); background: rgba(60, 44, 18, 0.92); }

#panel[hidden] { display: none; }

/* HUD: mission objectives and buttons */
.mtitle { font-weight: bold; font-size: 13px; margin-bottom: 2px; }
.obj { padding-left: 2px; }
.obj.met { color: #7ee08a; }
.obj .prog { opacity: 0.7; }
.obj.fail { color: #f2c94c; }
.badge { display: inline-block; padding: 0 6px; border-radius: 4px; background: #8a3b2a; font-size: 11px; font-weight: normal; }
.hud-buttons { display: flex; gap: 6px; margin-top: 8px; }
.hud-buttons button { flex: 1; font-size: 12px; background: #3a2418; }
.hud-buttons button:hover { background: #5a3624 !important; }

/* Overlays: intro, missions, end screen */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}
.overlay[hidden] { display: none; }
.screen {
  position: static;
  width: min(720px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 24px;
  font-size: 14px;
  line-height: 1.5;
  background: rgba(20, 10, 6, 0.95);
}
.screen.wide { width: min(980px, 100%); }
.screen h2 { margin: 0 0 8px; font-size: 20px; }
.screen h3 { margin: 16px 0 6px; font-size: 15px; }
.screen h4 { margin: 12px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.75; }
.screen ul { margin: 0; padding-left: 20px; }
.screen p { margin: 0 0 8px; }
.story p { margin: 0 0 8px; }
.log { padding: 8px 12px; border-left: 3px solid #f2c94c; background: rgba(242, 201, 76, 0.07); border-radius: 4px; font-style: italic; }
.lesson { margin: 4px 0 10px; padding: 6px 10px; background: rgba(46, 90, 122, 0.35); border-left: 3px solid #7fc8ff; border-radius: 4px; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.card { padding: 8px 10px; background: rgba(255, 200, 160, 0.07); border: 1px solid rgba(255, 200, 160, 0.18); border-radius: 6px; font-size: 13px; }
.card b { display: block; margin-bottom: 2px; }
.note { margin-top: 10px !important; font-size: 13px; opacity: 0.9; }
.fineprint { margin: 14px 0 0; font-size: 11px; opacity: 0.6; }
.controls { border-collapse: collapse; font-size: 13px; }
.controls td { padding: 2px 16px 2px 0; }
.controls td:first-child { font-weight: bold; white-space: nowrap; }
.screen-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.screen-actions button { font-size: 15px; padding: 6px 16px; }
button.primary { background: #2f7a4a; }
button.primary:hover:not(:disabled) { background: #3a9a5c; }
button:focus-visible { outline: 2px solid #ffd27a; outline-offset: 2px; }

.mission-layout { display: grid; grid-template-columns: 240px 1fr; gap: 20px; margin-top: 8px; }
.mission-list { list-style: none; margin: 0; padding: 0 !important; display: flex; flex-direction: column; gap: 4px; }
.mission-btn { display: flex; width: 100%; gap: 8px; align-items: center; text-align: left; padding: 7px 10px; background: rgba(255, 200, 160, 0.07); }
.mission-btn:hover:not(:disabled) { background: rgba(255, 200, 160, 0.16) !important; }
.mission-btn.selected { background: #8a3b2a; }
.mission-btn.selected:hover { background: #a84b33 !important; }
.mnum { width: 18px; opacity: 0.7; font-variant-numeric: tabular-nums; }
.mname { flex: 1; font-weight: bold; }
.mmark { font-size: 12px; color: #7ee08a; }
.mission-btn:disabled .mmark { color: inherit; }
.diff-row { display: flex; gap: 4px; }
.diff-btn { flex: 1; background: rgba(255, 200, 160, 0.07); }
.diff-btn.selected { background: #8a3b2a; }
.tips-row { display: flex; margin-top: 8px; }
.prio { margin: 6px 0; }
.prio-row { display: flex; gap: 4px; margin-top: 2px; }
.prio-btn { flex: 1; padding: 3px 0; font-size: 12px; background: rgba(255, 200, 160, 0.07); }
.prio-btn.selected { background: #8a3b2a; }
.briefing h3 { margin-top: 0; font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 1px 8px; border-radius: 10px; background: rgba(255, 200, 160, 0.1); font-size: 12px; }
.ptitle .close { font-size: 18px; }
.close[hidden] { display: none; }

.endbox { width: min(520px, 100%); }
.endbox h2 { text-align: center; }
#end-text { font-size: 15px; }
.unlock { color: #f2c94c; font-weight: bold; }

@media (max-width: 700px) {
  .mission-layout, .cards { grid-template-columns: 1fr; }
  .screen { padding: 16px; }
}
