:root {
  --bg: #f5efe3; /* bege clarinho; trocável em Ajustes */
  --card: #fffdf9;
  --text: #2b2620;
  --muted: #776e62;
  --border: #e6ddcd;
  --primary: #0f766e;
  --primary-text: #ffffff;
  --good: #15803d;
  --good-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --today: #ccfbf1;
}
/* Tema escuro: ligado quando o fundo escolhido é escuro */
:root[data-theme="dark"] {
  --bg: #0f1418;
  --card: #182026;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #2a343c;
  --primary: #14b8a6;
  --primary-text: #062a26;
  --good: #4ade80;
  --good-bg: #12301f;
  --bad: #f87171;
  --bad-bg: #3a1717;
  --today: #134e4a;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1, h2, h3 { margin: 0; }
h3 { font-size: 1.05rem; margin-bottom: 12px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--primary); color: var(--primary-text);
}
.topbar h1 { font-size: 1.15rem; }
.chip {
  border: 1px solid currentColor; background: transparent; color: inherit;
  border-radius: 999px; padding: 4px 12px; font: inherit; font-size: .85rem; cursor: pointer;
}

main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; margin-bottom: 12px;
}

/* Placar */
.score { text-align: center; }
.score .label { color: var(--muted); font-size: .85rem; }
.score .big { font-size: 2.4rem; font-weight: 800; margin: 4px 0; }
.score .big.good { color: var(--good); }
.score .big.bad { color: var(--bad); }
.score .msg { margin: 4px 0 12px; }
.score .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.score .stats div { background: var(--bg); border-radius: 10px; padding: 8px 4px; }
.score .stats b { display: block; font-size: .95rem; }
.score .stats small { color: var(--muted); font-size: .72rem; }

/* Calendário */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-nav h2 { font-size: 1.05rem; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 1.3rem; cursor: pointer;
}
.weekdays, .calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.weekdays span { text-align: center; color: var(--muted); font-size: .75rem; padding: 4px 0; }
.day {
  min-height: 52px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); padding: 4px 2px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px;
  font: inherit;
}
.day .n { font-size: .8rem; font-weight: 600; }
.day .v { font-size: .7rem; line-height: 1.1; white-space: nowrap; }
.day.empty { visibility: hidden; }
.day.under { background: var(--good-bg); }
.day.under .v { color: var(--good); }
.day.over { background: var(--bad-bg); }
.day.over .v { color: var(--bad); }
.day.today { outline: 2px solid var(--primary); outline-offset: -2px; }
.day.selected { box-shadow: inset 0 0 0 3px var(--text); }
.day.future { opacity: .55; }

/* Formulários e listas */
.row-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.row-form input { flex: 1 1 140px; }
.row-form input.small { flex: 0 1 110px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; }
input {
  font: inherit; font-size: 16px; padding: 10px 12px; min-width: 0;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
}
input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.btn {
  font: inherit; padding: 10px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; overflow-wrap: break-word; }
.list .sub { color: var(--muted); font-size: .8rem; }
.list .amt { font-weight: 600; white-space: nowrap; }
.list li.done .grow { text-decoration: line-through; color: var(--muted); }
.list input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.list .del {
  border: 0; background: transparent; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 4px 8px;
}
.list .pos { font-weight: 700; color: var(--primary); min-width: 1.6em; text-align: center; flex: none; }
.list .move { display: flex; flex-direction: column; flex: none; }
.list .move button {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  width: 30px; height: 22px; line-height: 1; font-size: .8rem; cursor: pointer; padding: 0;
}
.list .move button:first-child { border-radius: 6px 6px 0 0; }
.list .move button:last-child { border-radius: 0 0 6px 6px; border-top: 0; }
.list .move button:disabled { opacity: .3; cursor: default; }
.list .empty-msg { color: var(--muted); justify-content: center; }

/* Cor do app */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  border: 3px solid var(--card); box-shadow: 0 0 0 1px var(--border);
}
.swatch.active { box-shadow: 0 0 0 3px var(--text); }
.color-custom { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: .9rem; }
.color-custom input { width: 56px; height: 40px; padding: 2px; cursor: pointer; }

.muted { color: var(--muted); font-size: .9rem; margin: 8px 0 0; }
.error { color: var(--bad); font-size: .9rem; margin: 0; min-height: 1em; }

/* Barra inferior */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: .75rem;
  padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tabbar button span { font-size: 1.3rem; }
.tabbar button.active { color: var(--primary); font-weight: 600; }

.overlay {
  position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.overlay[hidden] { display: none; }
.dialog { width: 100%; max-width: 360px; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20;
  font-size: .9rem; max-width: calc(100% - 32px);
}
