:root {
  --desk: #c0c0c0;
  --face: #dddddd;
  --hilite: #ffffff;
  --shadow: #888888;
  --ink: #000000;
  --title: #cccccc;
  --panel: #000000;
  --green: #33ff66;
  --cyan: #66ddff;
  --blue: #7799ff;
  --yellow: #ffe14a;
  --white: #f4f4f4;
  --magenta: #ff66cc;
  --red: #ff5555;
  --gold: #c9a227;
  --menu: #ffffff;
  --font-ui: Charcoal, Chicago, Geneva, "Lucida Grande", "Segoe UI", Tahoma, sans-serif;
  --font-times: "Times New Roman", Times, serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--desk);
  color: var(--ink);
  font: 12px/1.25 var(--font-ui);
  overflow: hidden;
  user-select: none;
  cursor: default;
}
button, input { font: inherit; }
button { cursor: pointer; }

#desktop {
  position: relative;
  width: 100%; height: 100%;
  background:
    repeating-conic-gradient(#b8b8b8 0% 25%, #c8c8c8 0% 50%) 0 0 / 4px 4px;
}

/* Menu bar */
#menubar {
  position: absolute; left: 0; right: 0; top: 0; height: 20px;
  background: var(--menu);
  border-bottom: 1px solid #000;
  display: flex; align-items: stretch;
  z-index: 50;
  box-shadow: 0 1px 0 #fff;
}
#menubar .apple {
  width: 28px; display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
#menubar .item {
  padding: 0 10px;
  display: flex; align-items: center;
  position: relative;
}
#menubar .item:hover, #menubar .item.open {
  background: #000; color: #fff;
}
#menubar .grow { flex: 1; }
#menubar .clock {
  padding: 0 10px;
  display: flex; align-items: center;
  font-variant-numeric: tabular-nums;
}
.menu-drop {
  display: none;
  position: absolute;
  top: 20px; left: 0;
  min-width: 210px;
  background: #fff;
  border: 1px solid #000;
  box-shadow: 2px 2px 0 #000;
  padding: 2px 0;
  z-index: 60;
}
#menubar .item.open .menu-drop { display: block; }
.menu-drop button, .menu-drop .row {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
  background: none; border: 0;
  text-align: left;
  padding: 3px 16px 3px 14px;
  color: inherit;
}
.menu-drop button:hover, .menu-drop .row:hover {
  background: #000; color: #fff;
}
.menu-drop button:disabled { color: #999; }
.menu-drop button:disabled:hover { background: none; color: #999; }
.menu-drop .sep { height: 1px; background: #000; margin: 3px 8px; }
.menu-drop kbd {
  font: 11px var(--font-ui);
  opacity: 0.7;
}

/* Title */
#title-screen {
  position: absolute; inset: 20px 0 0 0;
  background: #000;
  overflow: hidden;
  z-index: 40;
}
#title-screen .planet {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}
#title-screen .scrim {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(0,0,0,.72) 0%, rgba(0,0,0,.28) 55%, rgba(0,0,0,.08) 100%);
}
#title-block {
  position: absolute; left: 36px; top: 28px; z-index: 2;
  color: #fff;
  text-shadow: 0 2px 0 #400;
}
#title-block h1 {
  margin: 0;
  font: italic 700 54px/0.95 var(--font-times);
  color: #c41212;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 #400, 0 0 18px rgba(180,0,0,.35);
}
#title-block .byline {
  margin: 8px 0 0;
  font: italic 16px var(--font-times);
  color: #ffd36a;
}
#title-block .ver {
  margin: 4px 0 0;
  color: #9aa;
  font-size: 11px;
  letter-spacing: 0.08em;
}
#story-wrap {
  position: absolute;
  left: 36px; top: 150px; bottom: 110px;
  width: min(520px, 52vw);
  overflow: hidden;
  z-index: 2;
  mask-image: linear-gradient(transparent, #000 8%, #000 92%, transparent);
}
#story {
  color: #d8c98a;
  font: 15px/1.55 var(--font-times);
  white-space: pre-wrap;
  animation: crawl 90s linear infinite;
}
@keyframes crawl {
  0% { transform: translateY(40%); }
  100% { transform: translateY(-100%); }
}
#title-controls {
  position: absolute; left: 36px; bottom: 22px; z-index: 2;
  display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap;
}
.skill-box { color: #cfc; }
.skill-box .lbl { font-size: 11px; margin-bottom: 4px; color: #9c9; }
.skill-grid { display: grid; grid-template-columns: repeat(10, 22px); gap: 3px; }
.skill-grid button {
  width: 22px; height: 18px; padding: 0;
  background: #0a5a12; color: #cfc; border: 1px solid #3f3;
}
.skill-grid button.on { background: #2f2; color: #031; font-weight: 700; }
#title-controls .actions { display: flex; gap: 8px; }

/* Game layout */
#game-screen {
  position: absolute; inset: 20px 8px 8px 8px;
  display: grid;
  grid-template-columns: 1fr 292px;
  grid-template-rows: 1fr;
  gap: 8px;
}
#game-screen.hidden, #title-screen.hidden, .hidden { display: none !important; }
#col-right {
  display: grid;
  grid-template-rows: minmax(150px, 0.9fr) minmax(180px, 1.15fr) minmax(150px, 0.85fr);
  gap: 8px;
  min-height: 0;
}

.mac-win {
  background: var(--face);
  border: 1px solid #000;
  box-shadow: inset -1px -1px 0 var(--shadow), inset 1px 1px 0 var(--hilite), 2px 2px 0 rgba(0,0,0,.25);
  display: flex; flex-direction: column;
  min-height: 0;
  position: relative;
}
.mac-win .tb {
  height: 18px;
  background: repeating-linear-gradient(to bottom, #eee 0 1px, #bbb 1px 2px);
  border-bottom: 1px solid #000;
  display: flex; align-items: center;
  position: relative;
  flex: 0 0 auto;
}
.mac-win.active .tb {
  background: repeating-linear-gradient(to bottom, #ddd 0 1px, #888 1px 2px);
}
.mac-win .tb .close {
  width: 11px; height: 11px; margin-left: 5px;
  background: #ddd;
  border: 1px solid #000;
  box-shadow: inset 1px 1px 0 #fff;
  z-index: 1;
}
.mac-win .tb .name {
  position: absolute; left: 50%; transform: translateX(-50%);
  background: var(--face);
  padding: 0 8px;
  font-size: 11px;
}
.mac-win .body {
  flex: 1;
  min-height: 0;
  background: var(--panel);
  color: var(--white);
  overflow: hidden;
  position: relative;
}

#map {
  width: 100%; height: 100%;
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
}

.panel {
  padding: 4px 6px 6px;
  font-size: 11px;
  height: 100%;
  overflow: auto;
}
.btnrow {
  display: flex; gap: 3px; flex-wrap: wrap;
  padding: 3px 4px 2px;
  background: #111;
  border-bottom: 1px solid #333;
}
.ibtn {
  width: 30px; height: 24px; padding: 0;
  border: 0; background: transparent;
  image-rendering: pixelated;
}
.ibtn img { width: 28px; height: 22px; display: block; image-rendering: pixelated; }
.ibtn:disabled { opacity: 0.35; }
.ibtn:hover:not(:disabled) { filter: brightness(1.15); }
.ibtn:active:not(:disabled) { transform: translate(1px, 1px); }

.sec {
  color: var(--green);
  font-weight: 700;
  text-align: center;
  margin: 3px 0 2px;
  font-size: 11px;
}
.kv {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 8px;
}
.kv .lab { color: var(--cyan); }
.kv .val { color: var(--yellow); text-align: right; font-variant-numeric: tabular-nums; }
.kv .span { grid-column: 1 / -1; }
.bad { color: var(--red) !important; font-weight: 700; }
.st-empire { color: var(--green); }
.st-occ { color: var(--magenta); }
.st-ind { color: var(--cyan); }

table.res {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin-top: 2px;
}
table.res th { color: var(--green); font-weight: 700; text-align: right; }
table.res th:first-child { text-align: left; }
table.res td { color: var(--yellow); text-align: right; padding: 0 2px; }
table.res td.n { color: var(--yellow); text-align: left; }
table.res td.na { color: #888; }

#view-body { display: grid; grid-template-columns: 10px 1fr 42%; height: 100%; }
#timebar {
  background: #111;
  border-right: 1px solid #333;
  position: relative;
}
#timebar i {
  position: absolute; left: 2px; right: 2px; bottom: 0;
  background: linear-gradient(#6f6, #0a0);
}
#view-text { padding: 6px 8px; font-size: 11px; color: var(--green); }
#view-text .vlab { color: var(--cyan); }
#view-globe { position: relative; overflow: hidden; }
#globe {
  position: absolute; right: -18%; bottom: -28%;
  width: 150%; height: 150%;
  display: block;
}

/* System 7 buttons */
.bit {
  min-width: 74px;
  padding: 3px 12px 4px;
  background: var(--face);
  border: 1px solid #000;
  box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #888;
}
.bit.default { outline: 2px solid #000; outline-offset: 2px; }
.bit:active { box-shadow: inset 1px 1px 0 #888; }
.bit:disabled { color: #888; }

/* Modal */
#modal {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.18);
  display: flex; align-items: center; justify-content: center;
  z-index: 80;
}
#modal.hidden { display: none !important; }
.dlog {
  background: var(--face);
  border: 1px solid #000;
  box-shadow: 3px 3px 0 rgba(0,0,0,.4), inset 1px 1px 0 #fff;
  min-width: 280px;
  max-width: min(560px, 92vw);
  max-height: 88vh;
  overflow: auto;
}
.dlog .dt {
  background: #000; color: #fff;
  text-align: center;
  padding: 3px 10px;
  font-size: 12px;
}
.dlog.battle .dt { background: #5b1d8a; color: #ffe14a; }
.dlog .dc { padding: 12px 16px 14px; display: flex; gap: 12px; }
.dlog .dc .ico { width: 32px; height: 32px; image-rendering: pixelated; flex: 0 0 32px; }
.dlog .dc .copy { flex: 1; }
.dlog .btns {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 0 16px 14px;
}
.dlog label { display: block; margin: 4px 0; }
.dlog input[type=number], .dlog input[type=text] {
  width: 72px;
  border: 1px solid #000;
  background: #fff;
  padding: 2px 4px;
  box-shadow: inset 1px 1px 0 #888;
}
.dlog input:focus { outline: 1px dotted #000; }
.dlog .hint { color: #444; font-size: 11px; margin-top: 4px; }
.dlog table.build { width: 100%; border-collapse: collapse; font-size: 12px; }
.dlog table.build td { padding: 3px 4px; }
.dlog table.build td:first-child { text-align: right; }

.battle-body {
  background: #3b0d66;
  color: #fff;
  padding: 10px 16px 14px;
  min-width: 320px;
  text-align: center;
  font-family: var(--font-times);
}
.battle-body h3 { margin: 0 0 6px; color: #ffe14a; font-size: 16px; }
.battle-body .phase { color: #9cf; margin-bottom: 8px; }
.battle-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.battle-cols .side { color: #9cf; }
.battle-cols .n { font-size: 22px; color: #ffe14a; }
.prob { margin: 8px 0; color: #9f9; }
.prob.danger { color: #f66; }
.note { min-height: 1.2em; color: #ffa; margin: 6px 0; }

#help-body {
  max-height: 360px; overflow: auto;
  font: 13px/1.4 var(--font-times);
  white-space: pre-wrap;
  padding: 8px 4px;
}
#help-nav { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
#help-nav button { font-size: 11px; padding: 2px 6px; }

.scores { width: 100%; border-collapse: collapse; font-size: 11px; }
.scores th, .scores td { border-bottom: 1px solid #bbb; padding: 2px 6px; text-align: right; }
.scores th:nth-child(2), .scores td:nth-child(2) { text-align: left; }

.end {
  width: min(720px, 94vw);
}
.end img {
  width: 100%; height: 220px; object-fit: cover;
  display: block; image-rendering: pixelated;
  border-bottom: 1px solid #000;
}
.end .copy { padding: 12px 16px; font: 14px/1.45 var(--font-times); }

.toast {
  position: absolute; top: 36px; left: 50%; transform: translateX(-50%);
  background: var(--face);
  border: 1px solid #000;
  box-shadow: 2px 2px 0 #000;
  padding: 8px 14px 8px 10px;
  display: flex; gap: 10px; align-items: center;
  z-index: 70;
}
.toast img { width: 32px; height: 32px; image-rendering: pixelated; }
