:root {
  --ink: #1b2330; --paper: #fff8ec; --go: #2fc46a; --go2: #1f9a50; --stop: #e8443a; --gold: #ffcf3f;
  --panel: rgba(20, 28, 40, 0.78); --btn: #ffffff; --btnink: #1b2330;
  font-family: "Arial Rounded MT Bold", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1d2633; color: #fff; user-select: none; touch-action: none; }
/* 100% = the visible viewport; 100vh on Android is the URL-bar-hidden height, which stretched the board under the bin */
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
svg { width: 100%; height: 100%; display: block; }

/* loading */
#loading { position: fixed; inset: 0; display: grid; place-content: center; gap: 28px; background: #1d2633; z-index: 50; transition: opacity .4s; }
body.loaded #loading { opacity: 0; pointer-events: none; }
.lb { width: min(420px, 70vw); height: 22px; border-radius: 11px; background: #34404f; overflow: hidden; margin: 0 auto; }
#loadbar { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), #ff8f3f); transition: width .2s; }
#loaderr { color: #ff9a9a; text-align: center; }

.logo { font-size: clamp(56px, 11vw, 132px); font-weight: 900; letter-spacing: 2px; text-align: center; line-height: 1; filter: drop-shadow(0 6px 0 rgba(0,0,0,.35)); }
.logo .c1 { color: var(--gold); -webkit-text-stroke: 3px #7a4a00; }
.logo .c2 { color: #6fd3ff; -webkit-text-stroke: 3px #0d4a73; margin-left: .25em; }

/* generic buttons */
.btn { border: 0; cursor: pointer; background: var(--btn); color: var(--btnink); border-radius: 22px; padding: 0; display: grid; place-items: center; box-shadow: 0 5px 0 rgba(0,0,0,.28); transition: transform .08s; font: inherit; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.28); }
.btn svg { width: 58%; height: 58%; }
.btn.round { width: 64px; height: 64px; border-radius: 50%; }
.btn.round.small { width: 58px; height: 58px; }
.btn.go { width: 104px; height: 72px; background: var(--go); color: #fff; box-shadow: 0 6px 0 var(--go2); }
.btn.go.stop { background: var(--stop); box-shadow: 0 6px 0 #a3241c; }
.btn.huge { width: 170px; height: 150px; border-radius: 36px; }
.btn.huge svg { width: 50%; height: 50%; }
.btn.sandbox { background: #ffcf3f; color: #5b3a00; box-shadow: 0 6px 0 #b8860b; }
.btn.danger { color: #d1342b; }
.btn.hint { color: #e0a800; }

.screen { position: fixed; inset: 0; display: none; z-index: 10; }
body[data-screen="title"] #title, body[data-screen="worlds"] #worlds, body[data-screen="levels"] #levels { display: flex; }

#title { flex-direction: column; align-items: center; justify-content: center; gap: 44px; background: radial-gradient(ellipse at center, rgba(15,20,30,.25), rgba(15,20,30,.7)); }
.row { display: flex; gap: 28px; align-items: center; justify-content: center; }
.row.small { gap: 18px; }

#worlds, #levels { flex-direction: column; align-items: center; justify-content: center; background: rgba(18, 24, 34, 0.72); gap: 26px; }
.btn.back { position: absolute; left: 18px; top: 18px; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 260px)); gap: 26px; }
@media (min-width: 1100px) { .cards { grid-template-columns: repeat(4, 240px); } }
.card { position: relative; border: 0; cursor: pointer; border-radius: 28px; background: var(--wc, #c96f3b); color: #fff; box-shadow: 0 8px 0 rgba(0,0,0,.35); font: inherit; transition: transform .08s; }
.card:active { transform: translateY(4px); }
.card.world { height: 250px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.card.world img { width: 130px; height: 130px; filter: drop-shadow(0 4px 4px rgba(0,0,0,.35)); }
.card .wn { font-size: 46px; font-weight: 900; text-shadow: 0 3px 0 rgba(0,0,0,.3); }
.card .stars { display: flex; align-items: center; gap: 6px; font-size: 22px; color: var(--gold); }
.card .stars svg { width: 26px; height: 26px; }
.card.locked { filter: grayscale(.85) brightness(.7); }
.card .lock { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; }
.card .lock svg { width: 70px; height: 70px; filter: drop-shadow(0 4px 0 rgba(0,0,0,.4)); }
.whead { display: flex; align-items: center; gap: 12px; font-size: 54px; font-weight: 900; }
.whead img { width: 84px; height: 84px; }
.lgrid { display: grid; grid-template-columns: repeat(4, 130px); gap: 22px; }
.card.lvl { height: 130px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.card.lvl .num { font-size: 56px; font-weight: 900; text-shadow: 0 3px 0 rgba(0,0,0,.3); }
.card.lvl .st { display: flex; gap: 2px; }
.card.lvl .st i { width: 30px; height: 30px; color: rgba(0,0,0,.28); }
.card.lvl .st i.on { color: var(--gold); filter: drop-shadow(0 2px 0 rgba(0,0,0,.35)); }

/* play HUD */
#topbar, #tray { display: none; }
body[data-screen="play"] #topbar, body[data-screen="play"] #tray { display: flex; }
#topbar { position: fixed; left: 0; right: 0; top: 0; height: 92px; padding: 12px 16px; gap: 14px; align-items: center; z-index: 20; pointer-events: none; }
#topbar > * { pointer-events: auto; }
#topbar .right { margin-left: auto; display: flex; gap: 14px; align-items: center; }
#goalpill { display: flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 40px; padding: 6px 18px 6px 10px; height: 64px; }
#goalpill img { width: 52px; height: 52px; }
#goalpill .lv { font-size: 26px; font-weight: 900; color: var(--gold); padding: 0 8px; }
#goalpill .lv svg { width: 34px; height: 34px; }
#goalpill .arrow { width: 34px; height: 34px; color: #fff; }
#goalpill .zone { width: 46px; height: 46px; color: var(--gold); }
#goalpill b { font-size: 24px; }

#tray { position: fixed; left: 0; right: 0; bottom: 0; height: 118px; padding: 10px 16px 14px; gap: 14px; justify-content: center; align-items: center; background: linear-gradient(0deg, rgba(14,19,28,.92), rgba(14,19,28,.6)); z-index: 20; overflow-x: auto; }
.titem { position: relative; flex: 0 0 auto; width: 94px; height: 94px; border-radius: 24px; background: #fff8ec; box-shadow: 0 5px 0 rgba(0,0,0,.35); cursor: grab; touch-action: none; }
.titem img { width: 100%; height: 100%; pointer-events: none; }
.titem .cnt { position: absolute; right: -6px; top: -8px; min-width: 34px; height: 34px; border-radius: 17px; background: #ff5d3a; color: #fff; font-size: 21px; font-weight: 900; display: grid; place-items: center; padding: 0 6px; box-shadow: 0 3px 0 rgba(0,0,0,.3); }
.titem .cnt:empty { display: none; }
.titem.empty { opacity: .35; }
body.running #tray { opacity: .45; pointer-events: none; }
body.running .btn.hint { opacity: .4; pointer-events: none; }

#selbar { position: fixed; display: none; gap: 10px; transform: translate(-50%, -100%); z-index: 25; padding: 6px; }
#selbar.show { display: flex; }

#modal { position: fixed; inset: 0; display: none; place-items: center; z-index: 40; background: rgba(10,14,22,.45); }
#modal.show { display: grid; }
.box { background: var(--paper); color: var(--ink); border-radius: 34px; padding: 30px 40px; display: flex; flex-direction: column; align-items: center; gap: 22px; box-shadow: 0 10px 0 rgba(0,0,0,.3); max-width: 92vw; }
.box h2 { margin: 0; font-size: 36px; }
.box p { margin: 0; font-size: 18px; text-align: center; line-height: 1.5; }
.bigstars { display: flex; gap: 12px; }
.bigstars i { width: 110px; height: 110px; color: #d8d0c0; }
.bigstars i.on { color: var(--gold); animation: pop .5s both; filter: drop-shadow(0 4px 0 #b8860b); }
@keyframes pop { 0% { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }

@media (max-width: 700px) {
  .btn.round { width: 54px; height: 54px; } .btn.go { width: 84px; height: 62px; }
  #goalpill img { width: 40px; height: 40px; } .titem { width: 80px; height: 80px; }
  .lgrid { grid-template-columns: repeat(4, 74px); gap: 12px; } .card.lvl { height: 84px; } .card.lvl .num { font-size: 34px; } .card.lvl .st i { width: 18px; height: 18px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 160px)); gap: 14px; } .card.world { height: 180px; } .card.world img { width: 80px; height: 80px; }
}

/* phases: which buttons show when */
.btn.edit-only, .btn.run-only, .btn.done-only { display: none; }
body[data-phase="edit"] .btn.edit-only { display: grid; }
body[data-phase="run"] .btn.run-only { display: grid; }
body[data-phase="done"] .btn.done-only { display: grid; }
body[data-phase="run"] #tray, body[data-phase="done"] #tray, body[data-phase="replay"] #tray { opacity: .45; pointer-events: none; }
.btn.dim { opacity: .45; }
.btn.on { background: var(--gold); }
#topbar .left { display: flex; gap: 12px; }
#goalpill .what { display: flex; align-items: center; gap: 6px; }
.nudge { animation: nudge .6s; }
@keyframes nudge { 0%,100% { transform: none; } 20% { transform: rotate(-14deg) scale(1.12); } 40% { transform: rotate(12deg) scale(1.12); } 60% { transform: rotate(-8deg); } 80% { transform: rotate(5deg); } }
.toast { position: fixed; left: 50%; bottom: 140px; transform: translateX(-50%); background: var(--panel); color: #fff; padding: 12px 20px; border-radius: 20px; z-index: 60; font-size: 18px; }
body[data-phase="replay"] #view { filter: saturate(.75) contrast(1.05); }
body[data-phase="replay"]::after { content: ""; position: fixed; inset: 0; pointer-events: none; box-shadow: inset 0 0 120px rgba(0,0,0,.55); z-index: 5; }
.box.win .row { flex-wrap: wrap; }

/* touch tablets / unfolded phones in landscape: slimmer bin so it covers less of the floor */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 760px) {
  #tray { height: 90px; padding: 6px 12px 8px; gap: 10px; }
  .titem { width: 70px; height: 70px; border-radius: 18px; } .titem .cnt { min-width: 26px; height: 26px; font-size: 16px; right: -5px; top: -6px; }
}
/* phones */
@media (max-width: 760px), (max-height: 520px) {
  #topbar { height: auto; padding: 8px 8px; gap: 8px; flex-wrap: wrap; }
  #topbar .left, #topbar .right { gap: 8px; }
  .btn.round { width: 48px; height: 48px; } .btn.round.small { width: 44px; height: 44px; } .btn.go { width: 70px; height: 52px; }
  #goalpill { height: 48px; padding: 4px 12px 4px 8px; order: 3; }
  #goalpill img { width: 36px; height: 36px; } #goalpill .lv { font-size: 18px; padding: 0 4px; } #goalpill .arrow { width: 24px; height: 24px; }
  #tray { height: 92px; padding: 8px 10px 10px; gap: 10px; justify-content: flex-start; }
  .titem { width: 72px; height: 72px; border-radius: 18px; } .titem .cnt { min-width: 28px; height: 28px; font-size: 17px; }
  .btn.huge { width: 130px; height: 116px; }
  .bigstars i { width: 72px; height: 72px; }
  .box { padding: 22px 22px; }
}
@media (max-width: 520px) and (orientation: portrait) {
  #topbar .right { margin-left: auto; }
  #goalpill { flex: 1 1 100%; justify-content: center; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #tray { height: 80px; } .titem { width: 62px; height: 62px; }
  #goalpill { order: 0; }
  #topbar { flex-wrap: nowrap; }
}
@media (orientation: portrait) {
  #title { justify-content: space-between; padding: 12vh 16px 6vh; }
  #title .logo { font-size: clamp(48px, 15vw, 96px); }
  #title .row { flex-wrap: wrap; }
  .lgrid { grid-template-columns: repeat(3, 96px); }
  .cards { grid-template-columns: repeat(2, minmax(0, 44vw)); }
}
body[data-phase="replay"] #topbar::after { content: "SLOW-MO"; position: absolute; left: 50%; top: 96px; transform: translateX(-50%); background: rgba(20,28,40,.8); color: #ffcf3f; font-weight: 900; letter-spacing: 3px; padding: 8px 18px; border-radius: 20px; font-size: 20px; }
/* level grid scales with level count */
#levels { overflow-y: auto; justify-content: flex-start; padding: 22px 16px 40px; gap: 18px; }
.lgrid { grid-template-columns: repeat(auto-fill, 112px); width: min(100%, 780px); justify-content: center; gap: 16px; }
.card.lvl { height: 112px; } .card.lvl .num { font-size: 46px; } .card.lvl .st i { width: 26px; height: 26px; }
#worlds { overflow-y: auto; }
@media (max-width: 700px) { .lgrid { grid-template-columns: repeat(auto-fill, 76px); gap: 10px; } .card.lvl { height: 80px; } .card.lvl .num { font-size: 30px; } .card.lvl .st i { width: 18px; height: 18px; } }
.cards { grid-template-columns: repeat(3, minmax(0, 250px)); gap: 22px; }
.card.world { height: 210px; } .card.world img { width: 104px; height: 104px; }
@media (max-width: 760px) { .cards { grid-template-columns: repeat(2, minmax(0, 44vw)); gap: 12px; } .card.world { height: 160px; } .card.world img { width: 70px; height: 70px; } .card .wn { font-size: 32px; } }
#tray { justify-content: safe center; scrollbar-width: thin; }
body.sandbox .btn.hint { display: none !important; }
/* depth pass: big bin icons everywhere (>= 64 px); in short landscape the bin sits on the right side */
.titem { min-width: 64px; min-height: 64px; }
.titem.linking { outline: 5px solid #7cf0a0; outline-offset: 2px; animation: pulse 0.9s ease-in-out infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.06); } }
@media (max-height: 520px) and (orientation: landscape) {
  #tray { left: auto; right: 0; top: 64px; bottom: 0; width: 96px; height: auto; flex-direction: column; justify-content: flex-start; align-items: center; padding: 12px 8px; gap: 12px; overflow-x: hidden; overflow-y: auto; background: linear-gradient(270deg, rgba(14,19,28,.92), rgba(14,19,28,.6)); }
  .titem { width: 68px; height: 68px; }
}
.warmhead { display: flex; align-items: center; gap: 12px; color: #fff; font-size: 30px; font-weight: 900; }
.warmhead svg { width: 40px; height: 40px; }
.card .wn.wsmall { font-size: 30px; }
/* staged hints: one stage of text at a time, under the top bar */
#hintbox { position: fixed; left: 50%; top: 100px; transform: translate(-50%, -12px); max-width: min(90vw, 620px); display: flex; gap: 12px; align-items: center; background: #fff8ec; color: #1d2633; border-radius: 22px; padding: 12px 20px; font-size: 22px; font-weight: 800; box-shadow: 0 6px 0 rgba(0,0,0,.3); z-index: 30; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
#hintbox.show { opacity: 1; transform: translate(-50%, 0); }
#hintbox .hstep { flex: none; background: #ffd23f; border-radius: 14px; padding: 2px 10px; font-size: 18px; }
@media (max-width: 760px), (max-height: 520px) { #hintbox { top: 118px; font-size: 18px; padding: 10px 14px; } }
/* portrait nudge: turn sideways (dismissible, never blocks) */
#nudge { position: fixed; left: 50%; bottom: 112px; width: min(calc(100vw - 32px), 520px); box-sizing: border-box; transform: translate(-50%, 20px); display: flex; align-items: center; gap: 10px; background: rgba(20,28,40,.9); color: #fff; border-radius: 22px; padding: 8px 8px 8px 14px; font-size: 16px; font-weight: 800; z-index: 31; opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; max-width: 92vw; }
#nudge.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#nudge span { flex: 1; font-size: 15px; line-height: 1.25; } #nudge i svg { width: 26px; height: 26px; color: #ffd23f; display: block; }
#nudge .x { border: 0; background: rgba(255,255,255,.15); color: #fff; width: 36px; height: 36px; border-radius: 18px; display: grid; place-items: center; cursor: pointer; flex: none; }
#nudge .x svg { width: 18px; height: 18px; }
