:root {
  --bg: #0d1226;
  --panel: #171e3a;
  --panel-2: #212a4f;
  --line: #34407a;
  --text: #eef0fa;
  --muted: #9aa3cc;
  --gold: #f2c94c;
  --good: #6fd08c;
  --bad: #ef6b6b;
  --ink: #0a0e1f;
  --floor: #171e3a;
  --floor2: #212a4f;
  --glow: #f2c94c;
  /* Screen pixels per pixel of an interface piece. The pieces themselves (--ui-panel, --ui-btn and the rest) and
     the colours above are set per sin by theme() in src/client/ui.ts. */
  --ui: 3;
  /* The same for panels, which read better with a thinner frame. */
  --frame: 2;
  --btn-text: var(--text);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(120% 80% at 50% 0%, var(--panel-2) 0%, var(--bg) 60%) fixed var(--bg);
  color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 1280px;
  min-height: 100%;
  margin: 0 auto;
  padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.px { image-rendering: pixelated; }

/* Home: the title hangs on a wooden sign between two candles, over a darkened scene. */
.hero { --sign: 3; position: relative; height: calc(var(--sign) * 96px); overflow: hidden; }
.hero::after { content: ''; position: absolute; inset: 0; background: linear-gradient(rgba(5, 4, 10, 0.35), var(--bg)); }
.hero .title { position: absolute; inset: 0; z-index: 1; display: flex; justify-content: center; align-items: flex-end; gap: calc(var(--sign) * 6px); }
.hero .candle { width: calc(var(--sign) * 11px); height: calc(var(--sign) * 23px); margin-bottom: calc(var(--sign) * 14px); }
.sign {
  width: calc(var(--sign) * 71px);
  height: calc(var(--sign) * 92px);
  padding-top: calc(var(--sign) * 22px);
  display: grid;
  place-items: center;
  background: 0 0 / 100% 100% no-repeat;
  image-rendering: pixelated;
}
h1 {
  margin: 0;
  font: 600 calc(var(--sign) * 9px)/1.05 Georgia, 'Times New Roman', serif;
  letter-spacing: 0.03em;
  text-align: center;
  color: #3a1c08;
}

h2 { margin: 0; font-size: 16px; }
p { margin: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* A button is the pack's slab stretched from its corners: the sin's colour, gold for the main action, grey when off. */
button {
  font: inherit;
  font-weight: 700;
  color: var(--btn-text);
  border: solid transparent;
  border-width: calc(var(--ui) * 3px) calc(var(--ui) * 4px) calc(var(--ui) * 4px);
  border-image: var(--ui-btn) 3 4 4 fill / calc(var(--ui) * 3px) calc(var(--ui) * 4px) calc(var(--ui) * 4px) stretch;
  background: none;
  padding: 3px 8px 2px;
  image-rendering: pixelated;
  cursor: pointer;
}
button:not(:disabled):hover { filter: brightness(1.15); }
button:not(:disabled):active { transform: translateY(calc(var(--ui) * 1px)); }
button:disabled { border-image-source: var(--ui-btn-off); color: #8a8590; cursor: default; }
button.primary:not(:disabled) { border-image-source: var(--ui-btn-gold); color: #2a2000; }
button.small { --ui: 2; padding: 1px 6px; font-size: 13px; }
button.quiet { align-self: center; border: 0; border-image: none; padding: 6px 10px; font-weight: 400; color: var(--muted); }

/* A panel is the pack's dark frame with knobs at the corners, its trim in the sin's colour. */
.panel, .topbar {
  position: relative;
  border: calc(var(--frame) * 5px) solid transparent;
  border-image: var(--ui-panel) 8 fill / calc(var(--frame) * 8px) stretch;
  image-rendering: pixelated;
}
.panel {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  font-size: 13px;
}
.topbar strong { font: 600 16px/1 Georgia, 'Times New Roman', serif; letter-spacing: 0.04em; color: var(--btn-text); }
.topbar .luz { display: flex; align-items: center; gap: 2px; margin: 0 0 0 auto; color: #ffe08a; font-weight: 700; }
.topbar .luz img { width: 28px; height: 28px; }
.hearts { display: flex; gap: 2px; }
.hearts img { width: 27px; height: 22.5px; }

/* Horizontal layout: enemy layers run back to front on the left, yours front to back on the right.
   The sin's backdrop is painted behind it in scene pixels of --px screen pixels; figures use the same size. */
.arena {
  --px: 3;
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: calc(var(--px) * 30px) 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.scene { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.arena > :not(.scene) { position: relative; }
/* A magic effect: a strip of frames stepped through by fx.ts, above the figures. */
.fx, .arena > .fx { position: absolute; z-index: 4; display: block; background-repeat: no-repeat; image-rendering: pixelated; pointer-events: none; }
.arena .layer-label, .arena .divider { color: var(--text); opacity: 0.7; text-shadow: 0 1px 2px #000; }

/* On the arena a unit stands on the floor: no tile, a ring where it may stand, health and form over its head. */
.arena .slot, .arena .slot.unit, .arena .slot.enemy.unit { border: 0; background: none; min-height: 112px; padding: 0; justify-content: flex-start; gap: 1px; }
.arena .slot::after {
  content: '';
  position: absolute;
  left: 50%;
  top: calc(var(--px) * 26px);
  width: calc(var(--px) * 22px);
  height: calc(var(--px) * 6px);
  margin-left: calc(var(--px) * -11px);
  border: 2px dotted rgba(255, 255, 255, 0.18);
  border-radius: 50%;
}
.arena .slot.unit::after { border-color: transparent; background: rgba(0, 0, 0, 0.42); }
.arena .slot.selected, .arena .slot.elite { box-shadow: none; }
.arena .slot.elite::after, .arena .slot.boss::after { border: 2px solid var(--aura); box-shadow: 0 0 8px var(--aura); }
.arena .slot.selected::after { border: 2px solid var(--gold); }
.arena .slot svg, .arena .slot svg.fig { width: calc(var(--px) * 24px); height: calc(var(--px) * 24px); position: relative; z-index: 1; }
.arena .slot .info { display: contents; }
.arena .slot .name { display: none; }
.arena .slot .hpbar { order: -2; width: calc(var(--px) * 16px); height: 7px; margin: 0; border: 1px solid #10131f; border-radius: 0; }
.arena .slot .stars { order: -1; font-size: 9px; line-height: 9px; text-shadow: 0 1px 2px #000; }
.arena .slot .stats { position: relative; z-index: 1; color: var(--text); text-shadow: 0 1px 2px #000, 0 0 4px #000; }
.field { display: flex; flex: 1; gap: 5px; }
.layer { flex: 1; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.layer .slot { flex: 1; }
.layer-label {
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.divider {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 22px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  writing-mode: vertical-rl;
}
.divider::before, .divider::after { content: ''; flex: 1; width: 1px; background: var(--line); }

.prep { display: grid; grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); gap: 12px; align-items: start; }
.board, .side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.difficulty { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.levels { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.sins { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 8px; }
.sins .panel.locked { opacity: 0.45; filter: grayscale(0.8); }

.slot {
  position: relative;
  min-height: 110px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.02);
}
.slot.unit { border-style: solid; background: var(--panel); }
.slot.enemy.unit { background: #1f2230; border-color: #4a4f6a; }
.slot.tappable { cursor: pointer; }
.slot.selected { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(242, 201, 76, 0.35); }
.slot.dead { opacity: 0.22; filter: grayscale(1); }
.slot svg { width: 48px; height: 48px; flex: none; }
.slot svg.fig, .card svg.fig { width: 60px; height: 60px; }

/* Pack figures carry every frame; one shows at a time. */
.fig { overflow: visible; }
.fig .f { visibility: hidden; }
.fig .i0 { animation: fig0 1.2s steps(1) infinite; }
.fig .i1 { animation: fig1 1.2s steps(1) infinite; }
.fig .i2 { animation: fig2 1.2s steps(1) infinite; }
.fig .i3 { animation: fig3 1.2s steps(1) infinite; }
.atk .fig .f { animation: none; }
.atk .fig .a0 { animation: fig0 var(--atk, 340ms) steps(1) 1; }
.atk .fig .a1 { animation: fig1 var(--atk, 340ms) steps(1) 1; }
.atk .fig .a2 { animation: fig2 var(--atk, 340ms) steps(1) 1; }
.atk .fig .a3 { animation: fig3 var(--atk, 340ms) steps(1) 1; }
.dead .fig .f { animation: none; }
.dead .fig .d { visibility: visible; }
.dead .fig .top { visibility: hidden; }
@keyframes fig0 { 0% { visibility: visible; } 25%, 100% { visibility: hidden; } }
@keyframes fig1 { 0%, 50%, 100% { visibility: hidden; } 25% { visibility: visible; } }
@keyframes fig2 { 0%, 75%, 100% { visibility: hidden; } 50% { visibility: visible; } }
@keyframes fig3 { 0%, 100% { visibility: hidden; } 75% { visibility: visible; } }
@media (prefers-reduced-motion: reduce) {
  .fig .f { animation: none !important; }
  .fig .i0 { visibility: visible; }
  .dead .fig .i0 { visibility: hidden; }
}
.slot .info { min-width: 0; width: 100%; }
.slot .name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot .stars { color: var(--gold); font-size: 10px; letter-spacing: 1px; }
.slot .stats { font-size: 11px; color: var(--muted); white-space: nowrap; }
.hpbar { height: 5px; border-radius: 3px; background: #0a0e1f; overflow: hidden; margin: 2px 0; }
.hpbar i { display: block; height: 100%; background: var(--good); transition: width 0.15s; }
.enemy .hpbar i { background: #c9a35a; }

.pop {
  position: absolute;
  left: 50%;
  top: 2px;
  transform: translateX(-50%);
  font-weight: 800;
  font-size: 17px;
  color: var(--bad);
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
  white-space: nowrap;
  z-index: 3;
}
.pop.heal { color: var(--good); }
.pop.note { color: var(--gold); font-size: 13px; }

.bench { display: grid; grid-template-columns: auto repeat(6, 1fr); gap: 4px; align-items: stretch; }
.bench .layer-label { grid-row: 1 / 3; writing-mode: vertical-rl; transform: rotate(180deg); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 3px; border-radius: 16px; padding: 1px 6px; font-size: 11px; border: 1px solid; background: rgba(0, 0, 0, 0.3); }
.chip b { color: var(--muted); }
.chip.player { border-color: #5b8def; }
.chip.enemy { border-color: #e0605a; }
.chip.active { background: var(--gold); border-color: #fff; box-shadow: 0 0 6px var(--gold); }
.chip.asleep { opacity: 0.45; }

.offer { display: grid; grid-template-columns: repeat(3, 102px); justify-content: center; gap: 14px 8px; padding-top: 10px; }
.odds { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; }
.odds span { color: var(--gold); white-space: nowrap; }
/* A shop card is the pack's frame, 102 by 158, painted in the sin's tones: portrait on top, a text panel, then
   the attack, form and health sockets. */
.card {
  position: relative;
  flex: none;
  width: 102px;
  height: 158px;
  padding: 0;
  border: 0;
  border-image: none;
  font-weight: 400;
  color: var(--text);
  background: none 0 0 / 100% 100% no-repeat;
  image-rendering: pixelated;
}
.card.off { opacity: 0.45; cursor: default; }
.card.off:hover { filter: none; }
.card.off:active { transform: none; }
.card svg, .card svg.fig { position: absolute; left: 15px; top: 14px; width: 72px; height: 72px; }
.card .name {
  position: absolute;
  left: 8px;
  right: 8px;
  top: -8px;
  z-index: 1;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  color: var(--ink);
  background: var(--glow);
  border: 2px solid var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .mid { position: absolute; left: 6px; right: 6px; top: 102px; height: 30px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15; }
.card .price { font-size: 12px; font-weight: 700; color: #fff3c4; text-shadow: 0 1px 0 #000; }
.card .tag { font-size: 9px; color: #fff; text-shadow: 0 1px 0 #000; white-space: nowrap; }
.card .atk, .card .hp, .card .lvl { position: absolute; top: 134px; height: 18px; font: 700 13px/18px ui-monospace, Menlo, Consolas, monospace; color: #fff; text-shadow: 1px 1px 0 var(--ink); text-align: center; }
.card .atk { left: 4px; width: 30px; }
.card .hp { left: 68px; width: 30px; }
.card .lvl { left: 36px; width: 30px; font-size: 7px; letter-spacing: -1px; color: var(--ink); text-shadow: none; }
.card.sold { border: 1px dashed var(--muted); opacity: 0.35; }
.luz { color: var(--gold); font-weight: 600; margin-right: 8px; }

.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; }
.detail { display: block; font-size: 12px; min-height: 34px; }

.banner {
  text-align: center;
  font: 600 22px/1.2 Georgia, serif;
  color: var(--gold);
}
.banner.lost { color: var(--bad); }
.angel { display: flex; gap: 10px; align-items: center; }
/* Story pages: a measure that reads well on a phone and on a desktop. */
.story { max-width: 40rem; width: 100%; margin: 0 auto; gap: 12px; font-size: 16px; line-height: 1.6; }
.story p { text-wrap: pretty; }
.story em { color: var(--muted); }
.story-actions { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.angel svg { width: 96px; height: 96px; flex: none; }
/* The freed angel stands alone while light comes down around it. */
.rise { position: relative; height: 120px; display: grid; place-items: center; }
.rise svg { width: 96px; height: 96px; position: relative; z-index: 1; }
.slot.elite { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.bench .slot, .bench .slot.unit {
  min-height: 62px;
  padding: 2px 3px;
  border: 0;
  border-radius: 0;
  background: linear-gradient(var(--floor) 0 calc(100% - 10px), var(--floor2) calc(100% - 10px) calc(100% - 7px), var(--ink) calc(100% - 7px));
  box-shadow: inset 0 0 0 2px var(--ink);
}
.bench .slot.selected { box-shadow: inset 0 0 0 2px var(--gold); }
.bench .slot svg.fig { width: 40px; height: 40px; }
.bench .slot .name { font-size: 10px; }
.bench .slot .hpbar, .bench .slot .stats { display: none; }

/* Statuses sit in the tile's corner. */
.badges { position: absolute; top: 2px; right: 3px; display: flex; gap: 1px; font-size: 12px; line-height: 1; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(5, 8, 20, 0.78);
  overflow: auto;
}
.modal .panel { --frame: 3; max-width: 860px; width: 100%; padding-top: calc(var(--frame) * 6px); }
/* The frame's tab sits on the top edge of a window. */
.modal .panel::before {
  content: '';
  position: absolute;
  top: calc(var(--frame) * -5px);
  left: calc(50% - var(--frame) * 15px);
  width: calc(var(--frame) * 30px);
  height: calc(var(--frame) * 10px);
  background: var(--ui-tab) 0 0 / 100% 100% no-repeat;
}
.branches { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.branch {
  --frame: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 400;
  color: var(--text);
  border-width: calc(var(--frame) * 5px);
  border-image: var(--ui-panel) 8 fill / calc(var(--frame) * 8px) stretch;
  padding: 4px 6px;
}
.branch strong { font-size: 14px; }
.branch .tag { color: var(--gold); text-transform: uppercase; letter-spacing: 0.08em; font-size: 10px; }
.branch .pair { display: flex; gap: 6px; }
.branch svg.fig { width: 56px; height: 56px; }

/* A small picture of a unit, an angel or a sin, standing still. */
.thumb { display: inline-flex; width: 28px; height: 28px; flex: none; }
.thumb svg, .slot .thumb svg.fig { width: 100%; height: 100%; }
.thumb.wide { margin: 0 5px; }
.thumb .fig .f, .thumb .bob { animation: none; }
.thumb .fig .i0 { visibility: visible; }

/* The auras in force sit over the board, each beside whoever grants it. */
.auras { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 32px; font-size: 11px; }
.aura {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 8px 1px 2px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}
.aura.enemy { border-color: #e0605a; }
.token { width: 14px; height: 14px; flex: none; border-radius: 50%; background: #0d0b13; }
.off { opacity: 0.3; filter: grayscale(1); }
/* A unit wears a token for every aura that reaches it. */
.tokens { position: relative; z-index: 1; display: flex; flex-wrap: wrap; justify-content: center; gap: 1px; min-height: 12px; }
.tokens i { display: flex; }
.tokens .token, .arena .slot .tokens .token { width: 12px; height: 12px; }
.bench .tokens { display: none; }

/* The detail card floats over whatever it describes. */
#tip {
  position: fixed;
  z-index: 20;
  display: block;
  max-width: min(300px, calc(100vw - 12px));
  font-size: 12px;
  pointer-events: none;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
}
#tip[hidden] { display: none; }
.hint { font-size: 12px; }

/* The sins and their angels are a third larger than a unit, and never quite still. */
.arena .slot svg.big { width: calc(var(--px) * 32px); height: calc(var(--px) * 32px); margin: 0 calc(var(--px) * -4px); }
.arena .slot.boss::after { top: calc(var(--px) * 34px); width: calc(var(--px) * 28px); margin-left: calc(var(--px) * -14px); }
.big .bob { animation: bob 1.4s steps(1) infinite; }
.dead .big .bob { animation: none; }
.atk svg.big { animation: strike var(--atk, 340ms) ease-in-out 1; }
@keyframes bob { 50% { transform: translateY(1px); } }
@keyframes strike { 50% { transform: scale(1.15); } }

/* Without tiles, light tells the ranks apart: a lesser angel shines, a guardian burns in its sin's colour
   and stands taller, and the sin itself glows. */
.risen { --halo: #ffe08a; }
.enemy.risen { --halo: var(--aura); }
.risen svg.fig { animation: shine 2.4s ease-in-out infinite; }
.arena .slot.elite svg.fig { margin-top: calc(var(--px) * 3px); }
.slot.elite svg.fig { transform: scale(1.15); transform-origin: 50% 100%; animation: burn 1.1s ease-in-out infinite; }
.slot.boss svg.fig { animation: shine 1.6s ease-in-out infinite; --halo: var(--aura); }
.slot.dead svg.fig { animation: none; filter: none; }
@keyframes shine {
  0%, 100% { filter: drop-shadow(0 0 1px var(--halo)) drop-shadow(0 0 2px var(--halo)); }
  50% { filter: drop-shadow(0 0 2px var(--halo)) drop-shadow(0 0 8px var(--halo)); }
}
@keyframes burn {
  0%, 100% { filter: drop-shadow(1px 0 0 var(--aura)) drop-shadow(-1px 0 0 var(--aura)) drop-shadow(0 -1px 0 var(--aura)) drop-shadow(0 -1px 3px var(--aura)); }
  50% { filter: drop-shadow(1px 0 0 var(--aura)) drop-shadow(-1px 0 0 var(--aura)) drop-shadow(0 -1px 0 var(--aura)) drop-shadow(0 -4px 9px var(--aura)); }
}
@media (prefers-reduced-motion: reduce) {
  .big .bob, .risen svg.fig, .slot.elite svg.fig, .slot.boss svg.fig { animation: none; }
  .risen svg.fig, .slot.boss svg.fig { filter: drop-shadow(0 0 2px var(--halo)) drop-shadow(0 0 5px var(--halo)); }
  .slot.elite svg.fig { filter: drop-shadow(1px 0 0 var(--aura)) drop-shadow(-1px 0 0 var(--aura)) drop-shadow(0 -1px 0 var(--aura)) drop-shadow(0 -2px 6px var(--aura)); }
}

/* Narrow screens: the shop goes under the board, and tiles shrink to fit six cells across. */
@media (max-width: 820px) {
  :root { --ui: 2; }
  .modal .panel { --frame: 2; }
  .hero { --sign: 2; }
  .prep { grid-template-columns: minmax(0, 1fr); }
  .slot { min-height: 92px; padding: 3px 2px; }
  .arena { --px: 2; padding-left: 4px; padding-right: 4px; }
  .arena .slot, .arena .slot.unit { min-height: 84px; }
  .slot .name { font-size: 10px; }
  .slot .stats { font-size: 9px; }
  .arena { gap: 4px; }
  .field { gap: 3px; }
  .divider { width: 14px; font-size: 9px; }
  .bench .slot svg.fig { width: 34px; height: 34px; }
  .thumb { width: 24px; height: 24px; }
  .tokens .token, .arena .slot .tokens .token { width: 10px; height: 10px; }
}
@media (max-width: 820px) {
  .field, .layer, .slot { min-width: 0; }
  .slot .info { overflow: hidden; }
}
