/* Great Tallies — counter grid + editor sheet. Built on the Great Apps
   framework tokens (--bg, --text, --border, …). Teal accent. */

:root {
  --accent: #14b8a6;
  --accent-dim: #0f766e;
}

.header-accent { color: #2dd4bf; }
.header-actions { display: flex; gap: 8px; }
.icon-btn.add { color: var(--text); }

/* ── Counter grid ─────────────────────────── */
.grid {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  align-content: start;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) {
  .grid { grid-template-columns: repeat(4, 1fr); max-width: 920px; margin: 0 auto; width: 100%; }
}

.card {
  --c: #14b8a6;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 152px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  background: color-mix(in srgb, var(--c) 13%, var(--bg-surface));
  border-color: color-mix(in srgb, var(--c) 32%, var(--border));
  overflow: hidden;
}

.card-menu {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 30px;
  height: 30px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.15rem;
  line-height: 1;
  border-radius: 8px;
  cursor: pointer;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
}
.card-menu:active { background: rgba(255, 255, 255, 0.1); }

.tap-zone {
  flex: 1;
  width: 100%;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 18px 10px 8px;
  -webkit-tap-highlight-color: transparent;
}
.tap-zone:active { background: color-mix(in srgb, var(--c) 20%, transparent); }

.card-emoji { font-size: 1.9rem; line-height: 1; }
.card-count {
  font-size: clamp(1.8rem, 8vw, 2.5rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--c);
  font-variant-numeric: tabular-nums;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-count.pop { animation: pop 0.18s ease; }
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); }
  100% { transform: scale(1); }
}
.card-name {
  font-size: 0.82rem;
  color: var(--text);
  text-align: center;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.card-actions {
  display: flex;
  border-top: 1px solid color-mix(in srgb, var(--c) 22%, var(--border));
}
.card-actions button {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.45rem;
  line-height: 1;
  padding: 9px 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card-actions button:active { background: color-mix(in srgb, var(--c) 16%, transparent); }
.card-actions .btn-minus { border-right: 1px solid color-mix(in srgb, var(--c) 22%, var(--border)); }
.card-actions .btn-plus { color: var(--c); font-weight: 700; }

/* ── Empty state ──────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 40px 24px;
}
.empty-emoji { font-size: 3rem; }
.empty-title { font-size: 1.2rem; font-weight: 600; }
.empty-copy { color: var(--text-muted); font-size: 0.9rem; max-width: 280px; line-height: 1.5; }

.foot-count { font-size: 0.7rem; color: var(--text-muted); }

/* ── Buttons ──────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { filter: brightness(0.92); }
.btn-primary.wide { width: 100%; margin-top: 18px; }

.ghost-btn {
  flex: 1;
  padding: 11px 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ghost-btn:active { background: var(--bg-hover); }
.ghost-btn.danger { color: #ef4444; border-color: rgba(239, 68, 68, 0.4); }

/* ── Scrim + bottom sheet ─────────────────── */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.22s ease;
}
.scrim.show { opacity: 1; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 8px 20px calc(22px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.open { transform: translateY(0); }
@media (min-width: 560px) {
  .sheet {
    left: 50%;
    right: auto;
    width: 440px;
    max-width: calc(100% - 24px);
    bottom: 12px;
    border-radius: 20px;
    transform: translate(-50%, 130%);
  }
  .sheet.open { transform: translate(-50%, 0); }
}

.sheet-grip {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 6px auto 8px;
}
.sheet-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.05rem;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sheet-close:active { background: rgba(255, 255, 255, 0.08); }
.sheet-title { font-size: 1.15rem; font-weight: 600; text-align: center; margin-bottom: 8px; }

.field-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 16px 0 7px;
}

.text-input {
  width: 100%;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
.text-input:focus { border-color: var(--accent); }
.text-input::placeholder { color: var(--text-muted); }

/* ── Emoji picker ─────────────────────────── */
.emoji-search-row { display: flex; align-items: center; gap: 10px; }
.emoji-preview {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.emoji-search { flex: 1; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 4px;
  margin-top: 10px;
  max-height: 176px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.emoji-cell {
  height: 42px;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.emoji-cell:hover { background: var(--bg-hover); }
.emoji-cell.sel { border-color: var(--accent); background: var(--bg-active); }
.emoji-empty { color: var(--text-muted); font-size: 0.85rem; padding: 10px 2px; }

/* ── Color swatches ───────────────────────── */
.swatch-row { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.swatch.sel::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 2px solid var(--text);
  border-radius: 50%;
}

/* ── Segmented (step) ─────────────────────── */
.segmented { display: flex; gap: 6px; }
.seg-btn {
  flex: 1;
  padding: 9px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.seg-btn.sel { border-color: var(--accent); color: var(--text); background: var(--bg-active); }

/* ── Count editor ─────────────────────────── */
.count-edit { display: flex; align-items: center; gap: 12px; }
.count-input { flex: 1; text-align: center; font-variant-numeric: tabular-nums; }
.round-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.round-btn:active { background: var(--bg-active); }

.edit-actions { display: flex; gap: 10px; margin-top: 12px; }

/* Hide number input spinners for a cleaner count field. */
.count-input::-webkit-outer-spin-button,
.count-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.count-input { -moz-appearance: textfield; }

/* ── Settings + cloud sync ────────────────── */
.set-section { margin-top: 22px; }
.set-section:first-of-type { margin-top: 14px; }
.set-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 10px;
}
.set-hint { font-size: 0.8rem; color: var(--text-muted); line-height: 1.5; margin-top: 10px; }

.st-sync:empty { display: none; }
.st-sync .btn-primary.wide { margin-top: 0; }
.sync-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.sync-state {
  font-size: 0.82rem;
  color: var(--text-muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ghost-btn.sync-off { flex: none; padding: 6px 10px; font-size: 0.78rem; }

.danger-btn {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(239, 68, 68, 0.4);
  background: transparent;
  color: #ef4444;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.danger-btn:active { background: rgba(239, 68, 68, 0.08); }
