/* Python Quest: mobile-first, works from 320px phones to wide laptop screens. */

:root {
  --bg: #f7f8fc;
  --bg-alt: #eef0f8;
  --surface: #ffffff;
  --text: #121629;
  --muted: #55607a;
  --border: #dde1ee;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-ink: #ffffff;
  --accent-soft: #e9e8ff;
  --ok: #0f7a45;
  --ok-soft: #e3f6ec;
  --bad: #c5221a;
  --bad-soft: #fdeceb;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --shadow: 0 10px 30px rgba(30, 41, 90, .08);
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --code-bg: #0e1330;
  --code-line: #1b2350;
  --code-text: #e8ecff;
  --code-dim: #8e99c4;
  --tok-kw: #c4a7ff;
  --tok-str: #86efac;
  --tok-num: #fbbf24;
  --tok-com: #8e99c4;
  --tok-bi: #7dd3fc;
  --tok-fn: #93c5fd;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --bg-alt: #0f1630;
    --surface: #141c3a;
    --text: #e8ecff;
    --muted: #9aa6cc;
    --border: #243058;
    --accent: #8b8dff;
    --accent-strong: #a5a7ff;
    --accent-ink: #0b1020;
    --accent-soft: #232a5c;
    --ok: #34d399;
    --ok-soft: #10281f;
    --bad: #ff8a80;
    --bad-soft: #321a1d;
    --warn: #fbbf24;
    --warn-soft: #302512;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --code-bg: #080c1f;
    --code-line: #151c40;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020;
  --bg-alt: #0f1630;
  --surface: #141c3a;
  --text: #e8ecff;
  --muted: #9aa6cc;
  --border: #243058;
  --accent: #8b8dff;
  --accent-strong: #a5a7ff;
  --accent-ink: #0b1020;
  --accent-soft: #232a5c;
  --ok: #34d399;
  --ok-soft: #10281f;
  --bad: #ff8a80;
  --bad-soft: #321a1d;
  --warn: #fbbf24;
  --warn-soft: #302512;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --code-bg: #080c1f;
  --code-line: #151c40;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: clamp(1.7rem, 5.5vw, 2.5rem); letter-spacing: -.01em; }
h2 { font-size: clamp(1.25rem, 3.8vw, 1.6rem); }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
a { color: var(--accent-strong); }
img { max-width: 100%; }
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
main:focus, h1[tabindex="-1"]:focus { outline: none; }
[hidden] { display: none !important; }

.skip { position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 10px; text-decoration: none; }
.skip:focus { top: 8px; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.top-in { max-width: 920px; margin: 0 auto; padding: 8px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 800; font-size: 1.05rem; min-height: 44px; min-width: 44px; white-space: nowrap; flex: none; }
:is(main h1, main h2, .fb, .btn, .opt, .piece, .tok) { scroll-margin-top: 84px; scroll-margin-bottom: 24px; }
.brand img { border-radius: 8px; }
.stats { display: flex; align-items: center; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: .9rem; white-space: nowrap; }
.chip-label { display: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 1.15rem; display: grid; place-items: center; }
.icon-btn:hover { border-color: var(--accent); }

/* ---------- layout ---------- */
main { width: 100%; max-width: 920px; margin: 0 auto; padding: 20px 16px 40px; flex: 1; }
.foot { text-align: center; color: var(--muted); font-size: .88rem; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); }
.foot p { margin: 0; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 14px 16px; }
.muted { color: var(--muted); }
.back { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; text-decoration: none; font-weight: 700; color: var(--accent-strong); }
.back:hover { text-decoration: underline; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 22px; border-radius: 14px; border: 2px solid var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 800; cursor: pointer; text-decoration: none; text-align: center; transition: transform .12s ease, filter .12s ease; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: transparent; color: var(--accent-strong); }
.btn.quiet { background: transparent; border-color: var(--border); color: var(--text); font-weight: 700; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; transform: none; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

progress { appearance: none; -webkit-appearance: none; width: 100%; height: 10px; border: 0; border-radius: 999px; background: var(--bg-alt); overflow: hidden; display: block; }
progress::-webkit-progress-bar { background: var(--bg-alt); border-radius: 999px; }
progress::-webkit-progress-value { background: linear-gradient(90deg, var(--accent), #c084fc); border-radius: 999px; }
progress::-moz-progress-bar { background: linear-gradient(90deg, var(--accent), #c084fc); border-radius: 999px; }

/* ---------- home ---------- */
.hero { background: linear-gradient(135deg, var(--accent-soft), var(--surface)); border: 1px solid var(--border); border-radius: 24px; padding: 24px 20px; box-shadow: var(--shadow); margin-bottom: 24px; }
.hero p { color: var(--muted); max-width: 56ch; }
.hero .meter { margin: 18px 0 6px; }
.hero .meter-label { font-size: .9rem; color: var(--muted); margin-bottom: 14px; }
.kinds { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 12px; margin: 0 0 28px; padding: 0; list-style: none; }
.kinds li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kinds b { display: block; margin-bottom: 4px; }
.kinds span { color: var(--muted); font-size: .92rem; }
.islands { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 14px; margin: 0 0 28px; padding: 0; list-style: none; }
.island { display: flex; flex-direction: column; gap: 8px; height: 100%; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease; }
a.island:hover { transform: translateY(-3px); border-color: var(--accent); }
.island.locked { opacity: .6; box-shadow: none; }
.island.done { border-color: var(--ok); }
.island .emoji { font-size: 2.1rem; line-height: 1; }
.island .name { font-weight: 800; font-size: 1.1rem; }
.island .blurb { color: var(--muted); font-size: .92rem; flex: 1; }
.island .meta { display: flex; justify-content: space-between; gap: 8px; font-size: .88rem; font-weight: 700; color: var(--muted); }
.stars { color: #d9a400; letter-spacing: 2px; white-space: nowrap; }
.stars .off { color: var(--border); }
.badge-box { text-align: center; background: linear-gradient(135deg, var(--warn-soft), var(--surface)); border: 2px solid #d9a400; border-radius: 24px; padding: 28px 18px; margin-bottom: 28px; }
.badge-box .big { font-size: 3.4rem; line-height: 1; }
.reset { text-align: center; margin-top: 8px; }
.linkish { background: none; border: 0; padding: 10px; color: var(--muted); text-decoration: underline; cursor: pointer; min-height: 44px; }

/* ---------- island page ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 22px; box-shadow: var(--shadow); }
.card h2 { margin-bottom: .6em; }
.card ul { margin: 0 0 14px; padding-left: 1.2em; }
.card li { margin-bottom: .5em; }
.island-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.island-head .emoji { font-size: 3rem; line-height: 1; }
.island-head p { margin: 0; color: var(--muted); }
.path { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 10px; }
.stop { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 60px; padding: 10px 14px; background: var(--surface); border: 2px solid var(--border); border-radius: 14px; text-align: left; text-decoration: none; color: var(--text); }
a.stop:hover { border-color: var(--accent); }
.stop.locked { opacity: .55; }
.stop.done { border-color: color-mix(in srgb, var(--ok) 60%, var(--border)); }
.stop .num { width: 38px; height: 38px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; font-weight: 800; }
.stop.done .num { background: var(--ok); color: var(--surface); }
.stop .label { flex: 1; font-weight: 700; }
.stop .kind { display: block; font-weight: 500; font-size: .85rem; color: var(--muted); }

/* ---------- code blocks ---------- */
.code { margin: 0 0 16px; background: var(--code-bg); color: var(--code-text); border-radius: 14px; padding: 12px 0; font-family: var(--mono); font-size: .92rem; line-height: 1.6; overflow-x: auto; border: 1px solid var(--code-line); direction: ltr; text-align: left; }
.code .line { display: flex; min-width: max-content; padding: 0 14px 0 0; }
.code .no { width: 2.6em; flex: none; text-align: right; padding-right: 1em; color: var(--code-dim); user-select: none; }
.code .src { white-space: pre; }
.k { color: var(--tok-kw); font-weight: 600; }
.s { color: var(--tok-str); }
.n { color: var(--tok-num); }
.c { color: var(--tok-com); font-style: italic; }
.b { color: var(--tok-bi); }
.f { color: var(--tok-fn); }
.term { margin: 0 0 16px; border-radius: 14px; border: 1px dashed var(--border); background: var(--bg-alt); padding: 10px 14px; direction: ltr; text-align: left; }
.term .tag { display: block; font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.term pre { margin: 0; font-family: var(--mono); font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- level ---------- */
.lvl-top { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; margin-bottom: 18px; }
.lvl-top .x { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; text-decoration: none; color: var(--text); font-weight: 800; }
.lvl-top .meter-label { font-size: .85rem; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.hearts { display: inline-flex; gap: 4px; font-size: 1.3rem; }
.heart { color: #e11d48; line-height: 1; }
.heart.lost { opacity: .25; filter: grayscale(1); }
.code .ans { font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.heart.pop { animation: pop .35s ease; }
.q { font-size: clamp(1.1rem, 3.8vw, 1.35rem); font-weight: 800; margin-bottom: 14px; }
.play.locked { pointer-events: none; }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 10px; margin-bottom: 16px; }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 14px; background: var(--surface); border: 2px solid var(--border); border-radius: 14px; text-align: left; cursor: pointer; font-family: var(--mono); font-size: .95rem; white-space: pre-wrap; overflow-wrap: anywhere; transition: border-color .12s ease, transform .12s ease; }
.opt:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.opt .ltr { flex: none; width: 28px; height: 28px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; font-family: var(--font); font-weight: 800; font-size: .85rem; }
.opt.good { border-color: var(--ok); background: var(--ok-soft); }
.opt.bad { border-color: var(--bad); background: var(--bad-soft); opacity: .8; }
.opt:disabled { cursor: default; }
.sub { font-weight: 700; margin: 4px 0 10px; }
.tools { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 16px; }

/* fill */
.blank { display: inline-block; min-width: 6ch; min-height: 40px; line-height: 1.2; padding: 8px .6em; margin: 2px .15em; vertical-align: middle; border: 0; border-bottom: 2px dashed var(--code-dim); border-radius: 6px 6px 0 0; background: rgba(139, 141, 255, .12); color: var(--tok-num); font: inherit; cursor: pointer; text-align: center; vertical-align: baseline; }
.blank.active { border-bottom: 2px solid var(--accent); background: rgba(139, 141, 255, .3); }
.blank.filled { border-bottom-style: solid; font-weight: 700; }
.pool { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 14px; }
.tok { min-height: 48px; min-width: 56px; padding: 8px 16px; background: var(--surface); border: 2px solid var(--border); border-radius: 12px; cursor: pointer; font-family: var(--mono); font-weight: 700; font-size: 1rem; }
.tok:hover:not(:disabled) { border-color: var(--accent); }
.tok:disabled { opacity: .3; cursor: default; }

/* bug */
.code .line.pick { width: 100%; background: none; border: 0; border-left: 4px solid transparent; padding: 6px 14px 6px 0; margin: 0; text-align: left; color: inherit; font: inherit; cursor: pointer; min-height: 40px; align-items: center; }
.code .line.pick:hover:not(:disabled) { background: rgba(139, 141, 255, .18); border-left-color: var(--accent); }
.code .line.pick:disabled { cursor: default; }
.code .line.pick.wrongpick { opacity: .45; text-decoration: line-through; text-decoration-color: var(--bad); }
.code .line.found { background: rgba(255, 138, 128, .18); border-left: 4px solid var(--bad); }
.code .line.fixed { background: rgba(52, 211, 153, .16); border-left: 4px solid var(--ok); }
.code .line { border-left: 4px solid transparent; }

/* order */
.stack { margin: 0 0 16px; background: var(--code-bg); border: 2px dashed var(--code-dim); border-radius: 14px; padding: 8px; min-height: 64px; display: grid; gap: 6px; align-content: start; }
.stack .hint-empty { color: var(--code-dim); font-size: .92rem; padding: 12px 6px; }
.piece { display: block; width: 100%; text-align: left; min-height: 46px; padding: 8px 12px; background: var(--code-bg); color: var(--code-text); border: 2px solid var(--code-line); border-radius: 10px; cursor: pointer; font-family: var(--mono); font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; direction: ltr; }
.piece:hover:not(:disabled) { border-color: var(--accent); }
.stack .piece { background: var(--code-line); }
.piece:disabled { cursor: default; }
.pieces { display: grid; gap: 8px; margin-bottom: 14px; }

/* feedback + hints */
.fb { border-radius: 14px; padding: 14px 16px; margin: 14px 0; border-left: 6px solid var(--accent); background: var(--accent-soft); }
.fb.good { border-color: var(--ok); background: var(--ok-soft); }
.fb.bad { border-color: var(--bad); background: var(--bad-soft); }
.fb p { margin: 0 0 .6em; }
.fb p:last-child { margin-bottom: 0; }
.fb strong.title { display: block; margin-bottom: 4px; }
.hint-list { margin: 0 0 14px; padding: 0; list-style: none; display: grid; gap: 8px; }
.hint-list li { background: var(--warn-soft); color: var(--text); border-left: 6px solid #d9a400; border-radius: 12px; padding: 10px 14px; }
.hint-list b { color: var(--warn); }
.result-stars { font-size: 1.6rem; margin: 6px 0; }
.shake { animation: shake .35s ease; }
.celebrate { text-align: center; padding: 28px 12px; }
.celebrate .big { font-size: 3.6rem; line-height: 1; animation: pop .5s ease; }
.celebrate p { color: var(--muted); }
.celebrate .row { justify-content: center; margin-top: 8px; }

@keyframes pop { 0% { transform: scale(.7); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ---------- larger screens ---------- */
@media (min-width: 600px) {
  main { padding: 28px 24px 56px; }
  .top-in { padding-left: 24px; padding-right: 24px; }
  .chip-label { display: inline; }
  .hero { padding: 36px 32px; }
  .code { font-size: 1rem; }
  .card { padding: 24px; }
}
@media (min-width: 900px) {
  .islands { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 440px) {
  .top-in { gap: 6px; }
  .brand { gap: 8px; font-size: .95rem; }
  .stats { gap: 6px; }
  .chip { padding: 5px 9px; font-size: .82rem; }
}
@media (max-width: 359px) {
  /* logo only on very narrow phones; the link keeps its accessible name */
  .brand-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .code { font-size: .85rem; }
}

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