:root {
  --bg: #f5f4fc;
  --bg-2: #ecebf8;
  --surface: #ffffff;
  --ink: #241f3a;
  --muted: #6f6a88;
  --faint: #a7a2bd;
  --line: #e7e4f4;
  --green: #16c079;
  --amber: #f5a623;
  --shadow-c: rgba(91, 124, 250, .16);
  --radius: 22px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(900px 500px at 90% -10%, rgba(255, 93, 143, .10), transparent 60%),
    radial-gradient(800px 500px at -5% 5%, rgba(91, 124, 250, .12), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100vh;
}

#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(28px, 6vw, 60px) clamp(18px, 5vw, 40px) 96px;
}

/* ---- Topnav (voltar) ---- */
.topnav { display: flex; margin-bottom: 20px; }
.topnav a { text-decoration: none; font-weight: 800; font-size: 13px; color: var(--muted); padding: 8px 16px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface); transition: color .14s, transform .12s; }
.topnav a:hover { color: var(--ink); transform: translateX(-2px); }
.topnav .csv-load {
  margin-left: auto; font: inherit; font-weight: 800; font-size: 13px; color: var(--muted); cursor: pointer;
  padding: 8px 16px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface);
  transition: border-color .14s, color .14s, transform .12s;
}
.topnav .csv-load:hover { color: var(--ink); transform: translateY(-1px); }

/* ---- Header ---- */
.eyebrow {
  display: inline-block;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: #fff;
  font-weight: 800;
  margin: 0 0 16px;
  background: linear-gradient(90deg, #ff5d8f, #ff8f3f);
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 8px 18px -8px rgba(255, 93, 143, .6);
}
h1 {
  font-size: clamp(32px, 7vw, 50px);
  line-height: 1.02;
  letter-spacing: -.03em;
  margin: 0 0 12px;
  text-wrap: balance;
  font-weight: 800;
}
h1 .pop {
  background: linear-gradient(90deg, #5b7cfa, #a06bf5);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lede {
  color: var(--muted);
  font-size: 16px;
  margin: 0;
  max-width: 46ch;
  font-weight: 500;
}

/* ---- Progress panel ---- */
.panel {
  margin-top: 32px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: 0 24px 48px -28px var(--shadow-c), 0 2px 0 rgba(36, 31, 58, .02);
}
.panel-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px 24px;
}
.field label {
  display: block;
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 8px;
  font-weight: 800;
}
.amount-input {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 10px 16px;
  transition: border-color .18s, box-shadow .18s;
}
.amount-input:focus-within {
  border-color: #5b7cfa;
  box-shadow: 0 0 0 4px rgba(91, 124, 250, .16);
}
.amount-input .prefix { color: var(--muted); font-size: 20px; font-weight: 800; }
.amount-input .suffix { color: var(--muted); font-size: 15px; font-weight: 700; }
.amount-input input {
  background: transparent;
  border: 0;
  color: var(--ink);
  font-size: 27px;
  font-weight: 800;
  width: 8ch;
  padding: 0;
  outline: none;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.amount-input input::-webkit-outer-spin-button,
.amount-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.amount-input input[type=number] { -moz-appearance: textfield; }

.save-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
}
#saveBtn {
  border: 0;
  border-radius: 16px;
  padding: 0 20px;
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: .01em;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(90deg, #5b7cfa, #a06bf5);
  box-shadow: 0 10px 22px -10px rgba(91, 124, 250, .7);
  transition: transform .14s, box-shadow .14s, filter .14s;
  white-space: nowrap;
}
#saveBtn:hover { transform: translateY(-2px); filter: saturate(1.1); }
#saveBtn:active { transform: translateY(0); }
#saveBtn:focus-visible { outline: 3px solid rgba(91, 124, 250, .45); outline-offset: 2px; }
#saveBtn.dirty {
  background: linear-gradient(90deg, #ff5d8f, #ff8f3f);
  box-shadow: 0 10px 22px -10px rgba(255, 93, 143, .7);
  animation: nudge 1.4s ease-in-out infinite;
}
@keyframes nudge {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}
.save-status {
  margin-top: 9px;
  font-size: 12.5px;
  font-weight: 600;
  min-height: 1em;
  color: var(--muted);
}
.save-status.ok { color: var(--green); }
.save-status.err { color: #d61f4c; }

.stat { text-align: right; }
.stat .num {
  font-size: 34px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  line-height: 1;
}
.stat .num #doneCount {
  background: linear-gradient(90deg, #16c079, #37c98b);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stat .num .sep { color: var(--faint); font-weight: 600; }
.stat .lbl {
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--faint);
  margin-top: 9px;
  font-weight: 800;
}

.next-line {
  margin-top: 24px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
}
.next-line .caption { color: var(--muted); font-weight: 500; }
.next-line .caption b { color: var(--ink); font-weight: 700; }
.next-line .pct {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(90deg, #ff5d8f, #ff8f3f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.bar {
  margin-top: 11px;
  height: 14px;
  background: var(--bg-2);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #5b7cfa, #a06bf5, #ff5d8f);
  background-size: 220% 100%;
  transition: width .7s cubic-bezier(.22, .61, .36, 1);
  position: relative;
  overflow: hidden;
}
.bar-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(45deg, rgba(255, 255, 255, .28) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, .28) 50%, rgba(255, 255, 255, .28) 75%, transparent 75%);
  background-size: 22px 22px;
  animation: stripes 1s linear infinite;
}
@keyframes stripes { from { background-position: 0 0; } to { background-position: 22px 0; } }

.all-done {
  margin-top: 18px;
  font-weight: 800;
  font-size: 15px;
  background: linear-gradient(90deg, #16c079, #5b7cfa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---- Timeline ---- */
.timeline { margin-top: 42px; display: flex; flex-direction: column; gap: 16px; }

.node { position: relative; }
.card {
  --c: #5b7cfa;
  background: var(--surface);
  border-radius: 20px;
  padding: 16px 18px 16px 16px;
  display: flex;
  align-items: center;
  gap: 15px;
  box-shadow: 0 12px 26px -20px rgba(36, 31, 58, .5);
  border: 2px solid var(--line);
  transition: transform .16s, box-shadow .16s, border-color .16s;
}
.card:hover { transform: translateY(-3px) rotate(-.4deg); box-shadow: 0 18px 30px -18px color-mix(in srgb, var(--c) 55%, transparent); }

.badge {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  font-size: 24px;
  background: color-mix(in srgb, var(--c) 14%, #fff);
  border: 2px solid color-mix(in srgb, var(--c) 35%, transparent);
  position: relative;
}
.badge .lvl {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--c);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 8px -3px color-mix(in srgb, var(--c) 70%, transparent);
  font-variant-numeric: tabular-nums;
}

.info { flex: 1; min-width: 0; }
.goal {
  font-size: 12px;
  letter-spacing: .02em;
  color: var(--c);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}
.reward {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.01em;
  margin-top: 2px;
}
.reward.placeholder { color: var(--faint); font-style: italic; font-weight: 500; }
.reward a {
  color: inherit;
  text-decoration: none;
  border-bottom: 2px solid color-mix(in srgb, var(--c) 40%, transparent);
  transition: border-color .15s, color .15s;
}
.reward a:hover { color: var(--c); border-color: var(--c); }
.reward a .ext { font-size: 12px; opacity: .7; margin-left: 3px; }

.pill {
  flex-shrink: 0;
  font-size: 10.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill.pending { color: var(--faint); background: var(--bg-2); }
.pill.next { color: #fff; background: linear-gradient(90deg, var(--c), color-mix(in srgb, var(--c) 60%, #ff8f3f)); box-shadow: 0 6px 14px -6px color-mix(in srgb, var(--c) 70%, transparent); }
.pill.done { color: #fff; background: linear-gradient(90deg, #16c079, #37c98b); box-shadow: 0 6px 14px -6px rgba(22, 192, 121, .6); }

/* States */
.node.is-done .card { border-color: color-mix(in srgb, #16c079 40%, transparent); }
.node.is-done .badge { background: linear-gradient(135deg, #16c079, #37c98b); border-color: transparent; }
.node.is-done .goal { color: #16c079; }

.node.is-next .card {
  border-color: var(--c);
  box-shadow: 0 16px 30px -16px color-mix(in srgb, var(--c) 60%, transparent);
}
.node.is-next .badge { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* ---- Botão de editar no card ---- */
.edit-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  border: 2px solid var(--line);
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: color .15s, border-color .15s, background .15s, transform .12s;
}
.edit-btn svg { width: 16px; height: 16px; }
.edit-btn:hover { color: var(--c); border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, transparent); transform: translateY(-1px); }
.edit-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--c) 45%, transparent); outline-offset: 2px; }

/* ---- Card em edição ---- */
.card-edit { display: block; border-color: var(--c); box-shadow: 0 16px 30px -16px color-mix(in srgb, var(--c) 55%, transparent); }
.card-edit:hover { transform: none; }
.btn-save {
  border: 0;
  border-radius: 14px;
  padding: 11px 20px;
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(90deg, #16c079, #37c98b);
  box-shadow: 0 10px 22px -10px rgba(22, 192, 121, .7);
  transition: transform .14s, filter .14s;
}
.btn-save:hover { transform: translateY(-2px); filter: saturate(1.08); }
.btn-save:focus-visible { outline: 3px solid rgba(22, 192, 121, .45); outline-offset: 2px; }
.btn-cancel {
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 11px 18px;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: border-color .14s, color .14s;
}
.btn-cancel:hover { border-color: var(--muted); color: var(--ink); }
.btn-cancel:focus-visible { outline: 3px solid var(--line); outline-offset: 2px; }

.btn-delete {
  --c: #e0245e;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 2px solid color-mix(in srgb, #e0245e 28%, var(--line));
  background: transparent;
  color: #d61f4c;
  border-radius: 14px;
  padding: 10px 15px;
  font: inherit;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  transition: background .14s, border-color .14s, transform .12s;
}
.btn-delete svg { width: 16px; height: 16px; }
.btn-delete:hover { background: #ffeef2; border-color: #e0245e; transform: translateY(-1px); }
.btn-delete:focus-visible { outline: 3px solid rgba(224, 36, 94, .4); outline-offset: 2px; }

/* ---- Indicador de salto (pulo > 10 mil entre metas) ---- */
.gap {
  --c: #5b7cfa;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  border: 2px dashed color-mix(in srgb, var(--c) 32%, var(--line));
  border-radius: 18px;
  background: color-mix(in srgb, var(--c) 5%, transparent);
}
.gap-track {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  gap: 6px;
  max-width: 108px;
  flex-shrink: 0;
}
.gap-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c) 45%, transparent);
}
.gap-label { display: flex; flex-direction: column; gap: 2px; }
.gap-jump { font-weight: 800; font-size: 13.5px; color: var(--c); }
.gap-steps {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 700;
}

/* ---- Adicionar meta ---- */
.add-panel { margin-top: 20px; }
.add-toggle {
  width: 100%;
  border: 2px dashed var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 18px;
  padding: 15px;
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  transition: border-color .16s, color .16s, background .16s;
}
.add-toggle .plus { color: #5b7cfa; font-weight: 800; }
.add-toggle:hover { border-color: #5b7cfa; color: var(--ink); background: rgba(91, 124, 250, .04); }
.add-toggle[aria-expanded="true"] { display: none; }

.add-form {
  background: var(--surface);
  border-radius: 20px;
  padding: 22px;
  border: 2px solid var(--line);
  box-shadow: 0 12px 26px -20px rgba(36, 31, 58, .5);
}
.add-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 16px;
}
.ff.ff-emoji { grid-column: auto; }
.ff label {
  display: block;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 7px;
  font-weight: 800;
}
.ff input {
  width: 100%;
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 11px 14px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  outline: none;
  transition: border-color .16s, box-shadow .16s;
}
.ff input::placeholder { color: var(--faint); font-weight: 500; }
.ff input:focus {
  border-color: #5b7cfa;
  box-shadow: 0 0 0 4px rgba(91, 124, 250, .16);
}
.add-actions {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
#addBtn {
  border: 0;
  border-radius: 15px;
  padding: 12px 22px;
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(90deg, #16c079, #37c98b);
  box-shadow: 0 10px 22px -10px rgba(22, 192, 121, .7);
  transition: transform .14s, filter .14s;
}
#addBtn:hover { transform: translateY(-2px); filter: saturate(1.08); }
#addBtn:active { transform: translateY(0); }
#addBtn:focus-visible { outline: 3px solid rgba(22, 192, 121, .45); outline-offset: 2px; }

@media (max-width: 480px) {
  .add-grid { grid-template-columns: 1fr; }
}

/* ---- Campo de emoji + seletor ---- */
.emoji-field { display: flex; }
.emoji-button {
  width: 100%;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px solid var(--line);
  background: var(--bg);
  border-radius: 14px;
  font-family: inherit;
  font-size: 24px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .12s;
}
.emoji-button::after {
  content: "▾";
  font-size: 12px;
  color: var(--faint);
}
.emoji-button:hover { border-color: #5b7cfa; background: rgba(91, 124, 250, .08); transform: translateY(-1px); }
.emoji-button:hover::after { color: #5b7cfa; }
.emoji-button:focus-visible { outline: 3px solid rgba(91, 124, 250, .4); outline-offset: 2px; }

.emoji-pop {
  position: fixed;
  z-index: 200;
  width: 350px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 50px -18px rgba(36, 31, 58, .45);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
/* garante que o atributo [hidden] realmente esconda (display:flex acima o venceria) */
.emoji-pop[hidden] { display: none; }
.emoji-search {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.emoji-search:focus { border-color: #5b7cfa; box-shadow: 0 0 0 3px rgba(91, 124, 250, .15); }
.emoji-search::placeholder { color: var(--faint); font-weight: 500; }

.emoji-tabs {
  display: flex;
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}
.emoji-tab {
  flex-shrink: 0;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 17px;
  cursor: pointer;
  opacity: .55;
  transition: opacity .14s, background .14s;
}
.emoji-tab:hover { opacity: 1; background: var(--bg-2); }
.emoji-tab.active { opacity: 1; background: rgba(91, 124, 250, .14); box-shadow: inset 0 0 0 2px rgba(91, 124, 250, .35); }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  max-height: 208px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-gutter: stable; /* reserva espaço da barra p/ não cortar a última coluna */
}
.emoji-cell {
  border: 0;
  background: transparent;
  border-radius: 10px;
  aspect-ratio: 1;
  font-size: 21px;
  line-height: 1;
  cursor: pointer;
  transition: background .12s, transform .1s;
}
.emoji-cell:hover { background: var(--bg-2); transform: scale(1.15); }
.emoji-cell:focus-visible { outline: 2px solid rgba(91, 124, 250, .5); outline-offset: 1px; }
.emoji-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--faint);
  font-size: 13px;
  font-weight: 600;
  padding: 24px 0;
}

.error {
  margin-top: 28px;
  background: #fff0f3;
  border: 2px solid #ffc2d0;
  color: #b3123b;
  border-radius: 16px;
  padding: 18px 20px;
  font-size: 14px;
  font-weight: 500;
}
.error code {
  background: #ffe1e8;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 13px;
}

.footnote {
  margin-top: 40px;
  text-align: center;
  color: var(--faint);
  font-size: 12.5px;
  font-weight: 500;
}
.footnote code {
  background: var(--bg-2);
  color: var(--muted);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12px;
}

@media (max-width: 480px) {
  .card { flex-wrap: wrap; }
  .info { flex-basis: calc(100% - 67px); }
  .pill { margin-left: 67px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  #confetti { display: none; }
}
