@font-face { font-family: "Baloo 2"; font-weight: 500; font-display: swap; src: url("/fonts/baloo-2-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Baloo 2"; font-weight: 700; font-display: swap; src: url("/fonts/baloo-2-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Baloo 2"; font-weight: 800; font-display: swap; src: url("/fonts/baloo-2-latin-800-normal.woff2") format("woff2"); }

:root {
  --noite: #2B1E16;
  --noite-2: #3D2C21;
  --noite-3: #574131;
  --pequi: #F2B705;
  --pequi-escuro: #B27A00;
  --pequi-claro: #FFE07A;
  --laterita: #B5462B;
  --cerrado: #7E9B3A;
  --po: #FFF4D6;
  --po-2: rgba(255, 244, 214, 0.72);
  --perigo: #E0533A;
  --vida: #8CC84B;
  --font: "Baloo 2", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #6FB7E0; }
body {
  font-family: var(--font); font-weight: 500; color: var(--po);
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  touch-action: none; overscroll-behavior: none;
}
input, select, button { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--pequi-claro); outline-offset: 2px; }

#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }

/* ---------- Telas ---------- */
.screen { position: fixed; inset: 0; display: flex; z-index: 10; }
.modal { align-items: center; justify-content: center; padding: 16px; background: rgba(30, 20, 14, 0.55); z-index: 30; }

.card {
  width: min(420px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  background: var(--noite); border-radius: 22px; padding: 26px 24px 22px;
  box-shadow: 0 14px 0 rgba(30, 20, 14, 0.45);
  display: flex; flex-direction: column; gap: 12px; user-select: text;
}
.card.wide { width: min(560px, 100%); }
.card h2 { margin: 0; font-weight: 800; font-size: 28px; line-height: 1.1; color: var(--pequi-claro); }
.card h3 { margin: 8px 0 0; font-weight: 700; font-size: 18px; color: var(--pequi-claro); }
.card p { margin: 0; line-height: 1.4; }
.card ul { margin: 0; padding-left: 20px; line-height: 1.45; }
.muted { color: var(--po-2); font-size: 15px; }

/* ---------- Menu ---------- */
#menu { align-items: center; padding: 16px calc(16px + var(--safe-r)) 16px calc(16px + var(--safe-l)); }
.menu-panel {
  width: min(430px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  margin-left: clamp(0px, 5vw, 72px);
  background: rgba(43, 30, 22, 0.9); border-radius: 26px; padding: 22px 24px 18px;
  box-shadow: 0 16px 0 rgba(43, 30, 22, 0.35);
  display: flex; flex-direction: column; gap: 8px;
}
.menu-cols, .menu-col { display: flex; flex-direction: column; gap: 8px; }
.logo { margin: 0 0 2px; line-height: 0.82; display: flex; flex-direction: column; font-weight: 800; }
.logo-bang {
  font-size: clamp(64px, 11vw, 104px); color: var(--pequi); letter-spacing: -0.02em;
  transform: rotate(-4deg); transform-origin: left bottom; display: inline-block;
  text-shadow: 4px 5px 0 var(--laterita), 7px 9px 0 rgba(30, 20, 14, 0.5);
}
.logo-cerrado { font-size: clamp(38px, 6.4vw, 60px); color: var(--po); letter-spacing: -0.01em; margin-left: 4px; }
.by { margin: 6px 0 6px; color: var(--po-2); font-size: 15px; }
.field { margin: 6px 0 0; font-weight: 700; font-size: 15px; color: var(--po-2); }

.input, .select {
  width: 100%; background: var(--noite-2); border: 2px solid rgba(255, 244, 214, 0.18);
  border-radius: 14px; padding: 9px 14px; font-size: 18px; font-weight: 700; user-select: text;
}
.input:focus, .select:focus { border-color: var(--pequi); outline: none; }
.select { width: auto; padding-right: 8px; }

.chars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.char-card {
  background: var(--noite-2); border: 2px solid transparent; border-radius: 16px;
  padding: 6px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 0;
  font-weight: 700; font-size: 14px; line-height: 1.1; transition: transform .12s ease, border-color .12s ease;
}
.char-card canvas { display: block; }
.char-card[aria-checked="true"] { border-color: var(--pequi); background: var(--noite-3); transform: translateY(-2px); }
.perk { margin: 0; min-height: 2.6em; font-size: 15px; line-height: 1.3; color: var(--po-2); }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: stretch; }
.grow { flex: 1; }

.btn {
  background: var(--noite-3); color: var(--po); border: 0; border-radius: 14px;
  padding: 10px 16px; font-weight: 700; font-size: 18px; line-height: 1.15;
  box-shadow: 0 4px 0 #1E140F; transition: transform .06s ease, box-shadow .06s ease, filter .12s;
  text-align: center; text-decoration: none; display: inline-block;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #1E140F; }
.btn.primary { background: var(--pequi); color: var(--noite); box-shadow: 0 4px 0 var(--pequi-escuro); }
.btn.primary:active { box-shadow: 0 1px 0 var(--pequi-escuro); }
.btn.ghost { background: transparent; box-shadow: none; border: 2px solid rgba(255, 244, 214, 0.28); }
.btn.ghost:active { transform: translateY(1px); }
.btn.danger { color: #FFB4A3; border-color: rgba(224, 83, 58, 0.5); }
.btn:disabled { opacity: .45; pointer-events: none; }

.links { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; }
.link { background: none; border: 0; padding: 4px 0; font-weight: 700; font-size: 16px; color: var(--pequi-claro); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px; }
.net { margin: 2px 0 0; font-size: 14px; color: var(--po-2); min-height: 1.3em; }
.net.ok::before, .net.off::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.net.ok::before { background: var(--vida); }
.net.off::before { background: var(--perigo); }

/* ---------- Espera ---------- */
.code { margin: 4px 0; font-size: 54px; font-weight: 800; letter-spacing: 0.14em; color: var(--pequi); text-align: center; user-select: all; }
.code-input { text-align: center; font-size: 34px; letter-spacing: 0.3em; text-transform: uppercase; }
.dots { display: flex; gap: 8px; justify-content: center; padding: 6px 0; }
.dots span { width: 12px; height: 12px; border-radius: 50%; background: var(--pequi); animation: pulo 1s infinite ease-in-out; }
.dots span:nth-child(2) { animation-delay: .15s; }
.dots span:nth-child(3) { animation-delay: .3s; }
@keyframes pulo { 0%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-8px); opacity: 1; } }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud button, #hud .chat-menu { pointer-events: auto; }
.hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: start; gap: 10px;
  padding: 10px calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
}
.pcards { display: flex; flex-direction: column; gap: 6px; }
.pcards.right { align-items: flex-end; }
.pcard {
  display: grid; grid-template-columns: 40px auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center;
  background: rgba(43, 30, 22, 0.82); border-radius: 14px; padding: 4px 12px 6px 4px; min-width: 170px; max-width: 230px;
  border: 2px solid transparent;
}
.pcard.turn { border-color: var(--pequi); }
.pcard.dead { opacity: .55; }
.pcard canvas { grid-row: span 2; border-radius: 10px; background: rgba(255, 244, 214, 0.08); }
.pcard .name { font-weight: 700; font-size: 15px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .hp { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; }
.pcard .hp .bar { width: 96px; }

.bar { height: 10px; border-radius: 6px; background: rgba(255, 244, 214, 0.16); position: relative; overflow: hidden; }
.bar > div { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; }
.hpfill { background: var(--vida); transition: width .35s ease, background-color .35s; }

.center-top { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.turnbox { background: rgba(43, 30, 22, 0.86); border-radius: 16px; padding: 4px 16px 6px; text-align: center; min-width: 220px; }
.turn-label { margin: 0; font-weight: 800; font-size: 19px; color: var(--pequi-claro); white-space: nowrap; }
.turn-meta { display: flex; gap: 16px; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; }
.wind { display: flex; align-items: center; gap: 6px; }
.wind svg { width: 34px; height: 14px; color: var(--po); transition: transform .3s ease; }
.wind.forte svg { color: #FFB4A3; }
.timer { min-width: 42px; height: 30px; border-radius: 15px; background: var(--noite-3); display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.timer.urgente { background: var(--perigo); }
#minimap { width: 240px; height: 72px; border-radius: 10px; pointer-events: auto; cursor: pointer; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; background: rgba(43, 30, 22, 0.86);
  display: grid; place-items: center; color: var(--po); padding: 0;
}
.icon-btn svg { width: 24px; height: 24px; }

.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: flex-end; gap: 10px; justify-content: center;
  padding: 0 calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
}
.weapons { display: flex; gap: 6px; background: rgba(43, 30, 22, 0.86); border-radius: 18px; padding: 6px; }
.weapon {
  position: relative; border: 2px solid transparent; background: var(--noite-2); border-radius: 13px;
  padding: 4px 10px 4px 6px; display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; line-height: 1.05; text-align: left;
}
.weapon canvas { flex: none; }
.weapon .key { position: absolute; top: -6px; left: -4px; font-size: 11px; background: var(--noite-3); border-radius: 6px; padding: 0 5px; }
.weapon[aria-checked="true"] { border-color: var(--pequi); background: var(--noite-3); }
.weapon .cd { position: absolute; inset: 0; border-radius: 11px; background: rgba(30, 20, 14, 0.72); display: grid; place-items: center; font-weight: 800; font-size: 15px; color: var(--po-2); }
.weapon:disabled { cursor: not-allowed; }

.gauges { background: rgba(43, 30, 22, 0.86); border-radius: 18px; padding: 8px 14px; display: flex; flex-direction: column; gap: 6px; min-width: 300px; }
.gauge-row { display: grid; grid-template-columns: 54px 1fr 52px; align-items: center; gap: 8px; }
.gauge-name { font-weight: 700; font-size: 14px; color: var(--po-2); }
.gauge-val { text-align: right; font-weight: 800; font-size: 17px; white-space: nowrap; }
.gauge-val.angle { font-size: 15px; color: var(--po-2); }
.gauge-val.angle b { color: var(--po); }
.power-bar { height: 16px; border-radius: 9px; background: linear-gradient(90deg, rgba(126,155,58,.35), rgba(242,183,5,.35) 60%, rgba(181,70,43,.4)); }
#power-fill { background: linear-gradient(90deg, var(--cerrado), var(--pequi) 60%, var(--laterita)); width: 0; border-radius: 9px; }
#power-last { position: absolute; top: -2px; bottom: -2px; width: 3px; background: var(--po); border-radius: 2px; left: -10px; }
.stamina-bar { height: 8px; }
#stamina-fill { background: #8FD3F4; width: 100%; transition: width .1s linear; }

.touch-move { display: none; gap: 10px; margin-right: auto; }
.move-btn { width: 64px; height: 64px; border-radius: 50%; border: 0; background: rgba(43, 30, 22, 0.86); color: var(--po); display: grid; place-items: center; }
.move-btn svg { width: 30px; height: 30px; }
.move-btn:active, .move-btn.held { background: var(--noite-3); color: var(--pequi-claro); }
.chat-btn { margin-left: 0; }
.chat-menu {
  position: absolute; right: calc(10px + var(--safe-r)); bottom: calc(66px + var(--safe-b)); background: var(--noite); border-radius: 16px; padding: 6px;
  display: flex; flex-direction: column; gap: 4px; min-width: 190px;
}
.chat-menu button { border: 0; background: var(--noite-2); border-radius: 10px; padding: 8px 12px; text-align: left; font-weight: 700; font-size: 16px; }
.chat-menu button:hover { background: var(--noite-3); }

.banner {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%) scale(.9); margin: 0;
  font-weight: 800; font-size: clamp(32px, 6vw, 60px); color: var(--pequi); white-space: nowrap;
  text-shadow: 3px 4px 0 var(--laterita), 0 0 24px rgba(43, 30, 22, 0.5);
  opacity: 0; transition: opacity .2s ease, transform .25s ease;
}
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.banner.small { font-size: clamp(22px, 3.6vw, 34px); color: var(--po); text-shadow: 2px 3px 0 var(--noite); }
.hint {
  position: absolute; left: 50%; bottom: calc(118px + var(--safe-b)); transform: translateX(-50%); margin: 0;
  background: rgba(43, 30, 22, 0.8); border-radius: 12px; padding: 4px 12px; font-size: 15px; font-weight: 700; white-space: nowrap;
  opacity: 0; transition: opacity .3s;
}
.hint.show { opacity: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 20px); z-index: 50;
  background: var(--noite); color: var(--po); border-radius: 14px; padding: 10px 18px; font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 0 rgba(30, 20, 14, 0.45); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Fim ---------- */
.end-card { text-align: center; align-items: center; }
.end-card h2 { font-size: 44px; }
.end-card .row { width: 100%; }
.end-thumb canvas { display: block; }

/* ---------- Ranking ---------- */
.rank-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.rank-list li { display: grid; grid-template-columns: 30px 36px 1fr auto; gap: 8px; align-items: center; background: var(--noite-2); border-radius: 12px; padding: 4px 12px 4px 8px; }
.rank-list .pos { font-weight: 800; color: var(--pequi); text-align: center; }
.rank-list .pts { font-weight: 800; }
.rank-list .sub { font-size: 13px; color: var(--po-2); }

/* ---------- Girar celular ---------- */
.rotate { display: none; position: fixed; inset: 0; z-index: 60; background: var(--noite); flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 24px; }
.rotate svg { width: 84px; height: 84px; color: var(--pequi); }
.rotate p { font-weight: 800; font-size: 24px; margin: 0; }

.demo-cta { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20; }

/* ---------- Telas pequenas e toque ---------- */
@media (pointer: coarse) {
  .touch-move { display: flex; }
  .hud-bottom { justify-content: flex-end; }
}
@media (max-width: 900px), (max-height: 520px) {
  .pcard { min-width: 0; grid-template-columns: 32px auto; padding: 3px 8px 4px 3px; }
  .pcard canvas { width: 32px !important; height: 32px !important; }
  .pcard .name { font-size: 13px; max-width: 110px; }
  .pcard .hp .bar { width: 64px; }
  .turnbox { min-width: 0; padding: 2px 10px 4px; }
  .turn-label { font-size: 15px; }
  .turn-meta { font-size: 13px; gap: 10px; }
  .timer { height: 24px; min-width: 34px; font-size: 15px; }
  #minimap { width: 170px; height: 51px; }
  .weapon span.wname { display: none; }
  .weapon { padding: 4px; }
  .gauges { min-width: 200px; padding: 6px 10px; }
  .gauge-row { grid-template-columns: 44px 1fr 36px; }
  .gauge-name { font-size: 12px; }
  .move-btn { width: 56px; height: 56px; }
  .icon-btn { width: 40px; height: 40px; }
  .hint { bottom: calc(96px + var(--safe-b)); font-size: 13px; }
}
@media (max-height: 720px) {
  .menu-panel { padding: 12px 18px; gap: 4px; }
  .logo { flex-direction: row; align-items: baseline; gap: 12px; }
  .logo-bang { font-size: 46px; }
  .logo-cerrado { font-size: 34px; }
  .by { margin: 0; }
  .char-card canvas { width: 48px !important; height: 48px !important; }
  .perk { min-height: 0; font-size: 14px; }
}
@media (max-height: 720px) and (min-width: 700px) {
  .menu-panel { width: min(780px, 100%); margin-left: 0; }
  .menu-cols { flex-direction: row; gap: 20px; }
  .menu-col { flex: 1; min-width: 0; gap: 6px; }
  .menu-col:last-child { justify-content: flex-end; }
  .actions { margin-top: 0; }
}
@media (max-width: 560px) {
  #menu { align-items: flex-end; }
  .menu-panel { margin: 0; width: 100%; }
}
@media (orientation: portrait) and (pointer: coarse) {
  body.in-game .rotate { display: flex; }
}
@media (prefers-reduced-motion: reduce) {
  .dots span { animation: none; opacity: 1; }
  .banner, .toast, .char-card, .btn { transition: none; }
}
