:root {
  --purple: #7c5cff;
  --pink: #ff5c9d;
  --orange: #ffb03b;
  --green: #2fce7a;
  --bg: #f4f2ff;
  --card: #ffffff;
  --text: #2b2440;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(160deg, #f4f2ff, #ffe9f3 60%, #fff6e5);
  color: var(--text);
  min-height: 100vh;
}

h1, h2, .brand, .btn {
  font-family: 'Baloo 2', sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 24px;
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 800;
  font-size: 1.6rem;
  color: var(--purple);
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.player-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.help-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  border: 2px solid var(--purple);
  background: white;
  color: var(--purple);
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.help-btn:hover {
  background: var(--purple);
  color: white;
}

.player-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 2px solid transparent;
  background: #ece9ff;
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.player-pill.active {
  background: white;
  border-color: var(--purple);
  color: var(--purple);
  box-shadow: 0 2px 8px rgba(124,92,255,0.25);
}

.player-pill.add-player {
  background: transparent;
  border: 2px dashed #c9c2f0;
  color: #8a8399;
}

.rename-player-btn {
  font-size: 0.8rem;
  opacity: 0.5;
}

.rename-player-btn:hover {
  opacity: 1;
}

.profile-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

#readerTypeSelect {
  margin-left: auto;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 10px;
  border-radius: 10px;
  border: 2px solid #e6e1ff;
  background: white;
  color: var(--purple);
  cursor: pointer;
}

.level-badge {
  background: var(--purple);
  color: white;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.xp-track {
  width: 140px;
  height: 10px;
  background: #e6e1ff;
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}

.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--pink), var(--orange));
  width: 0%;
  transition: width 0.4s ease;
}

.points {
  font-weight: 700;
  color: var(--pink);
  white-space: nowrap;
  flex-shrink: 0;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  background: #ece9ff;
  color: var(--text);
}

.btn.primary {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: white;
}

.btn.danger {
  background: #ffe3ea;
  color: #d63566;
}

.btn.danger:hover {
  background: #d63566;
  color: white;
}

.delete-confirm {
  border-top: 2px solid #ece9ff;
  margin-top: 4px;
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn.big {
  display: block;
  margin: 0 auto 28px;
  padding: 16px 28px;
  font-size: 1.15rem;
  border-radius: 18px;
  box-shadow: 0 8px 20px rgba(124,92,255,0.35);
}

.book-section {
  margin-bottom: 32px;
}

.book-section h2 {
  font-size: 1.1rem;
  margin-bottom: 10px;
}

.section-badge {
  display: inline-block;
  background: #ece9ff;
  color: var(--purple);
  padding: 6px 16px;
  border-radius: 999px;
}

.leaderboard {
  margin-top: 40px;
}

.leaderboard h2 {
  font-size: 1.1rem;
  margin-bottom: 10px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: 14px;
  padding: 12px 18px;
  margin-bottom: 10px;
  box-shadow: 0 4px 14px rgba(43,36,64,0.06);
}

.leaderboard-row .rank {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--purple);
  width: 28px;
}

.leaderboard-row .avatar {
  font-size: 1.4rem;
}

.leaderboard-row .name {
  font-weight: 700;
  flex: 1;
}

.edit-dates-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  opacity: 0.6;
}

.edit-dates-btn:hover { opacity: 1; }

.delete-book-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  opacity: 0.5;
}

.delete-book-btn:hover { opacity: 1; }

.edit-dates-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f8f7ff;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}

.book-row .edit-dates-form {
  flex-basis: 100%;
  margin-bottom: 0;
}

.edit-dates-form label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  gap: 8px;
}

.edit-dates-form input {
  font-family: inherit;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid #e6e1ff;
}

.edit-dates-form .row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.edit-dates-form .row-actions button {
  padding: 4px 10px;
  font-size: 0.85rem;
}

.leaderboard-row .stats {
  font-size: 0.9rem;
  color: #8a8399;
  text-align: right;
}

.book-bars {
  margin-top: 40px;
  margin-bottom: 20px;
  background: var(--card);
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: 0 4px 14px rgba(43,36,64,0.06);
}

.book-bars-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.book-bars h2 {
  font-size: 1.1rem;
  margin: 0;
}

#monthSelect {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 6px 10px;
  border-radius: 10px;
  border: 2px solid #e6e1ff;
  background: white;
  color: var(--purple);
  cursor: pointer;
}

.bar-scale,
.bar-row {
  display: grid;
  grid-template-columns: 100px 1fr 28px;
  align-items: center;
  gap: 10px;
}

.bar-scale {
  margin-bottom: 6px;
}

.bar-scale-track {
  position: relative;
  height: 16px;
}

.bar-scale-track span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: #a79fc2;
}

.bar-row {
  margin-bottom: 10px;
}

.bar-row-label {
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-row-track {
  background: #ece9ff;
  border-radius: 999px;
  height: 18px;
  overflow: hidden;
}

.bar-row-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--purple), var(--pink));
  width: 0%;
  transition: width 0.4s ease;
}

.bar-row-count {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--purple);
  text-align: right;
}

.book-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 40px;
}

.completed-month-heading {
  margin: 14px 0 -2px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #a79fc2;
}

.completed-month-heading:first-child {
  margin-top: 0;
}

.book-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  background: var(--card);
  border-radius: 14px;
  padding: 14px 18px;
  box-shadow: 0 4px 14px rgba(43,36,64,0.06);
}

.book-row .row-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.book-row .title-block h3 {
  margin: 0 0 2px;
  font-size: 1rem;
}

.book-row .meta {
  font-size: 0.85rem;
  color: #8a8399;
}

.book-row .row-side {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.book-row .dates {
  margin: 0;
  font-size: 0.8rem;
  color: #a79fc2;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  white-space: nowrap;
}

.book-row .quiz-score-label {
  font-weight: 700;
  color: var(--purple);
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.book-row .quiz-score-label:hover {
  color: var(--pink);
}

.book-row .action-btn {
  white-space: nowrap;
}

.points-badge {
  background: var(--pink);
  color: white;
  font-weight: 800;
  font-size: 0.8rem;
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
  border: none;
  font-family: inherit;
  cursor: pointer;
}

.points-badge:hover {
  background: var(--purple);
}

.empty-hint {
  color: #a79fc2;
  font-style: italic;
  font-size: 0.9rem;
}

dialog {
  border: none;
  border-radius: 20px;
  padding: 0;
  width: min(480px, 92vw);
  box-shadow: 0 20px 50px rgba(43,36,64,0.3);
}

dialog::backdrop {
  background: rgba(43,36,64,0.45);
}

.modal-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 600;
  font-size: 0.9rem;
}

.modal-form input, .modal-form select {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid #e6e1ff;
}

.checkbox-row {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
}

.checkbox-row input { width: auto; }

.lookup-status {
  margin: -4px 0 0;
  font-size: 0.85rem;
  color: #8a8399;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.question-block {
  margin-bottom: 16px;
}

.question-block p {
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-form label.choice {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  font-weight: 400;
}

.choice:hover { background: #f4f2ff; }

.result-summary {
  text-align: center;
}

.result-summary .big-score {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--purple);
}

.result-pass { color: var(--green); font-weight: 700; }
.result-fail { color: var(--pink); font-weight: 700; }

#helpModal {
  width: min(520px, 92vw);
}

.help-intro {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text);
  margin: 0;
}

.help-modal h3 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 0.95rem;
  margin: 4px 0 2px;
}

.help-note {
  font-size: 0.8rem;
  color: #8a8399;
  margin: 0 0 6px;
}

.help-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-bar-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 10px;
}

.help-bar-label {
  font-size: 0.8rem;
  color: #8a8399;
  white-space: nowrap;
}

.help-bar-track {
  background: #ece9ff;
  border-radius: 999px;
  height: 22px;
  overflow: hidden;
}

.help-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--purple), var(--pink));
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  min-width: 32px;
  box-sizing: border-box;
}

.help-bar-fill.alt {
  background: linear-gradient(90deg, var(--orange), var(--pink));
}

#quizReviewContent {
  max-height: 60vh;
  overflow-y: auto;
}

.review-question {
  margin-bottom: 18px;
}

.review-question-text {
  font-weight: 700;
  margin-bottom: 6px;
}

.review-choice {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #8a8399;
}

.review-choice.review-correct {
  background: #e6f9ef;
  color: var(--green);
  font-weight: 700;
}

.review-choice.review-wrong {
  background: #ffe9f0;
  color: var(--pink);
  font-weight: 700;
}

.breakdown-steps {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.breakdown-step {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  font-size: 0.9rem;
}

.breakdown-sub {
  color: #8a8399;
  font-size: 0.85rem;
  padding-left: 20px;
}

.breakdown-total {
  border-top: 2px solid #ece9ff;
  font-weight: 700;
  color: var(--purple);
}

.breakdown-final {
  border-top: 2px solid var(--pink);
  color: var(--pink);
  font-size: 1.05rem;
}

.rewards-star-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  border: 2px solid var(--orange);
  background: white;
  color: var(--orange);
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  text-decoration: none;
}

.rewards-star-btn:hover {
  background: var(--orange);
  color: white;
}

.rewards-title {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.6rem;
  color: var(--purple);
  margin: 0 0 4px;
}

.rewards-subtitle {
  color: #8a8399;
  margin: 0 0 20px;
}

.rewards-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 28px;
}

.reward-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: 14px;
  padding: 12px 18px;
  box-shadow: 0 4px 14px rgba(43,36,64,0.06);
}

.reward-level {
  font-weight: 800;
  color: var(--purple);
  min-width: 70px;
  white-space: nowrap;
}

.repeat-icon {
  font-size: 0.8rem;
  margin-right: 2px;
}

.reward-emoji {
  font-size: 1.6rem;
}

.reward-text {
  flex: 1;
  font-weight: 600;
}

.reward-actions {
  display: flex;
  gap: 10px;
}

.reward-actions button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.6;
}

.reward-actions button:hover { opacity: 1; }

.quest-track {
  max-width: 560px;
  margin-bottom: 32px;
}

.quest-track h2 {
  font-size: 1.2rem;
  margin-bottom: 4px;
}

.quest-add-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.quest-add-form input,
.quest-add-form select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px 10px;
  border-radius: 10px;
  border: 2px solid #e6e1ff;
  background: white;
}

.quest-add-form input[name="threshold"] { width: 90px; }
.quest-add-form input[name="emoji"] { width: 60px; }
.quest-add-form input[name="reward_text"] { flex: 1; min-width: 140px; }
.quest-add-form .mode-select { width: 100px; }

.pin-gate {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.pin-gate label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 600;
  font-size: 0.9rem;
}

.pin-gate input {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid #e6e1ff;
}

.error-text {
  color: var(--pink);
  font-weight: 700;
  width: 100%;
}

.rewards-widget {
  margin-top: 40px;
  margin-bottom: 20px;
}

.rewards-widget-card {
  background: var(--card);
  border-radius: 18px;
  padding: 18px 20px;
  box-shadow: 0 4px 14px rgba(43,36,64,0.06);
}

.quest-bar-block {
  margin-bottom: 20px;
}

.quest-bar-block:last-child {
  margin-bottom: 0;
}

.quest-bar-label {
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.quest-progress-track {
  position: relative;
  height: 26px;
  background: #ece9ff;
  border-radius: 999px;
  margin: 14px 0;
}

.quest-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--purple), var(--pink));
  transition: width 0.4s ease;
}

.quest-mark {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.3rem;
  cursor: pointer;
  background: white;
  border-radius: 50%;
  padding: 3px;
  box-shadow: 0 1px 4px rgba(43,36,64,0.2);
}

.quest-mark.reached {
  box-shadow: 0 0 0 3px var(--green), 0 1px 4px rgba(43,36,64,0.2);
}

.quest-tooltip {
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  z-index: 5;
  box-shadow: 0 4px 12px rgba(43,36,64,0.3);
}

.quest-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--text);
}

.rewards-next {
  font-size: 0.85rem;
  color: #8a8399;
  margin: 4px 0 0;
}

.goal-notices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.goal-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--orange), var(--pink));
  color: white;
  border-radius: 14px;
  padding: 10px 16px;
  font-weight: 700;
  flex-wrap: wrap;
}

.goal-notice .mark-delivered-btn {
  margin-left: auto;
  background: white;
  color: var(--pink);
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}

.celebration-content {
  text-align: center;
}

.celebration-emoji {
  font-size: 4rem;
  margin: 10px 0;
}

.kid-picker-row {
  margin-bottom: 20px;
}

.kid-picker-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 600;
  font-size: 0.9rem;
  max-width: 240px;
}

.kid-picker-row select {
  font-family: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid #e6e1ff;
  background: white;
  color: var(--purple);
  font-weight: 700;
  cursor: pointer;
}

.edit-reward-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: #f8f7ff;
  border-radius: 10px;
  padding: 10px;
  margin: -4px 0 10px;
}

.edit-reward-form input,
.edit-reward-form select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #e6e1ff;
  background: white;
}

.edit-reward-form .edit-mode { width: 90px; }
.edit-reward-form .edit-threshold { width: 80px; }
.edit-reward-form .edit-emoji { width: 50px; }
.edit-reward-form .edit-text { flex: 1; min-width: 140px; }

.edit-reward-form .row-actions {
  display: flex;
  gap: 6px;
}

.edit-reward-form .row-actions button {
  padding: 4px 10px;
  font-size: 0.85rem;
}

.unit-select {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px 6px;
  border-radius: 10px;
  border: 2px solid #e6e1ff;
}

.archived-section {
  margin-top: 20px;
  max-width: 560px;
}

.archived-title {
  font-size: 1.05rem;
  color: #8a8399;
  margin-bottom: 10px;
}

.archived-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.archived-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  font-size: 0.85rem;
  color: #8a8399;
  border-bottom: 1px solid #ece9ff;
}

.archived-emoji {
  font-size: 1rem;
}

.archived-text {
  flex: 1;
}

.archived-date {
  white-space: nowrap;
}

#authGateOverlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #f4f2ff, #ffe9f3 60%, #fff6e5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.auth-gate-card {
  background: var(--card);
  border-radius: 20px;
  padding: 32px 28px;
  width: min(340px, 100%);
  box-shadow: 0 20px 50px rgba(43,36,64,0.3);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.auth-gate-logo {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--purple);
}

.auth-gate-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  text-align: left;
}

.auth-gate-card input {
  font-family: inherit;
  font-size: 1.1rem;
  padding: 12px;
  border-radius: 10px;
  border: 2px solid #e6e1ff;
  text-align: center;
  letter-spacing: 4px;
}
