* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: #090910;
  color: #e8e0cf;
  font-family: 'Courier New', Consolas, monospace;
  overflow: hidden;
  user-select: none;
}

#game-wrap {
  position: relative;
  width: min(960px, 100vw);
  height: min(600px, 96vh);
  aspect-ratio: 960 / 600;
  margin: 2vh auto auto auto;
  background: #000;
  box-shadow: 0 0 40px rgba(0,0,0,0.6);
  overflow: hidden;
}

#game-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ---------------- HUD ---------------- */
.hud-root {
  position: absolute; top: 0; left: 0; width: 100%;
  pointer-events: none;
  z-index: 5;
  display: none;
}
.hud-bar {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 8px; gap: 8px;
  pointer-events: auto;
}
.hud-party { display: flex; gap: 6px; }
.party-card {
  background: rgba(10,10,18,0.78); border: 1px solid #4a3f2a;
  border-radius: 6px; padding: 4px 8px; display: flex; gap: 6px; align-items: center;
  min-width: 150px;
}
.party-card.down { opacity: 0.45; }
.party-portrait { image-rendering: pixelated; }
.party-info { display: flex; flex-direction: column; gap: 2px; }
.party-name { font-size: 12px; color: #ffe9b3; }
.lvl { color: #9fb3c8; font-size: 10px; }
.bar { position: relative; width: 110px; height: 11px; background: #1c1c24; border: 1px solid #333; border-radius: 3px; overflow: hidden; }
.bar.mini { width: 60px; height: 7px; }
.bar-fill { position: absolute; left: 0; top: 0; height: 100%; }
.hp-fill { background: linear-gradient(#e05555,#a52c2c); }
.mp-fill { background: linear-gradient(#4a90d9,#2b5f9e); }
.bar-text { position: absolute; left: 0; right: 0; top: -1px; text-align: center; font-size: 8px; color: #fff; text-shadow: 0 0 2px #000; }
.hud-right { display: flex; align-items: center; gap: 8px; background: rgba(10,10,18,0.78); border: 1px solid #4a3f2a; border-radius: 6px; padding: 6px 10px; }
.hud-currency { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #ffd27f; }
.hud-currency canvas { image-rendering: pixelated; }

/* ---------------- Buttons ---------------- */
.btn {
  pointer-events: auto;
  background: linear-gradient(#3a3a46,#24242c);
  border: 1px solid #55554f;
  color: #e8e0cf;
  font-family: inherit;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 5px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: linear-gradient(#49495a,#2f2f38); border-color: #d4af37; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 4px 9px; font-size: 11px; }
.btn-primary { background: linear-gradient(#caa24a,#8a6a1b); border-color: #ffdf8a; color: #1a1205; font-weight: bold; }
.btn-primary:hover { background: linear-gradient(#e0b858,#9a7a28); }
.btn-secondary { background: linear-gradient(#3a4452,#262c36); }
.btn-danger { background: linear-gradient(#7a2e2e,#4a1818); border-color: #c05050; }

/* ---------------- Overlay / Modals ---------------- */
.overlay-root {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.6);
  z-index: 20;
}
.overlay-root.show { display: flex; }
.modal-box {
  background: #15131c;
  border: 2px solid #4a3f2a;
  border-radius: 10px;
  padding: 20px 26px;
  max-width: 560px;
  max-height: 92%;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.7);
}
.modal-box.wide { max-width: 820px; width: 92%; }
.modal-box h1, .modal-box h2, .modal-box h3 { margin: 6px 0 10px; color: #ffd27f; }
.modal-box h1.game-title { font-size: 28px; letter-spacing: 2px; text-align: center; margin-bottom: 2px; }
.subtitle { text-align: center; color: #9fb3c8; margin-bottom: 20px; font-size: 13px; }
.menu-box { text-align: center; }
.menu-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; align-items: stretch; }
.intro-box { max-width: 480px; text-align: center; }
.intro-text { font-size: 14px; line-height: 1.6; margin: 10px 0 18px; color: #e8e0cf; }
.text-input {
  width: 100%; padding: 8px; margin: 8px 0 14px; background: #0d0c12; color: #fff;
  border: 1px solid #55554f; border-radius: 5px; font-family: inherit; font-size: 13px;
}
.muted { color: #8a8a92; font-size: 12px; }

/* class creation */
.class-pick { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 14px 0; }
.class-card {
  background: #1c1a24; border: 2px solid #3a3444; border-radius: 8px; padding: 10px; width: 140px;
  cursor: pointer; text-align: center;
}
.class-card:hover { border-color: #d4af37; }
.class-name { font-weight: bold; color: #ffd27f; margin: 4px 0; }
.class-tag { font-size: 11px; color: #9fb3c8; margin-bottom: 6px; }
.class-detail { font-size: 10px; text-align: left; color: #c9c2ab; margin-top: 3px; }

/* settings */
.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0; }
.settings-row label { font-size: 13px; color: #c9c2ab; }

/* items / inventory */
.item-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 16px; }
.item-list.scroll { max-height: 220px; overflow-y: auto; }
.item-card {
  display: flex; align-items: center; gap: 8px;
  background: #1c1a24; border: 1px solid #3a3444; border-left: 4px solid #777;
  border-radius: 5px; padding: 6px 10px;
}
.item-card.empty { color: #666; justify-content: center; }
.item-card canvas { image-rendering: pixelated; flex-shrink: 0; }
.item-info { flex: 1; }
.item-name { font-size: 12px; color: #ffe9b3; }
.item-stats { font-size: 10px; color: #9fb3c8; }
.rarity-common { border-left-color: #b7bdc6; }
.rarity-uncommon { border-left-color: #3fae4a; }
.rarity-rare { border-left-color: #3b8fd6; }
.rarity-epic { border-left-color: #b45cf0; }
.rarity-legendary { border-left-color: #f0a830; box-shadow: 0 0 8px rgba(240,168,48,0.3) inset; }

/* character screen */
.roster-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.char-sheet { display: flex; gap: 18px; }
.char-left { width: 230px; text-align: center; flex-shrink: 0; }
.char-right { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.char-title { font-weight: bold; color: #ffd27f; margin-top: 4px; }
.char-xp { font-size: 11px; color: #9fb3c8; margin-bottom: 8px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; font-size: 12px; text-align: left; background: #0d0c12; padding: 8px; border-radius: 5px; }
.abilities-list { margin-top: 10px; text-align: left; }
.ability-row { font-size: 11px; color: #c9c2ab; padding: 3px 0; border-bottom: 1px solid #2a2832; }
.heal-row { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.equip-slot { background: #1c1a24; border: 1px solid #3a3444; border-radius: 6px; padding: 8px; }
.slot-label { font-size: 10px; color: #9fb3c8; margin-bottom: 4px; letter-spacing: 1px; }
.picker-box { background: #0d0c12; border: 1px solid #4a3f2a; border-radius: 6px; padding: 10px; margin-top: 4px; }

/* shop / quartermaster */
.gold-label { color: #ffd27f; margin-bottom: 8px; }
.tab-row { display: flex; gap: 8px; margin-bottom: 12px; }
.roster-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.roster-row { display: flex; align-items: center; gap: 8px; background: #1c1a24; border: 1px solid #3a3444; border-radius: 5px; padding: 5px 10px; }
.roster-row canvas { image-rendering: pixelated; }
.roster-row span { flex: 1; font-size: 12px; }
.perk-list { display: flex; flex-direction: column; gap: 8px; }
.perk-row { display: flex; align-items: center; justify-content: space-between; background: #1c1a24; border: 1px solid #3a3444; border-radius: 6px; padding: 8px 12px; }
.perk-row.owned { border-color: #d4af37; }
.perk-info b { color: #ffe9b3; font-size: 13px; }
.owned-tag { color: #8fd957; font-size: 12px; font-weight: bold; }

/* portal select */
.bracket-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.bracket-btn { text-align: left; }

/* ---------------- Combat ---------------- */
.combat-root {
  position: absolute; inset: 0; z-index: 10;
  display: none;
  background: radial-gradient(circle at 50% 30%, #241a14, #0a0808 85%);
}
.combat-ui { display: flex; flex-direction: column; height: 100%; padding: 10px; gap: 8px; }
.combat-enemies { display: flex; gap: 18px; justify-content: center; align-items: flex-end; flex: 1; padding-top: 10px; flex-wrap: wrap; }
.enemy-card { text-align: center; padding: 6px; border-radius: 6px; transition: transform 0.1s; }
.enemy-card canvas { image-rendering: pixelated; }
.enemy-card.clickable { cursor: pointer; border: 2px solid #c0392b; background: rgba(192,57,43,0.12); }
.enemy-card.clickable:hover { transform: scale(1.06); background: rgba(192,57,43,0.25); }
.enemy-card.dead { opacity: 0.25; }
.enemy-name { font-size: 11px; color: #ffcfcf; margin-top: 2px; }
.combat-log {
  height: 110px; overflow-y: auto; background: rgba(0,0,0,0.5); border: 1px solid #3a3444;
  border-radius: 6px; padding: 6px 10px; font-size: 11px; color: #c9c2ab; line-height: 1.5;
}
.combat-bottom { display: flex; gap: 12px; align-items: stretch; }
.combat-party { display: flex; flex-direction: column; gap: 6px; width: 260px; }
.ally-card { display: flex; gap: 6px; align-items: center; background: rgba(20,18,28,0.8); border: 1px solid #3a3444; border-radius: 6px; padding: 5px 8px; }
.ally-card canvas { image-rendering: pixelated; }
.ally-card.down { opacity: 0.4; }
.ally-card.clickable { cursor: pointer; border-color: #4a90d9; background: rgba(74,144,217,0.15); }
.ally-card.clickable:hover { background: rgba(74,144,217,0.3); }
.ally-info { flex: 1; }
.combat-actions { flex: 1; background: rgba(20,18,28,0.8); border: 1px solid #3a3444; border-radius: 6px; padding: 10px; display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.turn-label { color: #ffd27f; font-size: 13px; text-align: center; }
.action-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.combat-wait { text-align: center; color: #9fb3c8; font-size: 13px; padding: 10px; }

/* ---------------- Toasts ---------------- */
.toast-root { position: absolute; top: 60px; right: 12px; z-index: 30; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.toast {
  background: rgba(15,13,20,0.92); border: 1px solid #4a3f2a; border-left: 4px solid #d4af37;
  border-radius: 5px; padding: 8px 12px; font-size: 12px; color: #ffe9b3;
  opacity: 1; transition: opacity 0.5s; max-width: 260px;
}
.toast.fade { opacity: 0; }
.toast-victory { border-left-color: #8fd957; }
.toast-level { border-left-color: #4a90d9; }
.toast-error { border-left-color: #c0392b; }
.toast-item.rarity-legendary { border-left-color: #f0a830; }
.toast-item.rarity-epic { border-left-color: #b45cf0; }
.toast-item.rarity-rare { border-left-color: #3b8fd6; }
.toast-item.rarity-uncommon { border-left-color: #3fae4a; }
