/* ===================== Design tokens ===================== */
:root {
  --void: #0d0e0c;
  --ash: #1c1d18;
  --ash-raised: #26271f;
  --amber: #b8863b;
  --amber-bright: #d9a856;
  --green: #5c6e4f;
  --green-bright: #7c9268;
  --rust: #7a3428;
  --rust-bright: #a3452f;
  --bone: #cfc6b8;
  --bone-dim: #8c8578;

  --font-display: 'Eczar', serif;
  --font-body: 'IBM Plex Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

/* Must come before any rule that sets display on an element that also uses
   the [hidden] attribute for show/hide logic (screens, forms). Without
   !important here, class-based display:flex rules below win the cascade
   over the browser's default [hidden]{display:none}, since they're
   equal-specificity and come later - meaning "hidden" elements stayed
   visible. This was a real bug caught by browser testing. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--void);
  color: var(--bone);
  font-family: var(--font-body);
  min-height: 100vh;
}

button, input, select {
  font-family: inherit;
}

/* ===================== Layout scaffolding ===================== */
#app {
  min-height: 100vh;
}

.screen {
  display: flex;
}

.screen--auth {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(184, 134, 59, 0.08), transparent 60%),
    var(--void);
}

.screen--narrow {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.screen--hub {
  min-height: 100vh;
  flex-direction: row;
  align-items: stretch;
}

/* ===================== Shared panel styling ===================== */
.panel, .auth-card {
  background: var(--ash);
  border: 1px solid #33342b;
  padding: 32px;
  width: 100%;
  max-width: 420px;
  position: relative;
}

.panel::before, .auth-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--amber), transparent);
  opacity: 0.6;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: 0.02em;
  color: var(--amber-bright);
  margin: 0 0 4px;
  text-align: center;
}

.brand-sub {
  text-align: center;
  color: var(--bone-dim);
  font-size: 0.85rem;
  margin: 0 0 28px;
  font-style: italic;
}

.panel-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  margin: 0 0 8px;
  color: var(--bone);
}

.panel-title--small {
  font-size: 1.05rem;
}

.panel-sub {
  color: var(--bone-dim);
  font-size: 0.85rem;
  margin: 0 0 24px;
}

.character-select-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.character-select-card {
  background: var(--ash-raised);
  border: 1px solid #33342b;
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: var(--font-body);
  transition: border-color 0.15s ease;
}

.character-select-card:hover { border-color: var(--amber); }

.character-select-name {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--amber-bright);
  margin: 0;
  font-size: 1.05rem;
}

.character-select-meta {
  color: var(--bone-dim);
  font-size: 0.78rem;
  margin: 2px 0 0;
  font-family: var(--font-mono);
}

/* ===================== Signature: jagged corruption dividers ===================== */
.crack-divider {
  height: 8px;
  margin: 20px 0;
  background: repeating-linear-gradient(
    100deg,
    transparent 0px, transparent 6px,
    #33342b 6px, #33342b 8px,
    transparent 8px, transparent 18px
  );
  clip-path: polygon(
    0% 40%, 8% 60%, 16% 35%, 24% 55%, 32% 30%, 40% 58%,
    48% 38%, 56% 52%, 64% 32%, 72% 60%, 80% 40%, 88% 55%,
    96% 35%, 100% 50%, 100% 100%, 0% 100%
  );
  opacity: 0.7;
}

.crack-divider--tight {
  margin: 12px 0;
  height: 5px;
}

/* ===================== Tabs (auth) ===================== */
.tab-row {
  display: flex;
  margin-bottom: 20px;
  border-bottom: 1px solid #33342b;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--bone-dim);
  padding: 10px 0;
  font-size: 0.9rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab-btn.is-active {
  color: var(--amber-bright);
  border-bottom-color: var(--amber);
}

/* ===================== Forms ===================== */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--bone-dim);
}

.field input, .field select {
  background: var(--void);
  border: 1px solid #33342b;
  color: var(--bone);
  padding: 10px 12px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.field input:focus, .field select:focus {
  border-color: var(--amber);
}

.form-error {
  color: var(--rust-bright);
  font-size: 0.82rem;
  min-height: 1.1em;
  margin: 0;
}

/* ===================== Buttons ===================== */
.btn {
  border: 1px solid transparent;
  padding: 12px 20px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.05s ease;
  letter-spacing: 0.01em;
}

.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--amber);
  color: var(--void);
}
.btn--primary:hover { filter: brightness(1.12); }

.btn--danger {
  background: var(--rust);
  color: var(--bone);
}
.btn--danger:hover { filter: brightness(1.15); }

.btn--large {
  width: 100%;
  padding: 16px;
  font-size: 1.05rem;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.03em;
}

.btn--ghost {
  background: none;
  border: 1px solid #33342b;
  color: var(--bone-dim);
  width: 100%;
}
.btn--ghost:hover { border-color: var(--amber); color: var(--amber-bright); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none !important;
}

/* ===================== Sidebar (hub) ===================== */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--ash);
  border-right: 1px solid #26271f;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
}

.sidebar-header { margin-bottom: 4px; }

.char-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  margin: 0;
  color: var(--amber-bright);
}

.char-class {
  margin: 2px 0 0;
  color: var(--bone-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-block {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gauge-row { display: flex; flex-direction: column; gap: 6px; }

.gauge-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--bone-dim);
  font-family: var(--font-mono);
}

/* Cracked-stone gauge styling: notched edges via clip-path, not a smooth pill */
.gauge {
  height: 14px;
  background: var(--void);
  border: 1px solid #33342b;
  position: relative;
  clip-path: polygon(
    0% 0%, 97% 0%, 100% 30%, 98% 55%, 100% 100%, 0% 100%
  );
}

.gauge-fill {
  height: 100%;
  width: 0%;
  transition: width 0.4s ease;
}

.gauge--life .gauge-fill { background: var(--rust); }
.gauge--energy .gauge-fill { background: var(--green); }
.gauge--xp .gauge-fill { background: var(--amber); }

.progression-gauge { margin: 10px 0 14px; }

.stat-allocation {
  margin: 8px 0 14px;
  padding: 10px;
  border: 1px solid #33342b;
  background: rgba(0, 0, 0, 0.18);
}

.allocation-row {
  display: grid;
  grid-template-columns: 1fr auto 28px;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
  color: var(--bone-dim);
  font-size: 0.78rem;
}

.stat-plus {
  width: 28px;
  height: 26px;
  border: 1px solid var(--amber);
  background: transparent;
  color: var(--amber-bright);
  cursor: pointer;
}

.stat-plus:disabled { opacity: 0.3; cursor: not-allowed; }
.allocation-note { margin: 9px 0 0; color: #77776d; font-size: 0.67rem; line-height: 1.35; }

.meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--bone-dim);
  margin-bottom: 8px;
}

.meta-row span:last-child {
  color: var(--bone);
  font-family: var(--font-mono);
}

.sidebar > .btn--ghost { margin-top: auto; }

/* ===================== Main panel (hub) ===================== */
.main-panel {
  flex: 1;
  padding: 40px;
  display: flex;
  flex-direction: row;
  gap: 24px;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
}

.main-content-column {
  position: relative;
  flex: 1;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center;
}

.zone-card {
  width: 100%;
  max-width: 480px;
  background: var(--ash);
  border: 1px solid #33342b;
  padding: 28px;
  text-align: center;
}

.zone-eyebrow {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--bone-dim);
  margin: 0;
}

.zone-name {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 4px 0 0;
  color: var(--bone);
}

.zone-card-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 0;
}

.btn--map {
  display: block;
  padding: 6px 20px;
  font-size: 0.78rem;
  width: auto;
}

/* Enemy portrait swaps between a monster silhouette (PvE) and a human
   warrior silhouette (PvP) - both live in the DOM, only one shown at a
   time via the is-pvp modifier, so no extra network fetch or flash of
   the wrong icon when switching fight types. */
.portrait-svg--human { display: none; }
.portrait--enemy.is-pvp .portrait-svg--monster { display: none; }
.portrait--enemy.is-pvp .portrait-svg--human { display: block; }

/* ===================== Equipment paper-doll: flanks the fight ===================== */
.doll-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  padding-top: 8px;
}

.doll-slot {
  width: 84px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--ash);
  border: 1px solid #33342b;
  padding: 6px;
  cursor: default;
  text-align: center;
  transition: border-color 0.15s ease;
}

.doll-slot.is-filled {
  cursor: pointer;
  border-color: var(--amber);
}

.doll-slot.is-filled:hover {
  border-color: var(--rust-bright);
}

.doll-slot-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bone-dim);
}

.doll-slot.is-filled .doll-slot-label {
  display: none;
}

.doll-item-name {
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.2;
  word-break: break-word;
}

.enemy-name {
  font-family: var(--font-mono);
  color: var(--rust-bright);
  font-size: 1rem;
  margin: 0 0 20px;
}

/* ===================== Map overlay ===================== */
/* Covers only .main-panel (zone card / combatants / log) - sidebar and
   inventory panel sit outside main-panel entirely, so they stay visible
   and usable while the map is open. */
.map-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(13, 14, 12, 0.97);
  border: 1px solid var(--amber);
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow-y: auto;
}

.map-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.map-overlay-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--amber-bright);
  margin: 0;
}

.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.shop-buy { flex-shrink: 0; }

.map-close-btn {
  background: none;
  border: 1px solid #33342b;
  color: var(--bone-dim);
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1;
}

.map-close-btn:hover { border-color: var(--rust-bright); color: var(--rust-bright); }

.map-path {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  max-width: 360px;
  margin: 0 auto;
  width: 100%;
}

.map-node {
  width: 100%;
  background: var(--ash);
  border: 1px solid #33342b;
  padding: 16px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.map-node:hover:not(.is-locked) { border-color: var(--amber); }

.map-node-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--bone);
  margin: 0;
}

.map-node-meta {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--bone-dim);
  margin: 4px 0 0;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Currently selected zone gets the same glow treatment used elsewhere for
   "this is the active/important thing" (matches boss portrait glow). */
.map-node.is-current {
  border-color: var(--amber-bright);
  box-shadow: 0 0 20px rgba(184, 134, 59, 0.35);
}

.map-node.is-current .map-node-name { color: var(--amber-bright); }

/* Locked nodes are visually inert - dimmed, not interactive, with a lock
   glyph so the state reads instantly without needing to read the meta text. */
.map-node.is-locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.map-node.is-locked .map-node-name::before {
  content: "🔒 ";
  font-size: 0.85em;
}

/* Jagged connector between nodes, reusing the crack-divider visual
   language rather than a plain straight line. */
.map-connector {
  width: 3px;
  height: 24px;
  background: repeating-linear-gradient(
    180deg,
    var(--amber) 0px, var(--amber) 4px,
    transparent 4px, transparent 8px
  );
  opacity: 0.5;
  flex-shrink: 0;
}

/* ===================== Combatants: portraits + health bars ===================== */
.combatants-row {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.combatant {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.portrait {
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ash);
  border: 1px solid #33342b;
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.portrait svg {
  width: 60%;
  height: 60%;
}

.portrait--player {
  color: var(--amber-bright);
  border-color: var(--amber);
}

.portrait--enemy {
  color: var(--rust-bright);
}

/* Boss crown spikes stay invisible on regular mobs - only the is-boss
   modifier reveals them, so the visual distinction is automatic. */
.boss-crown { display: none; }
.portrait--enemy.is-boss .boss-crown { display: block; }

.portrait--enemy.is-boss {
  border-color: var(--rust-bright);
  box-shadow: 0 0 20px rgba(163, 69, 47, 0.4);
}

.combatant-name {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--bone-dim);
  margin: 0;
  max-width: 120px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vs-divider {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--bone-dim);
  font-size: 0.85rem;
  opacity: 0.6;
}

/* Reuses the sidebar's cracked-stone gauge look at a smaller scale */
.gauge--combat {
  width: 100%;
  max-width: 130px;
  height: 10px;
}

.gauge-fill--player { background: var(--green); }
.gauge-fill--enemy { background: var(--rust); }

/* ===================== Combat log: scrying-glass terminal ===================== */
.log-panel {
  width: 100%;
  max-width: 480px;
  background: var(--void);
  border: 1px solid var(--amber);
  box-shadow: 0 0 24px rgba(184, 134, 59, 0.08);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Boss encounters get a distinctly more intense treatment - brighter rust
   glow instead of the usual amber, so a boss fight actually feels different
   the moment the log appears, before you've even read a line of it. */
.log-panel--boss {
  border-color: var(--rust-bright);
  box-shadow: 0 0 32px rgba(163, 69, 47, 0.35);
}

.zone-unlock-banner {
  width: 100%;
  max-width: 480px;
  background: var(--green);
  color: var(--void);
  text-align: center;
  padding: 12px 16px;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: -8px;
}

.log-header {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #33342b;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

#log-result { color: var(--amber-bright); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
#log-rewards { color: var(--green-bright); }

.log-scroll {
  max-height: 280px;
  overflow-y: auto;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
}

.log-line { margin: 0 0 4px; color: var(--bone-dim); }
.log-line .hit { color: var(--bone); }
.log-line .crit { color: var(--rust-bright); font-weight: 500; }
.log-line .miss { color: var(--bone-dim); font-style: italic; }

/* ===================== Inventory panel (hub) ===================== */
.inventory-panel {
  width: 300px;
  flex-shrink: 0;
  background: var(--ash);
  border-left: 1px solid #26271f;
  padding: 28px 22px;
  overflow-y: auto;
}

.inventory-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inventory-use-banner {
  background: var(--ash-raised);
  border: 1px solid var(--green);
  color: var(--green-bright);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 8px 12px;
  margin: 0 0 10px;
}

.inventory-use-banner--error {
  border-color: var(--rust-bright);
  color: var(--rust-bright);
}

.craft-picker-header {
  margin-bottom: 12px;
}

.craft-picker-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--amber-bright);
  margin: 0 0 8px;
}

.btn--craft-cancel {
  width: 100%;
  padding: 8px 0;
  font-size: 0.78rem;
}

.item-use-feedback {
  color: var(--rust-bright);
  font-size: 0.72rem;
  margin: 6px 0 0;
}

.empty-note {
  color: var(--bone-dim);
  font-size: 0.85rem;
  font-style: italic;
}

.item-card {
  background: var(--ash-raised);
  border: 1px solid #33342b;
  padding: 12px 14px;
  font-size: 0.85rem;
}

.item-card.is-equipped {
  border-color: var(--amber);
}

.item-name {
  font-weight: 600;
  color: var(--bone);
  margin: 0 0 2px;
}

.item-rarity-Normal { color: var(--bone-dim); }
.item-rarity-Magic { color: #6a8ec9; }
.item-rarity-Rare { color: var(--amber-bright); }

.item-quantity {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--bone-dim);
  margin-left: 6px;
}

.item-slot {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--bone-dim);
  margin: 0 0 8px;
}

.item-stats {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--green-bright);
  margin: 0 0 10px;
}

.item-actions {
  display: flex;
  gap: 6px;
}

.item-toggle, .item-sell {
  flex: 1;
  background: none;
  border: 1px solid #33342b;
  color: var(--bone-dim);
  padding: 6px 4px;
  font-size: 0.75rem;
  cursor: pointer;
}

.item-toggle:hover { border-color: var(--amber); color: var(--amber-bright); }

/* Sell uses the green accent (same family as gold/xp rewards elsewhere) so
   it reads as "this converts to currency", distinct from the equip toggle. */
.item-sell:hover { border-color: var(--green); color: var(--green-bright); }

.item-toggle:disabled, .item-sell:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===================== Responsive ===================== */
@media (max-width: 900px) {
  .screen--hub {
    flex-direction: column;
  }
  .sidebar, .inventory-panel {
    width: 100%;
    border: none;
    border-bottom: 1px solid #26271f;
  }
  .main-panel { padding: 24px; }
}

/* ===================== Accessibility ===================== */
:focus-visible {
  outline: 2px solid var(--amber-bright);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
