/* ===== Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ===== Design tokens (dark by default) ===== */
:root {
  --bg: #0f172a;           /* page background */
  --surface: #1e293b;      /* cards, sheets */
  --surface-2: #273449;    /* inputs, secondary buttons */
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;

  --accent: #10b981;       /* the one accent color (emerald) */
  --accent-press: #059669;
  --accent-text: #052e1f;  /* text on accent buttons */
  --danger: #f87171;

  --radius: 14px;
  --radius-sm: 10px;
  --gutter: 16px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  color-scheme: dark;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* Every button: no double-tap zoom, no text selection on rapid taps */
button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) var(--gutter) 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-muted);
}

.icon-btn:active {
  background: var(--surface-2);
  color: var(--text);
}

/* ===== Main layout ===== */
.app-main {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--gutter) var(--gutter) calc(env(safe-area-inset-bottom) + 32px);
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 16px 24px;
}

.empty-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: var(--surface);
  color: var(--accent);
  font-size: 1.75rem;
  font-weight: 800;
}

.empty-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.empty-text {
  color: var(--text-muted);
}

/* ===== Counter cards ===== */
.counter-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.counter-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.menu-btn {
  flex-shrink: 0;
}

.card-bottom {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}

.counter-value {
  flex: 1;
  min-width: 0;
  font-size: 3rem;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  transform-origin: left center;
}

/* Quick "pulse" when the number changes (class added by app.js) */
.counter-value.pulse {
  animation: pulse 220ms ease-out;
}

@keyframes pulse {
  0%   { transform: scale(1);    color: var(--text); }
  40%  { transform: scale(1.12); color: var(--accent); }
  100% { transform: scale(1);    color: var(--text); }
}

/* -1: smaller, secondary */
.minus-btn {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 1.05rem;
  font-weight: 700;
}

.minus-btn:active {
  background: var(--border);
}

.minus-btn:disabled {
  opacity: 0.35;
}

/* +1: the main action — big thumb target */
.plus-btn {
  flex-shrink: 0;
  width: 112px;
  height: 72px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.6rem;
  font-weight: 800;
}

.plus-btn:active {
  background: var(--accent-press);
  transform: scale(0.97);
}

/* ===== Add counter ===== */
.add-section {
  margin-top: 16px;
}

.add-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.text-input {
  width: 100%;
  height: 52px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px+ stops mobile browsers zooming into the field */
}

.text-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 6px;
}

.add-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* ===== Generic buttons ===== */
.btn {
  height: 48px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
}

.btn-block {
  width: 100%;
  height: 56px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-primary:active {
  background: var(--accent-press);
}

.btn-secondary {
  background: transparent;
  border: 1.5px dashed var(--border);
  color: var(--accent);
}

.btn-secondary:active {
  background: var(--surface);
}

.btn-ghost {
  color: var(--text-muted);
}

.btn-ghost:active {
  background: var(--surface-2);
}

/* ===== Bottom sheets (<dialog>) ===== */
.sheet {
  /* Pin to the bottom of the screen, full width up to a max */
  margin: auto auto 0;
  width: 100%;
  max-width: 560px;
  border: none;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--text);
  padding: 20px var(--gutter) calc(env(safe-area-inset-bottom) + 16px);
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.sheet-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-text {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-btn {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: left;
  font-weight: 600;
}

.sheet-btn:active {
  background: var(--border);
}

.sheet-btn:disabled {
  opacity: 0.35;
}

.sheet-btn.danger {
  color: var(--danger);
}

.sheet-btn.muted {
  background: transparent;
  color: var(--text-muted);
  text-align: center;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.95rem;
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* Very narrow phones: shrink the big number and +1 a little */
@media (max-width: 340px) {
  .counter-value { font-size: 2.4rem; }
  .plus-btn { width: 92px; }
}

/* Respect "reduce motion" accessibility setting */
@media (prefers-reduced-motion: reduce) {
  .counter-value.pulse { animation: none; }
}
