/* ==========================================================================
   SparkCode Adventures - shared styles
   ========================================================================== */
:root {
  --ink: #2b1d5c;
  --ink-soft: #5a4b8f;
  --paper: #fffaf0;
  --sky-1: #8fd8ff;
  --sky-2: #c9b8ff;
  --purple: #6c4ce0;
  --purple-dark: #4b31b0;
  --yellow: #ffcf3f;
  --yellow-dark: #e0a800;
  --coral: #ff6b6b;
  --coral-dark: #d94848;
  --teal: #2ec4b6;
  --teal-dark: #1e9488;
  --pink: #ff6b9a;
  --green: #1fbf75;
  --green-dark: #148f56;
  --card: #ffffff;
  --radius: 22px;
  --shadow: 0 8px 0 rgba(43, 29, 92, 0.18);
  --font-display: 'Baloo 2', 'Trebuchet MS', 'Comic Sans MS', sans-serif;
  --font-body: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  --font-code: 'JetBrains Mono', 'Cascadia Code', Consolas, 'Courier New', monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; }
html { background: var(--sky-2); }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.7) 0 60px, transparent 61px),
    radial-gradient(circle at 18% 16%, rgba(255, 255, 255, 0.7) 0 44px, transparent 45px),
    radial-gradient(circle at 82% 10%, rgba(255, 255, 255, 0.6) 0 50px, transparent 51px),
    linear-gradient(180deg, var(--sky-1), var(--sky-2));
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.1; margin: 0 0 0.4em; }

a { color: var(--purple); }

code {
  font-family: var(--font-code);
  background: #f1ecff;
  color: var(--purple-dark);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.88em;
}

img { max-width: 100%; }

[hidden] { display: none !important; }

:focus-visible { outline: 4px solid var(--yellow); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--purple);
  --btn-edge: var(--purple-dark);
  --btn-fg: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 0.65em 1.2em 0.55em;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-yellow { --btn-bg: var(--yellow); --btn-fg: var(--ink); }
.btn-green { --btn-bg: var(--green); }
.btn-coral { --btn-bg: var(--coral); }
.btn-teal { --btn-bg: var(--teal); }
.btn-white { --btn-bg: #fff; --btn-fg: var(--ink); }
.btn-big { font-size: 1.4rem; padding: 0.7em 1.5em 0.6em; }
.btn-small { font-size: 0.92rem; padding: 0.5em 0.9em 0.42em; box-shadow: 0 3px 0 var(--ink); border-width: 2.5px; }
.btn-small:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn-icon { padding: 0.5em; width: 2.6em; height: 2.6em; }

/* ---------- Brand ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.45rem;
  color: var(--ink);
  text-decoration: none;
}
.brand img { width: 38px; height: 38px; }
.brand span b { color: var(--purple); }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ==========================================================================
   Home page
   ========================================================================== */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
}
.site-header nav { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.hero {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  align-items: center;
  gap: 2rem;
  max-width: 1150px;
  margin: 0 auto;
  padding: 2rem clamp(1rem, 4vw, 3rem) 3rem;
}
.hero h1 {
  font-size: clamp(2.3rem, 5.5vw, 4rem);
  color: var(--ink);
  text-shadow: 0 4px 0 rgba(255, 255, 255, 0.7);
}
.hero h1 .pop { color: var(--purple); }
.hero p.lead { font-size: 1.25rem; max-width: 34em; line-height: 1.5; }
.hero-actions { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 1.5rem; }
.hero-art { position: relative; text-align: center; padding-top: 3.5rem; }
.hero-art .zip { width: min(320px, 70vw); animation: bob 3s ease-in-out infinite; }
.hero-art .bubble {
  position: absolute;
  top: 0;
  left: 50%;
  white-space: nowrap;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 20px;
  padding: 0.6rem 1rem;
  font-family: var(--font-display);
  font-weight: 700;
  box-shadow: var(--shadow);
  transform: translateX(-50%) rotate(-3deg);
}
.hero-art .orbit { position: absolute; font-size: 2.6rem; animation: bob 4s ease-in-out infinite; }
.hero-art .orbit.o1 { right: 4%; top: 12%; animation-delay: -1s; }
.hero-art .orbit.o2 { left: 6%; bottom: 14%; animation-delay: -2s; }
.hero-art .orbit.o3 { right: 12%; bottom: 4%; animation-delay: -3s; }

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

.section {
  max-width: 1150px;
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 4vw, 3rem) 3rem;
}
.section-title { text-align: center; font-size: clamp(1.8rem, 4vw, 2.6rem); }
.section-sub { text-align: center; font-size: 1.1rem; margin: 0 auto 2rem; max-width: 40em; }

.steps-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.step-card { padding: 1.4rem; text-align: center; }
.step-card .num {
  display: inline-grid;
  place-items: center;
  width: 3.2rem;
  height: 3.2rem;
  font-size: 1.8rem;
  border-radius: 50%;
  border: 3px solid var(--ink);
  margin-bottom: 0.6rem;
}
.step-card p { margin: 0; line-height: 1.45; }

/* Treasure map of islands */
.map {
  background:
    radial-gradient(ellipse at 20% 30%, rgba(255, 255, 255, 0.25), transparent 50%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.05) 0 14px, transparent 14px 28px),
    linear-gradient(180deg, #3cb6e3, #1f7fc9);
  border: 3px solid var(--ink);
  border-radius: 32px;
  padding: clamp(1rem, 3vw, 2rem);
  box-shadow: var(--shadow);
}
.islands { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.island {
  background: #fff8e1;
  border: 3px solid var(--ink);
  border-radius: 28px 28px 22px 22px;
  padding: 1rem;
  position: relative;
}
.island-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.6rem; }
.island-head .badge {
  font-size: 1.8rem;
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 3px solid var(--ink);
}
.island-head h3 { margin: 0; font-size: 1.35rem; }
.island-head small { display: block; color: var(--ink-soft); font-weight: 700; }
.quest-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.55rem; }
.quest-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  padding: 0.55rem 0.7rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  transition: transform 0.1s;
}
.quest-link:hover { transform: translateX(4px) rotate(-0.5deg); }
.quest-link .q-emoji { font-size: 1.6rem; }
.quest-link .q-text small { display: block; font-weight: 600; color: var(--ink-soft); }
.quest-link .done { margin-left: auto; font-size: 1.2rem; }

.parents { padding: 1.5rem; display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.parents ul { margin: 0; padding-left: 1.2rem; line-height: 1.7; }

.little-banner {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 1.2rem 1.5rem;
  color: var(--ink);
  text-decoration: none;
  background: linear-gradient(120deg, #fff3b8, #ffd6e7);
}
.little-banner h2 { margin: 0 0 0.2rem; font-size: 1.6rem; }
.little-banner .lb-art { font-size: 3rem; }
.little-banner .btn { margin-left: auto; }
@media (max-width: 640px) { .little-banner { flex-direction: column; text-align: center; } .little-banner .btn { margin: 0; } }

.site-footer { text-align: center; padding: 2rem 1rem 3rem; color: var(--ink-soft); font-weight: 700; }

/* ==========================================================================
   Studio
   ========================================================================== */
body.studio-page { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 1rem;
  background: rgba(255, 255, 255, 0.85);
  border-bottom: 3px solid var(--ink);
  flex-wrap: wrap;
}
.topbar .brand { font-size: 1.2rem; }
.topbar .brand img { width: 32px; height: 32px; }
.title-input {
  flex: 1 1 180px;
  min-width: 0;
  max-width: 340px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ink);
  border: 2.5px dashed var(--ink-soft);
  border-radius: 12px;
  padding: 0.35rem 0.7rem 0.25rem;
  background: #fff;
}
.title-input:focus { border-style: solid; border-color: var(--purple); outline: none; }
.topbar-actions { display: flex; gap: 0.5rem; margin-left: auto; flex-wrap: wrap; }

.studio {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
}
.pane { min-height: 0; display: flex; flex-direction: column; gap: 0.8rem; }

/* Quest card */
.quest-card { padding: 0.8rem 1rem; }
.quest-card-head { display: flex; align-items: center; gap: 0.6rem; }
.quest-card-head .q-emoji { font-size: 1.9rem; }
.quest-card-head h2 { font-size: 1.3rem; margin: 0; }
.quest-card-head small { color: var(--ink-soft); font-weight: 700; }
.quest-card-head .spacer { flex: 1; }
.quest-card-body { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 0.6rem; font-size: 0.95rem; }
.quest-card-body h3 { font-size: 1rem; margin-bottom: 0.3rem; }
.quest-card-body ol, .quest-card-body ul { margin: 0; padding-left: 1.2rem; line-height: 1.5; }
.quest-card.is-collapsed .quest-card-body { display: none; }
.try-list li::marker { content: '⭐ '; }

/* Editor */
.editor-wrap { flex: 1; min-height: 180px; display: flex; overflow: hidden; padding: 0; }
.editor {
  --code-size: 15px;
  --code-line: 1.6;
  flex: 1;
  display: flex;
  min-width: 0;
  background: #1f1640;
  border-radius: calc(var(--radius) - 4px);
  overflow: hidden;
  font-family: var(--font-code);
  font-size: var(--code-size);
  line-height: var(--code-line);
}
.editor-gutter {
  flex: 0 0 auto;
  min-width: 3em;
  padding: 14px 10px 14px 6px;
  text-align: right;
  color: #8a7cc4;
  background: #170f33;
  overflow: hidden;
  user-select: none;
}
.editor-gutter .is-error { background: var(--coral); color: #fff; border-radius: 6px; }
.editor-body { position: relative; flex: 1; min-width: 0; }
.editor-highlight, .editor-input {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 14px 16px;
  border: 0;
  font: inherit;
  line-height: inherit;
  letter-spacing: 0;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  word-wrap: normal;
}
.editor-highlight { color: #f4efff; pointer-events: none; }
.editor-highlight code { font: inherit; background: none; color: inherit; padding: 0; border-radius: 0; }
.editor-input {
  color: transparent;
  background: transparent;
  caret-color: var(--yellow);
  resize: none;
  outline: none;
}
.editor-input::selection { background: rgba(255, 207, 63, 0.35); color: transparent; }
.tk-comment { color: #8fd18f; font-style: italic; }
.tk-string { color: #ffd479; }
.tk-number { color: #ff9ec0; }
.tk-keyword { color: #c59bff; font-weight: 700; }
.tk-api { color: #6fe3ff; font-weight: 700; }
.tk-method { color: #7ef0c6; }
.tk-bracket { color: #ffffff; }

/* Messages box */
.messages {
  padding: 0.6rem 0.9rem;
  min-height: 3.2rem;
  max-height: 9rem;
  overflow: auto;
  font-weight: 700;
}
.messages .msg { display: flex; gap: 0.5rem; align-items: flex-start; padding: 0.15rem 0; }
.messages .msg-error { color: var(--coral-dark); }
.messages .msg-ok { color: var(--green-dark); }
.messages .msg-log { color: var(--ink-soft); font-family: var(--font-code); font-weight: 500; font-size: 0.9rem; }

/* Play pane */
.play-toolbar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.play-toolbar .spacer { flex: 1; }
.stage {
  position: relative;
  flex: 1;
  min-height: 260px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.35), transparent 60%),
    linear-gradient(160deg, #4b31b0, #2b1d5c);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.stage .game-frame { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); border: 0; background: transparent; }
.stage-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.6rem;
  color: #fff;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.3rem;
  padding: 1rem;
}
.stage-placeholder img { width: 120px; animation: bob 3s ease-in-out infinite; }

/* Share card */
.share-card { display: flex; gap: 1rem; align-items: center; padding: 0.8rem 1rem; }
.share-card .qr {
  flex: 0 0 auto;
  width: 120px;
  height: 120px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.share-card .qr img, .share-card .qr svg { width: 100%; height: 100%; display: block; }
.share-card .qr .qr-empty { font-size: 2.6rem; opacity: 0.4; }
.share-info { flex: 1; min-width: 0; }
.share-info h3 { font-size: 1.15rem; margin-bottom: 0.2rem; }
.share-info p { margin: 0 0 0.5rem; font-size: 0.95rem; line-height: 1.35; }
.share-url {
  display: block;
  font-family: var(--font-code);
  font-size: 0.85rem;
  background: #f1ecff;
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.5rem;
  color: var(--purple-dark);
}
.share-buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.phone-help { margin-top: 0.5rem; font-size: 0.9rem; text-align: left; }
.phone-help summary { cursor: pointer; font-weight: 800; color: var(--purple-dark); }
.phone-help ul { margin: 0.4rem 0 0; padding-left: 1.2rem; line-height: 1.45; }

.mobile-tabs { display: none; }

/* Drawers */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 10, 50, 0.45);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 100vw);
  background: var(--paper);
  border-left: 3px solid var(--ink);
  z-index: 50;
  transform: translateX(105%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
.drawer.is-open { transform: none; }
.drawer.is-open + .drawer-backdrop, .drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; gap: 0.6rem; padding: 0.9rem 1rem; border-bottom: 3px solid var(--ink); background: #fff; }
.drawer-head h2 { margin: 0; font-size: 1.4rem; flex: 1; }
.drawer-tabs { display: flex; gap: 0.5rem; padding: 0.7rem 1rem 0; }
.drawer-tabs button[aria-selected='true'] { --btn-bg: var(--yellow); --btn-fg: var(--ink); }
.drawer-body { overflow: auto; padding: 1rem; flex: 1; }

.cmd-group h3 { font-size: 1.15rem; margin: 0.8rem 0 0.5rem; }
.cmd { background: #fff; border: 2.5px solid var(--ink); border-radius: 14px; padding: 0.6rem 0.7rem; margin-bottom: 0.55rem; }
.cmd pre { margin: 0.35rem 0; font-family: var(--font-code); font-size: 0.85rem; background: #1f1640; color: #f4efff; padding: 0.5rem 0.6rem; border-radius: 10px; overflow: auto; }
.cmd p { margin: 0; font-size: 0.92rem; }
.cmd-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.cmd-top strong { font-family: var(--font-code); color: var(--purple-dark); }

.sprite-search { width: 100%; font: inherit; font-weight: 700; padding: 0.55rem 0.8rem; border: 2.5px solid var(--ink); border-radius: 12px; margin-bottom: 0.8rem; }
.sprite-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 0.5rem; }
.sprite-tile {
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  padding: 0.4rem 0.2rem;
  text-align: center;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
.sprite-tile:hover { background: #fff3c4; }
.sprite-tile .pic { display: block; font-size: 2rem; line-height: 1.2; }
.sprite-tile .pic img { width: 34px; height: 34px; }
.sprite-tile .nm { display: block; font-size: 0.78rem; font-weight: 800; word-break: break-all; }

.quest-drawer-list .island { margin-bottom: 1rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 250%);
  visibility: hidden;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  padding: 0.7rem 1.2rem;
  border-radius: 999px;
  z-index: 60;
  transition: transform 0.25s ease;
}
.toast.is-shown { transform: translate(-50%, 0); visibility: visible; }

/* ==========================================================================
   Play page (shared game, phone friendly)
   ========================================================================== */
body.play-page {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: linear-gradient(160deg, #4b31b0, #2b1d5c);
  overscroll-behavior: none;
}
.play-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  padding-top: max(0.5rem, env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 3px solid var(--ink);
}
.play-bar h1 { font-size: 1.15rem; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play-bar .brand img { width: 30px; height: 30px; }
.play-stage { position: relative; flex: 1; min-height: 0; }
.play-stage .game-frame { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); border: 0; }
.play-message { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 1rem; color: #fff; text-align: center; padding: 1.5rem; font-family: var(--font-display); font-size: 1.3rem; }
.play-message img { width: 110px; }
.play-error {
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 0.6rem 0.9rem;
  font-weight: 800;
  color: var(--coral-dark);
}

/* Guide page */
.guide { max-width: 900px; margin: 0 auto; padding: 1rem clamp(1rem, 4vw, 2rem) 3rem; }
.guide .card { padding: 1.4rem; margin-bottom: 1.25rem; }
.guide .cmd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.6rem; }
.guide ol, .guide ul { line-height: 1.7; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; text-align: center; }
  .hero p.lead { margin-left: auto; margin-right: auto; }
  .hero-actions { justify-content: center; }
  .islands, .steps-row, .parents { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .topbar { flex-wrap: nowrap; gap: 0.5rem; padding: 0.5rem 0.7rem; }
  .topbar .brand span { display: none; }
  .title-input { flex: 1 1 80px; font-size: 1rem; }
  .topbar-actions { flex-wrap: nowrap; gap: 0.35rem; }
  .topbar-actions .btn { padding: 0.45em 0.6em 0.4em; }
  .topbar-actions .label { display: none; }
  .mobile-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 0.6rem 1rem 0;
  }
  .mobile-tabs [role='tab'] { flex: 1; }
  .mobile-tabs button[aria-selected='true'] { --btn-bg: var(--yellow); --btn-fg: var(--ink); }
  .studio { grid-template-columns: 1fr; padding: 0.7rem; }
  #run { display: none; }
  .studio[data-tab='code'] .pane-play, .studio[data-tab='play'] .pane-code { display: none; }
  .quest-card-body { grid-template-columns: 1fr; }
  .editor { --code-size: 14px; }
}

@media (max-width: 520px) {
  .share-card { flex-direction: column; text-align: center; }
  .share-buttons { justify-content: center; }
  .site-header nav .btn-white { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
