:root {
  --wall: #0C0A09;
  --hex: #1C1917;
  --line: #3F3A36;
  --type: #E7E0D6;
  --ember: #D97757;
  --dim: #A8A29E;
  --mute: #78716C;
  --raised: #292524;
  --inset: #44403C;
  --sage: #6B8F7A;
  --danger: #B85C4A;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  background: var(--wall);
  color: var(--type);
  font-family: ui-sans-serif, system-ui, "Segoe UI", "Helvetica Neue", Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body { min-height: 100dvh; }

#app {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100dvh;
  min-height: 100svh;
  position: relative;
  background: var(--wall);
  overflow: hidden;
}

.screen {
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: calc(18px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  position: relative;
}

.hidden { display: none !important; }

/* —— start —— */
#screen-start { z-index: 1; gap: 10px; }
#start-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
#screen-start > *:not(#start-bg) { position: relative; z-index: 1; }

.hero { text-align: center; padding-top: 8px; }
.eyebrow {
  color: var(--mute);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 10px;
}
.hero h1 {
  font-size: 42px;
  letter-spacing: 0.16em;
  font-weight: 700;
  margin: 10px 0 4px;
  color: var(--type);
}
.sub {
  color: var(--ember);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 600;
}
.disclaimer {
  color: var(--mute);
  font-size: 11px;
  margin-top: 8px;
}

.rank-chip {
  align-self: center;
  border: 1px solid var(--line);
  background: var(--hex);
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 6px 12px;
  border-radius: 999px;
}

.choose {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  margin-top: 4px;
}

.class-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.class-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--hex);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px 8px 8px;
  color: var(--type);
  text-align: left;
  width: 100%;
  min-height: 58px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.class-card canvas { display: block; flex: 0 0 auto; }
.class-card .meta { flex: 1; min-width: 0; }
.class-card .meta strong {
  display: block;
  font-size: 15px;
  letter-spacing: 0.06em;
  font-weight: 650;
}
.class-card .meta span {
  display: block;
  color: var(--mute);
  font-size: 11px;
  margin-top: 2px;
}
.class-card.selected {
  border-color: var(--ember);
  box-shadow: 0 0 0 1px var(--ember) inset;
}
.class-card:active { transform: scale(0.985); }

.blurb {
  color: var(--dim);
  font-size: 13px;
  line-height: 1.4;
  min-height: 36px;
}

.btn-engage {
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 12px;
  background: var(--ember);
  color: #2A1612;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
}
.btn-engage:disabled {
  background: var(--raised);
  color: var(--mute);
  cursor: default;
}
.btn-engage:not(:disabled):active { filter: brightness(0.92); }

.how {
  color: var(--mute);
  font-size: 11px;
  line-height: 1.45;
  text-align: center;
}

/* —— game —— */
#screen-game {
  padding: calc(10px + var(--safe-t)) 0 calc(8px + var(--safe-b));
  gap: 6px;
}

.game-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 16px;
}
.brand strong {
  letter-spacing: 0.18em;
  font-size: 13px;
}
.brand span {
  color: var(--ember);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-left: 8px;
}
.turn-label {
  color: var(--mute);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.phase-hint {
  text-align: center;
  font-size: 12px;
  color: var(--ember);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  min-height: 16px;
}

.board-wrap {
  flex: 1;
  min-height: 280px;
  position: relative;
}
#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.log {
  padding: 0 16px;
  font-size: 12px;
  color: var(--dim);
  min-height: 32px;
  line-height: 1.35;
}

.hud {
  padding: 8px 16px 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, #141211 0%, var(--wall) 40%);
  border-top: 1px solid var(--line);
}

.hud-row { display: flex; gap: 8px; align-items: center; }
.hud-row.stats { justify-content: space-between; }
.stat { display: flex; align-items: center; gap: 8px; }
.stat label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mute);
}
.stat.hull { flex: 1; }
.hp-track {
  flex: 1;
  height: 8px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 99px;
  overflow: hidden;
  min-width: 80px;
}
#hp-fill {
  height: 100%;
  width: 100%;
  background: var(--sage);
  border-radius: inherit;
}
#hp-text { font-size: 12px; color: var(--dim); min-width: 36px; }

.pips { display: flex; gap: 5px; }
.pips i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--raised);
  border: 1px solid var(--inset);
  display: block;
}
.pips i.on { background: var(--ember); border-color: var(--ember); }

.chip {
  flex: 1;
  background: var(--hex);
  border: 1px solid var(--line);
  color: var(--type);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  text-align: left;
}
.chip em { font-style: normal; color: var(--ember); font-weight: 650; }
.chip.ghost { color: var(--dim); }
button.chip { cursor: pointer; }

.toggle {
  display: flex;
  width: 100%;
  background: var(--hex);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.toggle button {
  flex: 1;
  height: 42px;
  border: 0;
  background: transparent;
  color: var(--mute);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0.38;
  filter: grayscale(0.6);
}
.toggle button.on {
  opacity: 1;
  filter: none;
  background: var(--raised);
  color: var(--ember);
  box-shadow: inset 0 0 0 1px var(--ember);
}

.hud-row.actions { gap: 10px; }
.btn-skip {
  flex: 0 0 38%;
  height: 56px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--hex);
  color: var(--type);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.btn-go {
  flex: 1;
  height: 56px;
  border: 0;
  border-radius: 12px;
  background: var(--ember);
  color: #2A1612;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.btn-go:disabled {
  background: var(--raised);
  color: var(--mute);
  cursor: default;
}
.btn-go:not(:disabled):active { filter: brightness(0.92); }

/* —— overlay —— */
.overlay {
  position: absolute;
  inset: 0;
  background: #0C0A09cc;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 5;
}
.panel {
  width: 100%;
  background: var(--hex);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 24px 20px 18px;
  text-align: center;
}
.panel h2 {
  font-size: 28px;
  letter-spacing: 0.12em;
  margin: 8px 0 12px;
}
.panel p { color: var(--dim); font-size: 14px; line-height: 1.45; }
.panel .btn-engage { margin-top: 18px; }

@media (min-width: 500px) {
  #app {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

.god-panel {
  position: absolute;
  top: calc(8px + var(--safe-t));
  right: 8px;
  z-index: 6;
  width: 148px;
  background: var(--hex);
  border: 1px solid var(--ember);
  border-radius: 10px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.god-panel.hidden { display: none !important; }
.god-title {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ember);
}
.god-panel label {
  font-size: 10px;
  color: var(--mute);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.god-panel select, .god-panel button {
  background: var(--raised);
  color: var(--type);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  font-size: 11px;
}
.god-panel button.on { border-color: var(--ember); color: var(--ember); }
