/* Pale Spire - pixel-art styling.
   Pixel look carried by icons, frames, headings and numbers; body prose stays in a readable face.
   Headings use Silkscreen from fonts/pixel.woff2; the stack falls back to monospace if it is missing. */

@font-face {
  font-family: 'PixelUI';
  src: url('fonts/pixel.woff2') format('woff2');
  font-display: swap;
}

:root {
  --bg: #12151a;
  --bg-deep: #080a0d;
  --panel: #1a1f26;
  --panel-alt: #222831;
  --panel-lit: #2a323d;
  --border: #414c59;
  --border-lit: #5e6d80;
  --text: #ded7c9;
  --dim: #8792a0;
  --faint: #57616e;
  --gold: #e8b24a;
  --hp: #d84a4a;
  --skill: #4ad88a;
  --spell: #4a9ad8;
  --danger: #e0604a;
  --locked: #c05054;
  --ok: #6ad86a;
  --die-bg: #ded7c9;
  --die-pip: #10141a;

  --font-pixel: 'PixelUI', 'Lucida Console', 'Courier New', monospace;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

body {
  background-image:
    radial-gradient(circle at 20% 10%, #1e2632 0%, transparent 55%),
    radial-gradient(circle at 85% 90%, #171d26 0%, transparent 50%);
  background-attachment: fixed;
  min-height: 100vh;
}

.sprite { display: block; image-rendering: pixelated; }

/* ---------- shared chrome ---------- */

.frame {
  background: var(--panel);
  border: 3px solid var(--border);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .45), 0 3px 0 rgba(0, 0, 0, .5);
}

h1, h2, h3, .btn, .num, .panel-head, .step-title, th {
  font-family: var(--font-pixel);
  letter-spacing: .06em;
  text-transform: uppercase;
  font-weight: normal;
}

.btn {
  font-size: 13px;
  padding: 11px 16px;
  min-height: 44px;
  color: var(--text);
  background: var(--panel-alt);
  border: 3px solid var(--border);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .55);
  cursor: pointer;
  transition: none;
}
.btn:hover:not(:disabled) { background: var(--panel-lit); border-color: var(--border-lit); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.btn-primary { background: #4a3a20; border-color: var(--gold); color: var(--gold); }
.btn-primary:hover:not(:disabled) { background: #5d4826; }
.btn-danger { border-color: var(--locked); color: #ecb0b0; }

.screen { display: none; }
.screen.active { display: block; }

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

#screen-title { display: none; }
#screen-title.active {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}

.title-box { max-width: 460px; width: 100%; padding: 32px 28px; text-align: center; }
.game-title { font-size: 32px; margin: 0 0 6px; color: var(--gold); }
.subtitle { margin: 0 0 20px; color: var(--dim); font-size: 13px; }
.title-art { display: flex; justify-content: center; margin: 18px 0 24px; }
.title-buttons { display: flex; flex-direction: column; gap: 10px; }
.hint { color: var(--faint); font-size: 12px; margin: 16px 0 0; }

/* Credits + Offenlegung under the title box: legible, but never competing with the buttons. */
.colophon {
  max-width: 460px; width: 100%; margin: 22px auto 0;
  color: var(--faint); font-size: 11px; line-height: 1.45; text-align: center;
}
.colophon p { margin: 0 0 8px; }
.colophon p:last-child { margin-bottom: 0; }
.colophon strong, .colophon em { color: var(--dim); font-weight: inherit; font-style: normal; }
.colophon a { color: var(--dim); }
.colophon .disclosure { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 10px; }

/* ---------- character creation ---------- */

.create-wrap { max-width: 780px; margin: 0 auto; padding: 24px 16px 60px; }
.section-title { font-size: 20px; color: var(--gold); margin: 0 0 18px; }
.create-step { padding: 18px; margin-bottom: 16px; }
.step-title { font-size: 14px; margin: 0 0 12px; display: flex; align-items: center; gap: 10px; }
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; background: var(--gold); color: #12151a; font-size: 13px;
}
.step-note { color: var(--dim); font-size: 13px; margin: -4px 0 12px; }

#input-name {
  width: 100%; padding: 12px; font-family: var(--font-body); font-size: 16px;
  background: var(--bg); color: var(--text); border: 3px solid var(--border);
}
#input-name:focus { outline: none; border-color: var(--gold); }

.faction-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.faction-card {
  padding: 14px; background: var(--panel-alt); border: 3px solid var(--border);
  cursor: pointer; text-align: left; color: var(--text); min-height: 44px;
}
.faction-card:hover { border-color: var(--border-lit); }
.faction-card.selected { border-color: var(--gold); background: #3a2e1c; }
.faction-card .fname { font-family: var(--font-pixel); font-size: 13px; text-transform: uppercase; display: block; margin-bottom: 6px; }
.faction-card .fbonus { color: var(--gold); font-size: 13px; }

.attr-roll-area { display: flex; flex-direction: column; gap: 14px; }
.attr-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 8px; }
.attr-cell { background: var(--bg); border: 3px solid var(--border); padding: 10px 6px; text-align: center; }
.attr-cell .aname { font-family: var(--font-pixel); font-size: 11px; color: var(--dim); display: block; }
.attr-cell .aval { font-family: var(--font-pixel); font-size: 24px; color: var(--gold); display: block; margin-top: 4px; }
.attr-cell.rolling .aval { color: var(--dim); }

.derived-box { margin-top: 14px; padding: 14px; background: var(--bg); border: 3px solid var(--border); }
.derived-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px 18px; }
.derived-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 3px 0; }
.derived-row .dlabel { color: var(--dim); }
.derived-row .dval { font-family: var(--font-pixel); color: var(--text); }

.equip-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.equip-card {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  padding: 12px; background: var(--panel-alt); border: 3px solid var(--border);
  cursor: pointer; color: var(--text); min-height: 44px;
}
.equip-card:hover:not(:disabled) { border-color: var(--border-lit); }
.equip-card.selected { border-color: var(--gold); background: #3a2e1c; }
.equip-card:disabled { opacity: .35; cursor: not-allowed; }
.equip-card .ename { font-family: var(--font-pixel); font-size: 12px; text-transform: uppercase; display: block; margin-bottom: 5px; }
.equip-card .estats { font-size: 12px; color: var(--dim); }
.equip-card .eslot { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; }

.create-actions { display: flex; gap: 10px; justify-content: space-between; margin-top: 20px; }

/* ---------- game layout ---------- */

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
  min-height: 100vh;
}

/* Left: map (current floor only) above the character sheet. Right: the action area. */
.col-left { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 12px; }
.col-main { display: flex; flex-direction: column; min-height: calc(100vh - 24px); padding: 0; }

.panel { padding: 0; }
.panel-head {
  padding: 12px 14px; font-size: 12px; color: var(--dim);
  cursor: pointer; list-style: none; min-height: 44px; display: flex; align-items: center;
}
.panel-head::-webkit-details-marker { display: none; }
.panel-head::after { content: '▾'; margin-left: auto; }
.panel[open] .panel-head::after { content: '▴'; }
.panel-body { padding: 0 14px 14px; }

/* ---------- map ---------- */

.map-wing-label { font-family: var(--font-pixel); font-size: 10px; color: var(--faint); margin-bottom: 4px; text-transform: uppercase; }
.map-svg {
  /* Scales with the window instead of a fixed guess: a tall screen gets a big, readable map, a
     short one shrinks it before the character sheet has to give way. */
  width: 100%; height: auto; max-height: min(210px, 21vh); display: block; margin: 0 auto;
  background: var(--bg-deep); border: 2px solid var(--border);
}
.map-room { cursor: pointer; }
.map-room.unreachable { cursor: default; }
.map-legend { display: flex; flex-wrap: wrap; gap: 8px; font-size: 10px; color: var(--faint); margin-top: 4px; }
.map-legend span { display: flex; align-items: center; gap: 4px; }
.legend-swatch { width: 10px; height: 10px; display: inline-block; }

/* ---------- character sheet ---------- */

.sheet-name { font-family: var(--font-pixel); font-size: 14px; color: var(--gold); margin-bottom: 2px; }
.sheet-faction { font-size: 12px; color: var(--dim); margin-bottom: 9px; }

.bar-row { margin-bottom: 6px; }
.bar-label { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 3px; }
.bar-label .blabel { color: var(--dim); font-family: var(--font-pixel); }
.bar-label .bval { font-family: var(--font-pixel); }
.bar-track { height: 12px; background: var(--bg-deep); border: 2px solid var(--border); }
.bar-fill { height: 100%; transition: width .25s steps(8); }
.bar-fill.hp { background: var(--hp); }
.bar-fill.skill { background: var(--skill); }
.bar-fill.spell { background: var(--spell); }

/* Spendable pools, side by side under the HP bar. */
.pool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-top: 9px; }
.pool { background: var(--bg); border: 2px solid var(--border); padding: 5px 3px; text-align: center; }
.pool .pname { font-family: var(--font-pixel); font-size: 8px; color: var(--dim); display: block; text-transform: uppercase; }
.pool .pval { font-family: var(--font-pixel); font-size: 15px; display: block; margin-top: 2px; }
.pool.skill .pval { color: var(--skill); }
.pool.spell .pval { color: var(--spell); }
.pool.reroll .pval { color: var(--gold); }

/* Two headline combat numbers, then the four modifiers feeding them. */
.combat-head { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-bottom: 6px; }
.combat-big { background: var(--bg); border: 2px solid var(--border-lit); padding: 5px 4px; text-align: center; cursor: pointer; }
.combat-big .cname { font-family: var(--font-pixel); font-size: 9px; color: var(--dim); display: block; text-transform: uppercase; }
.combat-big .cval { font-family: var(--font-pixel); font-size: 20px; color: var(--gold); display: block; margin-top: 1px; }

.combat-mods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.combat-mod { background: var(--bg); border: 2px solid var(--border); padding: 4px 1px; text-align: center; cursor: pointer; }
.combat-mod .cname { font-family: var(--font-pixel); font-size: 7px; color: var(--faint); display: block; text-transform: uppercase; line-height: 1.3; }
.combat-mod .cval { font-family: var(--font-pixel); font-size: 13px; color: var(--text); display: block; margin-top: 2px; }

.sheet-section { margin-top: 7px; padding-top: 6px; border-top: 2px solid var(--border); }
.sheet-section-title { font-family: var(--font-pixel); font-size: 9px; color: var(--faint); text-transform: uppercase; margin-bottom: 4px; }

/* All seven attributes on one row so the sheet stays above the fold on desktop. */
.stat-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.stat-mini { background: var(--bg); border: 2px solid var(--border); padding: 4px 1px; text-align: center; }
.stat-mini .sname { font-family: var(--font-pixel); font-size: 8px; color: var(--dim); display: block; }
.stat-mini .sval { font-family: var(--font-pixel); font-size: 14px; color: var(--text); display: block; }

.derived-list { display: flex; flex-direction: column; gap: 3px; }
.derived-list .derived-row { font-size: 12px; }

.equip-slot { display: flex; gap: 8px; align-items: center; padding: 3px 0; border-bottom: 1px solid var(--border); }
.equip-slot:last-child { border-bottom: none; }
.equip-slot .slot-name { font-family: var(--font-pixel); font-size: 9px; color: var(--faint); width: 46px; flex-shrink: 0; text-transform: uppercase; }
.equip-slot .slot-item { font-size: 12px; }
.equip-slot .slot-item.empty { color: var(--faint); font-style: italic; }
.equip-slot .slot-stat { color: var(--gold); font-size: 11px; margin-left: auto; font-family: var(--font-pixel); }

.consum-row { display: flex; gap: 12px; flex-wrap: wrap; }
.consum { display: flex; align-items: center; gap: 5px; font-family: var(--font-pixel); font-size: 13px; }

.ability-chips { display: flex; flex-wrap: wrap; gap: 3px; }
.ability-chip {
  font-family: var(--font-pixel); font-size: 8px; text-transform: uppercase; cursor: pointer;
  padding: 3px 5px; background: var(--bg); border: 2px solid var(--border); color: var(--text);
}
.ability-chip.skill { border-color: #2f6b48; }
.ability-chip.spell { border-color: #2a5a80; }

/* Explanation bubble for [data-tip] elements, driven by game.js > Tooltips.
   A native title= only shows on hover, which a touch screen does not have, so the same text is
   opened by tap here. pointer-events stay off so a tap always lands on the page beneath. */
.tip-bubble {
  position: absolute; z-index: 40; max-width: 240px; pointer-events: none;
  padding: 7px 9px; font-size: 12px; line-height: 1.45;
  background: var(--panel-lit); color: var(--text);
  border: 2px solid var(--border-lit); box-shadow: 0 3px 0 rgba(0, 0, 0, .55);
}
.tip-bubble[hidden] { display: none; }

/* ---------- scene / main column ---------- */

.scene { padding: 18px; border-bottom: 3px solid var(--border); }
.room-title { font-family: var(--font-pixel); font-size: 16px; color: var(--gold); margin: 0 0 4px; text-transform: uppercase; }
.room-sub { font-size: 12px; color: var(--faint); margin-bottom: 12px; }
.room-text { font-style: italic; color: var(--dim); margin-bottom: 4px; }

.enemy-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 14px 0 4px; }
.enemy-card {
  flex: 1 1 180px; padding: 12px; background: var(--panel-alt); border: 3px solid var(--border);
  display: flex; gap: 10px; align-items: flex-start;
}
.enemy-card.target { border-color: var(--danger); background: #331f24; }
.enemy-card.dead { opacity: .3; }
.enemy-card.waiting { opacity: .55; }
.enemy-info { flex: 1; min-width: 0; }
.enemy-name { font-family: var(--font-pixel); font-size: 12px; text-transform: uppercase; margin-bottom: 5px; }
.enemy-stats { font-size: 11px; color: var(--dim); display: flex; gap: 8px; flex-wrap: wrap; }
.enemy-tag { font-family: var(--font-pixel); font-size: 9px; color: var(--faint); text-transform: uppercase; margin-top: 4px; }

.dice-area { display: flex; align-items: center; gap: 14px; margin: 14px 0; min-height: 60px; }
.die-face { image-rendering: pixelated; border: 3px solid var(--border); }
.die-face.rolling { animation: shake .12s steps(2) infinite; }
.dice-result { font-family: var(--font-pixel); font-size: 13px; }
.dice-result .hit { color: var(--ok); }
.dice-result .miss { color: var(--danger); }

@keyframes shake {
  0% { transform: translate(0, 0); }
  50% { transform: translate(-2px, 2px); }
  100% { transform: translate(2px, -1px); }
}

.shake { animation: shake .1s steps(2) 3; }

@keyframes flash {
  0%, 100% { filter: none; }
  50% { filter: brightness(2.6) saturate(.3); }
}
.flash { animation: flash .18s steps(2) 2; }

/* ---------- log ---------- */

.log {
  flex: 1; overflow-y: auto; padding: 14px 18px; min-height: 140px; max-height: 46vh;
  background: var(--bg-deep); border-bottom: 3px solid var(--border);
  display: flex; flex-direction: column-reverse;
}
.log-entry { padding: 5px 0; border-bottom: 1px solid #1f2630; font-size: 13px; }
.log-entry:first-child { border-bottom: none; }
.log-entry .calc { font-family: var(--font-pixel); font-size: 11px; color: var(--faint); display: block; margin-top: 2px; }
.log-entry.good { color: var(--ok); }
.log-entry.bad { color: var(--danger); }
.log-entry.loot { color: var(--gold); }
.log-entry.system { color: var(--dim); font-style: italic; }
.log-entry.head { font-family: var(--font-pixel); font-size: 11px; text-transform: uppercase; color: var(--dim); margin-top: 6px; }

/* ---------- actions ---------- */

.actions { padding: 14px 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 0 1 auto; }
.action-group { width: 100%; }
.action-group-title { font-family: var(--font-pixel); font-size: 10px; color: var(--faint); text-transform: uppercase; margin-bottom: 6px; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-sm { font-size: 11px; padding: 8px 11px; min-height: 40px; }
.btn .cost { color: var(--faint); font-size: 10px; margin-left: 5px; }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 4, 10, .82);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal-backdrop[hidden] { display: none; }
.modal { max-width: 520px; width: 100%; padding: 22px; max-height: 90vh; overflow-y: auto; }
.modal-title { font-size: 15px; color: var(--gold); margin: 0 0 12px; }
.modal-body { margin-bottom: 18px; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.compare-col { padding: 12px; background: var(--bg); border: 3px solid var(--border); }
.compare-col.new { border-color: var(--gold); }
.compare-label { font-family: var(--font-pixel); font-size: 10px; color: var(--faint); text-transform: uppercase; margin-bottom: 6px; }

/* ---------- end screen ---------- */

#screen-end { display: none; }
#screen-end.active { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.end-box { max-width: 480px; width: 100%; padding: 30px; text-align: center; }
.end-art { display: flex; justify-content: center; margin-bottom: 16px; }
.end-title { font-size: 22px; margin: 0 0 10px; }
.end-title.victory { color: var(--gold); }
.end-title.defeat { color: var(--danger); }
.end-text { color: var(--dim); margin-bottom: 20px; }
.stats { text-align: left; margin-bottom: 22px; padding: 14px; background: var(--bg); border: 3px solid var(--border); }
.stats .derived-row { font-size: 13px; }

/* ---------- desktop: panels always expanded ---------- */

@media (min-width: 900px) {
  .panel > .panel-head { display: none; }
  .panel:not([open]) > .panel-body { display: block; }
  .panel-body { padding: 14px; }
  /* Left column is pinned to the same height as the right one, so both end on the same line.
     overflow-y stays on the column itself: <details> hands its children to an internal slot, so
     flex-shrink on .panel-body does nothing and the sheet would silently overflow the window
     instead of scrolling. The map keeps its natural height; the sheet takes the rest. */
  .col-left { height: calc(100vh - 24px); overflow-y: auto; }
  #panel-map { flex: 0 0 auto; }
  /* grow, but never shrink: the sheet stretches to fill the column so both columns end on the same
     line even when the content is short. Shrinking is deliberately off - <details> hands its
     children to an internal slot, so a squeezed panel would hide content instead of scrolling. */
  #panel-sheet { flex: 1 0 auto; }
}

/* ---------- mobile ---------- */

@media (max-width: 899px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 8px;
    gap: 8px;
  }
  .col-left { position: static; }
  .col-main { min-height: auto; }
  .log { max-height: 40vh; }
  .scene { padding: 14px; }
  .actions { padding: 12px 14px; }
  .actions .btn { flex: 1 1 calc(50% - 4px); }
  .create-wrap { padding: 16px 10px 40px; }
  /* Vertical space is cheap on mobile once the panels collapse - go back to bigger stat cells. */
  .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .stat-mini { padding: 5px 2px; }
  .stat-mini .sname { font-size: 9px; }
  .stat-mini .sval { font-size: 15px; }
  .map-svg { max-height: 200px; }
  .compare-grid { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .actions .btn { flex: 1 1 100%; }
  .game-title { font-size: 26px; }
}
