/* Funke – look inspired by the Steam client: grey, flat, Motiva/Arial, blue & green accents
   The whole page scrolls (no position:fixed shell, no inner scroll containers) and the bars are sticky.
   On iPhone a fixed shell with inner scrolling made tap targets drift away from the buttons after scrolling. */
:root {
  --head: #171a21;
  --bg: #1f2226;
  --bg2: #2a2e34;
  --card: #32363d;
  --line: #3d424a;
  --text: #dcdedf;
  --muted: #8f98a0;
  --yellow: #e8c547;
  --yellow-d: #9c7f12;
  --green: #a4d007;
  --green-d: #4c6b22;
  --green-bg: #22301a;
  --red: #e2504c;
  --red-d: #8f2a27;
  --red-bg: #3a2023;
  --blue: #66c0f4;
  --blue-d: #1a9fff;
  --btn-green: linear-gradient(to right, #75b022 5%, #588a1b 95%);
  --btn-green-h: linear-gradient(to right, #8ed629 5%, #6aa621 95%);
  --btn-blue: linear-gradient(to right, #47bfff 5%, #1a44c2 95%);
  --font: "Motiva Sans", Arial, Helvetica, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --r: 4px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 var(--font);
  overscroll-behavior: none; -webkit-user-select: none; user-select: none;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; -webkit-touch-callout: none; }
input { font: inherit; -webkit-user-select: text; user-select: text; }
#haptic { position: fixed; left: -100px; top: 0; opacity: 0; pointer-events: none; }
#app { position: relative; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; background: var(--bg); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0;
  padding: calc(var(--safe-t) + 10px) 18px 10px; display: flex; justify-content: space-between; align-items: center;
  background: var(--head); border-bottom: 1px solid #000; box-shadow: 0 1px 0 rgba(255,255,255,.04); z-index: 10;
}
.stat { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 16px; }
.stat svg { width: 22px; height: 22px; }
.stat.off { opacity: .4; }

.scroll { flex: 1; padding-bottom: 30px; }

/* ---------- Tabbar ---------- */
.tabbar {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; background: var(--head); border-top: 1px solid #000;
  padding: 4px 8px calc(var(--safe-b) + 4px);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 6px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; border-top: 2px solid transparent; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--text); border-top-color: var(--blue); }
.tab.on svg { color: var(--blue); }

/* ---------- Learning path ---------- */
.unit-head {
  margin: 20px 12px 6px; padding: 14px 16px; border-radius: var(--r);
  background: linear-gradient(90deg, color-mix(in srgb, var(--uc) 28%, var(--bg2)) 0%, var(--bg2) 75%);
  border-left: 4px solid var(--uc);
}
.unit-head small { display: block; font-weight: 600; color: var(--uc); text-transform: uppercase; font-size: 11px; letter-spacing: 1.6px; }
.unit-head b { font-size: 20px; display: block; font-weight: 700; color: #fff; text-transform: uppercase; letter-spacing: .6px; margin: 2px 0; }
.unit-head span { font-size: 14px; color: var(--muted); }
.path { position: relative; display: flex; flex-direction: column; align-items: center; padding: 14px 0 6px; }
.node-wrap { position: relative; height: 90px; width: 100%; display: flex; justify-content: center; }
.node-wrap.quiz { height: 104px; }
.node {
  position: absolute; width: 64px; height: 64px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.25), 0 4px 10px rgba(0,0,0,.4);
  transition: transform .08s, filter .15s;
}
.node:active { filter: brightness(1.15); }
.node svg { width: 30px; height: 30px; }
.node.quiz { width: 78px; height: 78px; border-radius: 8px; }
.node.quiz svg { width: 38px; height: 38px; }
.node.locked { background: linear-gradient(160deg, #3a3f46, #2b2f35); color: #5e656d; }
.node.done { color: #10132a; }
.node.current::after {
  content: ""; position: absolute; inset: -7px; border-radius: 9px; border: 2px solid var(--c);
  opacity: .6; animation: pulse 1.6s infinite;
}
.node.quiz.current::after { border-radius: 11px; }
@keyframes pulse { 0% { transform: scale(.94); opacity: .8 } 100% { transform: scale(1.14); opacity: 0 } }
.start-tag {
  position: absolute; top: -36px; left: 50%; transform: translateX(-50%); background: var(--btn-blue); color: #fff;
  font-weight: 700; font-size: 11px; letter-spacing: 1.2px; padding: 5px 10px; border-radius: 2px; white-space: nowrap; animation: bob 1.4s ease-in-out infinite;
}
.start-tag::after { content: ""; position: absolute; bottom: -5px; left: 50%; margin-left: -5px; border: 5px solid transparent; border-top-color: #2f7fe0; border-bottom: 0; }
@keyframes bob { 50% { transform: translate(-50%, -4px) } }

/* Lesson popover */
.pop-bg { position: fixed; inset: 0; z-index: 20; }
.pop {
  position: fixed; left: 50%; transform: translateX(-50%); width: min(340px, calc(100% - 32px));
  border-radius: var(--r); padding: 16px; z-index: 21; background: var(--card); color: var(--text);
  border-top: 3px solid var(--uc, var(--blue)); box-shadow: 0 12px 40px rgba(0,0,0,.6);
  animation: popin .15s ease-out;
}
@keyframes popin { from { opacity: 0; transform: translateX(-50%) scale(.96) } }
.pop h3 { margin: 0 0 4px; font-size: 17px; text-transform: uppercase; letter-spacing: .6px; color: #fff; }
.pop p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: block; width: 100%; padding: 14px; border-radius: 2px; font-weight: 600; font-size: 15px;
  letter-spacing: 1.2px; text-transform: uppercase; background: var(--btn-green); color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,.3); transition: filter .1s;
}
.btn:active:not(:disabled) { background: var(--btn-green-h); }
.btn:disabled { background: #3d424a; color: #6b737c; text-shadow: none; }
.btn.green { background: var(--btn-green); }
.btn.red { background: linear-gradient(to right, #d9534f 5%, #a83a36 95%); }
.btn.white { background: var(--btn-blue); }
.btn.ghost { background: transparent; color: var(--blue); text-shadow: none; }

/* ---------- Lesson ---------- */
.lesson { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.lesson-top { position: sticky; top: 0; z-index: 10; padding: calc(var(--safe-t) + 12px) 16px 10px; display: flex; align-items: center; gap: 12px; background: var(--head); }
.x { width: 30px; height: 30px; color: var(--muted); flex: none; }
.bar { flex: 1; height: 10px; background: #0e1014; border-radius: 2px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,.6); }
.bar i { display: block; height: 100%; background: linear-gradient(to right, #47bfff, #1a9fff); border-radius: 2px; transition: width .4s cubic-bezier(.3,1.4,.6,1); }
.lesson-body { flex: 1; padding: 16px 18px 20px; }
.ex-kind { color: var(--blue); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 1.6px; margin-bottom: 6px; }
.q { font-size: 20px; font-weight: 700; margin: 0 0 16px; line-height: 1.3; color: #fff; }
.q code, .info code, .fb code { background: rgba(0,0,0,.35); padding: 1px 5px; border-radius: 2px; font-size: .9em; color: var(--blue); }
.again { display: inline-block; color: var(--red); font-size: 12px; font-weight: 700; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1px; }

.opts { display: flex; flex-direction: column; gap: 8px; }
.opts.grid { display: grid; grid-template-columns: 1fr 1fr; }
.opt {
  padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg2);
  text-align: left; font-weight: 600; font-size: 16px; transition: background .1s, border-color .1s;
}
.opt:active { background: var(--card); }
.opt.sel { border-color: var(--blue); background: rgba(102,192,244,.14); color: #fff; box-shadow: inset 0 0 0 1px var(--blue); }
.opt.ok { border-color: var(--green); background: var(--green-bg); box-shadow: inset 0 0 0 1px var(--green); }
.opt.bad { border-color: var(--red); background: var(--red-bg); box-shadow: inset 0 0 0 1px var(--red); }
.opt.gone { opacity: .2; pointer-events: none; }
.opt.center { text-align: center; }
.opt .k { display: inline-flex; width: 24px; height: 24px; border: 1px solid var(--line); border-radius: 2px; align-items: center; justify-content: center; font-size: 12px; margin-right: 10px; color: var(--muted); background: rgba(0,0,0,.2); }

.figure { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin-bottom: 16px; display: flex; justify-content: center; }
.figure svg { width: 100%; max-height: 210px; }

.info { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; font-size: 16px; }
.info h2 { margin: 0 0 10px; font-size: 19px; text-transform: uppercase; letter-spacing: .8px; color: #fff; }
.info p { margin: 0 0 10px; }
.info .tip { background: rgba(102,192,244,.1); border-left: 3px solid var(--blue); padding: 10px 12px; border-radius: 2px; font-size: 14px; }

/* Number input */
.numrow { display: flex; align-items: center; gap: 10px; }
.numrow input {
  flex: 1; min-width: 0; font-size: 26px; font-weight: 700; padding: 12px 14px; border-radius: 2px; border: 1px solid #000;
  background: #0e1014; color: var(--text); outline: none; box-shadow: inset 0 1px 3px rgba(0,0,0,.6);
}
.numrow input:focus { border-color: var(--blue); }
.numrow .unit { font-size: 22px; font-weight: 700; color: var(--muted); }

/* Code gap */
.code { background: #0e1014; border: 1px solid #000; border-radius: 2px; padding: 14px; font: 15px/1.6 ui-monospace, Menlo, monospace; margin-bottom: 16px; white-space: pre-wrap; overflow-x: auto; }
.code .gap { display: inline-block; min-width: 70px; border-bottom: 2px solid var(--blue); color: var(--blue); text-align: center; font-weight: 700; }
.code .cm { color: #6a737c; }
.code .kw { color: #c792ea; }
.code .fn { color: #66c0f4; }
.code .nu { color: #e8c547; }

/* Ordering */
.order-slot { min-height: 60px; border-bottom: 1px solid var(--line); margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; padding-bottom: 10px; }
.order-slot .opt { padding: 10px 14px; }

/* Switch / logic exercise */
.toggles { display: flex; gap: 10px; justify-content: center; margin-top: 4px; }
.tog {
  flex: 1; min-width: 0; max-width: 130px; padding: 10px; border-radius: var(--r); border: 1px solid var(--line); background: var(--bg2);
  font-weight: 700; font-size: 17px;
}
.tog small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: 1px; }
.tog.on { border-color: var(--blue); background: rgba(102,192,244,.15); box-shadow: inset 0 0 0 1px var(--blue); color: #fff; }
.goal { text-align: center; font-weight: 600; color: var(--muted); margin: 0 0 10px; font-size: 14px; }

/* Color band picker */
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 12px; }
.sw { height: 40px; border-radius: 2px; border: 2px solid transparent; font-size: 11px; font-weight: 700; display: flex; align-items: end; justify-content: center; padding-bottom: 2px; }
.sw.sel { border-color: #fff; transform: scale(1.06); box-shadow: 0 0 0 1px #000; }
.band-tabs { display: flex; gap: 6px; justify-content: center; }
.band-tab { padding: 6px 12px; border-radius: 2px; border: 1px solid var(--line); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.band-tab.on { border-color: var(--blue); color: var(--blue); background: rgba(102,192,244,.1); }
.readout { text-align: center; font-size: 24px; font-weight: 700; margin-top: 10px; color: #fff; }

/* Slider */
.slider-box { padding: 6px 4px; }
input[type=range] { width: 100%; -webkit-appearance: none; appearance: none; height: 8px; border-radius: 2px; background: #0e1014; outline: none; box-shadow: inset 0 1px 2px rgba(0,0,0,.6); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 30px; border-radius: 3px; background: linear-gradient(#67c1f5, #417a9b); box-shadow: 0 2px 4px rgba(0,0,0,.5); }
.slider-vals { display: flex; justify-content: space-between; margin-top: 14px; font-weight: 700; }
.slider-vals div { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px; text-align: center; flex: 1; color: #fff; }
.slider-vals div + div { margin-left: 10px; }
.slider-vals small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }

/* Footer + feedback */
.lesson-foot { position: sticky; bottom: 0; z-index: 10; padding: 14px 18px calc(var(--safe-b) + 16px); border-top: 1px solid #000; background: var(--head); transition: background .2s; }
.lesson-foot.ok { background: var(--green-bg); }
.lesson-foot.bad { background: var(--red-bg); }
.fb { display: none; margin-bottom: 14px; animation: slideup .25s ease-out; }
.fb.show { display: block; }
.fb h4 { margin: 0 0 4px; font-size: 18px; display: flex; align-items: center; gap: 8px; text-transform: uppercase; letter-spacing: .8px; }
.ok .fb h4 { color: var(--green); }
.bad .fb h4 { color: var(--red); }
.fb p { margin: 0; font-size: 15px; }
@keyframes slideup { from { transform: translateY(20px); opacity: 0 } }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px) } 40%, 80% { transform: translateX(7px) } }

/* ---------- Result ---------- */
.result { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(var(--safe-t) + 20px) 22px calc(var(--safe-b) + 20px); text-align: center; position: relative; overflow: hidden;
  background: radial-gradient(ellipse at 50% 30%, #2a475e 0%, var(--bg) 65%); }
.result h1 { font-size: 26px; margin: 12px 0 6px; color: #fff; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 700; }
.result .big-ico { width: 110px; height: 110px; animation: zap .7s cubic-bezier(.3,1.6,.5,1); filter: drop-shadow(0 0 18px rgba(232,197,71,.35)); }
@keyframes zap { from { transform: scale(.2) rotate(-20deg); opacity: 0 } }
.chips { display: flex; gap: 8px; margin: 22px 0 28px; width: 100%; max-width: 420px; }
.chip { flex: 1; border-radius: var(--r); background: rgba(0,0,0,.35); border: 1px solid var(--line); overflow: hidden; }
.chip small { display: block; color: var(--c); font-weight: 600; font-size: 11px; padding: 6px 4px 0; text-transform: uppercase; letter-spacing: 1.2px; }
.chip b { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 6px 4px 10px; font-size: 20px; color: #fff; }
.chip svg { width: 18px; height: 18px; color: var(--c); }
.confetti { position: absolute; width: 8px; height: 12px; top: -20px; border-radius: 1px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg) } }

/* ---------- Pages (practice, profile, tools) ---------- */
.page { padding: 16px 12px; }
.page h2 { margin: 6px 4px 14px; font-size: 22px; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 700; color: #fff; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 6px; font-size: 15px; text-transform: uppercase; letter-spacing: 1px; color: #fff; }
.card p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stats .card { margin: 0; display: flex; align-items: center; gap: 10px; padding: 12px; }
.stats svg { width: 28px; height: 28px; flex: none; }
.stats b { display: block; font-size: 20px; color: #fff; }
.stats small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.goalbar { height: 10px; background: #0e1014; border-radius: 2px; overflow: hidden; margin: 6px 0; }
.goalbar i { display: block; height: 100%; background: linear-gradient(to right, #75b022, #a4d007); }
.week { display: flex; justify-content: space-between; margin-top: 12px; }
.week div { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; }
.week span { display: flex; width: 34px; height: 34px; border-radius: 3px; background: #0e1014; margin-top: 4px; align-items: center; justify-content: center; }
.week span.on { background: var(--btn-green); color: #fff; }
.week span svg { width: 18px; height: 18px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; padding: 10px 4px; white-space: nowrap; font-size: 14px; border-radius: 2px; border: 1px solid var(--line); font-weight: 600; background: rgba(0,0,0,.2); }
.seg button.on { border-color: var(--blue); color: var(--blue); background: rgba(102,192,244,.12); }
.row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; }
.row + .row { border-top: 1px solid var(--line); }
.switch { width: 46px; height: 26px; border-radius: 13px; background: #0e1014; position: relative; transition: background .2s; flex: none; box-shadow: inset 0 1px 2px rgba(0,0,0,.6); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #8f98a0; transition: transform .2s, background .2s; }
.switch.on { background: #1a9fff; }
.switch.on::after { transform: translateX(20px); background: #fff; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
.field div { display: flex; gap: 8px; align-items: center; }
.field input { flex: 1; min-width: 0; padding: 11px 12px; border-radius: 2px; border: 1px solid #000; background: #0e1014; color: var(--text); font-weight: 600; font-size: 18px; outline: none; box-shadow: inset 0 1px 3px rgba(0,0,0,.6); }
.field input:focus { border-color: var(--blue); }
.field span { width: 24px; font-weight: 700; color: var(--muted); }
textarea.backup { width: 100%; height: 90px; background: #0e1014; color: var(--text); border: 1px solid #000; border-radius: 2px; padding: 10px; font: 16px ui-monospace, Menlo, monospace; -webkit-user-select: text; user-select: text; }
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 90px); transform: translateX(-50%); background: var(--card); color: #fff; border: 1px solid var(--line); padding: 10px 16px; border-radius: var(--r); font-weight: 600; z-index: 50; animation: popin .2s; box-shadow: 0 8px 24px rgba(0,0,0,.5); }

/* Install hint (only in a Safari tab) */
.install { margin: 12px 12px 0; padding: 12px 14px; border-radius: var(--r); background: rgba(102,192,244,.1); border: 1px solid rgba(102,192,244,.35); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.install b { color: var(--blue); }
.install button { color: var(--muted); font-size: 22px; line-height: 1; }

/* ---------- Schematic SVG ---------- */
.wire { stroke: #7a838c; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.wire.live { stroke: var(--yellow); filter: drop-shadow(0 0 3px rgba(232,197,71,.7)); }
.sym { stroke: #dcdedf; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.lbl { fill: #dcdedf; font: 700 14px Arial, Helvetica, sans-serif; }
.lbl.m { fill: var(--muted); font-size: 12px; }
.lamp-glow { transition: opacity .2s; }
.lockd { pointer-events: none; }
.tog:disabled { cursor: default; }
