:root {
  --void: #07080a;
  --panel: rgba(12, 12, 10, 0.86);
  --panel-solid: #0f0f0c;
  --brass: #c9a24e;
  --brass-hi: #efd28a;
  --brass-dim: #6e5830;
  --bone: #ece4d2;
  --dim: #a39884;
  --blood: #9a2a26;
  --blood-hi: #d84a3a;
  --heal: #7ad89a;
  --line: rgba(201, 162, 78, 0.45);
  --gothic: "Cinzel", Palatino, "Palatino Linotype", Georgia, serif;
  --prose: "IM Fell English", Palatino, Georgia, serif;
  --pixel: "Silkscreen", ui-monospace, "Cascadia Code", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--void);
  color: var(--bone);
  font-family: var(--prose);
}

body.ingame { cursor: none; }
body.ingame .overlay.modal, body.ingame .overlay.modal * { cursor: default; }
body.ingame .overlay.modal button { cursor: pointer; }

button, input { font: inherit; color: inherit; }

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

kbd {
  font-family: var(--pixel);
  font-size: 10px;
  padding: 0 4px;
  border: 1px solid var(--brass-dim);
  color: var(--brass-hi);
  margin-left: 6px;
}

/* ---------- common chrome ---------- */

.panel, .sheet {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6), 0 12px 40px rgba(0, 0, 0, 0.5);
  position: relative;
}

.panel::before, .sheet::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(201, 162, 78, 0.14);
  pointer-events: none;
}

.kicker {
  margin: 0 0 4px;
  color: var(--brass);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 10px;
  font-family: var(--pixel);
}

.fine { color: var(--dim); font-size: 13px; line-height: 1.4; margin: 6px 0 0; }
.prose { font-size: 16px; line-height: 1.5; color: #ddd3bd; }

h1, h2, h3 { font-family: var(--gothic); font-weight: 700; margin: 0; letter-spacing: 0.06em; }

button {
  background: linear-gradient(#1c1c16, #121210);
  border: 1px solid var(--brass-dim);
  padding: 10px 14px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  color: var(--bone);
}
button:hover { border-color: var(--brass); color: var(--brass-hi); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary {
  background: linear-gradient(#5a1a16, #3a0e0c);
  border-color: #c9a24e;
  color: #fff0d0;
}
button.primary:hover { background: linear-gradient(#7a2420, #4a1210); }

input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: #0c0c0a;
  border: 1px solid var(--brass-dim);
  outline: none;
  font-family: var(--pixel);
  font-size: 13px;
}
input:focus { border-color: var(--brass); }

label {
  display: block;
  margin: 14px 0 8px;
  color: var(--dim);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 10px;
  font-family: var(--pixel);
}

.track {
  position: relative;
  height: 6px;
  background: #1a120e;
  border: 1px solid #3a2e1c;
}
.track > span {
  display: block;
  height: 100%;
  width: 0;
  background: #8b9364;
  transition: width 120ms linear;
}
.track.xp > span { background: linear-gradient(90deg, #7a6a30, #c9a24e); }

/* ---------- title ---------- */

#title {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 16px 16px 16px max(16px, 7vw);
  background: linear-gradient(90deg, rgba(5, 5, 4, 0.92) 0%, rgba(5, 5, 4, 0.7) 38%, rgba(5, 5, 4, 0) 70%);
}
body.ingame #title { display: none; }

.title-card { width: min(440px, 100%); }

#title h1 {
  font-size: clamp(54px, 9vw, 104px);
  line-height: 0.88;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #efe2c0;
  text-shadow: 0 2px 0 #3a1a10, 0 0 40px rgba(200, 80, 40, 0.35);
  margin: 8px 0 14px;
}

.lede { font-size: 17px; line-height: 1.5; color: #d8ccb2; margin: 0 0 16px; }

.career {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid rgba(201, 162, 78, 0.3);
  background: rgba(10, 10, 8, 0.7);
}
.career img { width: 60px; height: 78px; image-rendering: pixelated; }
.career > div { flex: 1; }
#career-title { font-family: var(--gothic); font-size: 20px; margin: 0 0 6px; }

.row { margin: 8px 0; }
.row button { width: 100%; }
.join { display: flex; gap: 8px; }
.join input { width: 120px; margin: 0; text-align: center; letter-spacing: 0.35em; text-transform: uppercase; }
.join button { flex: 1; }
.credits { position: absolute; bottom: 14px; left: max(16px, 7vw); }

#link-lost {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  margin: 0;
  padding: 6px 12px;
  background: var(--blood);
  font-family: var(--pixel);
  font-size: 11px;
}

/* ---------- HUD ---------- */

#hud { display: none; }
body.ingame #hud { display: block; }
#hud > * { position: fixed; z-index: 2; }

#objective {
  top: 14px;
  left: 14px;
  width: min(300px, 42vw);
  padding: 10px 12px 12px;
  pointer-events: none;
}
#obj-title { font-size: 18px; margin-bottom: 6px; }
#obj-steps { margin: 0 0 8px; padding: 0; list-style: none; font-size: 14px; }
#obj-steps li { padding: 2px 0 2px 18px; position: relative; color: var(--dim); }
#obj-steps li::before { content: "◇"; position: absolute; left: 0; color: var(--brass-dim); }
#obj-steps li.now { color: var(--bone); }
#obj-steps li.now::before { content: "◆"; color: var(--brass-hi); }
#obj-steps li.done { color: #6a7a5a; text-decoration: line-through; }
#obj-steps li.done::before { content: "✓"; color: #7ad89a; }
#obj-fill { background: linear-gradient(90deg, #8a6a2a, #efd28a) !important; }
#obj-extra { font-family: var(--pixel); font-size: 11px; color: var(--brass-hi); }
.tickets { margin-top: 8px; font-family: var(--pixel); font-size: 10px; color: var(--dim); display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }
.tickets i { display: inline-block; width: 7px; height: 11px; background: #c9a24e; box-shadow: inset -1px -1px 0 #6e5830; }
.tickets i.spent { background: #2a2418; box-shadow: none; }

#bossbar {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, 46vw);
  text-align: center;
  pointer-events: none;
}
#boss-name {
  margin: 0 0 4px;
  font-family: var(--gothic);
  font-weight: 900;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 16px;
  color: #f0c8b0;
  text-shadow: 0 0 12px rgba(200, 40, 30, 0.7), 0 2px 0 #000;
}
.boss-track {
  position: relative;
  height: 14px;
  background: #140806;
  border: 1px solid #8a3a2a;
  box-shadow: 0 0 0 2px #0a0404, 0 0 20px rgba(160, 30, 20, 0.4);
}
.boss-track span { display: block; height: 100%; width: 100%; background: linear-gradient(#d84a3a, #7a1a14); transition: width 150ms; }
.boss-track .pip { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #efd28a; }
.boss-track .p1 { left: 33%; }
.boss-track .p2 { left: 66%; }
#bossbar.shield .boss-track span { background: linear-gradient(#efd28a, #8a6a2a); }

#squad {
  top: 14px;
  right: 14px;
  margin: 0;
  padding: 8px 10px;
  list-style: none;
  width: 200px;
  pointer-events: none;
}
#squad li { display: grid; grid-template-columns: 10px 1fr auto; gap: 4px 8px; align-items: center; padding: 3px 0; font-family: var(--pixel); font-size: 10px; }
#squad li .sw { width: 10px; height: 10px; }
#squad li .nm { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#squad li .lv { color: var(--dim); }
#squad li .hb { grid-column: 2 / 4; height: 3px; background: #2a1410; }
#squad li .hb span { display: block; height: 100%; background: #c9a24e; }
#squad li.downed .nm { color: #ff7060; }
#squad li.dead { opacity: 0.4; }
#squad li.me .nm { color: var(--brass-hi); }

#vox {
  left: 14px;
  bottom: 118px;
  width: min(420px, 44vw);
  pointer-events: none;
}
#vox p {
  margin: 0 0 3px;
  font-size: 14px;
  text-shadow: 0 1px 0 #000, 0 0 6px #000;
  animation: fade 12s forwards;
}
#vox p.alert { color: #ff9a80; }
#vox p.orders { color: var(--brass-hi); }
#vox p.rank { color: #b8e0a0; }
#vox p.chat { color: #a8c8e8; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

#vitals {
  left: 14px;
  bottom: 14px;
  width: 280px;
  padding: 10px 12px;
  pointer-events: none;
}
.vital-row { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 8px; margin: 3px 0; }
.vital-row .label { font-family: var(--pixel); font-size: 10px; color: var(--brass); text-transform: uppercase; }
.vital-row .track.big { height: 16px; }
#hp-fill { background: linear-gradient(#d4c08a, #8a7440) !important; }
#hp-fill.low { background: linear-gradient(#e05a4a, #8a1c16) !important; }
#hp-text { position: absolute; inset: 0; font-family: var(--pixel); font-size: 10px; font-weight: normal; text-align: center; line-height: 14px; text-shadow: 0 1px 0 #000; }
#heat-fill { background: linear-gradient(90deg, #d0a040, #ff5a20) !important; }
#heat-fill.over { background: repeating-linear-gradient(45deg, #9a2a26 0 6px, #3a0e0c 6px 12px) !important; }
.vital-row.small { grid-template-columns: auto 1fr; font-family: var(--pixel); font-size: 10px; color: var(--dim); }

#actions {
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  pointer-events: none;
}
.act {
  position: relative;
  width: 58px;
  height: 64px;
  background: var(--panel);
  border: 1px solid var(--brass-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 5px;
  overflow: hidden;
}
.act img { width: 32px; height: 32px; image-rendering: pixelated; }
.act b { position: absolute; top: 2px; left: 4px; font-family: var(--pixel); font-size: 9px; color: var(--brass-hi); }
.act small { font-family: var(--pixel); font-size: 8px; color: var(--dim); text-align: center; line-height: 1.1; margin-top: 3px; padding: 0 2px; }
.act .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.72); }
.act .cdt { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--pixel); font-size: 14px; color: #fff; text-shadow: 0 1px 0 #000; }
.act.ready { border-color: var(--brass); }
.act.sep { margin-left: 10px; }
.act .count { position: absolute; right: 4px; top: 2px; font-family: var(--pixel); font-size: 10px; color: #fff; }

#prompt {
  left: 50%;
  bottom: 170px;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid var(--brass-dim);
  font-family: var(--pixel);
  font-size: 11px;
  color: var(--brass-hi);
  pointer-events: none;
}

#hubbar {
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 14px;
  text-align: center;
  width: min(420px, 40vw);
}
#hubbar .hub-buttons { display: flex; gap: 8px; }
#hubbar button { flex: 1; font-size: 12px; padding: 8px; }
#room-code { color: var(--bone); letter-spacing: 0.3em; font-size: 13px; }

#chat-form { right: 14px; bottom: 200px; width: min(260px, 30vw); pointer-events: auto; opacity: 0.5; }
#chat-form:focus-within { opacity: 1; }
#chat { margin: 0; font-size: 11px; padding: 6px 8px; }

#ping { right: 14px; bottom: 186px; margin: 0; font-family: var(--pixel); font-size: 9px; color: var(--dim); }

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  pointer-events: none;
}
.overlay[hidden] { display: none; }
.overlay.modal { pointer-events: auto; background: rgba(4, 4, 3, 0.62); z-index: 6; }
.overlay.slim { align-items: end; padding-bottom: 200px; }
.overlay.slim .sheet { width: min(420px, 100%); padding: 12px 18px; text-align: center; background: rgba(20, 6, 4, 0.78); }
.overlay.slim h2 { font-size: 22px; margin-bottom: 4px; }
.overlay.slim p { margin: 0; font-size: 14px; }
.sheet { width: min(560px, 100%); padding: 22px 26px; max-height: calc(100vh - 32px); overflow: auto; }
.sheet.wide { width: min(980px, 100%); }
.sheet h2 { font-size: 30px; margin-bottom: 10px; }
.sheet h3 { font-size: 18px; margin: 18px 0 8px; }
.close { position: absolute; top: 10px; right: 10px; padding: 4px 10px; }
.countdown { font-family: var(--pixel); color: var(--brass-hi); font-size: 12px; margin: 14px 0 0; }
.countdown b { font-size: 18px; }

#brief-steps, #op-steps { padding-left: 20px; margin: 10px 0; color: var(--brass-hi); font-family: var(--gothic); font-size: 14px; }
#brief .sheet { border-color: rgba(201, 162, 78, 0.7); }
#death h2 { color: #ff8a70; }

#debrief-table { width: 100%; border-collapse: collapse; font-family: var(--pixel); font-size: 11px; margin-top: 10px; }
#debrief-table th, #debrief-table td { padding: 6px 8px; text-align: right; border-bottom: 1px solid rgba(201, 162, 78, 0.15); }
#debrief-table th:first-child, #debrief-table td:first-child { text-align: left; }
#debrief-table th { color: var(--brass); font-weight: normal; }
#debrief.won h2 { color: #d8e8b0; }
#debrief.lost h2 { color: #ff8a70; }

/* strategium */
.strat { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; }
@media (max-width: 760px) { .strat { grid-template-columns: 1fr; } }
.act-block { margin-bottom: 14px; }
.act-block h4 { margin: 0 0 6px; font-family: var(--gothic); font-size: 14px; color: var(--brass); letter-spacing: 0.1em; }
.act-block .place { font-family: var(--prose); font-style: italic; color: var(--dim); font-size: 13px; margin: -4px 0 8px; }
.ops { display: flex; flex-wrap: wrap; gap: 6px; }
.op {
  flex: 1 1 140px;
  text-align: left;
  padding: 8px 10px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: none;
}
.op small { display: block; font-family: var(--pixel); font-size: 9px; color: var(--dim); margin-top: 3px; letter-spacing: 0.1em; }
.op.cleared small { color: #7ad89a; }
.op.locked { opacity: 0.35; }
.op.sel { border-color: var(--brass-hi); background: linear-gradient(#2a2416, #16140c); box-shadow: 0 0 12px rgba(201, 162, 78, 0.3); }
#op-detail { border-left: 1px solid rgba(201, 162, 78, 0.25); padding-left: 18px; }
#op-title { font-size: 22px; }
.diff { display: flex; gap: 4px; margin: 12px 0; flex-wrap: wrap; }
.diff button { flex: 1; padding: 6px; font-size: 11px; }
.diff button.sel { border-color: var(--brass-hi); color: var(--brass-hi); }
#launch { width: 100%; padding: 14px; font-size: 15px; }

/* armoury */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.card {
  text-align: left;
  padding: 10px;
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--prose);
  font-weight: normal;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card img { width: 60px; height: 78px; image-rendering: pixelated; align-self: center; }
.card strong { font-family: var(--gothic); font-size: 15px; }
.card .meta { font-family: var(--pixel); font-size: 9px; color: var(--dim); }
.card .abs { font-family: var(--pixel); font-size: 9px; color: var(--brass); line-height: 1.5; }
.card p { margin: 0; font-size: 13px; color: #cfc4ac; }
.card.sel { border-color: var(--brass-hi); box-shadow: 0 0 14px rgba(201, 162, 78, 0.35); }
.card.locked { opacity: 0.35; }
.doctrines { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.doctrines button { text-align: left; text-transform: none; letter-spacing: 0.02em; font-size: 13px; }
.doctrines button small { display: block; font-family: var(--pixel); font-size: 9px; color: var(--dim); margin-top: 2px; }
.doctrines button.sel { border-color: var(--brass-hi); color: var(--brass-hi); }
.doctrines button.locked { opacity: 0.35; }

.menu-buttons { display: grid; gap: 8px; }
.manual { display: grid; grid-template-columns: 1fr 1.4fr; gap: 24px; }
@media (max-width: 760px) { .manual { grid-template-columns: 1fr; } }
.manual dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 15px; }
.manual dt { font-family: var(--pixel); font-size: 11px; color: var(--brass-hi); }
.manual dd { margin: 0; }

@media (max-width: 900px) {
  #squad { width: 150px; }
  #vitals { width: 220px; }
  .act { width: 48px; height: 56px; }
  .act img { width: 24px; height: 24px; }
  #hubbar { top: auto; bottom: 90px; }
}

/* ---------- touch controls (body.touch) ---------- */

#stick-base, #stick-knob, #touch-extra, #rotate-hint { display: none; }

body.touch, body.touch #view { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }

body.touch.ingame #stick-base {
  display: block;
  position: fixed;
  z-index: 4;
  width: 124px;
  height: 124px;
  margin: -62px 0 0 -62px;
  border-radius: 50%;
  border: 2px solid rgba(201, 162, 78, 0.55);
  background: radial-gradient(rgba(20, 16, 10, 0.25), rgba(20, 16, 10, 0.55));
  pointer-events: none;
}
body.touch.ingame #stick-base[hidden] { display: none; }
#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #efd28a, #8a6a2a 70%);
  box-shadow: 0 0 0 2px #1a140a, 0 4px 14px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, -50%);
}
body.touch.ingame #stick-knob { display: block; }

/* Ability bar becomes a thumb cluster, bottom right. */
body.touch #actions {
  left: auto;
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: none;
  pointer-events: auto;
  display: grid;
  grid-template-columns: repeat(3, 54px);
  gap: 8px;
  direction: rtl;
}
body.touch .act { width: 54px; height: 54px; border-radius: 50%; direction: ltr; touch-action: none; }
body.touch .act.sep { margin-left: 0; }
body.touch .act img { width: 26px; height: 26px; margin-top: 4px; }
body.touch .act small { display: none; }
body.touch .act b { left: 50%; transform: translateX(-50%); top: 3px; }
body.touch .act.pressed, body.touch #touch-extra button.pressed { background: rgba(201, 162, 78, 0.35); }

body.touch.ingame #touch-extra {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: fixed;
  z-index: 2;
  right: calc(12px + 3 * 54px + 3 * 8px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
}
#touch-extra button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  display: grid;
  place-items: center;
  background: var(--panel);
  touch-action: none;
}
#touch-extra small { display: block; font-family: var(--pixel); font-size: 7px; letter-spacing: 0; margin-top: -8px; }

/* Keep the rest of the HUD compact and out of the thumbs' way. */
body.touch #vitals { bottom: auto; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(220px, 30vw); padding: 4px 8px; }
body.touch .vital-row { grid-template-columns: 34px 1fr; margin: 1px 0; }
body.touch .vital-row .track.big { height: 12px; }
body.touch #hp-text { line-height: 10px; font-size: 8px; }
body.touch #vitals .vital-row.small { display: none; }
body.touch #objective { width: min(220px, 30vw); padding: 6px 8px; top: 8px; left: 8px; }
body.touch #objective .kicker { display: none; }
body.touch .tickets span { display: none; }
body.touch #objective h2 { font-size: 13px; margin-bottom: 2px; }
body.touch #obj-steps { font-size: 12px; }
body.touch #obj-steps li:not(.now) { display: none; }
body.touch #squad, body.touch #chat-form, body.touch #ping { display: none; }
body.touch #vox { bottom: auto; top: 32%; width: min(300px, 36vw); }
body.touch #vox p { font-size: 11px; }
body.touch #vox p:nth-last-child(n + 4) { display: none; }
body.touch #prompt { bottom: auto; top: 30%; }
body.touch #bossbar { top: calc(64px + env(safe-area-inset-top)); }
body.touch #hubbar { top: auto; left: 43%; transform: none; bottom: calc(10px + env(safe-area-inset-bottom)); width: min(240px, 26vw); padding: 6px; }
body.touch #hubbar .kicker { font-size: 8px; }
body.touch #hubbar .hub-buttons { flex-direction: column; gap: 4px; }
body.touch #hubbar button { font-size: 10px; padding: 6px; }
body.touch #hubbar kbd { display: none; }
body.touch #hubbar .fine { display: none; }
body.touch .overlay.slim { padding-bottom: 36vh; }
body.touch.ingame { cursor: default; }

@media (orientation: portrait) {
  body.touch.ingame #rotate-hint {
    display: block;
    position: fixed;
    z-index: 8;
    left: 50%;
    top: 40%;
    transform: translateX(-50%);
    margin: 0;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid var(--brass);
    font-family: var(--gothic);
    text-align: center;
    width: min(300px, 80vw);
  }
}
