:root {
  --soot: #0f0c0b;
  --iron: #1d1816;
  --iron-light: #3a322c;
  --iron-edge: #5a4b3b;
  --bone: #d8c8a0;
  --bone-dim: #9c8f72;
  --blood: #7a1c1f;
  --ember: #d8742a;
  --ember-bright: #ffb060;
  --verdigris: #5fa08c;
  --ward: #9fc4d8;
  --display: "Grenze Gotisch", "Palatino Linotype", Georgia, serif;
  --body: "IM Fell English", "Palatino Linotype", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--soot); color: var(--bone); font-family: var(--body); }
button { font-family: inherit; }

#world {
  position: fixed; inset: 0; width: 100vw; height: 100vh; display: block;
  image-rendering: pixelated; image-rendering: crisp-edges;
  cursor: crosshair;
}

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

/* Iron plate frames */
.plate {
  background: linear-gradient(180deg, #221c19 0%, #15110f 100%);
  border: 1px solid var(--iron-edge);
  box-shadow: 0 0 0 1px #060404, inset 0 0 0 1px #2d2622, 0 10px 30px rgba(0, 0, 0, 0.65);
  position: relative;
}
.plate::before, .plate::after {
  content: ""; position: absolute; width: 5px; height: 5px; background: var(--bone-dim);
  box-shadow: 0 0 0 1px #060404;
}
.plate::before { top: 3px; left: 3px; }
.plate::after { bottom: 3px; right: 3px; }

/* Top bar */
#topbar {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  height: 48px; min-width: 860px; padding: 0 18px;
  display: flex; align-items: center; gap: 28px;
}
.crest {
  font-family: var(--display); font-size: 26px; font-weight: 600; letter-spacing: 0.04em;
  color: var(--bone); text-shadow: 0 1px 0 #000, 0 0 18px rgba(216, 116, 42, 0.25);
  padding-right: 18px; border-right: 1px solid var(--iron-light);
}
.hud-group { display: flex; gap: 14px; align-items: center; font-size: 15px; color: var(--bone-dim); }
.hud-group .label { font-style: italic; }
#hud-round { color: var(--bone); }
.hud-phase-wrap { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
#hud-phase { font-family: var(--display); font-size: 19px; line-height: 1; color: var(--bone); }
#hud-phase[data-phase="battle"] { color: var(--ember-bright); }
#hud-phase[data-phase="paused"] { color: var(--ward); }
#hud-phase[data-phase="victory"] { color: var(--verdigris); }
#hud-phase[data-phase="defeat"] { color: #c9393d; }
.timer { height: 4px; background: #0a0807; box-shadow: inset 0 0 0 1px #2d2622; }
#hud-timer-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #8a3a16, var(--ember), var(--ember-bright)); }

.tithes { font-family: var(--display); font-size: 20px; color: var(--bone); line-height: 1; }
.tithes::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%; vertical-align: 1px;
  background: radial-gradient(circle at 40% 35%, #f0e0b0, #c9b58a 55%, #6a5a3a); box-shadow: 0 0 0 1px #3a2f27; }

/* Embers: a vertical column beside the hand, filling from the bottom */
#ember-column {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 6px 10px;
  margin-bottom: 26px; background: linear-gradient(180deg, #221c19, #15110f); border: 1px solid var(--iron-edge);
  box-shadow: 0 0 0 1px #060404, inset 0 0 0 1px #2d2622, 0 10px 30px rgba(0, 0, 0, 0.65);
}
.ember {
  width: 14px; height: 14px; border-radius: 50%; background: #2a211c; box-shadow: inset 0 0 0 1px #0a0807, 0 0 0 1px #3a2f27;
}
.ember.lit {
  background: radial-gradient(circle at 40% 35%, #ffd27a, var(--ember) 55%, #8a3a16);
  box-shadow: 0 0 10px rgba(255, 160, 60, 0.75), 0 0 0 1px #3a2f27;
}
.ember-count { font-family: var(--display); font-size: 24px; color: var(--ember-bright); line-height: 1; margin-bottom: 2px; }
.ember-label { font-size: 10px; font-style: italic; color: var(--bone-dim); writing-mode: vertical-rl; transform: rotate(180deg); margin-top: 2px; }

button.primary {
  margin-left: auto;
  background: linear-gradient(180deg, #5a1c1e, #3a1012);
  color: var(--bone); border: 1px solid #8a3a3a; padding: 7px 16px; font-size: 15px;
  cursor: pointer; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 0 0 1px #060404;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}
button.primary:hover { background: linear-gradient(180deg, #7a2426, #4a1416); color: #fff3dc; }
button.primary:disabled { opacity: 0.4; cursor: default; }
button.primary:focus-visible, button.ghost:focus-visible, .card:focus-visible { outline: 2px solid var(--bone); outline-offset: 2px; }
button.ghost { background: none; border: none; color: var(--bone-dim); font-size: 14px; font-style: italic; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
button.ghost:hover { color: var(--bone); }

/* Prompt and toast */
#prompt {
  position: absolute; top: 70px; left: 50%; transform: translateX(-50%);
  font-size: 16px; color: var(--bone); background: rgba(10, 8, 7, 0.75); padding: 6px 16px;
  border-top: 1px solid var(--iron-light); border-bottom: 1px solid var(--iron-light);
  pointer-events: none !important; white-space: nowrap;
}
#toast {
  position: absolute; top: 44%; left: 50%; transform: translate(-50%, -50%) translateY(6px);
  font-family: var(--display); font-size: 22px; color: #ffd8b8; text-shadow: 0 2px 0 #000;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none !important;
}
#toast.show { opacity: 1; transform: translate(-50%, -50%); }

/* Log */
#log {
  position: absolute; top: 72px; right: 14px; width: 300px; padding: 10px 14px;
  font-size: 13.5px; line-height: 1.4; color: var(--bone-dim); min-height: 40px;
}
.log-line { animation: logIn 0.4s ease-out; }
.log-line:last-child { color: var(--bone); }
@keyframes logIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Unit panel */
#unit-panel {
  position: absolute; left: 14px; bottom: 14px; width: 330px; padding: 12px;
  display: flex; gap: 14px; align-items: flex-start;
}
#unit-panel .portrait {
  width: 72px; height: 96px; image-rendering: pixelated;
  background: radial-gradient(circle at 50% 70%, #2a221d, #0f0c0b 75%);
  box-shadow: inset 0 0 0 1px #2d2622, 0 0 0 1px #060404;
}
.unit-info { flex: 1; min-width: 0; }
.unit-name { font-family: var(--display); font-size: 21px; line-height: 1.1; color: var(--bone); }
.unit-name.enemy { color: #e0706a; }
.unit-name small { font-family: var(--body); font-size: 12px; font-style: italic; color: var(--bone-dim); }
.hp-bar { position: relative; height: 12px; margin: 7px 0 8px; background: #0a0807; box-shadow: inset 0 0 0 1px #2d2622; }
.hp-fill { height: 100%; background: linear-gradient(180deg, #7fd0b0, var(--verdigris)); }
.hp-fill.enemy { background: linear-gradient(180deg, #e04a4a, #8a1c20); }
.hp-bar span { position: absolute; inset: 0; text-align: center; font-size: 10.5px; line-height: 12px; color: #fff; text-shadow: 0 1px 0 #000; }
.stats { display: flex; gap: 12px; font-size: 13px; color: var(--bone-dim); }
.stats span { white-space: nowrap; }
.statuses { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; }
.status { padding: 1px 7px; border: 1px solid; }
.status-haste { color: #e8d26a; border-color: #6a5e2a; }
.status-might { color: #e06a2a; border-color: #6a3a1a; }
.status-ward { color: var(--ward); border-color: #3a5a6a; }
.order { color: var(--bone-dim); font-style: italic; }
.others { margin-top: 6px; font-size: 12px; font-style: italic; color: var(--bone-dim); }

/* Ability button in the unit panel */
.ability {
  margin-top: 8px; display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  background: linear-gradient(180deg, #2a2320, #171310); border: 1px solid #5a4b3b; color: var(--bone);
  padding: 5px 8px; cursor: pointer; font-size: 13px;
}
.ability img { width: 28px; height: 28px; image-rendering: pixelated; background: #0c0908; box-shadow: inset 0 0 0 1px #3a2f27; }
.ability .ability-name { font-family: var(--display); font-size: 17px; line-height: 1; }
.ability .ability-state { font-size: 11.5px; color: var(--bone-dim); font-style: italic; }
.ability:hover:not(:disabled), .ability.active { border-color: var(--ember-bright); background: linear-gradient(180deg, #3a2a20, #1f1612); }
.ability:disabled { opacity: 0.5; cursor: default; }
.ability .key { margin-left: auto; font-size: 11px; color: var(--bone-dim); border: 1px solid #4a3c2a; padding: 0 5px; }

/* Hover card: stats of the unit under the cursor */
#hover-card {
  position: absolute; width: 250px; padding: 10px 12px; pointer-events: none !important;
  background: linear-gradient(180deg, #221c19, #110d0b); border: 1px solid #6a5a44;
  box-shadow: 0 0 0 1px #060404, inset 0 0 0 1px #2d2622, 0 12px 30px rgba(0, 0, 0, 0.7);
  font-size: 12.5px; color: var(--bone-dim); z-index: 4;
}
#hover-card .hc-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
#hover-card canvas { width: 36px; height: 48px; image-rendering: pixelated; background: #0c0908; box-shadow: inset 0 0 0 1px #2d2622; }
#hover-card .hc-name { font-family: var(--display); font-size: 19px; line-height: 1; color: var(--bone); }
#hover-card .hc-name.enemy { color: #e0706a; }
#hover-card .hc-tag { font-size: 11px; font-style: italic; }
#hover-card .hc-desc { font-style: italic; margin: 0 0 6px; line-height: 1.3; }
#hover-card .hc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; }
#hover-card .hc-grid span b { color: var(--bone); font-weight: normal; }
#hover-card .hc-ability { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--iron-light); }
#hover-card .hc-ability b { font-family: var(--display); font-size: 15px; color: var(--bone); font-weight: normal; }
#hover-card .statuses { margin-top: 6px; }

/* Hand */
#hand-wrap { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); display: flex; align-items: flex-end; gap: 10px; }
.hand-stack { display: flex; flex-direction: column; align-items: center; }
#hand { display: flex; gap: 6px; padding: 24px 24px 0; align-items: flex-end; height: 196px; }
.deck-count { font-size: 12px; font-style: italic; color: var(--bone-dim); padding: 2px 0 6px; }
.card {
  --rot: 0deg; --lift: 0px;
  position: relative; width: 128px; height: 182px; padding: 10px 10px 8px;
  background: radial-gradient(ellipse at 50% 20%, #2e2520, #17120f 70%);
  border: 1px solid #7a6a4a;
  box-shadow: inset 0 0 0 3px #110d0b, inset 0 0 0 4px #4a3c2a, 0 12px 24px rgba(0, 0, 0, 0.7);
  transform: rotate(var(--rot)) translateY(var(--lift));
  transition: transform 0.18s ease-out, box-shadow 0.18s;
  cursor: pointer; display: flex; flex-direction: column; text-align: center; user-select: none;
}
.card:hover, .card.active {
  transform: rotate(0deg) translateY(-22px) scale(1.06); z-index: 5;
  box-shadow: inset 0 0 0 3px #110d0b, inset 0 0 0 4px #7a6a4a, 0 16px 32px rgba(0, 0, 0, 0.8), 0 0 24px rgba(216, 116, 42, 0.25);
}
.card.active { border-color: var(--ember-bright); }
.card.disabled { filter: saturate(0.3) brightness(0.65); cursor: not-allowed; }
.card.disabled:hover { transform: rotate(var(--rot)) translateY(var(--lift)); }
.card-cost {
  position: absolute; top: -9px; left: -9px; width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #ffd27a, var(--ember) 55%, #6a2a10);
  box-shadow: 0 0 0 2px #110d0b, 0 0 10px rgba(255, 160, 60, 0.6);
  font-family: var(--display); font-size: 17px; line-height: 26px; color: #1a0e0c; text-align: center;
}
.card-key { position: absolute; top: -8px; right: -6px; font-size: 11px; color: var(--bone-dim); background: #110d0b; padding: 0 5px; border: 1px solid #4a3c2a; }
.card-art {
  height: 62px; margin: 2px 6px 6px; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 60%, #241c18, #0c0908 75%);
  box-shadow: inset 0 0 0 1px #4a3c2a;
}
.card-art img { width: 48px; height: 48px; image-rendering: pixelated; }
.card-name { font-family: var(--display); font-size: 18px; line-height: 1; color: var(--bone); margin-bottom: 5px; }
.card-text { font-size: 10.5px; line-height: 1.3; color: #c9bb97; flex: 1; }
.card-flavour { font-size: 9.5px; font-style: italic; color: #7f7360; line-height: 1.2; margin-top: 4px; }

/* Minimap */
#minimap { position: absolute; right: 14px; bottom: 14px; width: 192px; height: 192px; image-rendering: pixelated; cursor: pointer; }

/* Overlay panels */
#overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: radial-gradient(ellipse at center, rgba(15, 12, 11, 0.72), rgba(5, 4, 4, 0.92));
}
.panel {
  width: min(720px, 92vw); padding: 36px 44px 32px; text-align: center;
  background: linear-gradient(180deg, #221c19, #110d0b);
  border: 1px solid var(--iron-edge);
  box-shadow: 0 0 0 1px #060404, inset 0 0 0 1px #2d2622, inset 0 0 0 7px #110d0b, inset 0 0 0 8px #3a2f27, 0 30px 80px rgba(0, 0, 0, 0.8);
  animation: panelIn 0.5s ease-out;
}
@keyframes panelIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.panel h1 { font-family: var(--display); font-weight: 600; font-size: 64px; margin: 0 0 6px; line-height: 1; letter-spacing: 0.03em; text-shadow: 0 2px 0 #000, 0 0 40px rgba(216, 116, 42, 0.3); }
.panel h2 { font-family: var(--display); font-weight: 600; font-size: 42px; margin: 0 0 6px; line-height: 1; }
.lede { font-size: 17px; line-height: 1.5; color: #c9bb97; max-width: 56ch; margin: 10px auto 22px; }
.controls { text-align: left; font-size: 14.5px; line-height: 1.7; color: var(--bone-dim); max-width: 60ch; margin: 0 auto 26px; border-top: 1px solid var(--iron-light); border-bottom: 1px solid var(--iron-light); padding: 12px 0; }
.controls b { color: var(--bone); font-weight: normal; }
.panel .primary { margin: 0 auto; font-size: 18px; padding: 10px 26px; }
.reward-cards { display: flex; justify-content: center; gap: 26px; margin: 10px 0 22px; padding-top: 14px; }
.reward-cards .card { transform: none; }
.reward-cards .card:hover { transform: translateY(-10px) scale(1.06); }
.reward-cards .card.active { transform: translateY(-10px) scale(1.06); border-color: var(--ember-bright); }

/* Camp: muster and market */
.camp-panel { width: min(980px, 94vw); padding: 28px 36px 26px; text-align: left; }
.camp-panel h2 { text-align: center; }
.camp-panel .lede { text-align: center; max-width: 70ch; margin-bottom: 14px; }
.tithes-big { color: var(--bone); font-family: var(--display); font-size: 20px; font-weight: normal; }
.camp-section h3, .camp-col h3 { font-family: var(--display); font-weight: normal; font-size: 20px; margin: 0 0 8px; color: var(--bone); }
.camp-section { text-align: center; }
.camp-section .reward-cards { margin: 4px 0 14px; }
.camp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin: 6px 0 14px; }
.shop-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; border-top: 1px solid var(--iron-light); }
.shop-row:first-of-type { border-top: none; }
.shop-portrait { width: 24px; height: 32px; image-rendering: pixelated; flex: none; }
.shop-glyph { width: 24px; height: 24px; image-rendering: pixelated; flex: none; margin: 4px 0; }
.shop-info { flex: 1; min-width: 0; }
.shop-name { font-family: var(--display); font-size: 16px; line-height: 1.1; color: var(--bone); }
.shop-meta { font-size: 11.5px; color: var(--bone-dim); line-height: 1.25; }
button.buy {
  flex: none; min-width: 52px; padding: 4px 8px; font-size: 13px; cursor: pointer; color: var(--bone);
  background: linear-gradient(180deg, #3a2f27, #221c19); border: 1px solid #6a5a44;
}
button.buy::after { content: " t"; color: var(--bone-dim); font-style: italic; }
button.buy:hover:not(:disabled) { border-color: var(--ember-bright); color: #fff3dc; }
button.buy:disabled { opacity: 0.4; cursor: default; }
.camp-roster { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 0 16px; border-top: 1px solid var(--iron-light); font-size: 13px; }
.camp-roster .label { font-style: italic; color: var(--bone-dim); margin-right: 4px; }
.roster-chip { padding: 2px 8px; border: 1px solid #4a3c2a; color: var(--bone); background: #110d0b; }
.roster-empty { color: var(--bone-dim); font-style: italic; }
.deck-note { margin-left: auto; color: var(--bone-dim); font-style: italic; }
.camp-panel .primary { display: block; }
.camp-panel .primary:disabled { opacity: 0.4; }

.hidden { display: none !important; }
body.title #topbar, body.title #log, body.title #minimap, body.title #hand-wrap, body.title #prompt, body.title #unit-panel { visibility: hidden; }
body.cutscene #hand-wrap, body.cutscene #unit-panel, body.cutscene #minimap, body.cutscene #hover-card, body.cutscene #log { visibility: hidden; }
body.cutscene #prompt { top: auto; bottom: 22px; font-style: italic; color: var(--bone-dim); background: none; border: none; }
#hud-phase[data-phase="cutscene"] { color: var(--bone); font-style: italic; }

@media (prefers-reduced-motion: reduce) {
  .card, .log-line, .panel { transition: none; animation: none; }
}
@media (max-width: 1100px) {
  #topbar { min-width: 0; width: calc(100vw - 20px); gap: 14px; }
  #log { width: 220px; }
}
