/* ===== HomeQuest — tema RPG pixel art ===== */

:root {
  --bg: #1a1c2c;
  --bg-panel: #29366f;
  --ink: #f4f4f4;
  --ink-dim: #94b0c2;
  --accent: #41a6f6;
  --gold: #ffcd75;
  --green: #38b764;
  --red: #b13e53;
  --purple: #5d275d;
  --border: #566c86;
  --shadow: #0f0f1b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Press Start 2P', 'Courier New', monospace;
  -webkit-font-smoothing: none;
  overscroll-behavior: none;
}

body {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ===== HUD ===== */
.hud {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-panel);
  border-bottom: 4px solid var(--shadow);
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
}

.hud-row { display: flex; align-items: center; gap: 8px; }

.level-badge {
  background: var(--gold);
  color: var(--shadow);
  font-size: 9px;
  padding: 6px 6px;
  border: 3px solid var(--shadow);
  box-shadow: 2px 2px 0 var(--shadow);
  white-space: nowrap;
}

.xp-wrap { flex: 1; min-width: 0; }

.xp-bar {
  height: 12px;
  background: var(--shadow);
  border: 3px solid var(--border);
}

.xp-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(
    90deg,
    var(--green) 0px, var(--green) 6px,
    #6ce08a 6px, #6ce08a 8px
  );
  transition: width 0.3s steps(8);
}

.xp-text { font-size: 6px; color: var(--ink-dim); margin-top: 3px; text-align: right; }

.coin-stat, .streak-stat { font-size: 9px; white-space: nowrap; }

/* ===== Alerta de sequência em risco ===== */
.streak-alert {
  display: block;
  width: calc(100% - 24px);
  margin: 10px auto 0;
  background: var(--red);
  color: var(--ink);
  border: 3px solid var(--shadow);
  box-shadow: 3px 3px 0 var(--shadow);
  font-size: 8px;
  line-height: 1.7;
  padding: 10px 12px;
  text-align: left;
  animation: alert-pulse 1.6s steps(2) infinite;
}

@keyframes alert-pulse {
  50% { filter: brightness(1.25); }
}

/* ===== Mapa da casa ===== */
.map-wrap {
  padding: 10px 0 6px;
  line-height: 0;
}

#mapCanvas {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border: 4px solid var(--shadow);
  box-shadow: 4px 4px 0 var(--shadow);
  touch-action: manipulation;
}

.map-hint {
  font-size: 7px;
  color: var(--ink-dim);
  text-align: center;
  padding: 8px 0 14px;
  line-height: 1.6;
}

/* ===== Popup de tarefa ===== */
.spot-popup {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 448px;
  background: var(--bg-panel);
  border: 4px solid var(--gold);
  box-shadow: 4px 4px 0 var(--shadow);
  padding: 14px;
  z-index: 15;
  animation: pop-in 0.15s steps(3);
}

.spot-popup-name { font-size: 10px; line-height: 1.6; }
.spot-popup-xp { font-size: 9px; color: var(--gold); margin: 8px 0 12px; }
.spot-popup-actions { display: flex; gap: 8px; }
.spot-popup-actions .pixel-btn { flex: 1; font-size: 8px; padding: 10px 6px; }

/* ===== Zona do herói (Loja) ===== */
.hero-zone {
  text-align: center;
  padding: 14px 0 8px;
  background:
    linear-gradient(180deg, transparent 78%, #1f2b4d 78%),
    radial-gradient(circle at 50% 120%, #223057 0%, var(--bg) 70%);
}

#heroCanvas {
  width: 112px;
  height: 112px;
  image-rendering: pixelated;
}

.hero-title {
  font-size: 9px;
  color: var(--gold);
  margin-top: 6px;
  text-shadow: 2px 2px 0 var(--shadow);
}

/* ===== Painéis ===== */
main { flex: 1; padding: 0 12px; }

.tab-panel { padding: 8px 0 24px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0 12px;
}

.panel-head h2 {
  font-size: 12px;
  margin: 0;
  text-shadow: 2px 2px 0 var(--shadow);
}

/* ===== Sugestão (cadeia de Markov) ===== */
.suggest-card {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'label label' 'name btn' 'reason btn';
  align-items: center;
  gap: 2px 10px;
  background: var(--bg-panel);
  border: 3px solid var(--accent);
  box-shadow: 3px 3px 0 var(--shadow);
  padding: 10px;
  margin-bottom: 12px;
}

.suggest-label { grid-area: label; font-size: 6px; color: var(--accent); margin-bottom: 4px; }
.suggest-name { grid-area: name; font-size: 9px; line-height: 1.5; }
.suggest-reason { grid-area: reason; font-size: 7px; color: var(--ink-dim); margin-top: 3px; line-height: 1.6; }
.suggest-card .pixel-btn { grid-area: btn; }

/* ===== Lista de missões ===== */
.quest-list { list-style: none; margin: 0; padding: 0; }

.quest {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel);
  border: 3px solid var(--shadow);
  box-shadow: 3px 3px 0 var(--shadow);
  padding: 12px 10px;
  margin-bottom: 10px;
}

.quest.done { opacity: 0.55; }
.quest.done .quest-name { text-decoration: line-through; }

.quest-check {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border: 3px solid var(--border);
  background: var(--shadow);
  color: var(--green);
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.quest.done .quest-check { background: var(--green); color: var(--shadow); border-color: var(--green); }

.quest-body { flex: 1; min-width: 0; }

.quest-name { font-size: 9px; line-height: 1.5; word-wrap: break-word; }

.quest-meta { font-size: 7px; color: var(--ink-dim); margin-top: 4px; }

.quest-xp { font-size: 8px; color: var(--gold); white-space: nowrap; }
.quest-xp.hot { color: #ff8a5c; }

.quest-del {
  background: var(--red);
  color: var(--ink);
  border: 3px solid var(--shadow);
  font-size: 10px;
  width: 28px;
  height: 28px;
  padding: 0;
}

/* ===== Tudo limpo ===== */
.all-clear {
  text-align: center;
  padding: 24px 0;
  font-size: 10px;
  line-height: 1.8;
}
.all-clear-icon { font-size: 40px; }
.all-clear .sub { font-size: 8px; color: var(--ink-dim); }

/* ===== Botões ===== */
.pixel-btn {
  background: var(--accent);
  color: var(--shadow);
  border: 3px solid var(--shadow);
  box-shadow: 3px 3px 0 var(--shadow);
  font-size: 10px;
  padding: 12px 14px;
}

.pixel-btn:active { transform: translate(3px, 3px); box-shadow: none; }
.pixel-btn.wide { width: 100%; margin-top: 6px; }
.pixel-btn.small { font-size: 8px; padding: 8px 10px; }
.pixel-btn.ghost { background: var(--bg-panel); color: var(--ink); }
.pixel-btn.danger { background: var(--red); color: var(--ink); }
.pixel-btn.gold { background: var(--gold); }
.pixel-btn:disabled { opacity: 0.4; cursor: default; }

/* ===== Loja ===== */
.shop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.shop-item {
  background: var(--bg-panel);
  border: 3px solid var(--shadow);
  box-shadow: 3px 3px 0 var(--shadow);
  padding: 12px 8px;
  text-align: center;
}

.shop-item.equipped { border-color: var(--gold); }

.shop-swatch {
  width: 32px;
  height: 32px;
  margin: 0 auto 8px;
  border: 3px solid var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.shop-name { font-size: 8px; line-height: 1.5; min-height: 24px; }
.shop-price { font-size: 8px; color: var(--gold); margin: 6px 0; }
.shop-item .pixel-btn { font-size: 7px; padding: 8px; width: 100%; }

/* ===== Status ===== */
.stats-list { margin: 0; font-size: 9px; }

.stats-list .stat-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-panel);
  border: 3px solid var(--shadow);
  padding: 12px 10px;
  margin-bottom: 8px;
}

.stats-list dt { color: var(--ink-dim); }
.stats-list dd { margin: 0; color: var(--gold); text-align: right; }

/* ===== Barra de abas ===== */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--bg-panel);
  border-top: 4px solid var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 16px;
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tab-btn span { font-size: 6px; }
.tab-btn.active { color: var(--gold); }

/* ===== Overlays / fichas ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 27, 0.85);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  background: var(--bg-panel);
  border: 4px solid var(--shadow);
  width: 100%;
  max-width: 480px;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}

.sheet h3 { font-size: 12px; margin: 0 0 14px; text-shadow: 2px 2px 0 var(--shadow); }

.sheet label {
  display: block;
  font-size: 8px;
  color: var(--ink-dim);
  margin: 12px 0 6px;
}

.sheet input[type="text"],
.sheet input[type="email"],
.sheet input[type="password"] {
  width: 100%;
  background: var(--shadow);
  border: 3px solid var(--border);
  color: var(--ink);
  font-family: inherit;
  font-size: 10px;
  padding: 12px 10px;
  outline: none;
}

.sheet input[type="text"]:focus,
.sheet input[type="email"]:focus,
.sheet input[type="password"]:focus { border-color: var(--accent); }

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  background: var(--shadow);
  border: 3px solid var(--border);
  color: var(--ink-dim);
  font-size: 8px;
  padding: 8px 8px;
}

.chip.active {
  background: var(--accent);
  color: var(--shadow);
  border-color: var(--shadow);
}

.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions .pixel-btn { flex: 1; }

/* ===== Subiu de nível ===== */
.overlay:has(.levelup) { align-items: center; }

.sheet.levelup {
  width: calc(100% - 32px);
  max-width: 340px;
  text-align: center;
  border-color: var(--gold);
  animation: pop-in 0.25s steps(4);
}

@keyframes pop-in {
  from { transform: scale(0.6); }
  to { transform: scale(1); }
}

.levelup-burst { font-size: 34px; animation: spin-shine 1.2s steps(8) infinite; }

@keyframes spin-shine {
  0%, 100% { transform: rotate(-12deg) scale(1); }
  50% { transform: rotate(12deg) scale(1.2); }
}

.levelup-level { font-size: 20px; color: var(--gold); margin: 12px 0 8px; }
.levelup-title { font-size: 9px; color: var(--ink-dim); margin-bottom: 18px; }

/* ===== Efeitos ===== */
.float-xp {
  position: fixed;
  z-index: 30;
  font-size: 10px;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--shadow);
  pointer-events: none;
}

.confetti-px {
  position: fixed;
  z-index: 30;
  width: 6px;
  height: 6px;
  pointer-events: none;
}

/* ===== Tela de entrada (login) ===== */
.overlay.center { align-items: center; }

.auth-sheet {
  width: calc(100% - 32px);
  max-width: 380px;
  border-color: var(--gold);
}

.auth-logo { font-size: 40px; text-align: center; }

.auth-title {
  text-align: center;
  font-size: 16px;
  color: var(--gold);
  margin: 10px 0 4px;
}

.auth-loading {
  text-align: center;
  font-size: 8px;
  color: var(--ink-dim);
  padding: 18px 0 10px;
  animation: auth-blink 1s steps(2) infinite;
}

@keyframes auth-blink {
  50% { opacity: 0.3; }
}

.auth-sub {
  font-size: 8px;
  color: var(--ink-dim);
  text-align: center;
  line-height: 1.7;
  margin: 4px 0 6px;
}

.auth-error {
  color: #ff8a9a;
  font-size: 8px;
  line-height: 1.7;
  margin-top: 12px;
}

.auth-sheet .pixel-btn.wide { margin-top: 16px; }

.auth-switch {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 8px;
  width: 100%;
  margin-top: 16px;
  padding: 6px 0;
}

/* ===== Conquistas ===== */
.ach-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.ach-item {
  background: var(--bg-panel);
  border: 3px solid var(--shadow);
  padding: 10px 6px;
  text-align: center;
}

.ach-item.locked { opacity: 0.35; filter: grayscale(1); }
.ach-item.unlocked { border-color: var(--gold); box-shadow: 3px 3px 0 var(--shadow); }

.ach-icon { font-size: 20px; }

.ach-name {
  font-size: 6px;
  line-height: 1.6;
  margin-top: 6px;
  color: var(--ink);
}

.ach-toast {
  position: fixed;
  top: calc(70px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel);
  border: 4px solid var(--gold);
  box-shadow: 4px 4px 0 var(--shadow);
  padding: 10px 14px;
  z-index: 40;
  max-width: calc(100% - 32px);
  animation: pop-in 0.2s steps(3);
}

.ach-toast.out { opacity: 0; transition: opacity 0.35s; }
.ach-toast-icon { font-size: 22px; }
.ach-toast-label { font-size: 6px; color: var(--gold); }
.ach-toast-name { font-size: 9px; margin-top: 4px; }

/* ===== Conta ===== */
.account-box {
  background: var(--bg-panel);
  border: 3px solid var(--shadow);
  padding: 12px 10px;
  font-size: 8px;
  line-height: 1.9;
  word-break: break-all;
  margin-bottom: 4px;
}

.account-line.dim { color: var(--ink-dim); }
