:root {
  --ink: #fff4dc;
  --muted: #c9b8a6;
  --panel: rgba(29, 22, 38, 0.9);
  --line: rgba(255, 211, 107, 0.28);
  --gold: #ffd36b;
  --leaf: #9be05a;
  --orange: #ff9a3c;
  --teal: #7fd8c6;
  --bad: #ff7a7a;
  --good: #9be05a;
  --head: "Fredoka", "Segoe UI", system-ui, sans-serif;
  --body: "Fredoka", "Segoe UI", system-ui, sans-serif;
  --pix: "Silkscreen", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #1d1626; color: var(--ink); font-family: var(--body); overflow: hidden; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#app { position: fixed; inset: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
body.playing #cv { cursor: none; }
body.playing.touchy #cv { cursor: default; }

/* ---------- overlay screens */
.ui { position: absolute; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); overflow-y: auto; background: radial-gradient(ellipse at center, rgba(20, 14, 28, 0.15), rgba(20, 14, 28, 0.6)); }
.ui[hidden] { display: none; }
.panel { width: min(560px, 100%); max-height: 100%; overflow-y: auto; background: var(--panel); border: 2px solid var(--line); border-radius: 20px; padding: 24px 26px; box-shadow: 0 20px 60px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06); animation: rise 0.3s ease-out; }
.panel.wide { width: min(880px, 100%); }
.panel.small { width: min(420px, 100%); text-align: center; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.kicker { font: 700 12px/1.2 var(--pix); letter-spacing: 0.12em; color: var(--leaf); margin-bottom: 6px; }
.kicker.bad { color: var(--bad); }
h1, h2, h3 { font-family: var(--head); margin: 0 0 10px; font-weight: 700; }
h2 { font-size: clamp(24px, 4.5vw, 32px); }
h2.big { font-size: clamp(34px, 7vw, 50px); color: var(--gold); }
h3 { font-size: 16px; color: var(--gold); margin-top: 14px; }
p { line-height: 1.45; margin: 0 0 10px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.good { color: var(--good); } .bad { color: var(--bad); } .gold { color: var(--gold); } .teal { color: var(--teal); } .orange { color: var(--orange); }

/* title */
.title { text-align: center; width: min(520px, 100%); background: rgba(29, 22, 38, 0.78); }
.logo { margin: 0 0 4px; font: 700 clamp(46px, 11vw, 78px)/1 var(--head); letter-spacing: 0.02em; color: #ffe08a;
  text-shadow: 0 4px 0 #8a5a1e, 0 7px 0 #2a1c18, 0 10px 24px rgba(0,0,0,0.45); }
.logo span { color: var(--leaf); text-shadow: 0 4px 0 #4a7a22, 0 7px 0 #2a1c18, 0 10px 24px rgba(0,0,0,0.45); }
.logo-hero { display: block; margin: 0 auto 4px; width: 96px; height: 112px; }
.tag { color: var(--muted); margin: 8px 0 16px; }
.note { color: var(--muted); font-size: 14px; margin-top: 10px; }

/* buttons */
.menu { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.menu.row { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.menu.row button { flex: 1 1 150px; }
.menu.grid2 { display: grid; grid-template-columns: 1fr 1fr; }
button { font: 600 17px var(--body); color: var(--ink); background: rgba(255,255,255,0.07); border: 2px solid rgba(255,255,255,0.14); border-radius: 14px; padding: 11px 16px; cursor: pointer; transition: transform 0.08s, background 0.15s, border-color 0.15s; min-height: 46px; }
button:hover:not([disabled]) { background: rgba(255,211,107,0.13); border-color: rgba(255,211,107,0.5); }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
button:active:not([disabled]) { transform: scale(0.97); }
button.primary { background: linear-gradient(180deg, #a8e862, #5aa82a); border-color: #c8f58e; color: #17300a; font-weight: 700; box-shadow: 0 5px 0 #3a6e1a, 0 8px 20px rgba(80,160,40,0.3); }
button.primary:hover { background: linear-gradient(180deg, #b8f074, #66b832); }
button[disabled] { opacity: 0.4; cursor: not-allowed; }

/* level select */
.lgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lcard { display: flex; flex-direction: column; align-items: stretch; text-align: left; gap: 4px; padding: 8px; border-radius: 14px; }
.lcard canvas { width: 100%; height: auto; aspect-ratio: 2.4; border-radius: 8px; image-rendering: pixelated; background: #000; }
.lcard .n { font: 700 12px var(--pix); color: var(--leaf); }
.lcard .nm { font-size: 15px; line-height: 1.15; }
.lcard .st { font-size: 14px; color: var(--gold); letter-spacing: 2px; min-height: 1em; }
.lcard.locked { opacity: 0.45; }
.lcard.next { border-color: var(--leaf); }
.stars { letter-spacing: 3px; }
.stars .off { opacity: 0.25; }

/* level intro */
.intro .thumb { width: 100%; aspect-ratio: 3; border-radius: 12px; image-rendering: pixelated; background: #000; display: block; margin: 6px 0 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.chip { padding: 5px 10px; border-radius: 999px; background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.12); font-size: 14px; }
.chip b { color: var(--gold); }
.joblist { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.jl { display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border-radius: 12px; background: rgba(155,224,90,0.1); border: 1px solid rgba(155,224,90,0.35); font-size: 14px; }
.jl canvas { width: 22px; height: 24px; }
.jl b { color: var(--gold); font-family: var(--pix); }
.hint { background: rgba(255,211,107,0.1); border: 1px solid rgba(255,211,107,0.4); border-radius: 12px; padding: 10px 12px; color: #ffe9b0; font-size: 15px; }

/* results */
.tally { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 15px; text-align: left; }
.tally td { padding: 5px 2px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.tally td:last-child { text-align: right; font-family: var(--pix); font-size: 14px; }
.tally tr.tot td { color: var(--gold); font-weight: 700; border-bottom: 0; }
.bigstars { font-size: 40px; letter-spacing: 6px; margin: 4px 0 8px; }
.bigstars span { display: inline-block; animation: pop 0.4s ease-out backwards; }
.bigstars span.off { opacity: 0.2; animation: none; }
@keyframes pop { from { transform: scale(0.2) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
.meter { height: 14px; border-radius: 7px; background: rgba(255,255,255,0.1); position: relative; overflow: hidden; margin: 8px 0 4px; }
.meter i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, #5aa82a, #b8f074); border-radius: 7px; }
.meter u { position: absolute; top: -2px; bottom: -2px; width: 3px; background: var(--gold); }

/* how to play */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 4px 22px; }
.cols p { font-size: 15px; }
.jobhelp { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; margin: 8px 0; }
.jh { display: flex; gap: 10px; align-items: flex-start; padding: 8px; border-radius: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); }
.jh canvas { flex: none; width: 34px; height: 38px; }
.jh b { display: block; font-size: 15px; color: var(--gold); }
.jh span { display: block; font-size: 13px; color: var(--muted); line-height: 1.3; }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; margin: 0 2px 2px 0; font: 700 12px var(--pix); color: var(--ink); background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.2); border-bottom-width: 3px; border-radius: 6px; text-align: center; }

/* settings */
.slider { display: flex; align-items: center; gap: 12px; margin: 6px 0 10px; }
.slider input { flex: 1; accent-color: var(--leaf); }
.tog.sel { border-color: var(--gold); background: rgba(255,211,107,0.12); }

/* ---------- in-game panel */
.hud { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; background: linear-gradient(180deg, #2a2036, #1d1626); border-top: 2px solid #5a4470; padding: 0 max(6px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); }
.hud[hidden] { display: none; }
.status { display: flex; gap: 16px; align-items: center; font: 400 13px var(--pix); color: var(--muted); padding: 3px 4px 2px; white-space: nowrap; overflow: hidden; }
.status b { color: var(--ink); font-weight: 700; }
.status i { font-style: normal; }
.status .who { flex: 1; color: var(--gold); overflow: hidden; text-overflow: ellipsis; }
.status .time.low b { color: var(--bad); }
.bar { display: flex; gap: 6px; align-items: stretch; padding-bottom: 2px; }
.jobs { display: flex; gap: 4px; flex: 1 1 auto; min-width: 0; }
.jb, .cb { position: relative; min-height: 0; padding: 0; border-radius: 10px; border-width: 2px; background: rgba(255,255,255,0.06); }
.jb { flex: 1 1 0; min-width: 0; max-width: 78px; height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 3px; }
.jb canvas { width: 27px; height: 30px; margin-bottom: 0; }
.jb .n { position: absolute; top: 2px; left: 0; right: 0; text-align: center; font: 700 11px var(--pix); color: var(--ink); }
.jb .lb { font: 600 11px/1 var(--body); color: var(--muted); }
.jb .k, .cb .k { position: absolute; top: 3px; left: 5px; font: 700 10px/1 var(--pix); color: rgba(255,244,220,0.7); }
.cb .k { left: 0; right: 0; text-align: center; font-size: 8px; top: 3px; }
@media (pointer: coarse) { .jb .k, .cb .k { display: none; } }
.jb.sel { border-color: var(--gold); background: rgba(255,211,107,0.2); box-shadow: 0 0 0 1px var(--gold) inset; }
.jb.sel .lb { color: var(--gold); }
.jb.zero { opacity: 0.38; }
.jb.flash { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.rate, .ctl { display: flex; gap: 4px; flex: none; }
.cb { width: 46px; height: 60px; font-size: 20px; line-height: 1; }
.cb.on { border-color: var(--gold); background: rgba(255,211,107,0.22); }
.cb.nuke.arm { border-color: var(--bad); background: rgba(255,90,90,0.3); animation: shake 0.4s infinite; }
.rate .cb { width: 34px; font-size: 22px; }
.rv { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 38px; font: 700 15px var(--pix); color: var(--ink); }
.rv small { font: 400 8px var(--pix); color: var(--muted); }
.mm { flex: 0 0 auto; height: 60px; width: 200px; border-radius: 8px; border: 2px solid rgba(255,255,255,0.15); cursor: pointer; touch-action: none; background: #000; }
@media (max-width: 1020px) { .mm { display: none; } }
@media (max-width: 760px) { .cb { width: 40px; } .rate .cb { width: 30px; } .rv { width: 32px; } .jb .lb { font-size: 10px; } .status { gap: 10px; font-size: 12px; } }
@media (max-height: 460px) { .jb, .cb { height: 50px; } .jb canvas { width: 22px; height: 24px; } .status { padding: 2px 4px 1px; font-size: 11px; } }
/* phones held upright: two rows plus the map */
@media (orientation: portrait) and (max-width: 700px) {
  .bar { flex-wrap: wrap; row-gap: 5px; }
  .jobs { flex: 1 1 100%; order: 1; }
  .jb { max-width: none; height: 62px; }
  .rate { order: 2; } .ctl { order: 3; margin-left: auto; }
  .cb { height: 48px; width: 48px; }
  .mm { display: block; order: 4; flex: 1 1 100%; width: 100%; height: 54px; }
}

/* tip bubble on tutorial trails */
.tip { position: absolute; z-index: 2; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); width: min(560px, calc(100% - 120px)); padding: 9px 14px; border-radius: 14px; background: rgba(29,22,38,0.88); border: 2px solid var(--gold); color: #ffe9b0; font-size: 15px; line-height: 1.35; text-align: center; pointer-events: auto; cursor: pointer; animation: fadein 0.3s ease-out; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.tip[hidden] { display: none; }
.tip small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.watching { border-color: var(--teal); color: #c8fff2; }

/* online high scores */
.tabs { display: flex; gap: 6px; margin: 4px 0 12px; }
.tabs button { flex: 1; padding: 8px; min-height: 40px; font-size: 15px; }
.tabs button.sel { border-color: var(--gold); color: var(--gold); background: rgba(255,211,107,0.12); }
.scores { width: 100%; border-collapse: collapse; font-size: 15px; margin-bottom: 10px; text-align: left; }
.scores th { color: var(--muted); font-weight: 600; font-size: 12px; padding: 4px; }
.scores td { padding: 7px 4px; border-top: 1px solid rgba(255,255,255,0.08); }
.scores td:nth-child(3) { font-family: var(--pix); color: var(--gold); }
.scores tr.me td { background: rgba(255,211,107,0.12); }
.scores tr.gap td { text-align: center; color: var(--muted); border-top: 0; padding: 2px; }
.pilotbox { margin: 12px 0 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0,0,0,0.25); text-align: left; }
.pilotbox p { margin: 0 0 6px; }
.pilotbox .code { font-family: var(--pix); letter-spacing: 0.08em; color: var(--gold); }
.pilotbox .row, .pname .row { display: flex; gap: 8px; margin-top: 8px; }
.pilotbox input, .pname input { flex: 1; min-width: 0; font: 600 15px var(--body); color: var(--ink); background: rgba(0,0,0,0.35); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; -webkit-user-select: text; user-select: text; }
.pilotbox #rc { text-transform: uppercase; font-family: var(--pix); }
.pilotbox button[type="submit"], .pname button[type="submit"] { min-height: 0; padding: 9px 14px; border-radius: 10px; border-color: var(--gold); color: var(--gold); font-size: 14px; }
.linkish { min-height: 0; border: 0; background: none; padding: 0 2px; color: var(--gold); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }
.online { margin: 12px 0; }
.online .ranks { font-weight: 600; margin: 0 0 4px; }
.online .ranks b { color: var(--gold); font-family: var(--pix); }
.pname { margin: 10px 0 2px; text-align: left; }
.pname label { display: block; font-weight: 600; font-size: 14px; color: var(--gold); margin-bottom: 4px; }
.nmsg { min-height: 16px; margin: 6px 0 0; }
.nmsg.bad { color: var(--bad); } .nmsg.good { color: var(--good); }
.newbest { color: var(--gold); font-weight: 700; margin: 6px 0 0; }
.hint-rotate { display: none; color: var(--gold); font-size: 14px; margin-top: 10px; }
@media (orientation: portrait) and (pointer: coarse) { .hint-rotate { display: block; } }

/* ?poster: the share picture */
body.poster .ca-home { display: none !important; }
.posterlogo { position: absolute; z-index: 4; left: 4%; top: 6%; }
.posterlogo .logo { font-size: 92px; }
.posterlogo p { margin: 6px 0 0 4px; font: 600 30px var(--head); color: #fff; text-shadow: 0 3px 0 #2a1c18, 0 6px 18px rgba(0,0,0,0.5); }

/* controls card */
.ctrls { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin: 6px 0 10px; text-align: left; }
.cbox { padding: 12px 14px; border-radius: 14px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.12); }
.cbox h4 { margin: 0 0 8px; font: 700 16px var(--head); color: var(--gold); }
.cbox h4 + p, .cbox p { font-size: 15px; }
.cbox p + h4 { margin-top: 14px; }
.keys { width: 100%; border-collapse: collapse; font-size: 15px; }
.keys td { padding: 4px 4px; border-top: 1px solid rgba(255,255,255,0.07); vertical-align: middle; }
.keys td:first-child { white-space: nowrap; width: 1%; padding-right: 12px; }
.jobkeys { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 10px; font-size: 14px; color: var(--muted); }
.jk kbd { margin-right: 2px; }
.example { background: rgba(155,224,90,0.1); border: 1px solid rgba(155,224,90,0.4); border-radius: 12px; padding: 10px 12px; font-size: 15px; text-align: left; }
.keyline { font-size: 14px; color: var(--muted); margin: 4px 0 10px; line-height: 1.8; }
.tip kbd { font-size: 11px; }

.btnchip { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 22px; padding: 0 6px; margin: 0 2px 2px 0; border-radius: 7px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.22); font: 600 13px var(--body); color: var(--ink); }
.keys td small { color: var(--muted); font-size: 12px; }
.touchh { margin-top: 14px !important; }
.examples { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.examples .example { margin: 0; line-height: 1.6; }

/* tutorial bubble and pointer */
.tut { position: absolute; z-index: 4; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); width: min(600px, calc(100% - 24px)); padding: 12px 16px 14px; border-radius: 16px; background: rgba(29,22,38,0.96); border: 2px solid var(--leaf); box-shadow: 0 10px 30px rgba(0,0,0,0.45); text-align: center; animation: fadein 0.25s ease-out; }
.tut[hidden] { display: none; }
.tut .tstep { font: 700 11px var(--pix); color: var(--leaf); letter-spacing: 0.1em; margin-bottom: 4px; }
.tut p { margin: 0; font-size: 18px; line-height: 1.4; }
.tut p small { display: block; margin-top: 6px; font-size: 14px; color: var(--muted); }
.tut .row { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.tut button { min-height: 42px; padding: 8px 18px; font-size: 16px; }
.tut kbd { font-size: 11px; }
@media (max-width: 500px) { .tut p { font-size: 16px; } }
.tutarrow { position: absolute; z-index: 5; pointer-events: none; transform: translateX(-50%); }
.tutarrow[hidden] { display: none; }
.tutarrow span { display: block; font-size: 38px; line-height: 1; filter: drop-shadow(0 3px 0 #2a1c18); animation: bob 0.55s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(-6px); } to { transform: translateY(4px); } }
.jb.pulse { animation: pulse 0.8s ease-in-out infinite alternate; border-color: var(--leaf); }
@keyframes pulse { from { box-shadow: 0 0 0 0 rgba(155,224,90,0.0); } to { box-shadow: 0 0 0 5px rgba(155,224,90,0.55); } }

.rule { text-align: left; margin: 8px 0 12px; padding: 12px 16px; border-radius: 14px; background: rgba(255,211,107,0.12); border: 2px solid var(--gold); }
.rule h4 { margin: 0 0 6px; font: 700 18px var(--head); color: var(--gold); }
.rule p { margin: 0 0 6px; font-size: 16px; }
.rule ol { margin: 4px 0 8px 22px; padding: 0; font-size: 16px; line-height: 1.6; }
.ctrls + .ctrls { margin-top: -2px; }

.tut.low { top: auto; }
@media (max-height: 520px) {
  .tut { padding: 8px 12px 10px; width: min(640px, calc(100% - 20px)); }
  .tut p { font-size: 15px; line-height: 1.3; }
  .tut p small { font-size: 12px; margin-top: 3px; }
  .tut .row { margin-top: 6px; }
  .tut button { min-height: 34px; padding: 5px 14px; font-size: 14px; }
  .tut .tstep { font-size: 9px; margin-bottom: 2px; }
}
