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

:root {
  --bg:      #f7f6f2;
  --text:    #342019;
  --accent:  #f15b40;
  --accent2: #d14127;
  --border:  #d9d9d9;
  --muted:   #999;
  --card-bg: #ffffff;
  --radius:  12px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* ── HEADER ─────────────────────────────────── */
header {
  border-bottom: 1px solid var(--border);
  padding: 20px 16px 16px;
}

.header-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.subtitle {
  font-size: 14px;
  color: var(--muted);
  flex: 1;
}

.leaderboard-toggle {
  background: none;
  border: 1px solid var(--text);
  color: var(--text);
  font-family: Arial, sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: background 0.15s, color 0.15s;
}

.leaderboard-toggle:hover,
.leaderboard-toggle.active {
  background: var(--text);
  color: var(--bg);
}

/* ── GAME VIEW ──────────────────────────────── */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.instruction {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ── VOTING AREA ────────────────────────────── */
.voting-area {
  position: relative;
  display: flex;
  gap: 12px;
  width: 100%;
  align-items: center;
}

.card {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.22s ease,
              filter 0.22s ease, opacity 0.22s ease, border-color 0.22s ease;
}

.card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  display: block;
  transition: inherit;
}

.card-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px 8px;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
  flex-shrink: 0;
}

.char-num {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.char-date {
  font-size: 12px;
  color: var(--muted);
}

.card:hover {
  box-shadow: 0 8px 28px -6px rgba(52, 32, 25, 0.18);
  transform: translateY(-2px);
}

.card.winner {
  transform: scale(1.04);
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--text), 0 12px 40px -8px rgba(52, 32, 25, 0.25);
}

.card.loser {
  transform: scale(0.93);
  filter: grayscale(0.5) brightness(0.65);
  opacity: 0.5;
}

.card.leaving {
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.card.entering {
  opacity: 0;
  transform: scale(0.97);
}

.card.entered {
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* ── VS BADGE ───────────────────────────────── */
.vs-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  padding: 5px 9px;
  border-radius: 20px;
  pointer-events: none;
  user-select: none;
}

/* ── SKIP ───────────────────────────────────── */
.skip-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s;
}

.skip-btn:hover { color: var(--text); }

/* ── LEADERBOARD ────────────────────────────── */
#leaderboardView {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.lb-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.lb-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.lb-sub {
  font-size: 13px;
  color: var(--muted);
}

.lb-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

@media (max-width: 560px) {
  /* Full-viewport layout — no scrolling in game, scrollable in leaderboard */
  body {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  body.lb-open {
    overflow: auto;
    height: auto;
    max-height: none;
  }

  header { flex-shrink: 0; padding: 10px 16px; }

  /* Prevent "Hot or Not" from wrapping */
  .header-inner { flex-wrap: nowrap; }
  h1 { font-size: 17px; white-space: nowrap; }
  .subtitle { font-size: 12px; white-space: nowrap; }
  .leaderboard-toggle { font-size: 11px; padding: 5px 10px; white-space: nowrap; }

  main {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 10px 12px 6px;
    gap: 8px;
  }

  .instruction { font-size: 11px; }

  .voting-area {
    flex: 1;
    min-height: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  /* Cards grow to fill available height */
  .card {
    flex: 1;
    min-height: 0;
    width: 100%;
  }

  /* Image fills card height instead of forcing 1:1 aspect ratio */
  .card img {
    aspect-ratio: unset;
    flex: 1;
    min-height: 0;
    width: 100%;
    object-fit: contain;
  }

  .vs-badge {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}

@media (max-width: 479px) {
  .lb-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
}

.lb-item {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.lb-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px -5px rgba(52, 32, 25, 0.18);
}

.lb-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.lb-rank {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  line-height: 1.4;
}

.lb-wins {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  line-height: 1.4;
}

/* ── MODAL ──────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(52, 32, 25, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg);
  border-radius: 16px;
  padding: 20px;
  max-width: 360px;
  width: 100%;
  position: relative;
  box-shadow: 0 20px 60px -10px rgba(52, 32, 25, 0.35);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }

.modal-identity {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  padding: 0 2px;
}

.modal-num {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.modal-date {
  font-size: 13px;
  color: var(--muted);
}

.modal-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 16px;
}

.modal-stats {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.modal-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  border-right: 1px solid var(--border);
}
.modal-stat:last-child { border-right: none; }

.stat-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 3px;
}

/* ── UTILITY ────────────────────────────────── */
.hidden { display: none !important; }

/* ── LOADING STATE ──────────────────────────── */
.card.loading img {
  opacity: 0;
}
