@import url("https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Nunito:wght@400;700;800&display=swap");

:root {
  --bg: #0f0e1a;
  --panel: #1b1a2e;
  --panel-light: #262445;
  --accent: #ffd23f;
  --accent-2: #4be3ac;
  --accent-3: #ff5d8f;
  --text: #f4f4fb;
  --muted: #9b98c4;
  --danger: #ff5d5d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Nunito", system-ui, sans-serif;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

.retro-title {
  font-family: "Press Start 2P", monospace;
  letter-spacing: 1px;
}

/* ---------- Login screen ---------- */

#login-screen {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px;
  padding-bottom: 56px;
  text-align: center;
}

#login-screen h1 {
  font-size: 22px;
  color: var(--accent);
  text-shadow: 3px 3px 0 #6b4b00;
  max-width: 720px;
  line-height: 1.5;
}

#site-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  padding: 0 16px;
}

#site-footer a {
  color: var(--muted);
  text-decoration: underline;
}

#site-footer a:hover {
  color: var(--text);
}

.profile-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---------- Login screen: Pac-Man-style loading state ----------
   Shown while renderProfiles() is waiting on Cloud Functions (which can be
   slow to "cold start"); hidden the moment the real profile cards are on
   screen. See #profile-loading in index.html and renderProfiles in app.js. */

.profile-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 12px 0 4px;
}

.pacman-ghost {
  position: relative;
  width: 64px;
  height: 58px;
  animation: ghost-bob 1s ease-in-out infinite;
}

.ghost-body {
  position: absolute;
  inset: 0 0 10px 0;
  background: var(--accent-3);
  border-radius: 32px 32px 0 0;
}

/* The classic scalloped ghost "skirt": a repeating radial-gradient carves
   half-circle notches out of a solid strip along the bottom edge. */
.ghost-body::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -11px;
  height: 14px;
  background: radial-gradient(circle at 8px 0, transparent 8px, var(--accent-3) 8.5px) 0 0 / 16px 14px repeat-x;
}

.ghost-eye {
  position: absolute;
  top: 16px;
  width: 16px;
  height: 20px;
  background: var(--text);
  border-radius: 50%;
}

.ghost-eye.left { left: 11px; }
.ghost-eye.right { right: 11px; }

.ghost-pupil {
  position: absolute;
  top: 6px;
  left: 4px;
  width: 8px;
  height: 8px;
  background: #2b3a8f;
  border-radius: 50%;
  animation: ghost-look 1.6s ease-in-out infinite;
}

@keyframes ghost-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

@keyframes ghost-look {
  0%, 100% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
}

.loading-caption {
  font-family: "Press Start 2P", monospace;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 2px;
}

.loading-caption .dot {
  display: inline-block;
  opacity: 0.2;
  animation: dot-blink 1.4s infinite;
}

.loading-caption .dot:nth-child(2) { animation-delay: 0.2s; }
.loading-caption .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

.profile-card {
  background: var(--panel);
  border: 3px solid var(--panel-light);
  border-radius: 16px;
  padding: 20px 28px;
  width: 160px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.profile-card:hover, .profile-card:focus {
  transform: translateY(-4px) scale(1.03);
  border-color: var(--accent-2);
}

.profile-card .avatar {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

.profile-card .edit-name {
  display: block;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
}

#pin-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

#pin-dots {
  display: flex;
  gap: 10px;
}

.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--accent-2);
  background: transparent;
}

.pin-dot.filled { background: var(--accent-2); }

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  gap: 10px;
}

.pin-pad button {
  height: 56px;
  font-size: 20px;
  border-radius: 12px;
  border: none;
  background: var(--panel-light);
  color: var(--text);
  cursor: pointer;
}

.pin-pad button:active { background: var(--accent-2); color: #0f0e1a; }

#login-error {
  color: var(--danger);
  min-height: 20px;
  font-weight: 800;
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font-size: 14px;
}

/* ---------- App screen ---------- */

#app-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 3px solid var(--panel-light);
}

header .who { display: flex; align-items: center; gap: 8px; font-weight: 800; }
header .who .avatar { font-size: 26px; }

.budget-wrap {
  flex: 1;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.budget-bar {
  flex: 1;
  height: 12px;
  border-radius: 6px;
  background: var(--panel-light);
  overflow: hidden;
}

.budget-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.3s ease;
}

.budget-bar-fill.low { background: linear-gradient(90deg, var(--accent-3), var(--danger)); }

header .spacer { flex: 1; }

header button {
  background: var(--panel-light);
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}

header button:hover { background: var(--accent-2); color: #0f0e1a; }

main {
  flex: 1;
  display: flex;
  min-height: 0;
}

@media (max-width: 900px) {
  main { flex-direction: column; }
}

#chat-panel {
  width: 40%;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  border-right: 3px solid var(--panel-light);
  min-height: 0;
}

@media (max-width: 900px) {
  #chat-panel { width: 100%; border-right: none; border-bottom: 3px solid var(--panel-light); height: 45%; }
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 90%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.4;
  font-size: 14px;
  white-space: pre-wrap;
}

.msg.kid { align-self: flex-end; background: var(--accent-2); color: #0f0e1a; }
.msg.bot { align-self: flex-start; background: var(--panel-light); }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 14px 10px;
}

.chip {
  background: var(--panel-light);
  border: none;
  color: var(--text);
  border-radius: 20px;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
}

.chip:hover { background: var(--accent); color: #0f0e1a; }

#model-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px 0;
  font-size: 12px;
}

.model-toggle-label { color: var(--muted); }

.model-btn {
  background: var(--panel-light);
  border: none;
  color: var(--muted);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.model-btn.active {
  background: var(--accent-2);
  color: #0f0e1a;
}

#model-hint {
  padding: 4px 14px 8px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

#composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 3px solid var(--panel-light);
}

#composer input {
  flex: 1;
  border-radius: 10px;
  border: none;
  padding: 12px;
  background: var(--panel-light);
  color: var(--text);
  font-size: 14px;
}

#composer button {
  background: var(--accent);
  color: #0f0e1a;
  border: none;
  border-radius: 10px;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}

#composer button:disabled, #composer input:disabled { opacity: 0.5; cursor: not-allowed; }

#budget-banner {
  margin: 10px 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #2a1230;
  color: var(--accent-3);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

#preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#preview-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 3px solid var(--panel-light);
}

#preview-toolbar button {
  background: var(--panel-light);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}

#preview-toolbar button:hover { background: var(--accent-2); color: #0f0e1a; }

#preview-wrap {
  flex: 1;
  position: relative;
  background: #000;
}

#game-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

#preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

.typing-status {
  font-style: italic;
  animation: pulse-fade 1.4s ease-in-out infinite;
}
@keyframes pulse-fade { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* ---------- Leaderboard (login screen) ---------- */

#leaderboard {
  margin: 30px auto 0;
  width: 100%;
  max-width: 760px;
}

.lb-title {
  font-size: 14px;
  color: var(--accent);
  margin: 0 0 14px;
  letter-spacing: 0.5px;
}

#lb-boards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.lb-board {
  background: var(--panel);
  border: 2px solid var(--panel-light);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
}

.lb-board h3 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.4px;
}

.lb-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13px;
}

.lb-entry .lb-rank { width: 18px; color: var(--muted); font-size: 11px; }
.lb-entry .lb-av { font-size: 17px; }
.lb-entry .lb-name { flex: 1; font-weight: 700; }
.lb-entry .lb-val { color: var(--accent-2); font-weight: 800; }
.lb-entry.first .lb-name { color: var(--accent); }

.lb-empty { color: var(--muted); font-size: 12px; font-style: italic; }

.profile-card .badge-row {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.5;
  min-height: 20px;
}

.profile-card .streak-flame {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--accent-3);
  font-weight: 800;
}

/* ---------- Share modal ---------- */

.share-label, .share-section-title {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 6px;
}

#share-modal .modal { width: 400px; }

#share-title, #share-link {
  width: 100%;
  border-radius: 8px;
  border: none;
  padding: 10px;
  background: var(--panel-light);
  color: var(--text);
  font-size: 14px;
}

.share-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--panel-light);
}

.share-kid {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}

.share-kid:hover { background: var(--panel-light); }
.share-kid input { width: 16px; height: 16px; cursor: pointer; }
.share-kid .k-av { font-size: 20px; }

.share-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 0;
}

.share-toggle input { width: 16px; height: 16px; cursor: pointer; }

#share-link-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

#copy-link-btn {
  background: var(--accent-2);
  color: #0f0e1a;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 800;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.share-note {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.4;
}

#share-status {
  margin-top: 12px;
  font-size: 13px;
  color: var(--accent-2);
  font-weight: 700;
  min-height: 18px;
}

/* Badge celebration toast */
.badge-toast {
  align-self: center;
  background: linear-gradient(90deg, #2a2350, #3a2f6b);
  border: 2px solid var(--accent);
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
}

/* ---------- Code mode ---------- */

#code-panel {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: #0d0c16;
}

#code-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 2px solid var(--panel-light);
  flex-wrap: wrap;
}

#code-toolbar button {
  background: var(--panel-light);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

#code-toolbar button:hover { background: var(--accent-2); color: #0f0e1a; }
#code-toolbar #commit-btn { background: #1f7a3d; color: #eafff0; }
#code-toolbar #commit-btn:hover { background: #27ae60; }

#code-status { font-size: 12px; color: var(--accent-2); font-weight: 700; margin-left: auto; }

#code-view-wrap {
  flex: 1;
  overflow: auto;
  padding: 10px 0;
}

#code-view {
  margin: 0;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  counter-reset: codeline;
}

.code-line {
  display: block;
  white-space: pre;
  color: #c9d7ff; /* code: one color */
  padding: 0 14px 0 0;
}

.code-line::before {
  counter-increment: codeline;
  content: counter(codeline);
  display: inline-block;
  width: 44px;
  text-align: right;
  margin-right: 14px;
  color: #4a4869;
  user-select: none;
}

.code-note {
  display: block;
  white-space: pre-wrap;
  color: var(--accent); /* explanations: secondary color */
  font-style: italic;
  padding-left: 58px;
  opacity: 0.95;
}

#code-editor {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: #0d0c16;
  color: #c9d7ff;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  padding: 12px 14px;
  tab-size: 2;
}

#diff-view {
  flex: 1;
  overflow: auto;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  padding: 10px 0;
}

.diff-line { display: block; white-space: pre; padding: 0 14px; }
.diff-line.ctx { color: #6f6d94; }
.diff-line.add { background: rgba(46, 204, 113, 0.14); color: #7dffb0; }
.diff-line.del { background: rgba(231, 76, 60, 0.14); color: #ff9b8f; text-decoration: line-through; text-decoration-color: rgba(255,155,143,0.45); }
.diff-line.skip { color: #4a4869; text-align: center; font-style: italic; padding: 4px 0; }

#history-panel {
  flex: 1;
  overflow: auto;
  padding: 14px;
}

.version-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--panel-light);
  font-size: 13px;
}

.version-row .v-label { flex: 1; }
.version-row .v-time { color: var(--muted); font-size: 11px; }

.version-row button {
  background: var(--panel-light);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}

.version-row button:hover { background: var(--accent-2); color: #0f0e1a; }
.version-row.current .v-label::after { content: "  ← current"; color: var(--accent-2); font-weight: 700; }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--panel);
  border-radius: 14px;
  padding: 20px;
  width: 360px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal h2 { margin-top: 0; font-size: 16px; }

.game-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--panel-light);
}

.game-row .title { flex: 1; }

.game-row button {
  background: var(--panel-light);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}

.modal .close-btn {
  margin-top: 12px;
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #0f0e1a;
  border: none;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
}

/* ---------- Rank titles ---------- */

.hdr-rank {
  display: block;
  font-size: 11px;
  color: var(--accent-2);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.profile-card .rank-label {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--accent-2);
  font-weight: 700;
}


/* ---------- Surprise Me chip ---------- */

.surprise-chip {
  background: linear-gradient(90deg, var(--accent-3), var(--accent));
  color: #0f0e1a;
  font-weight: 800;
}

.surprise-chip:hover {
  background: var(--accent);
}

/* ---------- Badge gallery ---------- */

#badges-modal .modal { width: 420px; }

#badges-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.badge-card {
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  background: var(--panel-light);
  border: 2px solid transparent;
}

.badge-card.earned {
  border-color: var(--accent);
}

.badge-card.locked {
  opacity: 0.45;
}

.badge-card .badge-card-emoji {
  font-size: 32px;
  display: block;
}

.badge-card .badge-card-label {
  font-weight: 800;
  font-size: 12px;
  margin-top: 6px;
}

.badge-card .badge-card-hint {
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.3;
}

/* ---------- Badge celebration overlay ---------- */

#badge-celebration {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 14, 26, 0.75);
  pointer-events: none;
}

.badge-celebration-card {
  background: linear-gradient(160deg, #2a2350, #3a2f6b);
  border: 3px solid var(--accent);
  border-radius: 20px;
  padding: 32px 48px;
  text-align: center;
  animation: badge-pop 0.4s ease;
  box-shadow: 0 0 40px rgba(255, 210, 63, 0.5);
}

.badge-celebration-icon {
  font-size: 72px;
  line-height: 1;
}

.badge-celebration-title {
  margin-top: 10px;
  font-size: 14px;
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.badge-celebration-label {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
}

@keyframes badge-pop {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- QA / admin mode ---------- */

.qa-banner {
  display: inline-block;
  margin-left: 10px;
  background: var(--danger);
  color: #1a0505;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 8px;
  letter-spacing: 0.5px;
  vertical-align: middle;
}

#add-budget-btn {
  margin-left: 8px;
  background: var(--accent-2);
  color: #0f0e1a;
  border: none;
  border-radius: 8px;
  padding: 4px 10px;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
}

#add-budget-btn:hover {
  background: var(--accent);
}

/* ---------- Voice-to-text mic button ---------- */

#mic-btn {
  padding: 0 14px !important;
  font-size: 17px;
}

#mic-btn.listening {
  background: var(--danger);
  animation: mic-pulse 1.1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 90, 90, 0.55); }
  50% { box-shadow: 0 0 0 8px rgba(255, 90, 90, 0); }
}

/* ---------- Instructions button + modal ---------- */

/* Only present on a kid's very first login (per browser) -- see
   maybePulseInstructions in app.js -- and removed for good the first time
   they open it. */
#instructions-btn.pulsing {
  animation: instructions-pulse 1.3s ease-in-out infinite;
}

@keyframes instructions-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 209, 102, 0.6); }
  50% { box-shadow: 0 0 0 9px rgba(255, 209, 102, 0); }
}

#instructions-modal .modal {
  width: 440px;
}

#instructions-body p {
  margin: 0 0 12px;
  line-height: 1.5;
  font-size: 14px;
}

#instructions-body p:last-child {
  margin-bottom: 0;
}

#instructions-body a {
  color: var(--accent);
  font-weight: 700;
}
