/* บวก/ลบ — .step-row/.step-chip/.reset-btn are shared, defined in style.css */

.counter {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px calc(var(--safe-bottom) + 24px);
}

.counter-display-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.counter-display {
  position: relative;
  z-index: 2;
  font-size: 96px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -2px;
}

.counter-display.negative {
  color: var(--red);
}

.counter-display.bump {
  animation: counterBump var(--duration-slow) var(--ease-bounce);
}

@keyframes counterBump {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.counter-float {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  font-size: 28px;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  animation: counterFloat 0.7s ease forwards;
}

.counter-float.plus {
  color: var(--green);
}

.counter-float.minus {
  color: var(--red);
}

@keyframes counterFloat {
  0% { opacity: 0; transform: translate(-50%, -50%); }
  20% { opacity: 1; transform: translate(-50%, calc(-50% - 14px)); }
  75% { opacity: 1; transform: translate(-50%, calc(-50% - 44px)); }
  100% { opacity: 0; transform: translate(-50%, calc(-50% - 60px)); }
}

.streak-badge {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%) scale(0.7);
  background: var(--streak-color, var(--accent));
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
  box-shadow: 0 4px 20px var(--streak-glow, transparent);
  transition: opacity 0.15s ease;
}

.streak-badge.show {
  opacity: 1;
  animation: streakBadgePop 0.35s ease, streakBadgePulse 1.1s ease-in-out 0.35s infinite;
}

@keyframes streakBadgePop {
  0% { transform: translateX(-50%) scale(0.5); }
  60% { transform: translateX(-50%) scale(1.25); }
  100% { transform: translateX(-50%) scale(1); }
}

@keyframes streakBadgePulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.1); }
}

.counter-display-wrap.streak-plus-1 { --streak-color: #ffd60a; --streak-glow: rgba(255, 214, 10, 0.65); }
.counter-display-wrap.streak-plus-2 { --streak-color: #22d3ee; --streak-glow: rgba(34, 211, 238, 0.65); }
.counter-display-wrap.streak-plus-3 { --streak-color: #c026d3; --streak-glow: rgba(192, 38, 211, 0.75); }

.counter-display-wrap.streak-minus-1 { --streak-color: #3d4870; --streak-glow: rgba(61, 72, 112, 0.8); }
.counter-display-wrap.streak-minus-2 { --streak-color: #1e3a8a; --streak-glow: rgba(30, 58, 138, 0.85); }
.counter-display-wrap.streak-minus-3 { --streak-color: #1e1b4b; --streak-glow: rgba(30, 27, 75, 0.9); }

.streak-plus-1 .counter-display,
.streak-plus-2 .counter-display,
.streak-plus-3 .counter-display,
.streak-minus-1 .counter-display,
.streak-minus-2 .counter-display,
.streak-minus-3 .counter-display {
  animation: streakPulse 0.9s ease-in-out infinite;
}

@keyframes streakPulse {
  0%, 100% { text-shadow: 0 0 22px var(--streak-glow), 0 0 46px var(--streak-glow); }
  50% { text-shadow: 0 0 40px var(--streak-glow), 0 0 80px var(--streak-glow); }
}

.streak-plus-1 .counter-display.bump,
.streak-plus-2 .counter-display.bump,
.streak-plus-3 .counter-display.bump,
.streak-minus-1 .counter-display.bump,
.streak-minus-2 .counter-display.bump,
.streak-minus-3 .counter-display.bump {
  animation: streakBump var(--duration-slow) var(--ease-bounce), streakPulse 0.9s ease-in-out infinite;
}

@keyframes streakBump {
  0% { transform: scale(1) rotate(0deg); }
  40% { transform: scale(1.32) rotate(-2.5deg); }
  70% { transform: scale(1.05) rotate(1.5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.streak-glow-bg {
  position: absolute;
  inset: -25%;
  z-index: 0;
  border-radius: 50%;
  background: radial-gradient(circle, var(--streak-glow, transparent) 0%, transparent 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.streak-plus-1 .streak-glow-bg,
.streak-plus-2 .streak-glow-bg,
.streak-plus-3 .streak-glow-bg,
.streak-minus-1 .streak-glow-bg,
.streak-minus-2 .streak-glow-bg,
.streak-minus-3 .streak-glow-bg {
  opacity: 1;
  animation: streakGlowPulse 1s ease-in-out infinite;
}

@keyframes streakGlowPulse {
  0%, 100% { transform: scale(0.9); }
  50% { transform: scale(1.15); }
}

.streak-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 1;
  width: 160px;
  height: 160px;
  margin: -80px 0 0 -80px;
  border-radius: 50%;
  border: 4px solid var(--streak-color, transparent);
  opacity: 0;
  pointer-events: none;
}

.streak-ring.burst {
  animation: streakRingBurst 0.65s ease-out;
}

@keyframes streakRingBurst {
  0% { opacity: 0.9; transform: scale(0.35); }
  100% { opacity: 0; transform: scale(2.8); }
}

.streak-particle {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  font-size: 24px;
  pointer-events: none;
  opacity: 0;
  animation: streakParticleRise 0.9s ease-out forwards;
}

@keyframes streakParticleRise {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--angle)) translateY(0) scale(0.6); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--angle)) translateY(calc(-1 * var(--dist))) scale(1.15); }
}

.streak-flash {
  position: fixed;
  inset: 0;
  z-index: 900;
  opacity: 0;
  pointer-events: none;
  animation: streakFlash 0.45s ease-out forwards;
}

@keyframes streakFlash {
  0% { opacity: 0.5; }
  100% { opacity: 0; }
}

.buttons-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
  margin-bottom: 18px;
}

.big-btn {
  width: 92px;
  height: 92px;
  border-radius: var(--radius-circle);
  border: none;
  font-size: 40px;
  font-weight: 300;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}

.big-btn:active {
  transform: scale(0.94);
}

.big-btn.minus {
  background: var(--red);
  box-shadow: 0 4px 14px rgba(255,69,58,0.35);
}

.big-btn.plus {
  background: var(--green);
  box-shadow: 0 4px 14px rgba(52,199,89,0.35);
}

.counter-history {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 5;
}

.counter-names {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 5;
}

.counter-names .counter-history-panel {
  left: 0;
  right: auto;
}

.counter-history-toggle {
  position: relative;
  background: var(--card);
  border: none;
  color: var(--text);
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.counter-history-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

.counter-history-panel {
  position: absolute;
  top: 44px;
  right: 0;
  width: min(80vw, 280px);
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 12px;
}

.counter-history-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
}

.counter-history-panel-head-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.counter-history-pin {
  background: var(--card-hi);
  border: 1.5px solid transparent;
  color: var(--sub);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.counter-history-pin.active {
  border-color: var(--accent);
  color: var(--accent);
}

.counter-history-clear {
  background: none;
  border: none;
  color: var(--sub);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 2px;
}

.counter-history-list {
  max-height: 240px;
  overflow-y: auto;
}

.counter-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--hairline);
}

.counter-history-item:last-child {
  border-bottom: none;
}

.counter-history-delta {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--green);
  min-width: 40px;
}

.counter-history-delta.negative {
  color: var(--red);
}

.counter-history-time {
  flex: 1;
  color: var(--sub);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.counter-history-del {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--sub);
  font-size: 16px;
  width: 22px;
  height: 22px;
  cursor: pointer;
}

.counter-history-empty {
  text-align: center;
  color: var(--sub);
  font-size: 13px;
  padding: 8px 0;
}

.counter-name-status {
  font-size: 13px;
  font-weight: 600;
}

.counter-name-status.owe {
  color: var(--red);
}

.counter-name-status.owed {
  color: var(--green);
}

.counter-name-status.settled {
  color: var(--sub);
}

.name-tag-row {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-bottom: 14px;
}

.name-tag-btn {
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
}

.name-tag-btn.single {
  background: var(--accent);
}

.counter-name-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.2s ease;
  padding: 24px;
}

.counter-name-overlay.show {
  opacity: 1;
}

.counter-name-card {
  width: min(90vw, 320px);
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-xl);
}

.counter-name-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 14px;
  text-align: center;
}

.counter-name-direction-badge {
  display: block;
  width: fit-content;
  margin: 0 auto 14px;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.counter-name-direction-badge.give {
  background: var(--red);
}

.counter-name-direction-badge.receive {
  background: var(--green);
}

.counter-name-input {
  width: 100%;
  background: var(--card-hi);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px;
  font-size: 15px;
  margin-bottom: 12px;
}

.counter-name-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.counter-name-chip {
  background: var(--card-hi);
  border: none;
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.counter-name-actions {
  display: flex;
  gap: 10px;
}

.counter-name-actions button {
  flex: 1;
}

.counter-name-confirm {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
