/* Self-hosted font (optional, place GeistMono-Medium.woff2 in /fonts/) */
@font-face {
  font-family: 'Geist Mono';
  src: url('/fonts/GeistMono-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* Fallback: import Space Mono from Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&display=swap');

:root {
  /* surfaces - warm graphite, not black */
  --bg: #121210;
  --surface: #1A1A17;
  --surface-2: #232320;
  --line: #2F2E29;
  --edge: rgba(255,255,255,0.04);

  /* ink */
  --text: #ECEAE3;
  --text-dim: #9A968C;
  --text-faint: #615E57;

  /* signal - amber */
  --accent: #F5A524;
  --accent-ink: #121210;
  --accent-soft: #3A2C10;

  /* functional state */
  --pending: #56A39B;
  --pending-soft: #15302E;
  --danger: #E0593F;

  /* geometry */
  --r-card: 10px;
  --r-ctl: 7px;
  --gap: clamp(16px, 3vw, 28px);

  /* typography */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Geist Mono", "Space Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* type scale */
  --t-eyebrow: 0.72rem;
  --t-body: 0.95rem;
  --t-lead: 1.15rem;
  --t-count-sm: 1.9rem;
  --t-count: clamp(2.75rem, 7vw, 4.5rem);
}

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

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--t-body);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ===== HEADER ===== */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-mark {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.logo-text {
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--t-eyebrow);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.live-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== MAIN LAYOUT ===== */
main {
  max-width: 1000px;
  margin: 0 auto;
  padding: var(--gap);
}

/* ===== COUNTER GRID ===== */
.counter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--gap);
}

/* ===== COUNTER CARD ===== */
.counter-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: clamp(20px, 4vw, 28px);
  position: relative;
}

.counter-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 1px;
  right: 1px;
  height: 1px;
  background: var(--edge);
  border-radius: var(--r-card) var(--r-card) 0 0;
}

.counter-card__eyebrow {
  font-size: var(--t-eyebrow);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 1rem;
}

.counter-card__count {
  margin: 0.5rem 0;
}

.counter-card__description {
  font-size: var(--t-body);
  color: var(--text-dim);
  margin: 0 0 1.25rem;
}

.counter-card__actions {
  margin-top: 1rem;
}

/* ===== FLAP COUNT DISPLAY ===== */
.flap-display {
  display: flex;
  align-items: center;
  gap: 2px;
  perspective: 600px;
}

.flap-display--flash {
  animation: tick-flash 300ms ease-out;
}

@keyframes tick-flash {
  0% { filter: brightness(1); }
  30% { filter: brightness(1.3) saturate(1.2); }
  100% { filter: brightness(1); }
}

.flap-digit {
  position: relative;
  width: 1em;
  height: 1.4em;
  font-family: var(--font-mono);
  font-size: var(--t-count);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: var(--text);
  background: var(--surface-2);
  border-radius: var(--r-ctl);
  overflow: hidden;
}

.flap-digit::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--edge);
}

.flap-digit::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--bg);
  transform: translateY(-50%);
  z-index: 5;
}

.flap-digit__value {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.flap-separator {
  font-family: var(--font-mono);
  font-size: calc(var(--t-count) * 0.6);
  color: var(--text-faint);
  width: 0.3em;
  text-align: center;
}

/* Flap animation */
.flap-digit.flipping .flap-top {
  animation: flip-top 260ms cubic-bezier(.36,0,.66,-0.04) forwards;
}

@keyframes flip-top {
  0% { transform: rotateX(0deg); }
  100% { transform: rotateX(-90deg); }
}

.flap-top,
.flap-bottom {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  overflow: hidden;
  backface-visibility: hidden;
}

.flap-top {
  top: 0;
  transform-origin: bottom center;
  border-radius: var(--r-ctl) var(--r-ctl) 0 0;
  background: var(--surface-2);
  z-index: 10;
}

.flap-bottom {
  bottom: 0;
  border-radius: 0 0 var(--r-ctl) var(--r-ctl);
  background: var(--surface-2);
}

.flap-top__value,
.flap-bottom__value {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200%;
}

.flap-top__value {
  top: 0;
}

.flap-bottom__value {
  bottom: 0;
}

/* Small count for admin */
.flap-display--small .flap-digit {
  font-size: var(--t-count-sm);
}

/* Screen reader accessible value */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border: 1px solid transparent;
  border-radius: var(--r-ctl);
  font-family: var(--font-ui);
  font-size: var(--t-body);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 120ms, border-color 120ms, color 120ms;
  min-height: 44px;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: #ffb838;
}

.btn-primary:active {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: var(--text-faint);
}

.btn-danger {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.btn-danger:hover {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-small {
  padding: 0.375rem 0.75rem;
  font-size: 0.85rem;
  min-height: 36px;
}

/* ===== STEPPER ===== */
.stepper {
  display: flex;
  gap: 4px;
}

.stepper__btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  font-family: var(--font-mono);
  font-size: 1.25rem;
  color: var(--text);
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}

.stepper__btn:hover {
  background: var(--surface);
  border-color: var(--text-faint);
}

.stepper__btn:active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.stepper__btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== SUBMIT FORM ===== */
.submit-form {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  display: none;
}

.submit-form.open {
  display: block;
}

.textarea-wrapper {
  position: relative;
}

.submit-form textarea {
  width: 100%;
  padding: 0.75rem;
  padding-bottom: 1.75rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  font-family: var(--font-ui);
  font-size: var(--t-body);
  color: var(--text);
  resize: vertical;
  min-height: 80px;
}

.submit-form textarea::placeholder {
  color: var(--text-faint);
}

.submit-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.char-count {
  position: absolute;
  bottom: 0.5rem;
  right: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-faint);
  pointer-events: none;
}

.char-count--warn {
  color: var(--accent);
}

.turnstile-container {
  margin: 0.75rem 0;
}

.submit-form__actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.submit-form__message {
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--t-body);
}

.submit-form__message--success {
  color: var(--accent);
}

.submit-form__message--error {
  color: var(--danger);
}

.submit-form__message .gate-mark {
  width: 16px;
  height: 16px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-dim);
}

.empty-state__mark {
  width: 64px;
  height: 64px;
  color: var(--text-faint);
  margin: 0 auto 1.5rem;
  opacity: 0.5;
}

.empty-state__text {
  font-size: var(--t-lead);
  margin: 0;
}

/* ===== LOADING ===== */
.loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  padding: 0.75rem 1.25rem;
  font-family: var(--font-mono);
  font-size: var(--t-body);
  color: var(--text);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms;
}

.toast.visible {
  opacity: 1;
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 80ms !important;
  }

  .live-dot {
    animation: none;
    opacity: 1;
  }

  .flap-digit.flipping .flap-top {
    animation: none;
  }

  .flap-display--flash {
    animation: reduced-flash 200ms ease-out;
  }

  @keyframes reduced-flash {
    0% { color: var(--text); }
    50% { color: var(--accent); }
    100% { color: var(--text); }
  }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  header {
    padding: 1rem;
  }

  .logo-text {
    font-size: 0.875rem;
  }

  main {
    padding: 1rem;
  }

  .counter-card {
    padding: 1rem;
  }
}
