:root {
  --bg: #fff8f3;
  --surface: #ffffff;
  --text: #1f1d2b;
  --muted: #6e6a7c;
  --accent: #ff5a5f;
  --accent-dark: #e0484d;
  --border: #ece6e0;
  --pending: #f5a524;
  --approved: #17a34a;
  --rejected: #dc2626;
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.5rem; margin: 0 0 8px; line-height: 1.2; }
a { color: var(--accent); }
.muted { color: var(--muted); margin: 0 0 12px; font-size: .9rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.topbar form { margin: 0; }
button.link { background: none; border: 0; color: var(--muted); font: inherit; padding: 4px; }

/* Cards & forms */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.auth { margin-top: 24px; }
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 14px; }
input[type=text], input:not([type]), input[type=password] {
  display: block; width: 100%; margin-top: 6px;
  padding: 12px 14px; font-size: 16px; /* 16px stops iOS zooming in */
  border: 1px solid var(--border); border-radius: 12px; background: #fff;
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }
button.primary {
  width: 100%; padding: 14px; margin-top: 4px;
  font: inherit; font-weight: 600; color: #fff;
  background: var(--accent); border: 0; border-radius: 12px;
}
button.primary:active { background: var(--accent-dark); }
button.primary:disabled { opacity: .5; }
.switch { text-align: center; margin: 16px 0 0; font-size: .9rem; }

.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-size: .95rem; }
.flash.error { background: #fde8e8; color: #9b1c1c; }
.flash.success { background: #e3f6e9; color: #146c34; }

/* Progress */
.intro { margin-bottom: 16px; }
.bar { height: 10px; background: var(--border); border-radius: 99px; overflow: hidden; margin: 8px 0 6px; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* Bingo grid */
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.tile {
  position: relative; display: flex; flex-direction: column; justify-content: flex-end;
  aspect-ratio: 1; overflow: hidden;
  padding: 8px; border-radius: 12px;
  background: var(--surface); border: 2px solid var(--border);
  color: var(--text); text-decoration: none;
}
.tile:active { transform: scale(.97); }
.tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile .num {
  position: absolute; top: 6px; left: 8px;
  font-weight: 800; font-size: .8rem; color: var(--muted);
}
.tile .text {
  position: relative; font-size: .72rem; line-height: 1.2; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.tile.pending, .tile.approved, .tile.rejected { color: #fff; }
.tile.pending { border-color: var(--pending); }
.tile.approved { border-color: var(--approved); }
.tile.rejected { border-color: var(--rejected); }
.tile:has(img)::after { /* darken photo so the text stays readable */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(transparent 30%, rgba(0,0,0,.7));
}
.tile:has(img) .num, .tile:has(img) .text, .tile:has(img) .badge { z-index: 1; color: #fff; }
.tile .badge { position: absolute; top: 6px; right: 6px; }

.badge {
  display: inline-block; padding: 3px 8px; border-radius: 99px;
  font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  background: var(--border); color: var(--muted);
}
.pending .badge, .badge.pending { background: var(--pending); color: #fff; }
.approved .badge, .badge.approved { background: var(--approved); color: #fff; }
.rejected .badge, .badge.rejected { background: var(--rejected); color: #fff; }
.card > .badge { font-size: .75rem; margin-bottom: 16px; }

/* Assignment page */
.back { display: inline-block; margin-bottom: 12px; text-decoration: none; font-weight: 600; }
.preview { display: block; width: 100%; border-radius: 12px; margin-bottom: 16px; }
.picker {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 140px; padding: 12px; margin-bottom: 12px;
  border: 2px dashed var(--accent); border-radius: 12px;
  color: var(--accent); font-weight: 600; text-align: center; overflow: hidden;
}
.picker input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.picker img { max-width: 100%; max-height: 260px; border-radius: 8px; margin-bottom: 8px; }

/* Levels */
.level-easy      { --level: #17a34a; }
.level-average   { --level: #2563eb; }
.level-difficult { --level: #9333ea; }
.level-legendary { --level: #d97706; }
.level { margin-bottom: 20px; }
.level h2 {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 0 8px; padding-left: 10px; font-size: 1.05rem;
  border-left: 4px solid var(--level);
}
.level h2 span { font-size: .85rem; font-weight: 600; color: var(--muted); }
.level .tile.open { border-color: color-mix(in srgb, var(--level) 35%, var(--border)); }
.level-legendary .tile { background: linear-gradient(135deg, #fff7e6, #ffe8b3); }
.level-legendary .grid { grid-template-columns: 1fr; }
.level-legendary .tile { aspect-ratio: 2 / 1; }
.level-legendary .tile .text { font-size: .9rem; }
.level-tag {
  display: inline-block; margin-right: 6px; padding: 2px 8px; border-radius: 99px;
  background: var(--level); color: #fff; font-size: .7rem; font-weight: 700; text-transform: uppercase;
}

/* Admin */
.topbar form { display: flex; align-items: center; gap: 12px; }
.admin-link { font-weight: 600; text-decoration: none; }
.review-user { margin-bottom: 24px; }
.review-user h2 {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 0 8px; font-size: 1.15rem;
}
.review-user h2 span, .scores h2 span { font-size: .85rem; font-weight: 600; color: var(--muted); }
.review { padding: 12px; margin-bottom: 12px; }
.review img { display: block; width: 100%; max-height: 70vh; object-fit: contain; background: #000; border-radius: 10px; margin-bottom: 10px; }
.review p.muted { margin: 0 0 4px; }
.review h3 { margin: 0 0 12px; font-size: 1rem; }
.review-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.review-actions button {
  padding: 14px; font: inherit; font-weight: 700; border: 0; border-radius: 12px; color: #fff;
}
.review-actions .approve { background: var(--approved); }
.review-actions .decline { background: var(--rejected); }
.review-actions button:active { opacity: .8; }
.empty { text-align: center; margin-bottom: 24px; }
.scores h2 { font-size: 1.15rem; margin: 0 0 8px; }
.scores table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.scores th, .scores td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: .95rem; }
.scores th { font-size: .75rem; text-transform: uppercase; color: var(--muted); }
.scores tr:last-child td { border-bottom: 0; }

/* Leaderboard */
.leaderboard { margin-bottom: 28px; }
.leaderboard h2, .section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 1.15rem; margin: 0 0 8px;
}
.section-title span { font-size: .85rem; font-weight: 600; color: var(--muted); }
.lb-row { display: flex; align-items: center; gap: 12px; padding: 12px; margin-bottom: 8px; }
.lb-row.rank-1 { border-color: #f5c542; background: #fffaf0; }
.lb-rank { width: 32px; text-align: center; font-size: 1.4rem; font-weight: 800; color: var(--muted); flex-shrink: 0; }
.lb-main { flex: 1; min-width: 0; }
.lb-top { display: flex; justify-content: space-between; align-items: baseline; }
.lb-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-size: 1.2rem; font-weight: 800; }
.lb-score small { font-size: .8rem; font-weight: 600; color: var(--muted); }
.lb-main .bar { margin: 6px 0 8px; height: 8px; }
.lb-main .bar span { background: var(--approved); }
.lb-levels { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.level-chip {
  padding: 2px 7px; border-radius: 99px; font-size: .7rem; font-weight: 700;
  color: var(--level); background: color-mix(in srgb, var(--level) 12%, #fff);
}
.lb-pending { font-size: .75rem; color: var(--pending); font-weight: 700; margin-left: 4px; }

/* Admin tabs */
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 16px;
  padding: 4px; background: var(--border); border-radius: 14px;
}
.tabs a {
  padding: 10px; border-radius: 10px; text-align: center;
  font-weight: 700; color: var(--muted); text-decoration: none;
}
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tabs .count {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px;
  background: var(--accent); color: #fff; font-size: .75rem; line-height: 20px;
}
.tabs a { font-size: .9rem; padding: 10px 4px; white-space: nowrap; }

/* Players */
.player { padding: 14px; margin-bottom: 10px; }
.player-top { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.player-top strong { font-size: 1.05rem; }
.player p.muted { margin: 0 0 8px; font-size: .8rem; }
.player-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
.player-stats b { color: var(--text); }
.reset summary { cursor: pointer; font-weight: 600; color: var(--accent); font-size: .9rem; list-style: none; }
.reset summary::-webkit-details-marker { display: none; }
.reset form { margin-top: 10px; }
.reset input[type=text] {
  display: block; width: 100%; margin-bottom: 8px; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 12px;
}

/* Reset game */
.danger { margin-top: 28px; border-color: #f5c2c2; }
.danger h2 { margin: 0 0 4px; font-size: 1.1rem; color: var(--rejected); }
.choice { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; font-size: .9rem; margin-bottom: 10px; }
.choice input { margin-top: 3px; accent-color: var(--rejected); }
.danger input[type=text] {
  display: block; width: 100%; margin: 4px 0 10px; padding: 12px 14px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 12px;
}
.danger-btn {
  width: 100%; padding: 14px; font: inherit; font-weight: 700; color: #fff;
  background: var(--rejected); border: 0; border-radius: 12px;
}
