:root {
  --bg: #14121f;
  --card: #1f1c30;
  --card-2: #2a2640;
  --text: #f1eefc;
  --muted: #a49ec0;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --danger: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}
.topbar h1 { font-size: 1.25rem; margin: 0; }

main { padding: 0 16px 32px; max-width: 720px; margin: 0 auto; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.label { font-weight: 600; font-size: 0.95rem; }

textarea, input {
  width: 100%;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px;
  font: inherit;
  font-size: 16px; /* stops iOS zoom on focus */
  resize: vertical;
}
textarea:focus, input:focus { outline: none; border-color: var(--accent); }

button { font: inherit; cursor: pointer; border: 0; }

.primary {
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  color: white;
  padding: 14px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1rem;
}
.primary:disabled { opacity: 0.5; }
.secondary {
  background: var(--card-2);
  color: var(--text);
  padding: 14px 18px;
  border-radius: 12px;
}
.link { background: none; color: var(--accent-2); padding: 4px; }
.icon-btn {
  background: var(--card-2);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  font-size: 1.1rem;
  flex: none;
}

.stack { display: flex; flex-direction: column; gap: 12px; }

.quiz { display: flex; flex-direction: column; gap: 12px; animation: pop 0.25s ease-out; }
.quiz-q { font-size: 1.2rem; font-weight: 700; margin: 0; line-height: 1.35; }
.quiz-options { display: grid; gap: 10px; }
.quiz-option {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: var(--card-2);
  color: var(--text);
  padding: 14px;
  border-radius: 12px;
  font-size: 1rem;
  border: 2px solid transparent;
}
.quiz-option:active { border-color: var(--accent-2); transform: scale(0.98); }
.quiz-option .emoji { font-size: 1.6rem; flex: none; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.chip {
  flex: none;
  background: var(--card-2);
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
}

.progress { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid var(--card-2);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error { color: var(--danger); margin: 0; white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.muted a { color: var(--accent-2); }

.section-title { font-size: 1.05rem; margin: 24px 0 8px; }

.gallery { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.game-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.game-item .info { flex: 1; min-width: 0; }
.game-item .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-item .desc { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-item .play { padding: 10px 14px; }

.player {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  z-index: 10;
  overflow: hidden;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.player-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
}
.player-title { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#frame { flex: 1; min-height: 0; width: 100%; border: 0; background: #000; display: block; }

.tweak {
  flex: none;
  background: var(--bg);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tweak-actions { display: flex; justify-content: flex-end; }

dialog {
  background: var(--card);
  color: var(--text);
  border: 0;
  border-radius: var(--radius);
  width: min(92vw, 440px);
  padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.settings-form { display: flex; flex-direction: column; gap: 10px; }
.settings-form h2 { margin: 0 0 4px; }
.row { display: flex; gap: 10px; justify-content: flex-end; }

[hidden] { display: none !important; }

/* ---------- Professor ---------- */
.stage {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}
.professor { width: 120px; flex: none; }
.prof-svg { width: 100%; height: auto; display: block; overflow: visible; }
.bubble {
  position: relative;
  flex: 1;
  min-height: 72px;
  margin-bottom: 70px;
  background: #fff;
  color: #1e1b2e;
  border-radius: 18px;
  padding: 12px 14px;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.bubble::before {
  content: "";
  position: absolute;
  left: -10px;
  bottom: 16px;
  border: 10px solid transparent;
  border-right-color: #fff;
  border-left: 0;
}
.bubble .reaction { display: block; color: #7c3aed; margin-bottom: 6px; }

.prof-head { transform-origin: 100px 160px; animation: bob 2.8s ease-in-out infinite; }
.prof-hair { transform-origin: 100px 90px; animation: hair 1.6s ease-in-out infinite; }
.prof-lids rect { transform-box: fill-box; transform-origin: top; transform: scaleY(0); animation: blink 4.5s infinite; }
.prof-mouth { transform-box: fill-box; transform-origin: center; transform: scaleY(0.5); }
.prof-pupils { transition: transform 0.3s; }
.prof-brows path { transition: transform 0.3s; }
.prof-sparks, .prof-think { opacity: 0; transition: opacity 0.3s; }

[data-mood="talking"] .prof-mouth { animation: talk 0.18s ease-in-out infinite alternate; }

[data-mood="thinking"] .prof-head { animation: ponder 1.8s ease-in-out infinite; }
[data-mood="thinking"] .prof-pupils { transform: translate(6px, -8px); }
[data-mood="thinking"] .brow-r { transform: translateY(-8px); }
[data-mood="thinking"] .prof-think { opacity: 1; animation: float 1.2s ease-in-out infinite alternate; }

[data-mood="laughing"] .prof-head { animation: laugh 0.25s ease-in-out infinite alternate; }
[data-mood="laughing"] .prof-mouth { transform: scaleY(1.3); }
[data-mood="laughing"] .prof-lids rect { animation: none; transform: scaleY(0.55); }

[data-mood="working"] .prof-head { animation: shake 0.4s ease-in-out infinite; }
[data-mood="working"] .prof-hair { animation: zap 0.2s steps(2) infinite; }
[data-mood="working"] .prof-sparks { opacity: 1; animation: flicker 0.3s steps(2) infinite; }
[data-mood="working"] .prof-pupils { animation: dart 1s ease-in-out infinite; }
[data-mood="working"] .prof-mouth { transform: scaleY(1); }

@keyframes bob { 50% { transform: translateY(-4px) rotate(-1deg); } }
@keyframes hair { 50% { transform: scale(1.03) rotate(1deg); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(0); } 97% { transform: scaleY(1); } }
@keyframes talk { from { transform: scaleY(0.3); } to { transform: scaleY(1.2); } }
@keyframes ponder { 50% { transform: rotate(-6deg); } }
@keyframes float { to { transform: translateY(-6px); } }
@keyframes laugh { from { transform: rotate(-4deg) translateY(0); } to { transform: rotate(4deg) translateY(-6px); } }
@keyframes shake { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
@keyframes zap { 50% { transform: scale(1.08) rotate(-2deg); } }
@keyframes flicker { 50% { opacity: 0.2; } }
@keyframes dart { 25% { transform: translate(-6px, 0); } 75% { transform: translate(6px, 2px); } }

.answer-row { display: flex; gap: 8px; }
.answer-row input { flex: 1; min-width: 0; }
.answer-row .primary { padding: 12px 16px; }

@media (prefers-reduced-motion: reduce) {
  .prof-svg *, .quiz { animation: none !important; }
}

dialog.shake { animation: shake-dialog 0.35s; }
@keyframes shake-dialog { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

.version { color: var(--muted); font-size: 0.75rem; margin-top: 2px; }
.update-banner {
  display: block;
  width: calc(100% - 32px);
  margin: 0 16px 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--accent-2);
  color: #062a30;
  font-weight: 700;
}
#apkLink a { color: var(--accent-2); font-weight: 700; }

.publish-status { background: var(--card-2); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.publish-status a { color: var(--accent-2); font-weight: 700; }
.publish-status .step { display: flex; gap: 8px; align-items: center; }
#keep b { color: var(--text); }

.live { display: flex; flex-direction: column; gap: 6px; }
.live-bar { height: 10px; border-radius: 999px; background: var(--card-2); overflow: hidden; }
.live-bar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.6s ease;
}
.live-label { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.live pre {
  margin: 0; padding: 10px; border-radius: 10px; background: #0d0b16;
  font-size: 0.72rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word;
  overflow-y: auto; max-height: 140px;
}
.live-thinking { color: #d8d0ff; font-style: italic; }
.live-code { color: #7ee7c7; font-family: ui-monospace, Menlo, monospace; min-height: 3em; }
.live-code:empty::before { content: "Waiting for the first line of code…"; color: var(--muted); }
.tweak .live pre { max-height: 70px; }

.resume { background: var(--card-2); border: 2px solid var(--accent-2); border-radius: 12px; padding: 12px; }
.resume p { margin: 0 0 10px; }
.live-frame { width: 100%; height: 300px; border: 0; border-radius: 10px; background: #000; display: block; pointer-events: none; }
.tweak .live-frame { height: 160px; }
.live-stage { color: var(--accent-2); font-weight: 700; font-size: 0.85rem; }

.locked main, .locked .stage, .locked #settingsBtn, .locked #updateBanner { visibility: hidden; }
.admin { background: var(--card-2); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.admin[open] { padding-bottom: 14px; }
.admin summary { font-weight: 700; cursor: pointer; }
.admin > * + * { margin-top: 8px; }
.admin input { background: var(--card); }
#adminStatus.ok { color: #6ee7b7; }
.live-art { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.live-art figure { margin: 0; background: repeating-conic-gradient(#2a2640 0 25%, #1f1c30 0 50%) 0 0 / 16px 16px; border-radius: 10px; padding: 6px; display: grid; place-items: center; aspect-ratio: 1; }
.live-art img { max-width: 100%; max-height: 100%; animation: pop 0.3s ease-out; }
.live-art figure.bg { grid-column: span 3; aspect-ratio: 16 / 9; padding: 0; overflow: hidden; }
.live-art figure.bg img { width: 100%; height: 100%; object-fit: cover; }
