/* GANGS – Copenhagen 1857 */

@font-face { font-family: 'Playfair Display'; font-weight: 700; font-display: swap; src: url('../fonts/playfair-display-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Playfair Display'; font-weight: 900; font-display: swap; src: url('../fonts/playfair-display-latin-900-normal.woff2') format('woff2'); }
@font-face { font-family: 'Source Sans 3'; font-weight: 400; font-display: swap; src: url('../fonts/source-sans-3-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Source Sans 3'; font-weight: 600; font-display: swap; src: url('../fonts/source-sans-3-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Source Sans 3'; font-weight: 700; font-display: swap; src: url('../fonts/source-sans-3-latin-700-normal.woff2') format('woff2'); }

:root {
  --soot: #120d0a;
  --soot-2: #1c1511;
  --soot-3: #2a201a;
  --oak: #5a3a22;
  --oak-light: #8a5e3a;
  --parchment: #e9dcc0;
  --parchment-dim: #b9ab8e;
  --slate: #4e6a82;
  --slate-light: #8aa6bd;
  --blood: #9e1b14;
  --blood-bright: #d12a1e;
  --brass: #c9a227;
  --brass-light: #f0c64a;
  --move: #3b82d6;
  --head: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --body: 'Source Sans 3', 'Segoe UI', Roboto, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tap: 44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--soot); color: var(--parchment); font-family: var(--body); font-size: 16px; overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible { outline: 2px solid var(--brass-light); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--head); margin: 0; }

#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }

/* ---------- buttons ---------- */
.btn {
  min-height: var(--tap); padding: 10px 18px; border-radius: 10px;
  border: 1px solid rgba(233, 220, 192, 0.25); background: var(--soot-3);
  font-weight: 600; letter-spacing: 0.02em;
}
.btn.primary { background: linear-gradient(#b8231a, var(--blood)); border-color: #e0483a; box-shadow: 0 4px 0 #5e0f0b, 0 6px 18px rgba(0, 0, 0, 0.5); }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #5e0f0b; }
.btn.big { min-height: 56px; font-size: 1.15rem; padding: 12px 28px; }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: var(--blood-bright); color: #f0a49c; }

/* ---------- title ---------- */
#screen-title {
  background:
    radial-gradient(ellipse at 50% 30%, rgba(201, 162, 39, 0.18), transparent 60%),
    radial-gradient(ellipse at 50% 110%, rgba(158, 27, 20, 0.35), transparent 60%),
    linear-gradient(#0d0a08, #1a1310);
}
.title-card { max-width: 440px; margin: 0 auto; height: 100%; padding: calc(40px + var(--safe-top)) 28px calc(28px + var(--safe-bottom)); display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 14px; }
.kicker { font-family: var(--head); letter-spacing: 0.35em; text-transform: uppercase; color: var(--brass); margin: 0; font-size: 0.85rem; }
.logo { font-size: clamp(4rem, 22vw, 6.5rem); font-weight: 900; letter-spacing: 0.06em; line-height: 0.95; color: var(--parchment); text-shadow: 0 3px 0 var(--blood), 0 0 40px rgba(209, 42, 30, 0.35); }
.tagline { font-family: var(--head); font-size: 1.2rem; margin: 0; color: var(--parchment); }
.intro { color: var(--parchment-dim); line-height: 1.5; margin: 6px 0 12px; }
.intro em { color: var(--brass-light); font-style: normal; }
.small { color: var(--parchment-dim); font-size: 0.85rem; opacity: 0.8; }

/* ---------- battle ---------- */
.stage { position: absolute; inset: 0; }
#battle-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#float-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.hud-top {
  position: absolute; top: 0; left: 0; right: 0; padding: calc(6px + var(--safe-top)) 8px 6px;
  background: linear-gradient(rgba(12, 9, 7, 0.95) 70%, rgba(12, 9, 7, 0));
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.turn-bar { display: flex; align-items: center; gap: 6px; }
.round { font-family: var(--head); font-weight: 700; color: var(--brass); font-size: 0.95rem; white-space: nowrap; }
.turn { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn.enemy { color: var(--slate-light); }
.chip { min-width: var(--tap); min-height: var(--tap); padding: 0 10px; border-radius: 22px; background: var(--soot-3); border: 1px solid rgba(233, 220, 192, 0.2); font-weight: 700; }
.chip.on { background: var(--brass); color: var(--soot); border-color: var(--brass-light); }
.chip.icon { font-size: 1.2rem; }

.portrait-strip { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 2px; scrollbar-width: none; }
.portrait-strip::-webkit-scrollbar { display: none; }
.pcard {
  position: relative; flex: 0 0 auto; width: 62px; min-height: 80px; padding: 3px 3px 4px; border-radius: 10px;
  background: var(--soot-2); border: 2px solid rgba(233, 220, 192, 0.15);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.pcard img { width: 44px; height: 44px; border-radius: 8px; display: block; }
.pname { font-size: 0.72rem; font-weight: 700; max-width: 56px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pips { display: flex; gap: 3px; }
.pips i { width: 9px; height: 9px; border-radius: 50%; background: rgba(0, 0, 0, 0.6); border: 1px solid #000; }
.pips i.on { background: var(--blood-bright); }
.pcard.active { border-color: var(--brass-light); box-shadow: 0 0 12px rgba(240, 198, 74, 0.6); }
.pcard.acted { opacity: 0.5; }
.pcard.down { opacity: 0.4; filter: grayscale(1); }
.pcard .badge { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--brass); color: var(--soot); font-size: 0.7rem; font-weight: 700; display: grid; place-items: center; }
.pcard .badge.down { background: var(--blood); color: var(--parchment); }

.enemy-strip { display: flex; align-items: center; gap: 4px; font-size: 0.78rem; color: var(--slate-light); padding-top: 2px; }
.enemy-strip span { margin-right: 4px; font-weight: 700; }
.enemy-strip i { width: 10px; height: 10px; border-radius: 50%; background: var(--slate-light); }
.enemy-strip i.down { background: transparent; border: 1px solid var(--slate); }

.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px calc(8px + var(--safe-bottom));
  background: linear-gradient(rgba(12, 9, 7, 0), rgba(12, 9, 7, 0.94) 22%);
  pointer-events: none;
}
.hud-bottom > * { pointer-events: auto; }
.hint { margin: 0 0 6px; text-align: center; font-size: 0.85rem; color: var(--brass-light); min-height: 1.2em; text-shadow: 0 1px 3px #000; pointer-events: none; }

.unit-card { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 10px; background: rgba(28, 21, 17, 0.9); border: 1px solid rgba(201, 162, 39, 0.35); min-height: 58px; }
.unit-card.enemy { border-color: rgba(138, 166, 189, 0.4); }
.unit-card:empty { display: none; }
.unit-card img { width: 46px; height: 46px; border-radius: 8px; flex: 0 0 auto; }
.uc-main { min-width: 0; flex: 1; }
.uc-name { font-family: var(--head); font-weight: 700; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uc-name b { font-family: var(--body); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; padding: 1px 5px; border-radius: 4px; vertical-align: 2px; }
.uc-name .boss { background: var(--brass); color: var(--soot); }
.uc-name .rival { background: var(--slate); }
.uc-sub { font-size: 0.75rem; color: var(--parchment-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uc-stats { display: flex; gap: 8px; margin-top: 2px; font-weight: 700; font-size: 0.9rem; }
.uc-stats small { font-size: 0.6rem; color: var(--parchment-dim); margin-right: 2px; font-weight: 600; }
.uc-traits { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.uc-traits em { font-style: normal; font-size: 0.68rem; padding: 0 5px; border-radius: 4px; background: var(--oak); }

.combat-log { margin-top: 6px; height: 36px; overflow-y: auto; font-size: 0.75rem; color: var(--parchment-dim); padding: 2px 6px; border-radius: 6px; background: rgba(0, 0, 0, 0.35); cursor: pointer; transition: height 0.2s; }
.combat-log.expanded { height: 140px; }
.combat-log p { margin: 0 0 2px; }
.combat-log p:last-child { color: var(--parchment); }

.action-bar { display: grid; grid-template-columns: 1fr 1.2fr 1fr 1.2fr; gap: 6px; margin-top: 6px; }
.act { min-height: 54px; border-radius: 12px; font-weight: 700; font-size: 0.95rem; background: var(--soot-3); border: 2px solid rgba(233, 220, 192, 0.18); line-height: 1.1; }
.act.on { border-color: var(--move); background: #1d3550; }
.act.attack { background: linear-gradient(#b8231a, var(--blood)); border-color: #e0483a; }
.act.attack.on { box-shadow: 0 0 0 2px var(--brass-light); }
.act.end { background: var(--oak); border-color: var(--oak-light); }
.act.end.pulse { animation: pulse 1.2s infinite; }
.act:disabled { opacity: 0.35; filter: grayscale(0.7); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(240, 198, 74, 0.7); } 50% { box-shadow: 0 0 0 6px rgba(240, 198, 74, 0); } }

/* banner + toasts */
.banner { position: absolute; left: 0; right: 0; top: 36%; text-align: center; pointer-events: none; opacity: 0; }
.banner h2 { font-size: 2rem; font-weight: 900; text-shadow: 0 3px 0 var(--blood), 0 0 20px #000; }
.banner p { margin: 4px 0 0; color: var(--brass-light); font-weight: 600; text-shadow: 0 1px 4px #000; }
.banner.show { animation: banner 2.2s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: scale(1.15); } 12% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; } }
.toast { position: absolute; left: 50%; top: 42%; transform: translateX(-50%); padding: 8px 16px; border-radius: 20px; background: rgba(12, 9, 7, 0.9); border: 1px solid var(--brass); font-weight: 700; animation: toast 1.6s ease-out forwards; }
@keyframes toast { 0% { opacity: 0; } 15%, 70% { opacity: 1; } 100% { opacity: 0; } }

/* floating combat text */
.float-text { position: absolute; left: 0; top: 0; font-family: var(--head); font-weight: 900; font-size: 1.8rem; text-shadow: 0 2px 0 #000, 0 0 8px #000; white-space: nowrap; will-change: transform; }
.float-text.dmg { color: #ff4a3a; }
.float-text.saved { color: var(--slate-light); font-size: 1.3rem; }
.float-text.miss { color: var(--parchment-dim); font-size: 1.2rem; }
.float-text.down { color: var(--brass-light); font-size: 2.2rem; letter-spacing: 0.1em; }

/* dice */
.dice-tray { position: absolute; left: 50%; top: calc(178px + var(--safe-top)); transform: translateX(-50%) translateY(-10px); padding: 8px 12px; border-radius: 12px; background: rgba(12, 9, 7, 0.88); border: 1px solid rgba(201, 162, 39, 0.4); opacity: 0; pointer-events: none; transition: opacity 0.15s, transform 0.15s; min-width: 200px; }
.dice-tray.show { opacity: 1; transform: translateX(-50%); }
.dice-row { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dice-row + .dice-row { margin-top: 6px; }
.dice-row span { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--parchment-dim); }
.dice { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.die { width: 34px; height: 34px; border-radius: 7px; background: var(--parchment); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 4px; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25); transition: transform 0.2s; }
.die i { width: 6px; height: 6px; margin: auto; border-radius: 50%; }
.die i.on { background: var(--soot); }
.die.rolling { animation: wobble 0.12s infinite alternate; }
.die.hidden { visibility: hidden; }
.die.hit { background: var(--brass-light); transform: scale(1.1); }
.die.crit { background: #ff7a5a; box-shadow: 0 0 10px #ff4a3a; }
.die.miss { opacity: 0.45; }
.saves .die { background: var(--slate-light); }
.saves .die.saved { background: #cfe1ef; transform: scale(1.1); }
.saves .die.fail { opacity: 0.45; }
.die.ghost { width: 26px; height: 26px; padding: 3px; background: var(--brass-light); }
.die.ghost i { width: 5px; height: 5px; }
@keyframes wobble { from { transform: rotate(-12deg) translateY(-2px); } to { transform: rotate(12deg) translateY(2px); } }

/* sheets */
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; padding: 18px 16px calc(16px + var(--safe-bottom)); background: var(--soot-2); border-top: 2px solid var(--brass); border-radius: 18px 18px 0 0; transform: translateY(105%); transition: transform 0.22s ease-out; }
.sheet.open { transform: translateY(0); }
.sheet h2 { font-size: 1.4rem; margin-bottom: 10px; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 10px; margin-top: 14px; }
#menu-sheet .sheet-actions { grid-template-columns: 1fr; }
.vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; text-align: center; gap: 8px; }
.vs-side img { width: 56px; height: 56px; border-radius: 10px; display: block; margin: 0 auto 4px; }
.vs-side b { display: block; font-family: var(--head); font-size: 0.95rem; }
.vs-side small { color: var(--parchment-dim); }
.vs-mid { font-family: var(--head); font-weight: 900; color: var(--blood-bright); font-size: 1.1rem; }
.preview-dice { display: flex; justify-content: center; gap: 6px; margin: 12px 0 8px; }
.preview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preview-grid div { background: var(--soot); border-radius: 10px; padding: 8px 10px; }
.preview-grid span { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--parchment-dim); }
.preview-grid b { font-family: var(--head); font-size: 1.6rem; color: var(--brass-light); }
.preview-grid small { display: block; font-size: 0.72rem; color: var(--parchment-dim); }
.toggle { display: flex; align-items: center; justify-content: space-between; min-height: 52px; border-bottom: 1px solid rgba(233, 220, 192, 0.1); font-weight: 600; }
.toggle input { width: 26px; height: 26px; accent-color: var(--brass); }

/* ---------- result ---------- */
#screen-result { overflow-y: auto; background: radial-gradient(ellipse at 50% 0%, rgba(201, 162, 39, 0.15), transparent 60%), var(--soot); }
.result-card { max-width: 520px; margin: 0 auto; padding: calc(28px + var(--safe-top)) 18px calc(24px + var(--safe-bottom)); }
.result-card h1 { font-size: 3.4rem; font-weight: 900; text-align: center; }
.result-card.won h1 { color: var(--brass-light); text-shadow: 0 3px 0 #6a4a08; }
.result-card.lost h1 { color: var(--blood-bright); text-shadow: 0 3px 0 #3a0806; }
.result-sub { text-align: center; color: var(--parchment-dim); margin: 4px 0 18px; }
.loot { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; margin-bottom: 18px; }
.loot div { background: var(--soot-2); border: 1px solid rgba(201, 162, 39, 0.35); border-radius: 12px; padding: 10px 12px; }
.loot span { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--parchment-dim); }
.loot b { font-family: var(--head); font-size: 1.3rem; color: var(--brass-light); }
.loot small { display: block; color: var(--parchment-dim); font-size: 0.75rem; }
.result-card h3 { font-size: 1.1rem; margin-bottom: 8px; color: var(--parchment); }
.result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.result-list li { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 12px; background: var(--soot-2); }
.result-list li.dead { opacity: 0.6; filter: grayscale(0.8); }
.result-list img { width: 48px; height: 48px; border-radius: 8px; }
.result-list b { display: block; font-family: var(--head); }
.result-list span { font-size: 0.85rem; color: var(--parchment-dim); }
.result-list .bad { color: #ff6a5a; display: inline; font-family: var(--body); }
.result-list .warn { color: #e8a54a; display: inline; font-family: var(--body); }
.result-list .good { color: #8fd18a; display: inline; font-family: var(--body); }
.result-list .gold { color: var(--brass-light); display: inline; font-family: var(--body); }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.result-actions .primary { grid-column: 1 / -1; min-height: 56px; }

/* reduced motion */
.reduced-motion .banner.show { animation-duration: 1.6s; }
.reduced-motion .act.end.pulse { animation: none; box-shadow: 0 0 0 2px var(--brass-light); }
.reduced-motion .die.rolling { animation: none; }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop, .dice-tray { transition: none; } }

/* wider screens: keep the HUD phone-sized */
@media (min-width: 700px) {
  .hud-bottom, .hud-top { max-width: 560px; margin: 0 auto; }
  .hud-top { border-radius: 0 0 14px 14px; }
}
