:root {
  --bg: #0f1a14;
  --card: #182820;
  --option-bg: #21352b;
  --text: #e2f0d9;
  --muted: #8aa899;
  --accent: #3d8b6e;
  --accent-light: #52a987;
  --gold: #d4a742;
  --danger: #cf4d4d;
  --border-subtle: rgba(61, 139, 110, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  overflow-x: hidden;
}

#confettiCanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}

/* APP SHELL */
.app-container {
  width: 100%;
  max-width: 640px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.home-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}

.brand h1 {
  font-size: 1.5rem;
  color: #a8e0c4;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

.btn-gear-head, .btn-preset-open {
  background: var(--option-bg);
  border: 1px solid var(--border-subtle);
  color: #a8e0c4;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.player-card {
  margin-bottom: 20px;
}

.player-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.player-input {
  width: 100%;
  padding: 12px;
  background: var(--option-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: #fff;
  font-size: 0.95rem;
  outline: none;
}

.guest-notice {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 6px;
}

.action-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.btn-main, .btn-guest, .btn-ultimate {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
  border: none;
}

.btn-main {
  background: var(--accent);
  color: #fff;
}
.btn-main:hover {
  background: var(--accent-light);
}

.btn-guest {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--muted);
}

.btn-ultimate {
  background: linear-gradient(135deg, #3d8b6e, #2a5a48);
  border: 1px solid #a8e0c4;
  color: #fff;
}

/* LEADERBOARD CARD */
.leaderboard-card {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 16px;
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

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

.lb-trophy {
  font-size: 1.4rem;
}

.leaderboard-header h3 {
  font-size: 0.95rem;
  color: #a8e0c4;
}

.lb-sub {
  font-size: 0.72rem;
  color: var(--muted);
}

.btn-refresh {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 0.85rem;
}

.lb-rank {
  color: var(--gold);
  font-weight: 700;
  width: 32px;
}

.lb-name {
  flex: 1;
}

.lb-score {
  font-weight: 600;
}

.lb-loading {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  padding: 12px 0;
}

/* ACTIVE QUIZ SCREEN */
.stats {
  position: fixed;
  top: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 26, 20, 0.92);
  padding: 6px 14px;
  border-radius: 30px;
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(8px);
  z-index: 100;
}

.stat-pill {
  font-size: 0.8rem;
}

.btn-quit {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  cursor: pointer;
}

.btn-gear {
  background: transparent;
  border: none;
  font-size: 1rem;
  cursor: pointer;
}

.progress {
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
}

.timer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.75rem;
  margin-bottom: 12px;
}

.timer-bar-wrap {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  background: var(--gold);
}

.image-wrap {
  position: relative;
  height: 240px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.image-slot {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-placeholder {
  font-size: 3rem;
  opacity: 0.4;
}

.image-loading {
  position: absolute;
  font-size: 0.8rem;
  color: var(--muted);
}

#speciesImg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#speciesImg.revealed {
  opacity: 1;
}

.img-resize-handle {
  height: 14px;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: ns-resize;
  user-select: none;
}

.prompt-controls {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

.hint-btn, .spin-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: #a8e0c4;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
}

.prompt-box {
  margin-bottom: 16px;
}

.prompt-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.prompt {
  font-size: 1.3rem;
  font-weight: 700;
  color: #a8e0c4;
}

.options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option {
  padding: 12px;
  background: var(--option-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.option:hover:not(:disabled) {
  background: rgba(61, 139, 110, 0.25);
}

.option.correct {
  background: #2e694f !important;
  border-color: #68d391;
  color: #fff;
}

.option.wrong {
  background: #682c2c !important;
  border-color: #fc8181;
  color: #fff;
}

.feedback {
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}

.feedback.correct {
  background: rgba(46, 105, 79, 0.4);
  color: #68d391;
}

.feedback.wrong {
  background: rgba(104, 44, 44, 0.4);
  color: #fc8181;
}

.next-btn {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.type-answer-input {
  width: 100%;
  padding: 12px;
  background: var(--option-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: #fff;
  font-size: 0.95rem;
}

/* RESULTS */
.end-screen {
  text-align: center;
  padding: 20px 0;
}

.end-title {
  color: #a8e0c4;
  margin-bottom: 8px;
}

.end-msg {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.kv-notice {
  font-size: 0.8rem;
  padding: 8px;
  border-radius: 6px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.05);
}

.kv-notice.success {
  color: #68d391;
}

.kv-notice.guest {
  color: var(--muted);
}

.end-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* SIDEBAR SETTINGS */
.sidebar-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 200;
}

.settings-sidebar {
  position: fixed;
  top: 0;
  right: -320px;
  width: 320px;
  height: 100vh;
  background: var(--card);
  border-left: 1px solid var(--border-subtle);
  z-index: 210;
  display: flex;
  flex-direction: column;
  transition: right 0.25s ease;
}

.settings-sidebar.open {
  right: 0;
}

.sidebar-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-close-btn, .close-btn {
  background: transparent;
  border: none;
  font-size: 1.2rem;
  color: var(--muted);
  cursor: pointer;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.set-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #a8e0c4;
}

.mode-select, .pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mode-btn, .count-btn, .choice-btn {
  padding: 6px 12px;
  background: var(--option-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
}

.mode-btn.active, .count-btn.active, .choice-btn.active {
  background: var(--accent);
  color: #fff;
}

.slider {
  width: 100%;
  accent-color: var(--accent);
}

.chk-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  cursor: pointer;
}

/* WIDE MODAL FOR FORGIVING SEARCH & PRESETS */
.wide-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90vw;
  max-width: 1000px;
  height: 85vh;
  background: var(--card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  z-index: 220;
  display: flex;
  flex-direction: column;
  padding: 16px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge {
  background: var(--accent);
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.search-ribbon {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.search-input-wrap {
  flex: 1;
  display: flex;
  gap: 6px;
}

.search-input-wrap input {
  flex: 1;
  padding: 8px 12px;
  background: var(--option-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: #fff;
  font-size: 0.88rem;
  outline: none;
}

.btn-subtle, .btn-action {
  padding: 6px 12px;
  background: var(--option-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: #a8e0c4;
  font-size: 0.78rem;
  cursor: pointer;
}

.bulk-actions {
  display: flex;
  gap: 6px;
}

.picker-body {
  flex: 1;
  display: flex;
  gap: 12px;
  overflow: hidden;
  margin-top: 10px;
}

.family-sidebar {
  width: 220px;
  overflow-y: auto;
  border-right: 1px solid var(--border-subtle);
  padding-right: 8px;
}

.family-sidebar h3 {
  font-size: 0.85rem;
  color: #a8e0c4;
  margin-bottom: 8px;
}

.fam-sidebar-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 0.78rem;
  cursor: pointer;
}

.fam-sidebar-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.fam-btn-add {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: #a8e0c4;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.7rem;
  cursor: pointer;
}

.species-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
  align-content: start;
}

.species-card-label {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.species-card-label:hover {
  background: rgba(255, 255, 255, 0.06);
}

.name-block {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.common-txt {
  font-size: 0.85rem;
  font-weight: 600;
}

.sci-txt {
  font-size: 0.74rem;
  color: var(--muted);
}

.preset-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.preset-save-box, .preset-list-box {
  display: flex;
  gap: 6px;
}

.preset-save-box input, .preset-list-box select {
  padding: 6px 10px;
  background: var(--option-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: #fff;
  font-size: 0.82rem;
  outline: none;
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: #a8e0c4;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
}

.search-more-hint, .no-matches {
  grid-column: 1 / -1;
  text-align: center;
  padding: 12px;
  font-size: 0.8rem;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

@media (max-width: 768px) {
  .picker-body {
    flex-direction: column;
  }
  .family-sidebar {
    width: 100%;
    height: 120px;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
  .preset-footer {
    flex-direction: column;
    align-items: stretch;
  }
  .preset-save-box, .preset-list-box {
    flex-direction: column;
  }
}
