/* HIROLL — mobile-first UI. Tokens only, no raw values (see tokens.css). */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  -webkit-text-size-adjust: 100%;
}

#game-canvas {
  position: fixed;
  inset: 0;
  z-index: var(--z-world);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#ui-root {
  position: fixed;
  inset: 0;
  z-index: var(--z-hud);
  pointer-events: none;   /* screens/panels re-enable on themselves */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#ui-root .screen, #ui-root .panel, #ui-root .hud { pointer-events: auto; }

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s4);
  opacity: 0;
  transition: opacity var(--med) ease;
}
.screen.visible { opacity: 1; }
.screen.hidden { display: none; }

/* ---------- Boot ---------- */
#screen-boot .boot-logo {
  font-family: var(--font-display);
  font-size: var(--fs-hero);
  color: var(--ember);
  text-shadow: 0 0 24px rgba(255, 150, 64, .5);
  letter-spacing: 2px;
}
.boot-bar {
  width: min(260px, 70vw);
  height: 10px;
  border-radius: var(--r1);
  background: var(--bg-panel);
  overflow: hidden;
  border: 1px solid var(--stone);
}
.boot-bar > div {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--ember-lo), var(--ember), var(--flame));
  transition: width var(--fast) ease;
}
.boot-tip { color: var(--text-dim); font-size: var(--fs-sm); }

/* ---------- Menu ---------- */
#screen-menu { justify-content: flex-end; padding-bottom: var(--s6); gap: var(--s3); }
.menu-logo {
  font-family: var(--font-display);
  font-size: var(--fs-hero);
  line-height: 1;
  color: var(--flame);
  text-shadow: 0 2px 0 var(--ember-lo), 0 0 32px rgba(255, 150, 64, .45);
  letter-spacing: 3px;
  margin-bottom: var(--s2);
}
.menu-tagline { color: var(--text-dim); font-size: var(--fs-sm); margin-bottom: var(--s4); }

.menu-topbar {
  position: absolute;
  top: var(--s3); left: var(--s3); right: var(--s3);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s2);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  background: var(--bg-panel);
  border: 1px solid var(--stone);
  border-radius: var(--r2);
  padding: var(--s2) var(--s3);
  font-size: var(--fs-sm);
  color: var(--text);
  box-shadow: var(--shadow-panel);
}
.chip .val { color: var(--flame); font-weight: 700; }

.menu-row { display: flex; gap: var(--s2); flex-wrap: wrap; justify-content: center; }

.menu-socials {
  display: flex;
  gap: var(--s3);
  margin-top: var(--s3);
}
.menu-socials a {
  color: var(--text-dim);
  font-size: var(--fs-sm);
  text-decoration: none;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r1);
  transition: color var(--fast) ease, transform var(--fast) ease;
}
.menu-socials a:hover { color: var(--ember); transform: translateY(-1px); }
.menu-socials a:focus-visible { outline: 2px solid var(--ember); outline-offset: 2px; }

/* ---------- Buttons (5 states, playbook §10.3) ---------- */
.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--fs-md);
  color: var(--text);
  background: var(--bg-panel);
  border: 2px solid var(--stone);
  border-radius: var(--r2);
  padding: var(--s3) var(--s5);
  min-width: 44px;
  min-height: 44px;
  box-shadow: var(--shadow-btn);
  transition: transform var(--fast) ease, filter var(--fast) ease, box-shadow var(--fast) ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn:focus-visible { outline: 2px solid var(--flame); outline-offset: 2px; }
.btn:disabled {
  cursor: not-allowed;
  filter: grayscale(.6) brightness(.7);
  transform: none;
}
.btn .btn-reason { display: block; font-weight: 400; font-size: var(--fs-xs); color: var(--text-dim); }

.btn-primary {
  background: linear-gradient(180deg, var(--ember-hi), var(--ember) 55%, var(--ember-lo));
  border-color: var(--ember-lo);
  color: #331303;
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  letter-spacing: 1px;
  padding: var(--s3) var(--s6);
  text-shadow: 0 1px 0 rgba(255,255,255,.25);
}
.btn-primary:hover { box-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 24px rgba(255,150,64,.35); }

/* ---------- Run HUD ---------- */
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud.hidden { display: none; }
.hud-top {
  position: absolute;
  top: var(--s3); left: var(--s3); right: var(--s3);
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
}
.hud-cluster { display: flex; gap: var(--s2); pointer-events: auto; }
.hud-bottom {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom) + var(--s5));
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  pointer-events: auto;
}
.btn-roll { min-width: 180px; min-height: 56px; font-size: var(--fs-xl); }
.btn-bag { min-width: 44px; min-height: 44px; padding: var(--s2); font-size: 20px; }
.relic-strip {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 64px);
  left: var(--s3);
  display: flex;
  gap: var(--s1);
  flex-wrap: wrap;
  max-width: 40vw;
  pointer-events: auto;
}
.relic-pip {
  width: 34px; height: 34px;
  background: var(--bg-panel);
  border: 1px solid var(--ember);
  border-radius: var(--r1);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-panel);
}
.relic-pip img { width: 24px; height: 24px; object-fit: contain; }

/* ---------- Panels (Forge / Bag) ---------- */
.panel {
  position: absolute;
  inset: 0;
  z-index: var(--z-panel);
  background: color-mix(in srgb, var(--bg-deep) 88%, black);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}
.panel.hidden { display: none; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + var(--s3)) var(--s4) var(--s3);
  border-bottom: 1px solid var(--stone);
}
.panel-title { font-family: var(--font-display); font-size: var(--fs-lg); color: var(--flame); }
.panel-close { min-width: 44px; padding: var(--s2); }
.panel-body { overflow-y: auto; padding: var(--s4); display: flex; flex-direction: column; gap: var(--s5); }
.panel-section h3 { font-size: var(--fs-sm); color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: var(--s2); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--s2); }
.slot-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--s2); }
.card {
  display: flex;
  align-items: center;
  gap: var(--s3);
  background: var(--bg-panel);
  border: 1px solid var(--stone);
  border-left: 4px solid var(--grade, var(--stone));
  border-radius: var(--r2);
  padding: var(--s2) var(--s3);
  min-height: 64px;
}
.gear-card { border-left-color: var(--grade); }
.card img { width: 40px; height: 40px; object-fit: contain; image-rendering: auto; }
.card-info { flex: 1; display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-sm); }
.card-info small { color: var(--text-dim); }
.grade-tag { font-size: var(--fs-xs); color: var(--grade, var(--text-dim)); text-transform: capitalize; font-weight: 700; }
.qty-tag { font-size: var(--fs-xs); color: var(--flame); font-weight: 700; }
.empty-card {
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  text-transform: capitalize;
  border-style: dashed;
}
.empty-note { color: var(--text-dim); font-size: var(--fs-sm); padding: var(--s2); }
.btn-mini { min-height: 44px; padding: var(--s2) var(--s3); font-size: var(--fs-sm); }
.pet-portrait {
  width: 46px; height: 46px;
  border-radius: 50%;
  flex: none;
  object-fit: cover;
  border: 2px solid var(--grade, var(--stone));
}
.pet-actions { display: flex; flex-direction: column; gap: var(--s1); flex: none; }
/* Cards keep text and actions apart at every width. */
.grid, .slot-row { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.card { flex-wrap: nowrap; }
.card-info { min-width: 0; }
.card-info small { overflow-wrap: anywhere; }
.hatch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  flex-wrap: wrap;
  background: var(--bg-panel);
  border: 1px solid var(--stone);
  border-radius: var(--r2);
  padding: var(--s3);
}
.hatch-info { display: flex; flex-direction: column; gap: 2px; }
.hatch-info small { color: var(--text-dim); font-size: var(--fs-xs); }
.hatch-info .val { color: var(--flame); font-weight: 700; }
.quest-card img { width: 40px; height: 40px; object-fit: contain; }
.quest-card.quest-done { opacity: .55; }
.quest-bar { height: 7px; margin: var(--s1) 0; }
.quest-bar > div {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--ember-lo), var(--flame));
  transition: width var(--med) ease;
}
.quest-reward { color: var(--flame) !important; font-size: var(--fs-xs); }

/* ---------- Identity gate ---------- */
.gate { gap: var(--s3); background: rgba(20, 8, 16, .72); }
.gate-wallets { display: flex; flex-direction: column; gap: var(--s2); width: min(420px, 88vw); }
.wallet-row {
  display: flex;
  align-items: center;
  gap: var(--s3);
  background: var(--bg-panel);
  border: 1px solid var(--stone);
  border-radius: var(--r2);
  padding: var(--s2) var(--s3);
}
.wallet-name { flex: 1; font-size: var(--fs-sm); }
.wallet-badge {
  width: 36px; height: 36px;
  border-radius: 10px;
  flex: none;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  color: #1b0d16;
  background: var(--brand, var(--stone));
  box-shadow: inset 0 -3px 8px rgba(0,0,0,.3);
}
.gate-guest { margin-top: var(--s2); }
.gate-note {
  max-width: min(420px, 88vw);
  text-align: center;
  color: var(--text-dim);
  font-size: var(--fs-xs);
}
a.btn { text-decoration: none; }
.btn-chip { padding: var(--s2) var(--s3); font-size: var(--fs-sm); font-weight: 400; }

/* ---------- Claim ---------- */
.claim-note {
  background: var(--bg-panel);
  border: 1px solid var(--ember);
  border-radius: var(--r2);
  padding: var(--s3);
  font-size: var(--fs-sm);
  color: var(--text);
  margin-bottom: var(--s3);
}
.claim-conditions { list-style: none; display: flex; flex-direction: column; gap: var(--s1); margin-bottom: var(--s3); }
.claim-conditions li { font-size: var(--fs-sm); }
.claim-conditions .met { color: var(--teal); }
.claim-conditions .pending { color: var(--text-dim); }

/* ---------- Relic choice ---------- */
.relic-sheet {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  z-index: var(--z-modal);
  background: linear-gradient(180deg, transparent, rgba(20, 8, 16, .92) 18%);
  padding: var(--s6) var(--s4) calc(env(safe-area-inset-bottom) + var(--s5));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s4);
  pointer-events: auto;
  opacity: 0;
  transition: opacity var(--med) ease;
}
.relic-sheet.visible { opacity: 1; }
.relic-sheet.hidden { display: none; }
.relic-head {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  color: var(--flame);
  text-shadow: 0 0 20px rgba(255, 150, 64, .5);
}
.relic-cards {
  display: flex;
  gap: var(--s3);
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 760px;
}
.relic-card {
  flex: 1 1 200px;
  max-width: 240px;
  background: var(--bg-panel);
  border: 2px solid var(--stone);
  border-radius: var(--r2);
  padding: var(--s3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  text-align: center;
  box-shadow: var(--shadow-panel);
  transition: transform var(--fast) ease, border-color var(--fast) ease;
}
.relic-card:hover { transform: translateY(-3px); border-color: var(--ember); }
.relic-card img { width: 56px; height: 56px; object-fit: contain; }
.relic-card b { color: var(--flame); font-size: var(--fs-md); }
.relic-card small { color: var(--text-dim); font-size: var(--fs-xs); min-height: 3em; }

/* ---------- Battle HUD ---------- */
.battle-hud {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + var(--s4));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  pointer-events: auto;
  z-index: var(--z-hud);
}
.battle-hud.hidden { display: none; }
.battle-info {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 64px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: var(--s2);
  flex-wrap: wrap;
  justify-content: center;
  max-width: 92vw;
}
.enemy-chip { font-size: var(--fs-xs); gap: var(--s1); }
.mini-bar {
  display: inline-block;
  width: 52px; height: 7px;
  background: rgba(0,0,0,.5);
  border-radius: 4px;
  overflow: hidden;
  vertical-align: middle;
}
.mini-bar > i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--hp), #ff8a7a);
}
.mana-wrap { width: min(280px, 70vw); }
.bar {
  height: 10px;
  background: rgba(0,0,0,.5);
  border: 1px solid var(--stone);
  border-radius: var(--r1);
  overflow: hidden;
}
.mana-bar > div {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #2f6db3, var(--mana));
  transition: width var(--fast) linear;
}
.skill-row { display: flex; gap: var(--s3); align-items: center; }
.btn-skill {
  position: relative;
  min-width: 56px; min-height: 56px;
  font-size: 24px;
  padding: var(--s2);
  border-radius: 50%;
  overflow: hidden;
}
.btn-skill .cd-sweep { position: absolute; inset: 0; pointer-events: none; border-radius: 50%; }
.btn-skill .cd-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm); font-weight: 800; color: var(--flame);
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,.8);
}
.btn-skill.no-mana { box-shadow: inset 0 0 0 2px var(--mana); filter: saturate(.4); }
.pot-count {
  position: absolute;
  right: 2px; bottom: 2px;
  font-size: var(--fs-xs); font-weight: 800;
  background: var(--bg-deep);
  border-radius: 8px;
  padding: 0 5px;
  color: var(--flame);
}

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  top: calc(env(safe-area-inset-top) + var(--s4));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  pointer-events: none;
}
.toast {
  background: var(--bg-panel);
  border: 1px solid var(--ember);
  color: var(--text);
  border-radius: var(--r2);
  padding: var(--s2) var(--s4);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-panel);
  animation: toast-in var(--med) ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
