:root {
  --bg0: #070910;
  --cream: #e8eef8;
  --muted: #8e97a8;
  --gold: #e4c48a;
  --gold-dim: rgba(228, 196, 138, 0.16);
  --line: rgba(255, 255, 255, 0.1);
  --panel: rgba(10, 14, 22, 0.94);
  --font: "Segoe UI", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--cream);
  font: 14px/1.4 var(--font);
  background:
    radial-gradient(ellipse at 18% 0%, #1a3050 0%, transparent 55%),
    radial-gradient(ellipse at 90% 100%, #1a1528 0%, transparent 50%),
    var(--bg0);
}

button, input { font: inherit; }

button { cursor: pointer; }

.screen { position: absolute; inset: 0; }
.screen[hidden] { display: none !important; }

.screen--title {
  display: grid;
  place-items: center;
  padding: 24px;
}

.title-panel { text-align: center; max-width: 520px; }

.title-panel h1 {
  margin: 0;
  font-size: clamp(1.7rem, 4.6vw, 2.5rem);
  letter-spacing: 0.08em;
  color: var(--gold);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}

.title-panel p.title-panel__tag {
  font-size: 1.15rem;
  color: var(--cream);
}

.title-panel p {
  margin: 14px auto 0;
  max-width: 460px;
  color: var(--muted);
  line-height: 1.45;
}

.title-panel p.title-panel__hook {
  margin-bottom: 22px;
  font-style: italic;
  color: var(--cream);
}

.boot-error {
  color: #ffb4b4;
  min-height: 1.2em;
}

.btn-primary, .btn-secondary, .btn-drill {
  appearance: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 700;
}

.btn-primary {
  border: 1px solid rgba(228, 196, 138, 0.55);
  background: linear-gradient(165deg, #e4c48a, #a68445);
  color: #1a1408;
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }

.btn-primary:disabled, .btn-drill:disabled {
  cursor: default;
  opacity: 0.45;
  filter: none;
}

.btn-secondary {
  border: 1px solid var(--line);
  background: #161c28;
  color: var(--cream);
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn-drill {
  border: 1px solid rgba(228, 196, 138, 0.45);
  background: var(--gold-dim);
  color: var(--gold);
  width: 100%;
  margin-top: 8px;
}

.screen--game { padding: 10px; }

.game-layout {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr clamp(260px, 24%, 340px);
  gap: 10px;
  min-height: 0;
}

.panel { order: 2; }
.view { order: 1; }

.view {
  position: relative;
  height: 100%;
  min-width: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #070910;
  border: 1px solid rgba(140, 180, 220, 0.28);
  box-shadow: inset 0 0 90px rgba(0, 0, 0, 0.55);
  touch-action: none;
}

.view canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#webgl { z-index: 0; }
#overlay { z-index: 1; }

.focus-info {
  position: absolute;
  z-index: 4;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, calc(100% - 140px));
  padding: 8px 12px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(8, 12, 20, 0.82);
  pointer-events: none;
  text-align: center;
}

.focus-info[hidden] { display: none !important; }

.focus-info__head {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.focus-info .is-done { color: var(--gold); text-decoration: line-through; }
.focus-info .swatches { justify-content: center; }
.focus-info .meter { margin: 8px 0 4px; }
.focus-info .tiers { justify-content: center; margin: 0; }

.focus-nav {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.focus-nav[hidden] { display: none !important; }

.focus-nav button {
  pointer-events: auto;
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid var(--gold);
  background: rgba(8, 12, 20, 0.9);
  color: var(--gold);
  font-size: 28px;
  line-height: 1;
}

#focusPrev { left: 16px; top: 50%; transform: translateY(-50%); }
#focusNext { right: 16px; top: 50%; transform: translateY(-50%); }
#focusBack { left: 50%; bottom: 112px; transform: translateX(-50%); }

.dice-bar {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 18px;
  padding: 8px 16px 10px;
  border-radius: 12px;
  border: 1px solid rgba(140, 180, 220, 0.28);
  background: rgba(8, 12, 20, 0.9);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.dice-bar[hidden] { display: none !important; }

.screen--game.is-astrium .dice-bar { z-index: 30; }

.dice-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 54px;
}

.dice-zone[data-zone="main"] { min-width: 150px; }

.dice-zone__label {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

.focus-nav button:disabled {
  opacity: 0.32;
  cursor: default;
}

.round-badge, .survey {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.round-badge {
  top: 18px;
  left: 18px;
  transform: rotate(-12deg);
  transform-origin: left center;
  font-family: "Arial Black", "Segoe UI Black", Impact, sans-serif;
  font-size: clamp(1.4rem, 2.6vw, 2.1rem);
  letter-spacing: 0.04em;
  color: #7dffd4;
  text-shadow:
    0 0 8px rgba(125, 255, 212, 0.85),
    0 0 22px rgba(40, 180, 255, 0.45);
}

.survey {
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(8, 12, 20, 0.8);
  color: var(--gold);
  font-size: 12px;
}

.rock-dialog {
  position: absolute;
  z-index: 3;
  left: 14px;
  bottom: 14px;
  width: min(440px, calc(100% - 28px));
  max-height: min(78%, 640px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(8, 12, 20, 0.94);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.rock-dialog[hidden] { display: none !important; }

.rock-dialog__head, .panel__head, .row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.rock-dialog h2, .panel h2 {
  margin: 0;
  font-size: 1.05rem;
}

.muted { color: var(--muted); font-size: 12px; margin: 4px 0 0; }

.swatches, .ore-row, .pips, .slots, .dice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.swatch, .ore-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
}

.swatch i, .ore-chip i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: block;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.meter {
  position: relative;
  height: 10px;
  margin: 10px 0 6px;
  border-radius: 99px;
  background: #1c2433;
  overflow: hidden;
}

.meter__fill {
  height: 100%;
  border-radius: inherit;
}

.meter__tick {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: rgba(255, 255, 255, 0.85);
}

.tiers {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 12px;
}

.tiers .is-done { color: var(--gold); text-decoration: line-through; }

.crew-block {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.crew-block header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}

.slot {
  width: 58px;
  min-height: 64px;
  border-radius: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px;
}

.slot.is-hot {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(228, 196, 138, 0.45);
}

.slot__label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.die, .ghost.die {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid rgba(48, 28, 14, 0.45);
  background: linear-gradient(165deg, #fffdf8, #e6d3bc);
  box-shadow: inset 0 -7px 10px rgba(90, 48, 16, 0.18), 0 2px 0 rgba(0, 0, 0, 0.35);
}

.die-face {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 5px;
}

.die-face i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  justify-self: center;
  align-self: center;
  background: transparent;
}

.die-face i.is-on {
  background: #1c140e;
  box-shadow: inset 0 -1px 1px rgba(255, 255, 255, 0.35);
}

.die[data-locked="1"] { opacity: 0.7; cursor: default; }
.die[data-placed="0"] { cursor: grab; }

.panel {
  min-height: 0;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.brand {
  font-size: 1.15rem;
  letter-spacing: 0.12em;
  color: var(--gold);
  font-weight: 750;
}

.astrium {
  font-size: 1.8rem;
  font-weight: 750;
  color: var(--gold);
  margin: 0;
}

.astrium span { font-size: 0.85rem; letter-spacing: 0.08em; color: var(--muted); margin-right: 6px; }

.pips i {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(228, 196, 138, 0.5);
  background: transparent;
  display: block;
}

.pips i.is-on { background: var(--gold); }

.piles {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}

.piles strong { color: var(--cream); }

.hand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  min-width: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
}

.crew-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.crew-head h3 { margin: 0; }

.dossier {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(16, 22, 34, 0.96);
  color: var(--cream);
  user-select: none;
  touch-action: none;
}

.dossier.is-broke { opacity: 0.45; }
.dossier.is-playable { cursor: grab; }

.dossier__frame {
  position: relative;
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid rgba(244, 241, 232, 0.55);
  background: #090c12;
}

.dossier__frame img {
  position: absolute;
  width: 77px;
  height: 85px;
  max-width: none;
  left: -7px;
  top: 4px;
  pointer-events: none;
}

.dossier__body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  flex: 1;
  padding-right: 2px;
}

.dossier__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
}

.dossier__name {
  margin: 0;
  min-width: 0;
  font-size: 15px;
  font-weight: 750;
  line-height: 1.15;
  letter-spacing: 0;
  text-transform: none;
  color: var(--cream);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dossier__ability {
  font-weight: 650;
  font-size: 14px;
  line-height: 1.2;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dossier__active {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.mini-slot {
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border-radius: 5px;
  border: 1px dashed rgba(255, 255, 255, 0.5);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0;
}

.dossier__gt { color: var(--muted); font-size: 13px; font-weight: 750; }

.dossier__power {
  font-size: 16px;
  font-weight: 800;
  color: var(--gold);
}

.dossier__cost {
  display: flex;
  gap: 2px;
  flex: none;
}

.dossier__cost i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 1px rgba(228, 196, 138, 0.35);
}

.stores {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.store {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  font-size: 12px;
  font-weight: 700;
}

.store i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: block;
}

.store--astrium { color: var(--gold); }

.cargo-drawer summary {
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 750;
}

.cargo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.cargo-slot {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.28);
  color: inherit;
  font-size: 22px;
}

.cargo-slot.is-filled {
  border-style: solid;
  border-color: rgba(126, 240, 255, 0.45);
  cursor: pointer;
}

.cargo-pick {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.cargo-pick button, .relic button {
  font: inherit;
  font-size: 11px;
  color: var(--cream);
  background: transparent;
  border: 1px solid rgba(228, 196, 138, 0.5);
  border-radius: 6px;
  padding: 2px 6px;
  cursor: pointer;
}

.card {
  min-width: 0;
  border-radius: 10px;
  padding: 8px;
  background: var(--card, #243044);
  color: var(--ink, var(--cream));
  border: 1px solid rgba(255, 255, 255, 0.12);
  user-select: none;
  touch-action: none;
}

.card.is-broke { opacity: 0.45; }
.card.is-playable { cursor: grab; }

.card__top {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: baseline;
}

.card h3 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
  color: inherit;
}
.card__cost {
  font-weight: 800;
  font-size: 13px;
}

.card p { margin: 4px 0 0; font-size: 11px; line-height: 1.35; }

.btn-end {
  appearance: none;
  align-self: flex-end;
  margin: 0 0 4px 8px;
  border-radius: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(228, 196, 138, 0.55);
  background: linear-gradient(165deg, #e4c48a, #a68445);
  color: #1a1408;
  font-weight: 700;
  white-space: nowrap;
}

.btn-end:disabled {
  cursor: default;
  opacity: 0.45;
}

.log {
  position: absolute;
  z-index: 3;
  left: 14px;
  bottom: 108px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
  max-width: 42%;
}

.log li:first-child { color: var(--cream); }

#spriteStage {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  visibility: hidden;
}

#spriteStage.is-on { visibility: visible; }

#spriteStage, #spriteStage * { pointer-events: none; }

#spriteStage canvas,
#dragSprite {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#fieldSprites {
  position: absolute;
  overflow: hidden;
}

.crew-sprite {
  position: absolute;
  left: 0;
  top: 0;
  width: 293px;
  height: 327px;
  transform-origin: 0 0;
}

.crew-sprite[hidden] { display: none !important; }

.crew-sprite img {
  position: absolute;
  left: 0;
  top: 0;
  width: 293px;
  height: 327px;
  user-select: none;
  -webkit-user-drag: none;
}

.crew-sprite__head:not(.is-on) { visibility: hidden; }

#ghost {
  position: fixed;
  z-index: 90;
  pointer-events: none;
  transform: translate(-50%, -60%);
}

#slotLayer {
  position: fixed;
  z-index: 21;
  pointer-events: none;
}

#phaseLayer {
  position: fixed;
  z-index: 24;
  pointer-events: none;
}

#phaseLayer[hidden] { display: none !important; }

.relic {
  border: 1px solid rgba(126, 240, 255, 0.35);
  border-radius: 8px;
  padding: 6px 8px;
  margin-top: 6px;
  background: rgba(12, 18, 28, 0.65);
}

.relic__top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.relic p { margin: 4px 0; font-size: 11px; color: var(--muted); }

.relic__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.relic button {
  font: inherit;
  font-size: 11px;
  color: var(--cream);
  background: transparent;
  border: 1px solid rgba(228, 196, 138, 0.5);
  border-radius: 6px;
  padding: 2px 6px;
  cursor: pointer;
}

#ghost[hidden] { display: none !important; }

.card-ghost {
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(20, 28, 42, 0.95);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-weight: 700;
}

body.is-dragging, body.is-dragging * { cursor: grabbing !important; }

h3 {
  margin: 8px 0 4px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}

@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(240px, 1fr) auto;
  }

  .view { order: -1; }
  .panel { max-height: 46vh; }
}
