/* Reino: jogo 2D (canvas), HUD, direcional de toque e chat. */
.realm-page { padding-top: 22px; padding-bottom: 56px; overflow-x: clip; }
.realm-head { margin-bottom: 16px; }
.realm-kicker { display: inline-flex; align-items: center; gap: 6px; margin: 0 0 6px; padding: 4px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-size: .76rem; font-weight: 800; letter-spacing: 0; text-transform: none; }
.realm-kicker .icon { width: 15px; height: 15px; }
.realm-title { margin: 0; font-family: var(--font-display); font-weight: 900; letter-spacing: -.02em; font-size: clamp(2rem, 5vw, 3.2rem); }
.realm-sub { margin: 6px 0 0; color: var(--text-soft); max-width: 60ch; }

.realm-game { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1000px) { .realm-game { grid-template-columns: minmax(0, 1fr) 320px; } }

.realm-stage { position: relative; overflow: hidden; border-radius: 20px; background: #0b1a10; box-shadow: 0 24px 50px -30px rgba(0, 0, 0, .7), 0 0 0 1px var(--border); aspect-ratio: 4 / 3; max-height: 72vh; }
@media (max-width: 640px) { .realm-stage { aspect-ratio: 1 / 1; } }
.realm-canvas { display: block; width: 100%; height: 100%; outline: none; touch-action: none; }
.realm-canvas:focus-visible { box-shadow: inset 0 0 0 3px var(--accent); }

.realm-hud { position: absolute; left: 10px; top: 10px; display: flex; flex-wrap: wrap; gap: 6px; max-width: calc(100% - 20px); pointer-events: none; }
.realm-hud > span { padding: 4px 10px; border-radius: 999px; background: rgba(10, 12, 20, .6); color: #fff; font-size: .8rem; font-weight: 700; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.realm-hud-pos { font-variant-numeric: tabular-nums; opacity: .85; }
.realm-status { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0; padding: 6px 14px; border-radius: 999px; background: rgba(160, 30, 30, .85); color: #fff; font-size: .85rem; font-weight: 700; max-width: calc(100% - 24px); text-align: center; }
.realm-status[hidden] { display: none; }

.realm-gate { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; padding: 20px; text-align: center; background: rgba(8, 10, 18, .72); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); color: #fff; }
.realm-gate h2 { margin: 0; font-family: var(--font-display); font-weight: 900; }
.realm-gate p { margin: 0 0 6px; opacity: .85; }

.realm-dpad { position: absolute; right: 12px; bottom: 12px; display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(2, 52px); gap: 6px; opacity: .92; }
.realm-key { display: grid; place-items: center; width: 52px; height: 52px; border: 0; border-radius: 16px; background: rgba(10, 12, 20, .62); color: #fff; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.realm-key:active, .realm-key.is-down { background: var(--accent); color: var(--accent-ink); }
.realm-key .icon { width: 24px; height: 24px; }
.realm-key--up { grid-column: 2; grid-row: 1; }
.realm-key--left { grid-column: 1; grid-row: 2; }
.realm-key--down { grid-column: 2; grid-row: 2; }
.realm-key--right { grid-column: 3; grid-row: 2; }
@media (hover: hover) and (pointer: fine) { .realm-dpad { display: none; } }

.realm-chat { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 10px; padding: 16px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); min-width: 0; }
.realm-chat-title { margin: 0; font-size: .8rem; letter-spacing: 0; text-transform: none; color: var(--accent-text); font-weight: 800; }
.realm-chat-log { list-style: none; margin: 0; padding: 0; display: grid; align-content: end; gap: 6px; min-height: 120px; max-height: 280px; overflow-y: auto; }
.realm-chat-log li { overflow-wrap: anywhere; font-size: .92rem; line-height: 1.35; }
.realm-chat-log b { color: var(--accent-text); }
.realm-chat-log li.is-me b { color: var(--text); }
.realm-chat-form { display: flex; gap: 8px; }
.realm-chat-form .input { flex: 1; min-width: 0; font-size: 16px; }

/* Etapa 2: barras, ouro e botão de ataque */
.realm-hud-gold { display: inline-flex; align-items: center; gap: 5px; }
.realm-hud-gold .icon { width: 14px; height: 14px; color: #ffd666; }
.realm-bars { position: absolute; left: 10px; right: 10px; top: 46px; display: grid; gap: 4px; max-width: 260px; pointer-events: none; }
.realm-bar { position: relative; height: 12px; border-radius: 999px; background: rgba(10, 12, 20, .62); overflow: hidden; }
.realm-bar i { display: block; height: 100%; width: 100%; transform-origin: left; transform: scaleX(0); transition: transform .2s ease; border-radius: inherit; }
.realm-bar--hp i { background: linear-gradient(90deg, #d94a4a, #f27a5a); }
.realm-bar--xp { height: 6px; }
.realm-bar--xp i { background: linear-gradient(90deg, #4a8ad0, #7fc4ff); }
.realm-bar span { position: absolute; inset: 0; display: grid; place-items: center; font-size: .66rem; font-weight: 800; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, .7); }
.realm-attack { position: absolute; left: 12px; bottom: 12px; display: inline-flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 20px; border: 0; border-radius: 16px; background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 800; cursor: pointer; touch-action: none; box-shadow: 0 12px 26px -12px rgba(0, 0, 0, .6); }
.realm-attack:active, .realm-attack.is-down { filter: brightness(.9); transform: scale(.97); }
.realm-attack .icon { width: 20px; height: 20px; }
.realm-chat-log li.is-event { color: var(--text-soft); font-style: italic; }
.realm-chat-log li.is-event.is-bad { color: var(--danger); }
.realm-chat-log li.is-event.is-good { color: var(--accent-text); }
@media (prefers-reduced-motion: reduce) { .realm-bar i { transition: none; } }

/* Etapa 3: mochila e mercador */
.realm-side { display: grid; gap: 16px; min-width: 0; }
.realm-bag { display: grid; gap: 10px; padding: 16px; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); min-width: 0; }
.realm-equip { margin: 0; font-size: .85rem; color: var(--text-soft); display: grid; gap: 2px; }
.realm-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.realm-items li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); min-width: 0; }
.realm-item-main { flex: 1; min-width: 0; display: grid; }
.realm-item-main strong { overflow-wrap: anywhere; font-size: .92rem; }
.realm-item-main small { color: var(--muted); font-size: .78rem; }
.realm-items .btn { min-height: 34px; padding: 0 12px; font-size: .82rem; }
.realm-bag-msg { margin: 0; min-height: 1.2em; font-size: .85rem; color: var(--accent-text); }
.realm-bag-msg.is-bad { color: var(--danger); }
.realm-empty { color: var(--muted); font-size: .88rem; padding: 6px 2px; }
@media (min-width: 1000px) {
  .realm-game .realm-stage { grid-column: 1; grid-row: 1 / span 2; }
  .realm-game .realm-bag { grid-column: 2; grid-row: 1; }
  .realm-game .realm-chat { grid-column: 2; grid-row: 2; }
}

/* Ranking e missões */
.realm-rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-width: 760px; }
.realm-rank-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); min-width: 0; }
.realm-rank-row.is-me { border-color: var(--accent); background: var(--accent-soft); }
.realm-rank-pos { flex: 0 0 34px; text-align: center; font-family: var(--font-display); font-weight: 900; font-size: 1.2rem; color: var(--muted); }
.realm-rank-row:nth-child(-n+3) .realm-rank-pos { color: var(--accent-text); }
.realm-rank-name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.realm-rank-stat { display: grid; justify-items: center; min-width: 54px; }
.realm-rank-stat b { font-variant-numeric: tabular-nums; }
.realm-rank-stat small { color: var(--muted); font-size: .7rem; }
@media (max-width: 520px) { .realm-rank-extra { display: none; } }
.realm-quest-bar { height: 5px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-top: 4px; }
.realm-quest-bar i { display: block; height: 100%; background: var(--accent); }
.realm-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* Etapa 5: mana, magias, denúncia */
.realm-bar--mana i { background: linear-gradient(90deg, #4a6ad0, #7fa2ff); }
.realm-actions { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; max-width: calc(100% - 190px); }
.realm-actions .realm-attack { position: static; }
.realm-spell { display: inline-flex; align-items: center; gap: 6px; min-height: 52px; padding: 0 14px; border: 0; border-radius: 16px; background: rgba(10, 12, 20, .66); color: #fff; font: inherit; font-weight: 700; cursor: pointer; touch-action: none; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.realm-spell:active, .realm-spell.is-down { background: var(--accent); color: var(--accent-ink); }
.realm-spell .icon { width: 18px; height: 18px; }
.realm-report { margin-left: 8px; padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: .75rem; text-decoration: underline; cursor: pointer; }
.realm-report:disabled { cursor: default; text-decoration: none; }
@media (max-width: 520px) { .realm-spell span { display: none; } .realm-spell { padding: 0 12px; } }

/* Etapa 7: som, tela cheia, chat compacto e poção rápida */
.realm-hud { max-width: calc(100% - 110px); }
.realm-tools { position: absolute; right: 10px; top: 10px; display: flex; gap: 6px; }
.realm-tool { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 12px; background: rgba(10, 12, 20, .62); color: #fff; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.realm-tool:hover { background: rgba(10, 12, 20, .82); }
.realm-tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.realm-tool .icon { width: 20px; height: 20px; }
.realm-tool .realm-ico-off { display: none; }
.realm-tool.is-off .realm-ico-on, .realm-tool.is-on .realm-ico-on { display: none; }
.realm-tool.is-off .realm-ico-off, .realm-tool.is-on .realm-ico-off { display: grid; }
.realm-tool.is-off { opacity: .75; }
.realm-tool--chat { display: none; }
.realm-potion b { display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: .72rem; font-variant-numeric: tabular-nums; }
.realm-potion.is-empty { opacity: .55; }
.realm-fs-chat { display: none; }
.realm-fs-log { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; justify-items: start; }
.realm-fs-log li { padding: 3px 10px; border-radius: 10px; background: rgba(8, 10, 20, .55); color: #fff; font-size: .78rem; line-height: 1.3; max-width: 100%; overflow-wrap: anywhere; }
.realm-fs-log li.is-bad { color: #ffb0a8; }
.realm-fs-log li.is-good { color: #a8f0b8; }
.realm-fs-form { display: flex; gap: 6px; pointer-events: auto; }
.realm-fs-form[hidden] { display: none; }
.realm-fs-form .input { flex: 1; min-width: 0; font-size: 16px; }

html.realm-fs-lock, html.realm-fs-lock body { overflow: hidden; overscroll-behavior: none; }
.realm-stage.is-full { position: fixed; inset: 0; z-index: 100000; width: 100%; height: 100vh; height: 100dvh; max-height: none; aspect-ratio: auto; border-radius: 0; box-shadow: none; }
.realm-stage.is-full .realm-hud { left: calc(10px + env(safe-area-inset-left, 0px)); top: calc(10px + env(safe-area-inset-top, 0px)); max-width: calc(100% - 170px); }
.realm-stage.is-full .realm-bars { left: calc(10px + env(safe-area-inset-left, 0px)); top: calc(46px + env(safe-area-inset-top, 0px)); }
.realm-stage.is-full .realm-tools { right: calc(10px + env(safe-area-inset-right, 0px)); top: calc(10px + env(safe-area-inset-top, 0px)); }
.realm-stage.is-full .realm-tool--chat { display: grid; }
.realm-stage.is-full .realm-actions { left: calc(12px + env(safe-area-inset-left, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
.realm-stage.is-full .realm-dpad { right: calc(12px + env(safe-area-inset-right, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
.realm-stage.is-full .realm-status { bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
.realm-stage.is-full .realm-fs-chat { display: grid; position: absolute; left: calc(12px + env(safe-area-inset-left, 0px)); bottom: calc(78px + env(safe-area-inset-bottom, 0px)); width: min(420px, calc(100% - 24px)); gap: 6px; pointer-events: none; }
@media (max-width: 640px) and (orientation: portrait) { .realm-stage.is-full .realm-fs-chat { bottom: calc(140px + env(safe-area-inset-bottom, 0px)); } }
@media (max-height: 460px) { .realm-stage.is-full .realm-fs-log li:nth-child(-n+3) { display: none; } }
@media (hover: hover) and (pointer: fine) { .realm-stage.is-full .realm-dpad { display: none; } }
@media (max-width: 520px) {
  .realm-hud > span { padding: 3px 9px; font-size: .74rem; }
  .realm-hud-pos { display: none; }
  .realm-hud { gap: 4px; }
}

/* alpha.104: no computador o mapa (4:3 limitado pela altura) deixava uma faixa vazia antes da mochila.
   Formato mais largo, que acompanha a coluna, e a coluna lateral encosta no mapa. */
@media (min-width: 1000px) {
  .realm-stage { aspect-ratio: 16 / 10; max-height: 80vh; }
}
