:root {
  --asphalt: #1b1b1f;
  --asphalt-2: #26262c;
  --yellow: #ffd400;
  --red: #e8312a;
  --white: #ffffff;
  --blue: #2a52be;
  /* used for accent text sitting directly on the page background (not on the
     fixed-dark cards/track/toasts) — pure yellow is too low-contrast on a
     light-mode white page, so light mode swaps this to a darker amber */
  --accent-text: var(--yellow);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: linear-gradient(160deg, #16294f 0%, var(--asphalt) 55%, var(--asphalt) 100%);
  background-attachment: fixed;
  background-size: 100% 100vh;
  color: var(--white);
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ---------- LIGHT MODE ---------- */
body.light-mode {
  --asphalt: #eef1f7;
  --asphalt-2: #eaf1fb;
  --white: #1a1a1a;
  --accent-text: #b8780b;
  background: linear-gradient(160deg, #e7edfb 0%, #eef1f7 55%, #eef1f7 100%);
  background-attachment: fixed;
  background-size: 100% 100vh;
}
/* softer, pale-blue cards instead of the high-contrast dark boxes used in
   dark mode — only light mode gets this treatment */
body.light-mode .task-card,
body.light-mode .reward-card,
body.light-mode .history-item {
  background: #dce8fb;
  border-color: #b9cdef;
}
body.light-mode .task-card.special {
  background: linear-gradient(135deg, #fdeec0, #dce8fb);
  border-color: #e8cf7a;
}
body.light-mode .task-card.penalty {
  background: linear-gradient(135deg, #fbdada, #dce8fb);
  border-color: #e3a6a6;
}
body.light-mode .card-name {
  color: #1a1a1a;
}
body.light-mode .card-points {
  color: #8a6a00;
}
body.light-mode .card-cost {
  color: #a23b35;
}
body.light-mode .card-desc {
  color: #5a6678;
}
body.light-mode .history-date {
  color: #6a7689;
}
body.light-mode .btn-primary {
  background: #ffe49a;
  color: #5b3a00;
}
body.light-mode .btn-secondary {
  background: #dde4f0;
  color: #33415c;
}
body.light-mode .btn-danger {
  background: #f8d4d2;
  color: #8a1f1f;
}
body.light-mode .points-big {
  text-shadow: none;
}
body.light-mode .app-header-title {
  text-shadow: none;
}
body.light-mode .checkpoint-pole {
  background: #888;
}
body.light-mode .bottom-nav {
  border-top-color: rgba(0,0,0,0.1);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}
body.light-mode .child-gate-box input,
body.light-mode .modal-box input,
body.light-mode .modal-box textarea {
  background: #ffffff;
  color: #1a1a1a;
  border: 1px solid #ccc;
}

.hidden { display: none !important; }

/* ---------- CHILD ENTRY PIN GATE ---------- */
#childGate {
  position: fixed;
  inset: 0;
  padding-top: env(safe-area-inset-top);
  z-index: 2100;
  background: var(--asphalt);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.child-gate-box {
  text-align: center;
  width: min(90vw, 320px);
}
.child-gate-icon { font-size: 48px; margin-bottom: 6px; }
.child-gate-box h2 { color: var(--accent-text); margin: 0 0 16px; }
.child-gate-box input {
  width: 100%;
  padding: 12px;
  font-size: 20px;
  text-align: center;
  border-radius: 8px;
  border: none;
  margin-bottom: 12px;
  background: #111;
  color: white;
}
.child-gate-box .btn { width: 100%; font-size: 18px; padding: 12px; }

/* ---------- SPLASH SCREEN ---------- */
#splashScreen {
  position: fixed;
  inset: 0;
  padding-top: env(safe-area-inset-top);
  z-index: 2000;
  background: linear-gradient(180deg, #1b1b1f 0%, #2a2410 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.splash-tractor-wrap {
  transform: translateX(-220%);
  transition: transform 1s ease-out;
}
.splash-tractor-wrap.entered {
  transform: translateX(0);
}
.splash-tractor-wrap.exiting {
  transform: translateX(220%);
  transition: transform 0.8s ease-in;
}

.splash-tractor {
  width: min(60vw, 280px);
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,0.4));
  animation: tractorBounce 1.4s ease-in-out infinite;
}
@keyframes tractorBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.splash-title {
  font-size: 36px;
  color: var(--yellow);
  margin: 24px 0 8px;
  text-shadow: 2px 2px 0 var(--red);
}
.splash-subtitle {
  font-size: 18px;
  color: var(--white);
  margin: 0 0 28px;
}
.splash-btn {
  font-size: 20px;
  padding: 14px 36px;
}

/* ---------- EMOJI PICKER ---------- */
#emojiPicker {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
}
.emoji-picker-box {
  background: white;
  border-radius: 12px;
  padding: 16px;
  width: min(90vw, 420px);
  max-height: 70vh;
  overflow-y: auto;
}
.emoji-picker-box h3 { margin: 0 0 10px; color: #222; font-size: 16px; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.emoji-grid button {
  font-size: 24px;
  border: none;
  background: #f0f1f4;
  border-radius: 8px;
  padding: 6px 0;
  cursor: pointer;
}
.emoji-grid button:hover { background: #ddd; }
.emoji-picker-close {
  margin-top: 10px;
  width: 100%;
}
.emoji-preview-btn {
  font-size: 24px;
  width: 48px;
  height: 40px;
  border: 1px solid rgba(128,128,128,0.3);
  border-radius: 6px;
  background: var(--asphalt);
  cursor: pointer;
}

/* ---------- SEQUENTIAL ENTRANCE ANIMATION ---------- */
.reveal-section {
  opacity: 0;
  transform: translateY(40px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.reveal-section.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- CHILD VIEW ---------- */
#childView {
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(72px + env(safe-area-inset-bottom, 0px));
  min-height: 100vh;
}

.child-page.hidden { display: none; }

/* ---------- BOTTOM NAVIGATION (mobile tab bar) ---------- */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 500;
  display: flex;
  background: var(--asphalt-2);
  border-top: 2px solid #333;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transition: background 0.3s ease;
}
.bottom-nav-btn {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #888;
  padding: 12px 2px;
  cursor: pointer;
}
.bottom-nav-btn.active { color: var(--accent-text); }
.bottom-nav-icon { font-size: 24px; display: inline-block; }
.bottom-nav-btn.active .bottom-nav-icon {
  animation: navIconGlow 1.2s ease-in-out infinite;
}
@keyframes navIconGlow {
  0%, 100% { text-shadow: 0 0 0px var(--accent-text); transform: scale(1); }
  50% { text-shadow: 0 0 12px var(--accent-text); transform: scale(1.15); }
}

.nav-badge {
  position: absolute;
  top: 2px;
  right: 18%;
  background: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}

.app-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 0;
}
.app-header-icon {
  width: 36px;
  height: auto;
  image-rendering: pixelated;
}
.app-header-title {
  font-size: 18px;
  color: var(--accent-text);
  text-shadow: 1px 1px 0 var(--red);
  margin: 0;
  text-align: center;
}

/* ---------- STICKY PAGE HEADERS ---------- */
/* bleeds past #childView's own padding so the sticky background reaches the
   screen edges, then re-applies that padding inside */
#trackSection.reveal-section {
  position: sticky;
  top: 0;
  z-index: 60;
  background: linear-gradient(160deg, #16294f 0%, var(--asphalt) 55%, var(--asphalt) 100%);
  background-attachment: fixed;
  background-size: 100% 100vh;
  margin: -8px -16px 0;
  padding: 8px 16px 4px;
}

.page-sticky-header {
  position: sticky;
  top: 0;
  z-index: 60;
  background: linear-gradient(160deg, #16294f 0%, var(--asphalt) 55%, var(--asphalt) 100%);
  background-attachment: fixed;
  background-size: 100% 100vh;
  margin: -8px -16px 8px;
  padding: 6px 16px 8px;
}

body.light-mode #trackSection.reveal-section,
body.light-mode .page-sticky-header {
  background: linear-gradient(160deg, #e7edfb 0%, #eef1f7 55%, #eef1f7 100%);
  background-attachment: fixed;
  background-size: 100% 100vh;
}

.center-title {
  text-align: center;
  border-left: none;
  padding-left: 0;
}

.track-wrap { margin: 8px 0 12px; }

.track {
  position: relative;
  height: 70px;
  background: repeating-linear-gradient(
    90deg, #333 0 30px, #3a3a3a 30px 60px
  );
  border-top: 4px dashed var(--yellow);
  border-bottom: 4px dashed var(--yellow);
  border-radius: 8px;
  overflow: hidden;
}

.track::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 3px;
  transform: translateY(-50%);
  background: repeating-linear-gradient(
    90deg, #fff 0 18px, transparent 18px 36px
  );
  pointer-events: none;
}

.flag {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 40px;
}

.car {
  position: absolute;
  left: 0;
  top: 50%;
  /* 🏎️ faces left by default; mirror it so the front points toward the goal on the right */
  transform: translate(0, -50%) scaleX(-1);
  font-size: 46px;
  transition: left 0.6s cubic-bezier(.34,1.56,.64,1);
}

.checkpoints {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.checkpoint-marker {
  position: absolute;
  bottom: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
  filter: grayscale(1) opacity(0.5);
}
.checkpoint-marker.reached {
  filter: none;
  animation: checkpointPop 0.4s ease-out;
}
.checkpoint-flag {
  font-size: 18px;
  background: var(--yellow);
  border-radius: 6px 6px 6px 0;
  padding: 2px 5px;
  line-height: 1;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}
.checkpoint-marker.reached .checkpoint-flag {
  background: #6dc24b;
}
.checkpoint-pole {
  width: 2px;
  height: 30px;
  background: white;
}
@keyframes checkpointPop {
  0% { transform: translateX(-50%) scale(0.4); }
  60% { transform: translateX(-50%) scale(1.3); }
  100% { transform: translateX(-50%) scale(1); }
}

.points-big {
  text-align: center;
  font-size: 36px;
  font-weight: 900;
  color: var(--accent-text);
  margin-top: 8px;
  text-shadow: 2px 2px 0 var(--red);
}

.rewards-points {
  font-size: 26px;
  margin: 4px 0 4px;
}

/* ---------- ACHIEVEMENT TOAST (Xbox-style) ---------- */
#achievementLayer {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.achievement-toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #1f1f24, #2a2a30);
  border-left: 5px solid #6dc24b;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  padding: 12px 18px;
  min-width: 260px;
  max-width: 320px;
  transform: translateX(360px);
  opacity: 0;
  animation: toastSlide 4s ease forwards;
}
.achievement-toast.negative {
  border-left-color: var(--red);
}
.achievement-toast.negative .achievement-label { color: var(--red); }

@keyframes toastSlide {
  0%   { transform: translateX(360px); opacity: 0; }
  8%   { transform: translateX(0); opacity: 1; }
  85%  { transform: translateX(0); opacity: 1; }
  100% { transform: translateX(360px); opacity: 0; }
}

.achievement-icon {
  font-size: 36px;
  flex-shrink: 0;
}

.achievement-text { line-height: 1.3; }
.achievement-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6dc24b;
  font-weight: 700;
}
.achievement-title {
  font-size: 15px;
  font-weight: 700;
  color: white;
}
.achievement-points {
  font-size: 13px;
  color: var(--yellow);
  font-weight: 700;
}

/* ---------- EMOJI CONFETTI (reward claim) ---------- */
#confettiLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1050;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  top: -40px;
  font-size: 28px;
  animation: confettiFall 4.2s ease-in forwards;
}
@keyframes confettiFall {
  0%   { transform: translateY(0) translateX(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) translateX(var(--drift, 0px)) rotate(540deg); opacity: 0; }
}

.section-title {
  font-size: 18px;
  margin: 14px 0 8px;
  color: var(--accent-text);
  border-left: 6px solid var(--red);
  padding-left: 10px;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-card, .reward-card {
  /* fixed colors on purpose — these cards look identical in light/dark mode */
  background: #26262c;
  border: 3px solid #ffffff;
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s;
  position: relative;
}

.card-info { flex: 1; min-width: 0; }
.card-trailing {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}

.task-card:active, .reward-card:active { transform: scale(0.95); }

.task-card.done {
  border-color: #4caf50;
  opacity: 0.55;
  cursor: default;
}

.task-card.special {
  border-color: var(--yellow);
  background: linear-gradient(135deg, #3a3210, #26262c);
}

.task-card.penalty {
  border-color: var(--red);
  background: linear-gradient(135deg, #3a1010, #26262c);
}
.task-card.penalty .card-points { color: var(--red); }

.reward-card.locked {
  opacity: 0.45;
  cursor: default;
}

.reward-card.claimable {
  border-color: var(--yellow);
  animation: rewardGlow 1.2s ease-in-out infinite;
}
.reward-card.claimed {
  border-color: #4caf50;
  opacity: 0.6;
  cursor: default;
}
@keyframes rewardGlow {
  0%, 100% { box-shadow: 0 0 0px var(--yellow); }
  50% { box-shadow: 0 0 16px var(--yellow); }
}

.history-item {
  /* same fixed dark look as task/reward cards — always readable regardless of theme */
  background: #26262c;
  border: 2px solid #444;
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
}
.history-date { font-size: 12px; color: #999; margin-top: 2px; }
.history-note { font-size: 12px; color: #bbb; margin-top: 1px; font-style: italic; }
body.light-mode .history-note { color: #5a6678; }

.task-card.reset-points-card {
  border-color: var(--red);
  opacity: 0.7;
}
.task-card.reset-points-card:active { opacity: 1; }

@keyframes rewardClaimPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.2) rotate(-4deg); }
  70% { transform: scale(0.95) rotate(3deg); }
  100% { transform: scale(1); }
}
.reward-card.claim-pop { animation: rewardClaimPop 0.5s ease-out; }

.card-emoji { font-size: 32px; flex-shrink: 0; line-height: 1; }
.card-name { font-size: 16px; font-weight: 700; color: #ffffff; }
.card-points { font-size: 15px; color: var(--yellow); font-weight: 700; flex-shrink: 0; white-space: nowrap; }
.card-cost { font-size: 15px; color: var(--red); font-weight: 700; white-space: nowrap; }
.card-lock { font-size: 16px; white-space: nowrap; }
.card-desc { font-size: 12px; color: #aaa; margin-top: 2px; }
.card-pending-badge {
  position: absolute; top: 6px; right: 6px;
  background: var(--red); color: white;
  font-size: 11px; padding: 2px 6px; border-radius: 8px;
}

/* float +points animation */
#floatLayer { position: fixed; inset: 0; pointer-events: none; z-index: 999; }
.float-points {
  position: absolute;
  font-size: 28px;
  font-weight: 900;
  color: var(--yellow);
  animation: floatUp 1s ease-out forwards;
}
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-60px) scale(1.3); }
}

@keyframes carJolt {
  0% { transform: translate(0, -50%) scaleX(-1) scale(1); }
  30% { transform: translate(0, -50%) scaleX(-1) scale(1.25) rotate(6deg); }
  100% { transform: translate(0, -50%) scaleX(-1) scale(1); }
}
.car.jolt { animation: carJolt 0.5s; }

/* ---------- MODALS ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--asphalt-2);
  border: 2px solid var(--yellow);
  border-radius: 14px;
  padding: 20px;
  width: min(90vw, 400px);
}
.modal-box textarea, .modal-box input {
  width: 100%;
  padding: 10px;
  font-size: 18px;
  border-radius: 8px;
  border: none;
  margin-top: 10px;
  background: #111;
  color: white;
}
.modal-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }
.error { color: var(--red); font-weight: 700; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary { background: var(--yellow); color: #222; }
.btn-secondary { background: #555; color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-small { padding: 6px 10px; font-size: 13px; margin: 2px; }

/* ---------- PARENT VIEW ---------- */
/* follows the same light/dark toggle as the child view via the shared
   --asphalt/--asphalt-2/--white variables, instead of a hardcoded light theme
   that used to stay blindingly white even with dark mode switched on */
#parentView.parent {
  background: var(--asphalt);
  color: var(--white);
  min-height: 100vh;
  font-family: 'Segoe UI', Arial, sans-serif;
  transition: background 0.3s ease, color 0.3s ease;
}
.parent-sticky-top {
  position: sticky;
  top: 0;
  padding-top: env(safe-area-inset-top);
  z-index: 60;
}
.parent-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: #20232a;
  color: white;
}
.parent-header h1 { font-size: 17px; margin: 0; }
.parent-header .btn { flex-shrink: 0; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--asphalt-2);
  padding: 8px 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  border: none;
  background: transparent;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  border-radius: 8px;
  color: #888;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab-btn.active { background: var(--yellow); color: #1a1a1a; font-weight: 700; }
body.light-mode .tab-btn.active { background: #ffe49a; color: #5b3a00; }

.tab-panel { padding: 16px; max-width: 900px; margin: 0 auto; }
.tab-panel h2 { margin-top: 0; font-size: 19px; }
.tab-panel h3 { margin-top: 24px; font-size: 15px; color: #888; }

.inline-form, .inline-form-col {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--asphalt-2); padding: 14px; border-radius: 12px;
  margin-bottom: 16px; border: 1px solid rgba(128,128,128,0.2);
}
.inline-form-col { flex-direction: column; align-items: stretch; }
.inline-form input, .inline-form select {
  padding: 10px; border: 1px solid rgba(128,128,128,0.3); border-radius: 8px;
  font-size: 14px; background: var(--asphalt); color: var(--white);
  flex: 1 1 130px; min-width: 0;
}
.inline-form-col label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.inline-form-col input {
  padding: 10px; border: 1px solid rgba(128,128,128,0.3); border-radius: 8px;
  background: var(--asphalt); color: var(--white);
}

table { width: 100%; border-collapse: collapse; background: var(--asphalt-2); border-radius: 10px; overflow: hidden; }
th, td { padding: 10px; border-bottom: 1px solid rgba(128,128,128,0.15); text-align: left; font-size: 13px; }
th { background: rgba(128,128,128,0.1); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: #888; }
.table-wrap { margin-bottom: 14px; overflow-x: auto; border-radius: 10px; }
.empty-note { color: #888; padding: 10px; font-size: 14px; }

.history-subtitle { font-size: 14px; color: var(--yellow); margin: 14px 0 6px; }
