:root {
  --wine: #7a1f2b;
  --wine-dark: #5a1620;
  --wine-light: #a8384a;
  --gold: #d4a437;
  --cream: #fdf8f0;
  --ink: #2b1a12;
  --muted: #8a7a6d;
  --card-bg: #ffffff;
  --danger: #b3382c;
  --radius: 16px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, var(--wine) 0%, var(--wine-dark) 220px, var(--cream) 220px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  min-height: 100vh;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 20px) 16px calc(env(safe-area-inset-bottom, 20px) + 24px);
}

.header {
  position: relative;
  text-align: center;
  padding: 20px 0 12px;
  color: #fff;
}

.header h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.8);
  letter-spacing: 0.02em;
}

.lang-switch {
  position: absolute;
  top: 2px;
  right: 0;
  display: flex;
  gap: 4px;
}

.lang-btn {
  padding: 4px 8px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  cursor: pointer;
}

.lang-btn.active {
  color: var(--wine-dark);
  background: var(--gold);
  border-color: var(--gold);
}

.ferris-wheel {
  width: 122px;
  height: 122px;
  margin: 4px auto 2px;
  color: var(--gold);
  filter: drop-shadow(0 0 9px rgba(212, 164, 55, 0.5));
}

.ferris-wheel svg {
  width: 100%;
  height: 100%;
}

.ferris-wheel .fw-rim {
  stroke: var(--gold);
}

.ferris-wheel .fw-hub {
  fill: var(--gold);
}

.ferris-wheel .fw-spokes {
  stroke: rgba(255, 255, 255, 0.5);
}

.ferris-wheel .fw-legs {
  stroke: rgba(255, 255, 255, 0.38);
}

.ferris-wheel .fw-gondola circle {
  fill: var(--gold);
  animation: fw-twinkle 2.4s ease-in-out infinite;
}

.ferris-wheel .fw-gondola circle:nth-child(2) { animation-delay: 0.3s; }
.ferris-wheel .fw-gondola circle:nth-child(3) { animation-delay: 0.6s; }
.ferris-wheel .fw-gondola circle:nth-child(4) { animation-delay: 0.9s; }
.ferris-wheel .fw-gondola circle:nth-child(5) { animation-delay: 1.2s; }
.ferris-wheel .fw-gondola circle:nth-child(6) { animation-delay: 1.5s; }
.ferris-wheel .fw-gondola circle:nth-child(7) { animation-delay: 1.8s; }
.ferris-wheel .fw-gondola circle:nth-child(8) { animation-delay: 2.1s; }

@keyframes fw-twinkle {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .ferris-wheel .fw-gondola circle {
    animation: none;
    opacity: 0.9;
  }
}

.counter-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(90, 22, 32, 0.18);
  margin-top: 8px;
}

.count-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
}

#count {
  font-size: 4.5rem;
  font-weight: 800;
  color: var(--wine);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.count-label {
  font-size: 0.95rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 4px;
}

.btn-add {
  width: 100%;
  padding: 20px;
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--wine-light), var(--wine));
  border: none;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(122, 31, 43, 0.35);
  cursor: pointer;
  transition: transform 0.08s ease;
  touch-action: manipulation;
}

.btn-add:active {
  transform: scale(0.96);
}

.add-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.add-row .btn-add {
  flex: 1;
  width: auto;
}

.btn-add-half {
  flex: 0 0 auto;
  padding: 20px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--wine);
  background: var(--cream);
  border: 2px solid var(--wine-light);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.08s ease;
  touch-action: manipulation;
}

.btn-add-half:active {
  transform: scale(0.96);
}

.btn-add-zero {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1.5px dashed #d8c7b2;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.08s ease;
  touch-action: manipulation;
}

.btn-add-zero:active {
  transform: scale(0.97);
}

.secondary-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.btn-secondary {
  flex: 1;
  padding: 12px 8px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--wine-dark);
  background: var(--cream);
  border: 1px solid #e7d9c9;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-secondary:active {
  transform: scale(0.97);
}

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

.stats-card, .history-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-top: 16px;
  box-shadow: 0 4px 16px rgba(90, 22, 32, 0.08);
}

.stats-card {
  display: flex;
  padding: 16px 8px;
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 4px;
  border-right: 1px solid #f0e6d9;
}

.stat:last-child {
  border-right: none;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--wine);
}

.stat-name {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-card {
  padding: 16px 18px 8px;
}

.history-card h2 {
  margin: 0 0 8px;
  font-size: 1rem;
  color: var(--wine-dark);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}

.history-list li {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #f0e6d9;
  font-size: 0.92rem;
}

.history-list li:last-child {
  border-bottom: none;
}

.history-index {
  color: var(--gold);
  font-weight: 700;
  margin-right: 8px;
}

.history-time {
  color: var(--muted);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 20px 0;
}

.day-divider {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 12px 0 4px;
}

.group-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-top: 16px;
  box-shadow: 0 4px 16px rgba(90, 22, 32, 0.08);
  padding: 18px 20px;
}

.group-card h2 {
  margin: 0 0 4px;
  font-size: 1rem;
  color: var(--wine-dark);
}

.group-hint {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.group-toggle {
  display: flex;
  gap: 10px;
}

.group-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.group-form input {
  padding: 12px;
  font-size: 0.95rem;
  border: 1px solid #e7d9c9;
  border-radius: 10px;
  background: var(--cream);
  color: var(--ink);
}

.btn-small {
  padding: 12px;
  font-size: 1rem;
  margin-top: 2px;
}

.group-error {
  margin: 10px 0 0;
  padding: 8px 10px;
  font-size: 0.85rem;
  color: var(--danger);
  background: #fbe9e6;
  border-radius: 8px;
}

.group-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.group-code {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.group-code strong {
  color: var(--wine);
  letter-spacing: 0.08em;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--wine);
  text-decoration: underline;
  cursor: pointer;
}

.link-danger {
  color: var(--danger);
  white-space: nowrap;
}

.standings-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.standing-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid #f0e6d9;
  font-size: 0.92rem;
}

.standing-row:last-child {
  border-bottom: none;
}

.standing-rank {
  color: var(--gold);
  font-weight: 700;
  text-align: center;
}

.standing-name {
  color: var(--ink);
}

.standing-count {
  font-weight: 700;
  color: var(--wine);
}

.standing-me {
  background: #fdf3e7;
  border-radius: 8px;
  padding-left: 6px;
  padding-right: 6px;
  margin: 0 -6px;
}

.standing-me .standing-name {
  font-weight: 700;
}
