:root {
  --fundo: #f6f7f9;
  --superficie: #ffffff;
  --superficie-2: #eef1f4;
  --texto: #15191e;
  --texto-2: #5b6570;
  --borda: #dde2e7;
  --destaque: #0e7490;
  --destaque-texto: #ffffff;
  --perigo: #c62828;
  --sucesso: #2e7d32;
  --sombra: 0 1px 2px rgb(0 0 0 / 0.06), 0 2px 8px rgb(0 0 0 / 0.05);

  /* Paleta validada para daltonismo (claro e escuro). Cor segue a entidade. */
  --cor-P: #2a78d6;
  --cor-T: #eb6834;
  --cor-L: #1baf7a;
  --cor-J: #e87ba4;
  --cor-R: #008300;
  --cor-A: #4a3aa7;
  --cor-H: var(--destaque);
  --tinta-P: #ffffff;
  --tinta-T: #1c0d05;
  --tinta-L: #04170f;
  --tinta-J: #2a0a17;
  --tinta-R: #ffffff;
  --tinta-A: #ffffff;

  --r-comum: #8a949e;
  --r-incomum: #2e9d4f;
  --r-raro: #2f7fe0;
  --r-epico: #9b4de0;
  --r-lendario: #f08a18;

  --raio: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fundo: #0f1215;
    --superficie: #181c21;
    --superficie-2: #222830;
    --texto: #e8ecf0;
    --texto-2: #9aa5b1;
    --borda: #2c333b;
    --destaque: #22b8d6;
    --destaque-texto: #06222a;
    --perigo: #ef5350;
    --sucesso: #66bb6a;
    --sombra: none;
    --cor-P: #3987e5;
    --cor-T: #d95926;
    --cor-L: #199e70;
    --cor-J: #d55181;
    --cor-R: #008300;
    --cor-A: #9085e9;
    --tinta-T: #ffffff;
    --tinta-L: #ffffff;
    --tinta-J: #ffffff;
    --tinta-A: #120d33;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fundo: #0f1215;
  --superficie: #181c21;
  --superficie-2: #222830;
  --texto: #e8ecf0;
  --texto-2: #9aa5b1;
  --borda: #2c333b;
  --destaque: #22b8d6;
  --destaque-texto: #06222a;
  --perigo: #ef5350;
  --sucesso: #66bb6a;
  --sombra: none;
  --cor-P: #3987e5;
  --cor-T: #d95926;
  --cor-L: #199e70;
  --cor-J: #d55181;
  --cor-R: #008300;
  --cor-A: #9085e9;
  --tinta-T: #ffffff;
  --tinta-L: #ffffff;
  --tinta-J: #ffffff;
  --tinta-A: #120d33;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fundo);
  color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
h3 { font-size: 0.95rem; }
.num { font-variant-numeric: tabular-nums; }
.sutil { color: var(--texto-2); font-size: 0.875rem; }
.perigo { color: var(--perigo); }
.sucesso { color: var(--sucesso); }

.topo {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--fundo);
  border-bottom: 1px solid var(--borda);
}
.topo h1 { font-size: 1.2rem; }
.icone { background: none; border: 0; font-size: 1.3rem; padding: 6px; border-radius: 10px; }

main { max-width: 640px; margin: 0 auto; padding: 14px 16px 24px; display: grid; gap: 14px; }

.cartao {
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 14px;
  box-shadow: var(--sombra);
  display: grid; gap: 10px;
  min-width: 0;
}
.cartao-cab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }

.abas {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--superficie);
  border-top: 1px solid var(--borda);
  padding-bottom: env(safe-area-inset-bottom);
}
.abas button {
  background: none; border: 0; padding: 8px 2px 10px;
  display: grid; justify-items: center; gap: 2px;
  font-size: 0.68rem; color: var(--texto-2); position: relative;
}
.abas button span:first-child { font-size: 1.25rem; }
.abas button[aria-current="page"] { color: var(--destaque); font-weight: 600; }
.selo {
  position: absolute; top: 4px; left: calc(50% + 6px);
  background: var(--perigo); color: #fff; border-radius: 99px;
  font-size: 0.68rem; min-width: 18px; padding: 1px 5px; font-weight: 700;
}

.botao {
  border: 1px solid var(--borda); background: var(--superficie-2);
  border-radius: 10px; padding: 8px 12px; min-height: 40px;
}
.botao.primario { background: var(--destaque); color: var(--destaque-texto); border-color: transparent; font-weight: 600; }
.botao.perigo { color: var(--perigo); }
.botao.pequeno { min-height: 32px; padding: 4px 10px; font-size: 0.875rem; }
.botao:disabled { opacity: 0.45; cursor: not-allowed; }
.linha { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.linha.entre { justify-content: space-between; }

/* Ranking */
.ranking { display: grid; gap: 12px; }
.cat { display: grid; gap: 4px; }
.cat-cab { display: flex; align-items: center; gap: 8px; }
.pos { font-weight: 700; color: var(--texto-2); width: 1.4em; }
.peso {
  margin-left: auto; font-weight: 800; border-radius: 8px; padding: 2px 8px;
  background: var(--superficie-2);
}
.barra { position: relative; height: 10px; background: var(--superficie-2); border-radius: 99px; overflow: visible; }
.barra > i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; }
.barra > b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--texto); border-radius: 2px; }
.ponto { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }

.grande { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.grade-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 380px) { .grade-2 { grid-template-columns: 1fr; } }

.pacote { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.progresso-mini { flex: 1; min-width: 80px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 99px; padding: 3px 10px; font-size: 0.8rem;
  background: var(--superficie-2); border: 1px solid var(--borda);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.escolha {
  border: 1.5px solid var(--borda); background: var(--superficie);
  border-radius: 99px; padding: 6px 12px; min-height: 38px; font-weight: 600;
}
.escolha[aria-pressed="true"] { border-color: transparent; }
.escolha.tam { min-width: 46px; border-radius: 10px; }
.escolha.tam[aria-pressed="true"] { background: var(--destaque); color: var(--destaque-texto); }

/* Marcações */
.blocos { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.bloco {
  border-radius: var(--raio); padding: 12px; display: grid; gap: 8px;
  color: var(--tinta); background: var(--cor);
}
.bloco .rotulo { display: flex; justify-content: space-between; font-weight: 600; }
.bloco .valor { font-size: 2rem; font-weight: 800; text-align: center; line-height: 1; }
.bloco .botoes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.bloco button {
  border: 0; border-radius: 10px; padding: 10px 0; font-weight: 800; font-size: 1.05rem;
  background: rgb(255 255 255 / 0.22); color: inherit;
}
.bloco button:active { transform: scale(0.96); }
.bloco small { opacity: 0.85; text-align: center; font-size: 0.75rem; }

.lista { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.item {
  display: flex; gap: 10px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--borda); border-radius: 12px; background: var(--superficie);
}
.item .corpo { flex: 1; min-width: 0; }
.item .nome { font-weight: 600; overflow-wrap: anywhere; }
.item .acoes { display: flex; gap: 4px; flex: none; }

input[type="text"], input[type="number"] {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1.5px solid var(--borda); border-radius: 10px; background: var(--superficie);
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--destaque); outline-offset: 2px; }
.dividir { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.dividir label { display: grid; gap: 2px; font-size: 0.8rem; color: var(--texto-2); }
.mini { display: grid; gap: 2px; font-size: 0.72rem; color: var(--texto-2); width: 64px; flex: none; }
.mini input { min-height: 38px; padding: 4px 6px; }
details > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }

/* Hábitos */
.habito-hoje {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px; border-radius: 12px; border: 1.5px solid var(--borda); background: var(--superficie);
  text-align: left;
}
.habito-hoje[aria-pressed="true"] { border-color: var(--sucesso); background: color-mix(in srgb, var(--sucesso) 12%, var(--superficie)); }
.caixa { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--borda); display: grid; place-items: center; flex: none; font-weight: 800; }
[aria-pressed="true"] > .caixa { background: var(--sucesso); border-color: var(--sucesso); color: #fff; }
.semana { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.semana th, .semana td { padding: 4px 2px; text-align: center; }
.semana th:first-child, .semana td:first-child { text-align: left; }
.semana td button {
  width: 30px; height: 30px; border-radius: 8px; border: 1.5px solid var(--borda); background: var(--superficie);
}
.semana td button[aria-pressed="true"] { background: var(--sucesso); border-color: var(--sucesso); color: #fff; }
.semana .hoje { color: var(--destaque); font-weight: 800; }
.missao {
  border-radius: var(--raio); padding: 12px 14px;
  background: linear-gradient(120deg, #7c3aed, #db2777); color: #fff;
}
.niveis { position: relative; height: 14px; background: var(--superficie-2); border-radius: 99px; }
.niveis > i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #a16207, #9ca3af, #eab308, #22d3ee); border-radius: 99px; }
.niveis > b { position: absolute; top: -18px; font-size: 0.8rem; transform: translateX(-50%); }
.niveis > s { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--fundo); }

/* Baús */
.bau-linha { font-size: 1.8rem; }
.raridade { font-weight: 700; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }

.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgb(5 8 12 / 0.9);
  display: grid; place-items: center; padding: 16px;
}
.modal[hidden] { display: none; }
.janela {
  background: var(--superficie); color: var(--texto);
  border-radius: 18px; padding: 18px; width: 100%; max-width: 440px;
  max-height: 90vh; overflow: auto; display: grid; gap: 12px;
}
.palco { display: grid; justify-items: center; gap: 14px; text-align: center; color: #fff; width: 100%; max-width: 440px; }
.bau-fechado { font-size: 6rem; background: none; border: 0; animation: tremer 1.2s ease-in-out infinite; }
@keyframes tremer {
  0%, 60%, 100% { transform: rotate(0); }
  65% { transform: rotate(-8deg); } 70% { transform: rotate(8deg); }
  75% { transform: rotate(-6deg); } 80% { transform: rotate(6deg); }
}
.cartas { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; }
.carta { perspective: 800px; background: none; border: 0; padding: 0; min-height: 150px; }
.carta-miolo {
  position: relative; width: 100%; height: 100%; min-height: 150px;
  transition: transform 0.6s; transform-style: preserve-3d;
}
.carta.virada .carta-miolo { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; border-radius: 14px; backface-visibility: hidden;
  display: grid; place-items: center; align-content: center; gap: 6px; padding: 10px;
}
.face.costas { background: repeating-linear-gradient(45deg, #334155 0 10px, #1e293b 10px 20px); color: #cbd5e1; font-size: 2rem; border: 2px solid #475569; }
.face.frente { transform: rotateY(180deg); background: #111827; color: #fff; border: 3px solid var(--rar); box-shadow: 0 0 18px var(--rar); }
.face.frente .emoji { font-size: 2rem; }
.face.frente .raridade { color: var(--rar); }
.face.frente button { background: rgb(255 255 255 / 0.15); color: #fff; border: 0; border-radius: 8px; padding: 4px 8px; font-size: 0.8rem; }

.aviso {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--texto); color: var(--fundo); padding: 10px 16px; border-radius: 12px;
  width: max-content; max-width: calc(100% - 32px); z-index: 30; opacity: 0; pointer-events: none; transition: opacity 0.2s;
  font-size: 0.9rem; text-align: center;
}
.aviso.visivel { opacity: 1; }
.aviso.com-acao { pointer-events: auto; display: flex; align-items: center; gap: 12px; }
.aviso.com-acao span { flex: 1; text-align: left; }
.aviso.com-acao button { white-space: nowrap; flex: none; }
.aviso button {
  background: none; border: 0; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.03em; padding: 6px 4px; min-height: 36px;
  color: #67e8f9;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .aviso button { color: #0e7490; } }
:root[data-theme="dark"] .aviso button { color: #0e7490; }

@media (prefers-reduced-motion: reduce) {
  .bau-fechado { animation: none; }
  .carta-miolo { transition: none; }
}

/* Gráficos */
.grafico svg { display: block; max-width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.g-grade { stroke: var(--borda); stroke-width: 1; }
.g-zero { stroke: var(--texto-2); stroke-width: 1; }
.g-ref { stroke: var(--texto-2); stroke-width: 1; opacity: 0.5; }
.g-eixo { fill: var(--texto-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.g-valor { fill: var(--texto); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.g-linha { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.g-ponto { stroke: var(--superficie); stroke-width: 2; }
.g-alvo { fill: transparent; cursor: crosshair; }
.g-mira { stroke: var(--texto-2); stroke-width: 1; opacity: 0; }
.g-alvo-grupo.ativo .g-mira { opacity: 0.6; }
.g-legenda { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.8rem; color: var(--texto-2); }
.g-legenda span { display: inline-flex; align-items: center; gap: 6px; }
.g-legenda i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.g-tabela summary { font-size: 0.8rem; color: var(--texto-2); font-weight: 500; }
.g-tabela table { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin-top: 6px; }
.g-tabela th, .g-tabela td { padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--borda); white-space: nowrap; }
.g-tabela th:first-child, .g-tabela td:first-child { text-align: left; }
.g-dica {
  position: fixed; z-index: 40; pointer-events: none; white-space: pre-line;
  background: var(--texto); color: var(--fundo); border-radius: 8px; padding: 6px 10px;
  font-size: 0.78rem; line-height: 1.4; font-variant-numeric: tabular-nums; max-width: 240px;
}
.g-dica[hidden] { display: none; }

/* Saldo de Lazer na aba Marcar */
.saldo-lazer {
  display: grid; justify-items: center; gap: 2px; padding: 12px;
  border-radius: 12px; background: var(--superficie-2); text-align: center;
}
.saldo-lazer span { font-weight: 600; color: var(--texto-2); font-size: 0.9rem; }
.saldo-lazer strong { font-size: 2.6rem; line-height: 1.05; }
.saldo-lazer small { color: var(--perigo); font-weight: 600; }
.saldo-lazer.negativo strong { color: var(--perigo); }
.saldo-lazer.recarregou { animation: recarregou 1.4s ease-out; }
@keyframes recarregou {
  0% { background: color-mix(in srgb, var(--sucesso) 45%, var(--superficie-2)); transform: scale(1.04); }
  100% { background: var(--superficie-2); transform: scale(1); }
}
.bloco.esgotado .valor { opacity: 0.55; }
@media (prefers-reduced-motion: reduce) { .saldo-lazer.recarregou { animation: none; outline: 2px solid var(--sucesso); } }
