*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --success: #059669;
  --success-bg: #d1fae5;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --redeemed-opacity: 0.55;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --surface: #1f2937;
    --text: #f3f4f6;
    --text-muted: #9ca3af;
    --border: #374151;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --success-bg: #064e3b;
    --danger-bg: #7f1d1d;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.header {
  margin-bottom: 1.5rem;
}

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

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.contribute-info {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--text-muted);
  box-shadow: var(--shadow);
}

.contribute-info p {
  margin: 0 0 0.5rem;
}

.contribute-info ul {
  margin: 0;
  padding-left: 1.25rem;
}

.contribute-info li + li {
  margin-top: 0.25rem;
}

.contribute-info code {
  font-family: "Cascadia Code", "Consolas", "Courier New", monospace;
  font-size: 0.85em;
  color: var(--text);
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.error-banner {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.stats-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-value-wrap {
  position: relative;
  display: block;
  width: fit-content;
  margin: 0 auto;
}

.stat-unredeemed.stat-has-alert {
  cursor: pointer;
}

.stat-unredeemed.stat-has-alert:hover {
  border-color: var(--danger);
}

.stat-dot {
  position: absolute;
  top: 0;
  right: -0.55rem;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface);
  animation: stat-dot-pulse 1.8s ease-in-out infinite;
}

@keyframes stat-dot-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.75;
  }
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.toolbar {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.search-wrap {
  display: block;
}

.search-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.search-input {
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}

.search-input::placeholder {
  color: var(--text-muted);
}

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

.filter-tabs {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}

.filter-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.filter-tab:hover {
  color: var(--text);
}

.filter-tab.active {
  background: var(--accent);
  color: #fff;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.codes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.codes-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.col-tip {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.85;
}

.codes-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.codes-table tbody tr:last-child td {
  border-bottom: none;
}

.codes-table tbody tr.redeemed {
  opacity: var(--redeemed-opacity);
}

.code-cell {
  font-family: "Cascadia Code", "Consolas", "Courier New", monospace;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  user-select: all;
}

.code-cell.redeemed-code {
  text-decoration: line-through;
}

.code-cell:hover {
  color: var(--accent);
}

.loading-cell,
.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem !important;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-available {
  background: var(--success-bg);
  color: var(--success);
}

.badge-redeemed {
  background: var(--border);
  color: var(--text-muted);
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-redeem {
  background: var(--accent);
  color: #fff;
}

.btn-redeem:hover {
  background: var(--accent-hover);
}

.btn-unredeem {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-unredeem:hover {
  background: var(--bg);
  color: var(--text);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.25rem;
}

.page-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.45rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}

.page-btn:hover:not(:disabled) {
  background: var(--bg);
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-info {
  font-size: 0.875rem;
  color: var(--text-muted);
  min-width: 7rem;
  text-align: center;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.5rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 100;
  pointer-events: none;
  transition: opacity 0.2s;
}

@media (max-width: 600px) {
  .stats-bar {
    flex-direction: column;
    gap: 0.5rem;
  }

  .filter-tabs {
    display: flex;
    width: 100%;
  }

  .filter-tab {
    flex: 1;
    text-align: center;
    padding: 0.5rem 0.4rem;
  }
}
