:root {
  --bg: #141119;
  --bg-2: #1b1822;
  --tint: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.09);
  --ink: #e7e2d6;
  --dim: #948ea1;
  --accent: #c0303c;
  --accent-bright: #d8454f;
  --gold: #e8c07a;
  --enemy: #8a8f3a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

/* Top bar: character sheet + language */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.sheet {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem 0.8rem;
  font-size: 0.9rem;
}
.sheet-name { font-weight: 700; color: var(--gold); }
.sheet-stat { color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.lang { display: flex; gap: 0.3rem; flex: none; }
.lang-opt {
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--dim);
  font-size: 0.8rem;
  font-weight: 600;
  user-select: none;
}
.lang-opt.on { color: #fff; background: var(--accent); border-color: var(--accent); }

/* Headings + flavor */
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: 0.01em; margin: 0 0 0.3rem; }
.flavor { color: var(--dim); margin: 0 0 1.25rem; }
.outcome { color: var(--ink); font-size: 1.05rem; margin: 0 0 0.85rem; }

/* Combatants */
.arena { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.combatant {
  background: var(--tint);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "sprite name hp" "bar bar bar";
  align-items: center;
  gap: 0.45rem 0.7rem;
}
.sprite { grid-area: sprite; font-size: 1.6rem; line-height: 1; }
.name { grid-area: name; font-weight: 600; }
.hp { grid-area: hp; color: var(--dim); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.bar { grid-area: bar; height: 7px; background: rgba(0, 0, 0, 0.4); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent-bright); border-radius: 99px; transition: width 0.25s ease; }
.combatant.enemy .bar-fill { background: var(--enemy); }

/* Buttons — base is the primary (accent) style */
.action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 1rem;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease, transform 0.04s ease;
}
.action:hover { background: var(--accent-bright); }
.action:active { transform: translateY(1px); }

/* Combat action row — pinned directly under the combatants */
.controls { margin-bottom: 0.85rem; }
.actions { display: flex; gap: 0.5rem; }
.actions .action { flex: 1; }

/* Quiet (navigation) buttons: exits + ghost */
.exit,
.action.ghost {
  background: var(--tint);
  color: var(--ink);
  border: 1px solid var(--line);
}
.exit:hover,
.action.ghost:hover { background: var(--bg-2); }
.exit { justify-content: flex-start; gap: 0.4rem; }

/* Descend stays primary */
.descend { margin-bottom: 0.85rem; }

/* Combat log — fixed height, scrolls internally, never pushes the buttons */
.log {
  background: var(--tint);
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  height: 30vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  color: var(--dim);
  font-size: 0.92rem;
}
.log p { margin: 0.3rem 0; }
.log p:first-child { margin-top: 0; }
.log p:last-child { color: var(--ink); }

/* Town */
.exits { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 0.85rem; }
.presence { margin: 0.25rem 0 1rem; min-height: 1.2rem; color: var(--dim); font-size: 0.95rem; }
.presence .dim { color: var(--dim); }

/* Dungeon */
.dstatus { display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; margin-bottom: 0.6rem; font-variant-numeric: tabular-nums; }
.dhp { color: var(--gold); font-weight: 600; }
.dmob { color: var(--dim); }
.grid { display: grid; gap: 2px; margin-bottom: 0.6rem; }
.cell {
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(0.9rem, 5vw, 1.4rem);
  border-radius: 4px;
}
.cell.floor { background: var(--tint); }
.cell.wall { background: #0c0a10; }
.dlog { display: block; min-height: 2.4rem; margin-bottom: 0.6rem; color: var(--dim); font-size: 0.9rem; }
.dlog span { display: block; }
.dlog span:last-child { color: var(--ink); }
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas: ". up ." "left . right" ". down .";
  gap: 0.5rem;
  max-width: 260px;
  margin: 0 auto 0.6rem;
}
.pad { min-height: 52px; font-size: 1.3rem; }
.pad.up { grid-area: up; }
.pad.left { grid-area: left; }
.pad.right { grid-area: right; }
.pad.down { grid-area: down; }
