:root {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #1a2540;
  --primary: #14b8a6;
  --primary-dark: #0f766e;
  --text: #e6edf6;
  --muted: #8ba0bd;
  --accent: #f59e0b;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font-family: inherit; cursor: pointer; }

.hidden { display: none !important; }

/* --- Layout de ecrãs --- */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 1rem calc(1rem + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  min-height: 3rem;
}
.topbar form { margin: 0; }
.brand { font-weight: 700; letter-spacing: 0.02em; }

.link {
  background: none; border: none; color: var(--muted);
  font-size: 1rem; padding: 0.4rem; text-decoration: underline;
}
.link:active { color: var(--text); }

/* --- Botões base --- */
.btn-primary, .btn-secondary {
  border: none; border-radius: 14px; font-weight: 700;
  padding: 1rem; font-size: 1.15rem; width: 100%;
  touch-action: manipulation;
}
.btn-primary { background: var(--primary); color: #04211d; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-secondary:active { background: #24304f; }
.btn-huge { padding: 1.5rem; font-size: 1.4rem; border-radius: 18px; }

/* --- Início --- */
.home-main {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1.25rem; text-align: center;
}
.home-message { font-size: 1.25rem; color: var(--muted); margin: 0; }
.big-total {
  font-size: 5.5rem; font-weight: 800; line-height: 1;
  color: var(--primary); font-variant-numeric: tabular-nums;
}
.progress { width: 100%; max-width: 340px; }
.progress-bar {
  height: 12px; background: var(--surface-2);
  border-radius: 999px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.4s ease;
}
.progress-label { color: var(--muted); font-size: 0.95rem; margin: 0.5rem 0 0; }
.progress-label .link { padding: 0; font-weight: 700; color: var(--accent); }
.stats-link { margin-top: 0.5rem; }
.btn-huge { max-width: 340px; }

/* --- Contar --- */
.count-total { font-size: 1.15rem; color: var(--muted); }
.count-total strong { color: var(--primary); font-size: 1.5rem; font-variant-numeric: tabular-nums; }

.flash {
  height: 2rem; text-align: center; font-weight: 700;
  color: var(--accent); opacity: 0; transition: opacity 0.15s;
  font-size: 1.2rem;
}
.flash.show { opacity: 1; }

.pad {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  align-content: center;
  padding: 0.5rem 0;
}
.tbtn {
  background: var(--surface-2); color: var(--text);
  border: 2px solid transparent; border-radius: 18px;
  font-size: 2rem; font-weight: 800;
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation; user-select: none;
}
.tbtn:active { background: var(--primary); color: #04211d; transform: scale(0.96); }
.tbtn-other { font-size: 1.2rem; background: var(--surface); border-color: var(--surface-2); }
#undo-btn { margin-top: 0.5rem; }

/* --- Estatísticas --- */
.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem;
  margin-top: 0.5rem;
}
.stat-card {
  background: var(--surface); border-radius: 16px; padding: 1.1rem 0.75rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.35rem;
}
.stat-num { font-size: 2rem; font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.85rem; color: var(--muted); text-align: center; }

.chart-title { font-size: 1rem; color: var(--muted); margin: 1.5rem 0 0.5rem; font-weight: 600; }
.chart {
  display: flex; align-items: flex-end; gap: 4px;
  height: 160px; padding: 0.5rem; background: var(--surface);
  border-radius: 14px; overflow-x: auto;
}
.bar {
  flex: 0 0 auto; width: 18px; min-height: 3px;
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  border-radius: 5px 5px 0 0; position: relative;
}
.bar.best { background: linear-gradient(180deg, var(--accent), #b45309); }

/* --- Login --- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh; padding: 1rem;
}
.login-card {
  background: var(--surface); border-radius: 20px; padding: 2rem 1.5rem;
  width: 100%; max-width: 360px; text-align: center;
}
.login-card .logo { font-size: 3.5rem; }
.login-card h1 { font-size: 1.4rem; margin: 0.5rem 0 1.5rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-card input, .modal-card input {
  padding: 1rem; border-radius: 12px; border: 1px solid var(--surface-2);
  background: var(--bg); color: var(--text); font-size: 1.1rem; width: 100%;
  text-align: center;
}
.error { color: var(--danger); margin: 0 0 0.5rem; }

/* --- Modal --- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  z-index: 10;
}
.modal-card {
  background: var(--surface); border-radius: 18px; padding: 1.5rem;
  width: 100%; max-width: 320px;
}
.modal-card p { margin: 0 0 1rem; font-weight: 700; text-align: center; font-size: 1.1rem; }
.modal-actions { display: flex; gap: 0.75rem; margin-top: 1rem; }
.modal-actions button { flex: 1; }
