:root {
  --child-color: #a3e635;
  --grandchild-color: #22c55e;
  --greatgrandchild-color: #06b6d4;
  --ink: #1f2933;
  --muted: #6b7280;
  --border: #d1d5db;
  --bg: #f7f7f5;
  --card-bg: #ffffff;
  --accent: #3b82f6;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 20px; margin: 0; }

.topbar-title { display: flex; align-items: center; gap: 10px; }

.rules-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.rules-btn:hover { background: var(--border); color: var(--ink); }

.whoami { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.whoami .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
#whoami-name { font-weight: 600; color: var(--ink); }

main#app {
  max-width: 1100px;
  margin: 32px auto;
  padding: 0 16px 64px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  max-width: 420px;
  margin: 40px auto;
}

.card h2 { margin-top: 0; text-align: center; }

form label {
  display: block;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--muted);
}

form input[type="text"],
form input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  color: var(--ink);
}

.generation-field {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
}
.generation-field legend { padding: 0 6px; font-size: 13px; color: var(--muted); }
.radio-row { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--ink); margin-bottom: 8px; }
.radio-row input { width: auto; }

.admin-passcode-field { font-size: 12px; }
.hint { font-weight: 400; font-size: 12px; }

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-left: 6px;
}
.swatch-child { background: var(--child-color); }
.swatch-grandchild { background: var(--grandchild-color); }
.swatch-greatgrandchild { background: var(--greatgrandchild-color); }

.btn-primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(0.95); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
}

.switch-link { text-align: center; font-size: 14px; color: var(--muted); margin-top: 20px; }

.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin: -6px 0 12px;
}

/* Gallery */
.gallery { max-width: 1100px; }

.admin-panel {
  background: #fffbea;
  border: 1px dashed #d4a72c;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14px;
}
.admin-panel h3 { margin: 0 0 8px; font-size: 14px; }
#admin-upload-status { margin-left: 10px; color: var(--muted); }

.gallery-instructions {
  font-size: 15px;
  color: var(--ink);
  margin: 0 4px 4px;
}

.upload-btn {
  display: inline-block;
  padding: 8px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
.upload-btn:hover { filter: brightness(0.95); }
.upload-hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; max-width: 520px; }

.thumb-strip {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  padding: 18px 10px 14px 18px;
}

.thumb {
  position: relative;
  flex: 0 0 auto;
  width: 110px;
  height: 90px;
  border-radius: 10px;
  border: 3px solid transparent;
  cursor: pointer;
  background: #eee;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.thumb.active {
  border-width: 4px;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35), 0 3px 10px rgba(0, 0, 0, 0.25);
  transform: translateY(-3px);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 7px; }

.thumb-number {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.65);
  color: white;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  pointer-events: none;
}
.thumb-badges {
  position: absolute;
  top: -16px;
  left: -16px;
  display: flex;
  pointer-events: none;
}
.thumb-badges .badge-ast {
  font-size: 46px;
  line-height: 1;
  font-weight: 900;
  text-shadow: 0 0 2px rgba(0,0,0,0.9), 0 0 1px rgba(0,0,0,0.9);
  margin-right: -18px;
}

.thumb-delete-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: white;
  font-size: 14px;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.thumb-delete-btn:hover { filter: brightness(0.9); }

.gallery-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}

.image-wrap {
  position: relative;
  display: inline-block;
  width: 100%;
  min-height: 200px;
  background: #f0f0ee;
  border-radius: 10px;
  overflow: hidden;
}
.image-wrap img {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  user-select: none;
}
#no-images-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  margin: 0;
}

.asterisk-layer { position: absolute; inset: 0; }
.asterisk {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: var(--asterisk-size, 48px);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  text-shadow: 0 0 2px rgba(0,0,0,0.9), 0 0 1px rgba(0,0,0,0.9);
  filter: drop-shadow(1px 3px 2px rgba(0,0,0,0.55));
  user-select: none;
}
.asterisk.filtered-out { display: none; }

.gallery-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  flex-wrap: wrap;
  gap: 12px;
}
.filter-row { font-size: 14px; display: flex; align-items: center; gap: 8px; }
.size-control { font-size: 14px; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.size-control input[type="range"] { width: 120px; }

@keyframes bmp-asterisk-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(1.18); }
}
.asterisk {
  animation: bmp-asterisk-pulse 2.4s ease-in-out infinite;
}
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.legend-item { display: flex; align-items: center; gap: 6px; }

.tooltip {
  position: fixed;
  background: #111827;
  color: white;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  pointer-events: none;
  z-index: 1000;
  transform: translate(-50%, -140%);
  white-space: nowrap;
}

/* Admin stats screen */
.stats-btn { margin-left: 10px; }

.stats-screen { max-width: 1100px; }

.stats-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
}

.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.stats-header h2 { margin: 0; }

.stats-totals {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 14px 18px;
  background: var(--bg);
  border-radius: 10px;
  font-size: 14px;
}
.stats-totals strong { display: block; font-size: 22px; color: var(--ink); }

.stats-table-wrap { overflow-x: auto; }

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.stats-table th,
.stats-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.stats-table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.stats-table tr:last-child td { border-bottom: none; }
.stats-name-admin::after {
  content: " (Admin)";
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
}

.stats-delete-btn {
  border: none;
  background: none;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  opacity: 0.7;
}
.stats-delete-btn:hover { opacity: 1; background: var(--bg); }

/* Rules modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 2000;
}

.modal-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 28px;
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.modal-header h2 { margin: 0; }

.modal-close {
  border: none;
  background: none;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }

.rules-list {
  margin: 16px 0 0;
  padding-left: 20px;
  font-size: 15px;
  line-height: 1.5;
}
.rules-list > li { margin-bottom: 14px; }
.rules-list ul { margin: 8px 0 0; padding-left: 20px; }
.rules-list ul li { margin-bottom: 6px; }
