:root {
  --bg: #141519;
  --panel: #1c1d23;
  --line: #2c2e36;
  --paper: #f4f1e8;
  --gold: #ffd23f;
  --noun: #ffd23f;
  --adj: #7fe3ff;
  --verb: #ff5fa2;
  --danger: #ff4d4d;
  --xp: #5ff7d0;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--paper);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.s-substantivo { color: var(--noun); }
.s-adjetivo { color: var(--adj); }
.s-verbo { color: var(--verb); }
.gold { color: var(--gold); }
.muted { color: #8a8d99; font-size: 0.85rem; }
.hidden { display: none !important; }

/* ------------------------------------------------------------------ HUD */

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  visibility: hidden;
}
body.playing #hud { visibility: visible; }

.topbar {
  position: absolute;
  top: calc(8px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, 92vw);
  display: grid;
  gap: 4px;
}

.bar {
  height: 10px;
  background: #0007;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.bar > div {
  height: 100%;
  width: 0;
  transition: width 0.12s linear;
}
.bar.hp > div { background: linear-gradient(90deg, #c62828, var(--danger)); }
.bar.xp { height: 6px; }
.bar.xp > div { background: var(--xp); }
.bar.breath { height: 6px; width: min(420px, 92vw); margin: 0 auto 6px; }
.bar.breath > div { background: #8fb8ff; transition: none; }
.bar.breath > div.low { background: var(--danger); }

.stats {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 0.9rem;
  text-shadow: 0 1px 2px #000;
}

#weapons {
  position: absolute;
  top: calc(70px + var(--safe-t));
  left: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 44vw;
}
.weapon {
  pointer-events: auto;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: baseline;
  column-gap: 6px;
  text-align: left;
  background: #000a;
  border: 1px solid var(--line);
  border-left: 4px solid var(--c);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.8rem;
}
.weapon strong { color: var(--c); letter-spacing: 0.04em; }
.weapon em { font-style: normal; color: #a3a6b3; font-size: 0.72rem; }
.weapon small { grid-column: 2 / 4; color: var(--adj); font-size: 0.68rem; }
.weapon .wkey { color: #6c6f7c; font-size: 0.7rem; }
.weapon.selected { border-color: var(--c); box-shadow: 0 0 0 1px var(--c), 0 0 12px -2px var(--c); }

#verbs {
  position: absolute;
  top: calc(70px + var(--safe-t));
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}
.verb {
  background: #000a;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #8a8d99;
}
.verb.ready { color: var(--verb); border-color: var(--verb); }

#hint {
  position: absolute;
  left: 50%;
  bottom: calc(196px + var(--safe-b));
  transform: translateX(-50%);
  width: max-content;
  max-width: 92vw;
  text-align: center;
  font-size: 0.95rem;
  background: #000b;
  border-radius: 8px;
  padding: 6px 12px;
  text-shadow: 0 1px 2px #000;
}
#hint:empty { display: none; }

.bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(10px + var(--safe-b));
  display: flex;
  flex-direction: column;
  align-items: center;
}

#typed {
  min-height: 2.6rem;
  font: 900 2.2rem/1.2 Impact, 'Arial Black', sans-serif;
  letter-spacing: 0.12em;
  color: var(--gold);
  text-shadow: 0 2px 0 #000, 0 0 16px #ffd23f88;
}

#suggest {
  min-height: 1.3rem;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 4px;
  text-shadow: 0 1px 2px #000;
}

#tray {
  display: flex;
  gap: 5px;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 96vw;
}
.tile {
  pointer-events: auto;
  width: 44px;
  height: 48px;
  border-radius: 7px;
  background: #1a1710;
  border: 2px solid var(--gold);
  color: var(--gold);
  font: 900 1.45rem/1 ui-monospace, Menlo, Consolas, monospace;
  box-shadow: 0 3px 0 #6b5510;
  transition: transform 0.06s;
}
.tile.empty {
  border: 2px dashed #3a3c45;
  background: #0006;
  box-shadow: none;
}
.tile.used {
  background: var(--gold);
  color: #1a1710;
  transform: translateY(-6px);
}
.tile:active { transform: translateY(2px); }

.actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.btn {
  pointer-events: auto;
  border: 2px solid var(--line);
  background: #23252c;
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 800;
  letter-spacing: 0.06em;
}
.btn.primary { background: var(--gold); border-color: var(--gold); color: #1a1710; }
.btn.big { padding: 14px 26px; font-size: 1.1rem; }
.btn:focus-visible { outline: 3px solid var(--adj); outline-offset: 2px; }

#btn-back,
#btn-cancel,
#btn-ok { display: none; }
body.writing #btn-write { display: none; }
body.writing #btn-back,
body.writing #btn-cancel,
body.writing #btn-ok { display: inline-block; }

/* Joystick virtual */
#joy {
  position: fixed;
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  border: 2px solid #ffffff33;
  background: #ffffff0d;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
}
#joy.visible { opacity: 1; }
#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #ffd23f88;
  transform: translate(-50%, -50%);
}

/* ------------------------------------------------------------------ Telas */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000b8;
  padding: 16px;
  z-index: 10;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  width: min(420px, 100%);
  max-height: 92vh;
  overflow: auto;
  text-align: center;
  user-select: text;
}
.panel.wide { width: min(640px, 100%); }
.panel h2 { margin: 0 0 12px; }

h1 {
  margin: 0;
  font: 900 3.2rem/1 Impact, 'Arial Black', sans-serif;
  letter-spacing: 0.04em;
  color: var(--paper);
}
h1 span { color: var(--gold); margin-left: 0.25em; }
.tagline { margin: 6px 0 14px; color: #c9c6bb; }

.howto {
  text-align: left;
  margin: 0 0 12px;
  padding-left: 1.3rem;
  line-height: 1.45;
  font-size: 0.95rem;
}
.howto li { margin-bottom: 4px; }

.opt { display: block; margin: 8px 0; font-size: 0.9rem; }

details {
  text-align: left;
  margin: 10px 0 16px;
  background: #0004;
  border-radius: 8px;
  padding: 8px 12px;
}
summary { cursor: pointer; font-weight: 700; }
.grimoire {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.grimoire h3 { margin: 4px 0; font-size: 0.95rem; }
.grimoire ul { margin: 0; padding: 0; list-style: none; font-size: 0.8rem; line-height: 1.5; }
.grimoire li span { color: #9a9daa; }

#choices { display: grid; gap: 8px; }
.choice {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  text-align: left;
  background: #26282f;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.choice:hover,
.choice:focus-visible { border-color: var(--xp); }
.choice .key {
  grid-row: span 2;
  align-self: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--xp);
  color: #0f2a24;
  font-weight: 900;
  display: grid;
  place-items: center;
}
.choice span:last-child { color: #a3a6b3; font-size: 0.85rem; }

.over-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.over-stats div { background: #0005; border-radius: 8px; padding: 8px 4px; }
.over-stats span { display: block; font-size: 0.75rem; color: #9a9daa; }
.over-stats strong { font-size: 1.4rem; color: var(--gold); }
#over-detail { text-align: left; font-size: 0.9rem; }
#over-detail p { margin: 6px 0; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

/* ------------------------------------------------------------------ Celular */

@media (max-width: 560px) {
  .tile { width: 36px; height: 42px; font-size: 1.2rem; }
  #weapons { top: calc(62px + var(--safe-t)); }
  .weapon { font-size: 0.7rem; padding: 2px 6px; }
  #hint { font-size: 0.8rem; bottom: calc(184px + var(--safe-b)); }
  #typed { font-size: 1.7rem; min-height: 2.1rem; }
  h1 { font-size: 2.4rem; }
  .over-stats { grid-template-columns: repeat(2, 1fr); }
}
