.tally-app {
  padding: 1.25rem 1rem 1.5rem;
}

/* Counter tabs: a horizontal strip that scrolls when there are many counters. */

.tally-tabs-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  margin-bottom: 1rem;
}

.tally-tabs {
  flex: 1;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 2px 2px 6px;
}

.tally-tab {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 44px;
  max-width: 10rem;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--kis-border);
  border-radius: var(--kis-radius);
  background: var(--kis-surface);
  color: var(--kis-text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}

.tally-tab[aria-pressed="true"] {
  border-color: var(--kis-accent);
  box-shadow: inset 0 0 0 1px var(--kis-accent);
}

.tally-tab-name {
  font-size: 0.8rem;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tally-tab-count {
  font-size: 0.8rem;
  color: var(--kis-text-muted);
  font-variant-numeric: tabular-nums;
}

.tally-add {
  flex: 0 0 auto;
  font-size: 0.85rem;
  padding: 0 0.9rem;
  border-radius: var(--kis-radius);
  align-self: flex-start;
}

/* The big tap area */

.tally-tap {
  --tap-color: #c4452c;
  width: 100%;
  min-height: min(52vh, 420px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  border: none;
  border-radius: 24px;
  background: var(--tap-color);
  color: #ffffff;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation; /* no double-tap zoom on fast tapping */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  box-shadow: var(--kis-shadow);
}

.tally-tap[data-theme="ocean"] { --tap-color: #1d6aa5; }
.tally-tap[data-theme="forest"] { --tap-color: #2b7a4b; }
.tally-tap[data-theme="grape"] { --tap-color: #6a4cb3; }
.tally-tap[data-theme="berry"] { --tap-color: #b0325e; }
.tally-tap[data-theme="slate"] { --tap-color: #3d4450; }

.tally-tap:active {
  filter: brightness(0.92);
}

.tally-tap.bump .tally-tap-count {
  animation: tally-bump 0.15s ease-out;
}

@keyframes tally-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.tally-tap-name {
  font-size: 1rem;
  font-weight: 700;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tally-tap-count {
  font-size: clamp(4rem, 22vw, 7rem);
  font-weight: 800;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  max-width: 95%;
  overflow-wrap: anywhere;
}

.tally-tap-hint {
  font-size: 0.9rem;
  font-weight: 500;
}

.tally-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.tally-actions {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.tally-minus {
  min-width: 5rem;
  font-weight: 700;
}

.kis-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Edit & settings */

.tally-more {
  margin-top: 1.5rem;
  border-top: 1px solid var(--kis-border);
  padding-top: 0.5rem;
}

.tally-more summary {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  cursor: pointer;
  color: var(--kis-text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.tally-section {
  margin-top: 1.25rem;
}

.tally-section-title {
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
}

.tally-fields {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.tally-fields label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--kis-text-muted);
}

.tally-fields input {
  min-height: 44px;
  width: 100%;
  padding: 0 0.75rem;
  border: 1px solid var(--kis-border);
  border-radius: var(--kis-radius);
  background: var(--kis-surface);
  color: var(--kis-text);
  font: inherit;
  font-size: 1rem;
}

.tally-themes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tally-theme {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0 0.8rem 0 0.4rem;
  border: 1px solid var(--kis-border);
  border-radius: var(--kis-radius-pill);
  cursor: pointer;
  font-size: 0.85rem;
}

.tally-theme input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.tally-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.tally-theme:has(input:checked) {
  border-color: var(--kis-accent);
  box-shadow: inset 0 0 0 1px var(--kis-accent);
  font-weight: 700;
}

.tally-theme:has(input:focus-visible) {
  outline: 3px solid var(--kis-focus);
  outline-offset: 2px;
}

.tally-check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  cursor: pointer;
}

.tally-check input {
  width: 22px;
  height: 22px;
}

.tally-hint {
  font-size: 0.8rem;
  color: var(--kis-text-muted);
  margin: 0;
}

.tally-small {
  font-size: 0.85rem;
  padding: 0 1rem;
}

.tally-backup {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0 0;
}

@media (prefers-reduced-motion: reduce) {
  .tally-tap.bump .tally-tap-count {
    animation: none;
  }
}
