/* Mago da Torre: uma tela só, com a ilha inteira à vista (docs/mago-da-torre-mvp.md, seção 5).
   Materiais do GUIA-DO-SITE.md: pedra, madeira, pergaminho, latão e azul arcano. */
.mg {
  --ease-out: cubic-bezier(.215, .61, .355, 1);
  max-width: 1560px; margin: 0 auto; padding: 0 16px;
}
main:has(.mg) { padding: 14px 0 28px; }
.mg-carregando { text-align: center; color: var(--muted); padding: 80px 0; }

/* ---------- recursos: faixa dentro da janela do jogo, em caixas de largura fixa ---------- */
.mg-recursos {
  position: absolute; z-index: 1; top: 6px; left: 6px; right: 6px; margin: 0; padding: 0; list-style: none;
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px;
  pointer-events: none; /* não atrapalha os cliques nem o cursor do mapa */
}
.mg-rec {
  display: flex; align-items: center; gap: 5px; min-width: 0; padding: 3px 7px 3px 5px; border-radius: 3px;
  white-space: nowrap; overflow: hidden; line-height: 1.15; font-size: .85rem;
  color: var(--parch-ink); background: var(--parch) var(--tex-parch);
  box-shadow: inset 0 0 10px rgba(120, 70, 20, .45), 0 0 0 1px rgba(60, 30, 5, .8), 0 3px 8px rgba(0, 0, 0, .45);
}
.mg-rec .val { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; } /* número à direita: a caixa não mexe */
.mg-rec b { font-family: var(--font-ui); font-weight: 700; font-variant-numeric: tabular-nums; }
.mg-rec small { color: var(--parch-muted); font: .75rem var(--font-ui); font-variant-numeric: tabular-nums; }
.mg-rec.cheio b { color: #7a1d12; }
.mg-quadro { container-type: inline-size; }
@container (max-width: 760px) {  /* janela estreita: os nomes somem da vista (o leitor de tela continua lendo) */
  .mg-rec .nome { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
@container (max-width: 480px) {
  .mg-recursos { gap: 3px; top: 4px; left: 4px; right: 4px; }
  .mg-rec { font-size: .75rem; padding: 2px 4px 2px 3px; gap: 3px; }
  .mg-rec small { display: none; }
}
.mg-ico { width: 16px; height: 16px; flex-shrink: 0; image-rendering: pixelated; background-repeat: no-repeat; }

.mg-mapa { position: absolute; line-height: 0; }   /* a ilha, centralizada dentro da janela do jogo */
.mg-quadro {
  position: relative; margin: 0 auto; line-height: 0; border-radius: 3px; overflow: hidden; touch-action: manipulation;
  background: #41a6f6; image-rendering: pixelated;
  box-shadow: inset 0 0 0 100vmax var(--noite, transparent), 0 0 0 2px var(--brass-dark), 0 0 0 3px #000, 0 14px 30px rgba(0, 0, 0, .6);
}
.mg-quadro canvas { display: block; width: 100%; height: 100%; cursor: pointer; }
.mg-quadro.com-zoom canvas { cursor: grab; touch-action: none; }
/* cursor próprio desenhado no canvas: a seta do sistema some sobre o mapa */
.mg-quadro.cursor-proprio canvas, .mg-quadro.cursor-proprio .mg-alvo { cursor: none; }
.mg-quadro[data-cursor="info"] canvas { cursor: help; }
.mg-quadro.arrastando canvas { cursor: grabbing; }
.mg-quadro.cursor-proprio.arrastando canvas { cursor: none; } /* o cursor desenhado (mão fechada) já aparece: a do sistema some */

/* palco: recursos + mapa; é ele que vai para a tela cheia */
.mg-palco:fullscreen { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px; background: #0a0c0f var(--tex-rock); }

/* botões de zoom no canto do mapa */
.mg-zoom { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 4px; line-height: 1; z-index: 1; }
.mg-zoom button {
  display: grid; place-items: center; width: 32px; height: 32px; padding: 0; cursor: pointer; border-radius: 3px;
  color: var(--brass-light); background: rgba(36, 21, 10, .88); border: 1px solid var(--brass-dark); box-shadow: 0 0 0 1px #000;
}
.mg-zoom button:hover:not(:disabled) { border-color: var(--brass); color: #fff; }
.mg-zoom button:disabled { opacity: .45; cursor: default; }
.mg-zoom button:focus-visible { outline: 2px solid var(--arcane-2); outline-offset: 2px; }
.mg-zoom svg { width: 16px; height: 16px; fill: currentColor; }
.mg-quadro canvas:focus-visible { outline: 3px solid var(--arcane-2); outline-offset: -3px; }

/* botões invisíveis por cima do mapa (teclado e leitor de tela) */
.mg-alvo {
  position: absolute; padding: 0; border: 0; background: transparent; cursor: pointer; border-radius: 4px;
}
.mg-alvo:focus-visible { outline: 3px solid var(--arcane-2); outline-offset: 2px; box-shadow: 0 0 18px rgba(0, 168, 232, .6); }

/* números que sobem do clique */
.mg-flutua {
  position: absolute; pointer-events: none; line-height: 1; white-space: nowrap; transform: translate(-50%, -50%);
  font: 700 .95rem var(--font-ui); color: #fff3b0; text-shadow: 0 1px 0 #1a1c2c, 1px 0 0 #1a1c2c, -1px 0 0 #1a1c2c, 0 -1px 0 #1a1c2c;
  animation: mg-sobe .9s var(--ease-out) forwards;
}
.mg-flutua.madeira { color: #e8c39e; } .mg-flutua.pedra { color: #dfe8ef; } .mg-flutua.mana { color: #7fd6f7; }
@keyframes mg-sobe { from { opacity: 1; translate: 0 0; } to { opacity: 0; translate: 0 -28px; } }

/* balão de detalhes no mapa */
.mg-balao {
  position: absolute; z-index: 2; max-width: 230px; padding: 8px 10px; line-height: 1.35; font-size: .9rem; border-radius: 3px;
  color: var(--parch-ink); background: var(--parch) var(--tex-parch); transform: translate(-50%, calc(-100% - 10px));
  box-shadow: inset 0 0 14px rgba(120, 70, 20, .45), 0 0 0 1px rgba(60, 30, 5, .8), 0 8px 16px rgba(0, 0, 0, .5);
  animation: mg-aparece .18s var(--ease-out);
}
.mg-balao strong { font-family: var(--font-head); display: block; }
@keyframes mg-aparece { from { opacity: 0; scale: .96; } }

/* modo de escolher lugar */
.mg-escolha {
  position: absolute; left: 50%; top: 40px; translate: -50% 0; z-index: 4; line-height: 1.3; padding: 6px 12px; font-size: .9rem;
  border-radius: 3px; color: var(--arcane-2); background: rgba(10, 12, 15, .88); border: 1px solid var(--arcane-mid); text-align: center;
}

/* ---------- HUD: tudo dentro da janela do jogo ---------- */
.mg-quadro { --hud: rgba(20, 13, 7, .92); }

/* barra de comandos, embaixo à esquerda */
.mg-dock { position: absolute; z-index: 2; left: 8px; bottom: 8px; right: 128px; display: flex; flex-wrap: wrap; gap: 6px; line-height: 1.1; }
.mg-dock-grupo { display: flex; gap: 3px; padding: 3px; border-radius: 4px; background: var(--hud); border: 1px solid var(--brass-dark); box-shadow: 0 0 0 1px #000, 0 6px 14px rgba(0, 0, 0, .5); }
.mg-dock-btn {
  display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; cursor: pointer; border-radius: 3px;
  font: 500 .82rem var(--font-head); letter-spacing: .03em; color: var(--brass-light);
  background: linear-gradient(180deg, #3a2716, var(--wood-dark)); border: 1px solid transparent;
  transition: border-color .2s, box-shadow .2s, transform .1s;
}
.mg-dock-btn.so-icone { width: 32px; padding: 0; justify-content: center; }
.mg-dock-btn:hover { border-color: var(--brass); color: #fff; }
.mg-dock-btn:active { transform: translateY(1px); }
.mg-dock-btn.ativo { border-color: var(--arcane-2); color: #fff; box-shadow: inset 0 0 10px rgba(0, 168, 232, .35); }
.mg-dock-btn:focus-visible { outline: 2px solid var(--arcane-2); outline-offset: 2px; }
.mg-dock-btn.chama { border-color: #ff8a3d; box-shadow: 0 0 10px rgba(255, 138, 61, .55); } /* tem magia urgente para usar */
@container (max-width: 620px) {   /* jogo estreito: os painéis ficam só com o ícone */
  .mg-dock { right: 8px; bottom: 46px; }
  .mg-dock-btn { padding: 0 8px; }
  .mg-dock-btn span:not(.mg-ico) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

/* painel aberto: por cima do mapa, acima da barra */
.mg-janela {
  position: absolute; z-index: 3; left: 8px; bottom: 50px; width: min(340px, calc(100% - 16px));
  max-height: calc(100% - 100px); display: flex; flex-direction: column; line-height: 1.35;
  border-radius: 4px; color: var(--text); background: var(--hud) var(--tex-grain);
  border: 1px solid var(--brass-dark); box-shadow: 0 0 0 1px #000, 0 14px 30px rgba(0, 0, 0, .6);
  animation: mg-aparece .16s var(--ease-out);
}
.mg-janela[hidden] { display: none; }
.mg-janela header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 6px 12px; border-bottom: 1px solid rgba(201, 162, 74, .25); }
.mg-janela h2 { margin: 0; font-size: 1rem; color: var(--brass-light); }
.mg-janela h2::after { display: none; }
.mg-janela-corpo { padding: 10px 12px 12px; overflow-y: auto; display: grid; gap: 6px; align-content: start; overscroll-behavior: contain; }
.mg-janela-corpo p { margin: 0; font-size: .92rem; }
.mg-fechar { display: grid; place-items: center; width: 28px; height: 28px; padding: 0; cursor: pointer; border-radius: 3px; color: var(--brass-light); background: transparent; border: 1px solid transparent; }
.mg-fechar:hover { border-color: var(--brass-dark); color: #fff; }
.mg-fechar:focus-visible { outline: 2px solid var(--arcane-2); outline-offset: 1px; }
.mg-fechar svg { width: 14px; height: 14px; fill: currentColor; }
@container (max-width: 620px) { .mg-janela { bottom: 88px; max-height: calc(100% - 130px); } }
.mg-dica { color: var(--muted); font-size: .85rem !important; }

.mg-cmd {
  display: grid; grid-template-columns: 1fr; gap: 2px; width: 100%; padding: 7px 10px; text-align: left;
  font: inherit; color: var(--text); cursor: pointer; border-radius: 3px; border: 1px solid var(--brass-dark);
  background: linear-gradient(180deg, #3a2716, var(--wood-dark)); transition: border-color .2s, box-shadow .2s, transform .1s;
}
.mg-cmd:hover:not(:disabled) { border-color: var(--brass); box-shadow: 0 0 14px rgba(0, 168, 232, .35); }
.mg-cmd:active:not(:disabled) { transform: translateY(1px); }
.mg-cmd:disabled { cursor: not-allowed; opacity: .55; }
.mg-cmd strong { font-family: var(--font-head); font-size: .92rem; color: var(--brass-light); }
.mg-cmd small { grid-column: 1 / -1; color: var(--muted); font-size: .82rem; line-height: 1.25; }
.mg-cmd .custo { font-size: .82rem; color: var(--arcane-2); white-space: nowrap; }

/* alertas: faixa curta no topo do jogo, logo abaixo dos recursos */
.mg-alertas { position: absolute; z-index: 2; top: 40px; left: 50%; translate: -50% 0; width: min(560px, calc(100% - 16px)); display: grid; gap: 4px; line-height: 1.3; }
.mg-alerta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 5px 6px 5px 12px; font-size: .88rem; border-radius: 3px;
  color: var(--text); background: rgba(40, 10, 6, .92); border: 1px solid #8a2a1c; box-shadow: 0 0 0 1px #000, 0 0 16px rgba(255, 60, 30, .3);
}
.mg-alerta strong { font-family: var(--font-head); color: #ff9b8a; }
.mg-alerta span { flex: 1; min-width: 0; }
.mg-alerta em { color: var(--arcane-2); font-style: normal; padding-right: 6px; }
.mg-alerta-btn {
  padding: 4px 10px; cursor: pointer; border-radius: 3px; font: 600 .82rem var(--font-ui); color: #00171f;
  background: var(--arcane-2); border: 1px solid var(--arcane); box-shadow: 0 0 10px rgba(0, 168, 232, .45);
}
.mg-alerta-btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.mg-alerta-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
@container (max-width: 480px) { .mg-alertas { top: 30px; } .mg-alerta { font-size: .78rem; } }

.mg-diario { list-style: none; margin: 0; padding: 0; font-size: .88rem; line-height: 1.35; }
.mg-diario li { padding: 4px 0; border-top: 1px solid rgba(255, 255, 255, .06); }
.mg-diario li:first-child { border-top: 0; }
.mg-diario time { color: var(--muted); font-size: .8rem; margin-right: 4px; }
.mg-diario .ruim { color: #ffb3a6; } .mg-diario .bom { color: #c8f0a0; }

.mg-dialogo {
  max-width: 420px; width: calc(100% - 32px); padding: 18px 20px; border-radius: 4px; color: var(--parch-ink);
  background: var(--parch) var(--tex-parch); border: 0; box-shadow: inset 0 0 24px rgba(120, 70, 20, .5), 0 0 0 2px var(--brass-dark), 0 20px 50px rgba(0, 0, 0, .7);
}
.mg-dialogo::backdrop { background: rgba(0, 0, 0, .6); }
.mg-dialogo h2 { margin: 0 0 10px; color: var(--parch-ink); font-size: 1.2rem; }
.mg-dialogo h2::after { display: none; }
.mg-dialogo ul { margin: 0 0 14px; padding-left: 18px; }

@media (prefers-reduced-motion: reduce) {
  .mg-flutua { animation: mg-some .9s linear forwards; }
  .mg-balao, .mg-janela { animation: none; }
  @keyframes mg-some { to { opacity: 0; } }
}

/* aviso de entrar (sem conta) */
.mg-painel {
  padding: 14px 16px; border-radius: 4px; background: linear-gradient(180deg, rgba(29, 34, 40, .94), rgba(10, 12, 15, .96)), var(--tex-grain);
  border: 1px solid var(--brass-dark); box-shadow: 0 0 0 1px #000, 0 10px 24px rgba(0, 0, 0, .55);
}

/* aba Construir */
.mg-sub { margin: 6px 0 0; font: 700 .78rem var(--font-head); letter-spacing: .08em; text-transform: uppercase; color: var(--arcane-2); }
.mg-sub::after { display: none; }
.mg-coletor { display: grid; gap: 4px; padding: 8px; border-radius: 3px; background: rgba(255, 255, 255, .04); border: 1px solid rgba(201, 162, 74, .2); }
.mg-coletor > strong { font-family: var(--font-head); color: var(--brass-light); font-size: .95rem; }
.mg-coletor p { font-size: .85rem !important; color: var(--text); }
.mg-enfeites { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
