/* Theme variables are supplied by each app's theme.css. Apps load THIS file
   first, then their theme.css, so a theme can override component rules too.
   These fallbacks keep the page legible when theme.css is missing; :where()
   gives them zero specificity, so a plain :root in any app theme wins the
   cascade no matter which order the two stylesheets happen to load in.

   Every fallback below is deliberately NEUTRAL — greys (#111/#222/#333/#c8c8c8/
   #f8f8f8) and one amber accent (#f5c542/#ffe08a), plus the semantic red/green.
   An app that forgets a variable degrades to monochrome-and-amber, never to
   another app's brand. Do not copy an app's palette back into this block. */
:where(:root) {
  --bg-deep: #111;
  --bg: #222;
  --surface: #333;
  --accent: #f5c542;
  --accent-light: #ffe08a;
  --accent-glow: #f5c542;
  --cream: #f8f8f8;
  --text: #f8f8f8;
  --text-dim: #c8c8c8;
  --danger: #ff4d4d;
  --success: #2ecc71;
  --accent-dark: #b8901f;
  --accent-shadow: rgba(245, 197, 66, 0.35);
  --surface-deep: #222;
  --surface-shadow: rgba(17, 17, 17, 0.5);
  --title-glow: rgba(245, 197, 66, 0.45);
  --placeholder: rgba(248, 248, 248, 0.4);
  --card-bg: rgba(51, 51, 51, 0.55);
  --card-border: rgba(255, 224, 138, 0.18);
  --tile-bg: rgba(51, 51, 51, 0.6);
  --tile-border: rgba(255, 224, 138, 0.15);
  --chip-border: rgba(255, 224, 138, 0.2);
  --ghost-border: rgba(255, 224, 138, 0.5);
  --dialog-border: rgba(255, 224, 138, 0.3);
  --info-bg: rgba(255, 224, 138, 0.14);
  --info-border: rgba(255, 224, 138, 0.35);
  --badge-bg: rgba(255, 224, 138, 0.18);
  --badge-border: rgba(255, 224, 138, 0.35);
  --danger-bg: rgba(255, 77, 77, 0.18);
  --danger-border: rgba(255, 77, 77, 0.4);
  --danger-text: #ffd0d0;
  --success-bg: rgba(46, 204, 113, 0.18);
  --success-border: rgba(46, 204, 113, 0.4);
  --success-text: #d0ffe4;
  --pill-active-bg: rgba(46, 204, 113, 0.2);
  --pill-active-text: #7dffb0;
  --pill-closed-bg: rgba(255, 77, 77, 0.2);
  --pill-closed-text: #ffb0b0;
  --pill-complete-bg: rgba(245, 197, 66, 0.25);
  --votes-pill-bg: rgba(245, 197, 66, 0.18);
  --emoji-selected-bg: rgba(245, 197, 66, 0.2);
  --link: #ffe08a;
  --link-dark: #b8901f;
  --link-shadow: rgba(245, 197, 66, 0.35);
  --qr-text: #111;
  --qr-hint: #333;
  --confetti-colors: #f5c542, #ffe08a, #ffffff, #c8c8c8;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: radial-gradient(ellipse at top, var(--bg) 0%, var(--bg-deep) 65%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  width: 100%;
  flex: 1;
}

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.5rem;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

header.top a.brand {
  color: var(--accent-light);
  text-decoration: none;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

h1 {
  font-size: 1.9rem;
  margin: 0.5rem 0 0.25rem;
  text-align: center;
  text-shadow: 0 0 18px var(--title-glow);
}

h1 .glow {
  color: var(--accent-light);
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin: 0 0 1.75rem;
  font-size: 1rem;
}

.big-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.big-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 1.75rem 1rem;
  font-size: 1.3rem;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 10px 24px var(--accent-shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  cursor: pointer;
  min-height: 96px;
}

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

.big-btn.secondary {
  background: linear-gradient(160deg, var(--surface) 0%, var(--surface-deep) 100%);
  box-shadow: 0 10px 24px var(--surface-shadow);
}

.big-btn .emoji {
  font-size: 2.4rem;
  line-height: 1;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  backdrop-filter: blur(4px);
}

label {
  display: block;
  font-weight: 700;
  margin: 1rem 0 0.4rem;
  color: var(--accent-light);
}

input[type='text'],
textarea,
input[type='password'] {
  width: 100%;
  padding: 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--placeholder);
}

.file-input-wrap {
  margin-top: 0.4rem;
}

input[type='file'] {
  width: 100%;
  color: var(--text-dim);
}

input[type='file']::file-selector-button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 0.9rem 1.4rem;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  min-height: 52px;
  margin-right: 0.8rem;
}

input[type='file']::file-selector-button:active {
  transform: scale(0.97);
}

.preview {
  margin-top: 0.75rem;
  border-radius: 14px;
  overflow: hidden;
  max-width: 260px;
  display: none;
}

.preview img {
  width: 100%;
  display: block;
}

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 0.9rem 1.4rem;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  min-width: 52px;
}

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

.btn.full {
  width: 100%;
  margin-top: 1.5rem;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--ghost-border);
  color: var(--accent-light);
}

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

.btn.small {
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  min-height: 40px;
}

.msg {
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin: 1rem 0;
  font-size: 0.95rem;
}

.msg.error {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
}

.msg.success {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-text);
}

.msg.info {
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  color: var(--text-dim);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-top: 1rem;
}

@media (min-width: 480px) {
  .grid {
    grid-template-columns: 1fr 1fr;
  }
}

.trunk-card {
  background: var(--tile-bg);
  border: 2px solid var(--tile-border);
  border-radius: 16px;
  overflow: hidden;
  text-align: left;
  cursor: pointer;
  padding: 0;
  color: var(--text);
  font-family: inherit;
  display: flex;
  flex-direction: column;
}

.trunk-card:active {
  transform: scale(0.98);
}

.trunk-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-shadow);
}

.trunk-card .photo {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.3);
  display: block;
}

.trunk-card .info {
  padding: 0.65rem 0.75rem 0.85rem;
}

.trunk-card .name {
  font-weight: 800;
  font-size: 1rem;
  margin: 0 0 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.trunk-card .desc {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.3;
}

.vote-badge {
  display: none;
  color: var(--accent-light);
}

.trunk-card.selected .vote-badge {
  display: inline;
}

/* Category chip bar (vote page) */

.category-bar {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  padding: 0.25rem 0.1rem 0.75rem;
  margin: -0.25rem -0.1rem 0.5rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.category-chip {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--tile-bg);
  border: 2px solid var(--chip-border);
  color: var(--text);
  border-radius: 999px;
  padding: 0.6rem 1rem;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
  min-height: 44px;
}

.category-chip .chip-emoji {
  font-size: 1.1rem;
}

.category-chip .chip-check {
  display: none;
  color: var(--success);
  font-weight: 900;
}

.category-chip.voted .chip-check {
  display: inline;
}

.category-chip.active {
  border-color: var(--accent);
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-dark) 100%);
  box-shadow: 0 6px 18px var(--accent-shadow);
}

.category-chip:active {
  transform: scale(0.97);
}

/* Voter picker (vote page): one ballot per kid on a shared device */

.voter-bar-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.voter-bar {
  margin-bottom: 0.25rem;
}

.voter-chip.active {
  border-color: var(--link);
  background: linear-gradient(160deg, var(--link-dark) 0%, var(--surface) 100%);
  box-shadow: 0 6px 18px var(--link-shadow);
}

.voter-add {
  border-style: dashed;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.emoji-option {
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.5rem 0;
  min-height: 48px;
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
}

.emoji-option.selected {
  border-color: var(--accent);
  background: var(--emoji-selected-bg);
}

.cat-badges {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}

.cat-badge {
  background: var(--badge-bg);
  border: 1px solid var(--badge-border);
  border-radius: 999px;
  padding: 0.1rem 0.4rem;
  font-size: 0.9rem;
  line-height: 1.4;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem 1rem;
}

.spinner {
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
}

/* Admin */

.status-pill {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
}

.status-pill.active {
  background: var(--pill-active-bg);
  color: var(--pill-active-text);
}

.status-pill.closed {
  background: var(--pill-closed-bg);
  color: var(--pill-closed-text);
}

.status-btn.current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.status-pill.complete {
  background: var(--pill-complete-bg);
  color: var(--accent-light);
}

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

/* Admin action buttons: equal-width tiles that wrap cleanly on narrow screens */
.admin-btn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.admin-btn-grid .btn {
  width: 100%;
  margin: 0;
  white-space: nowrap;
}

.tally-hint {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

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

table.tally th,
table.tally td {
  text-align: left;
  padding: 0.5rem 0.3rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  vertical-align: middle;
}

table.tally .thumb-cell {
  padding-left: 0;
}

table.tally .thumb-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: block;
  border-radius: 8px;
}

table.tally img.thumb {
  width: 72px;
  height: 54px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

table.tally .cat-count {
  text-align: center;
  color: var(--text-dim);
}

.hidden-row {
  opacity: 0.45;
}

.dialog-photo {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 0.5rem;
}

/* Share-this-page QR */

.qr-btn {
  background: transparent;
  border: 1px solid var(--ghost-border);
  color: var(--accent-light);
  border-radius: 12px;
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  min-height: 44px;
}

.qr-overlay {
  cursor: pointer;
}

.qr-card {
  background: #fff;
  border-radius: 20px;
  padding: 1.25rem;
  max-width: 340px;
  width: 100%;
  text-align: center;
}

.qr-card img {
  width: 100%;
  display: block;
  border-radius: 8px;
}

.qr-card .qr-url {
  color: var(--qr-text);
  font-weight: 800;
  margin-top: 0.6rem;
  word-break: break-all;
}

.qr-card .qr-hint {
  color: var(--qr-hint);
  font-size: 0.8rem;
  margin-top: 0.3rem;
}

/* Modal / dialog */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.overlay[hidden] {
  display: none !important;
}

.dialog {
  background: var(--bg);
  border: 1px solid var(--dialog-border);
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 400px;
  width: 100%;
}

.dialog h2 {
  margin-top: 0;
  color: var(--accent-light);
}

.dialog .actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* Reveal */

.reveal-stage {
  text-align: center;
  padding: 2rem 0;
}

.reveal-medal {
  font-size: 4rem;
  line-height: 1;
}

.reveal-photo {
  width: 100%;
  max-width: 360px;
  border-radius: 20px;
  margin: 1.25rem auto;
  display: block;
  box-shadow: 0 12px 40px var(--accent-shadow);
}

.reveal-name {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 0.5rem 0 0.25rem;
}

.reveal-desc {
  color: var(--text-dim);
  margin: 0 0 1.5rem;
}

.reveal-votes {
  display: inline-block;
  background: var(--votes-pill-bg);
  color: var(--accent-light);
  border-radius: 999px;
  padding: 0.35rem 1rem;
  font-weight: 800;
  margin: 0.25rem 0 1rem;
}

.reveal-fade {
  animation: reveal-fade-in 1s ease both;
}

.reveal-fade.dramatic {
  animation-duration: 2.4s;
  animation-delay: 0.5s;
}

@keyframes reveal-fade-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.btn.full.reveal-back {
  margin-top: 0.75rem;
}

.reveal-tapnote {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 2rem;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

footer.foot {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 1rem;
}

.pin-gate {
  max-width: 320px;
  margin: 3rem auto;
  text-align: center;
}

/* ---- Countdown-to-close banner ---- */

.countdown-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  text-align: center;
  padding: 0.65rem 1rem;
  padding-bottom: calc(0.65rem + env(safe-area-inset-bottom));
  background: var(--accent);
  color: var(--bg-deep);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
}

.countdown-banner.urgent {
  background: var(--danger);
  color: #fff;
  animation: countdown-pulse 1s ease-in-out infinite;
}

@keyframes countdown-pulse {
  50% {
    opacity: 0.75;
  }
}

.admin-timer-count {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent-light);
}
