/* Look borrowed from Cubby's Journey: Fredoka toy font, pastel sky, chunky rounded buttons with a solid drop shadow. */
@font-face { font-family: "Fredoka Toy"; src: url("fonts/fredoka-latin-wght-normal.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }
:root {
  --toy: "Fredoka Toy", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  --green: #4cb944; --green-d: #2c8a2e; --blue: #3d9be9; --blue-d: #1f68b0; --orange: #f39a2b; --orange-d: #bd6a0f;
  --red: #ec4a4a; --red-d: #b02828; --yellow: #f2c94c; --yellow-d: #b8932a; --purple: #9b6fe0; --purple-d: #6a43aa;
  --cream: #fff8e6; --cream-d: #d9c49a; --ink: #3b2a14; --ink-soft: #7a6544;
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom); --sal: env(safe-area-inset-left); --sar: env(safe-area-inset-right);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--toy); color: var(--ink); overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: 0.45; }
[hidden] { display: none !important; }
#app { position: fixed; inset: 0; }
.sky { position: absolute; inset: 0; background: linear-gradient(180deg, #7cc4f5 0%, #b9e3f7 42%, #dff3f7 62%, #cfeeb8 82%, #8fd070 100%); overflow: hidden; }
.cloud { position: absolute; width: 9rem; height: 2.6rem; background: #fff; border-radius: 2rem; opacity: 0.85; filter: blur(0.3px); animation: drift 60s linear infinite; }
.cloud::before, .cloud::after { content: ""; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 3.6rem; height: 3.6rem; left: 1.4rem; top: -1.6rem; }
.cloud::after { width: 2.6rem; height: 2.6rem; left: 4.4rem; top: -1rem; }
.c1 { top: 12%; left: -10%; } .c2 { top: 30%; left: 50%; transform: scale(0.7); animation-duration: 80s; } .c3 { top: 55%; left: 10%; transform: scale(0.55); animation-duration: 95s; opacity: 0.6; }
@keyframes drift { from { translate: -20vw 0; } to { translate: 120vw 0; } }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* chunky toy buttons (Cubby menu) */
.toy { --c: var(--green); --d: var(--green-d); background: var(--c); color: #fff; border-radius: 1.1rem; padding: 0.6rem 0.9rem; min-height: 52px;
  font-weight: 600; text-shadow: 0 2px 0 rgba(0,0,0,0.22); box-shadow: 0 6px 0 var(--d), 0 12px 14px rgba(20,40,20,0.3);
  transition: transform 0.08s, box-shadow 0.08s; display: flex; align-items: center; gap: 0.7rem; text-align: left; }
.toy:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 var(--d), 0 4px 6px rgba(20,40,20,0.3); }
.toy-green { --c: var(--green); --d: var(--green-d); } .toy-blue { --c: var(--blue); --d: var(--blue-d); } .toy-orange { --c: var(--orange); --d: var(--orange-d); }
.toy-red { --c: var(--red); --d: var(--red-d); } .toy-purple { --c: var(--purple); --d: var(--purple-d); }
.toy-yellow { --c: var(--yellow); --d: var(--yellow-d); color: #5a3b0a; text-shadow: 0 1px 0 rgba(255,255,255,0.4); }
.toy.small { min-height: 44px; padding: 0 0.85rem; border-radius: 1rem; box-shadow: 0 4px 0 var(--d), 0 8px 10px rgba(20,40,20,0.25); font-size: 1rem; }
.toy.small:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--d); }
.toy.icon { width: 44px; padding: 0; justify-content: center; font-size: 1.35rem; }
.toy .b { font-size: 1.12rem; font-weight: 600; display: block; }
.toy .sub { font-size: 0.78rem; font-weight: 500; display: block; color: rgba(255,255,255,0.95); }
.toy .t { flex: 1; min-width: 0; }
.toy .ic { font-size: 1.3rem; width: 1.6rem; text-align: center; }
.toy .chev { font-size: 1.6rem; line-height: 1; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; pointer-events: none; }
.screen > * { pointer-events: auto; }

/* menu */
.menu-screen { max-width: 34rem; margin: 0 auto; padding: max(1.2rem, var(--sat)) max(1rem, var(--sar)) max(1rem, var(--sab)) max(1rem, var(--sal)); }
.menu-head { text-align: center; pointer-events: none; }
.menu-title { margin: 0; line-height: 0.95; font-weight: 700; color: #fff; letter-spacing: 0.03em; }
.menu-title span { display: block; }
.mt-a { font-size: clamp(2.4rem, 12vw, 3.4rem); text-shadow: 0 4px 0 #2a7fc4, 0 8px 16px rgba(20,70,130,0.45); }
.mt-b { font-size: clamp(2rem, 10vw, 2.8rem); color: #ffe27a; text-shadow: 0 4px 0 #e0832a, 0 8px 16px rgba(120,60,0,0.35); }
.menu-rule { margin: 0.6rem auto 0; display: flex; align-items: center; gap: 0.7rem; justify-content: center; color: #fff; font-weight: 600; font-size: 0.72rem; letter-spacing: 0.24em; text-shadow: 0 2px 0 #e0832a; }
.menu-rule::before, .menu-rule::after { content: ""; height: 4px; width: 3rem; border-radius: 3px; background: linear-gradient(90deg, transparent, #ffc94d); }
.menu-rule::after { transform: scaleX(-1); }
.menu-spacer { flex: 1; pointer-events: none; }
.menu-actions { display: flex; flex-direction: column; gap: 0.7rem; }
.menu-play { height: 3.7rem; justify-content: center; font-size: 1.4rem; }
.menu-play .b { font-size: 1.4rem; font-weight: 700; }
.menu-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.menu-row2 .toy { justify-content: center; }
.menu-foot { margin: 0.3rem 0 0; text-align: center; color: rgba(255,255,255,0.95); font-weight: 600; font-size: 0.7rem; letter-spacing: 0.2em; text-shadow: 0 1px 4px rgba(10,30,60,0.6); }

/* list screens */
.list-screen { background: linear-gradient(180deg, #7cc4f5 0%, #b9e3f7 40%, #cfeeb8 75%, #8fd070 100%); }
.bar { display: grid; grid-template-columns: 6rem 1fr 6rem; align-items: center; padding: max(0.7rem, var(--sat)) max(0.9rem, var(--sar)) 0.6rem max(0.9rem, var(--sal)); }
.bar h2 { margin: 0; text-align: center; color: #fff; font-size: 1.6rem; text-shadow: 0 3px 0 #2a7fc4; }
.list-body { flex: 1; overflow-y: auto; padding: 0.6rem max(1rem, var(--sar)) max(1.2rem, var(--sab)) max(1rem, var(--sal)); display: flex; flex-direction: column; gap: 0.9rem; max-width: 34rem; width: 100%; margin: 0 auto; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 0.8rem; }
.ltile { background: var(--cream); border-radius: 1rem; padding: 0.7rem 0.8rem; text-align: left; box-shadow: 0 4px 0 var(--wa, var(--cream-d)), 0 7px 8px rgba(20,40,20,0.22); color: var(--ink); min-height: 6rem; display: flex; flex-direction: column; gap: 0.2rem; }
.ltile:active { transform: translateY(3px); }
.ltile .n { color: var(--ink-soft); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; }
.ltile .nm { font-weight: 600; font-size: 1rem; line-height: 1.15; }
.ltile .st { color: var(--orange); font-size: 1.05rem; letter-spacing: 0.1em; margin-top: auto; }
.ltile .tag { font-size: 0.7rem; color: var(--ink-soft); }
.ltile.done { background: #e4f6d4; }
.lede { margin: 0; color: var(--ink); font-weight: 500; text-align: center; }
.lede.small { font-size: 0.8rem; color: var(--ink-soft); }
.tier { flex-direction: column; align-items: flex-start; gap: 0.1rem; min-height: 4.6rem; justify-content: center; }
.tier .b { font-size: 1.3rem; }

/* game */
.game-screen { padding: 0; }
.hud-top { display: grid; grid-template-columns: 44px 1fr 44px 44px; gap: 0.5rem; align-items: center; padding: max(0.6rem, var(--sat)) max(0.8rem, var(--sar)) 0 max(0.8rem, var(--sal)); }
.hud-top .toy.small:first-child { width: 44px; padding: 0; justify-content: center; font-size: 1.5rem; }
.hud-title { text-align: center; color: #fff; text-shadow: 0 2px 0 #2a7fc4, 0 3px 8px rgba(20,70,130,0.35); min-width: 0; }
#lv-name { font-weight: 700; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-sub { font-size: 0.85rem; font-weight: 600; }
.hud-tip { margin: 0.5rem auto 0; max-width: 30rem; width: calc(100% - 2rem); background: rgba(255,248,230,0.92); border-radius: 0.9rem; padding: 0.4rem 0.75rem; font-size: 0.85rem; font-weight: 500; text-align: center; box-shadow: 0 3px 0 var(--cream-d); }
.hud-tip:empty { display: none; }
.board-spacer { flex: 1; pointer-events: none; }
.hud-bottom { display: flex; align-items: flex-end; justify-content: space-between; gap: 0.6rem; padding: 0 max(0.8rem, var(--sar)) max(0.8rem, var(--sab)) max(0.8rem, var(--sal)); }
.power-tray { display: flex; flex-direction: column; gap: 0.45rem; }
.power { position: relative; display: flex; align-items: center; gap: 0.4rem; background: var(--cream); color: var(--ink); border-radius: 0.95rem; padding: 0.35rem 0.75rem 0.35rem 0.45rem; min-height: 44px; min-width: 7rem;
  box-shadow: 0 4px 0 var(--cream-d), 0 7px 8px rgba(20,40,20,0.2); font-weight: 600; }
.power:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--cream-d); }
.power .pi { font-size: 1.25rem; }
.power .count { margin-left: auto; min-width: 1.5rem; height: 1.5rem; line-height: 1.5rem; border-radius: 999px; background: var(--orange); color: #fff; text-align: center; font-size: 0.85rem; }
.power.is-on { background: #fff3c4; box-shadow: 0 4px 0 var(--orange-d); }
.power-bar { flex: 1; background: rgba(255,248,230,0.96); border-radius: 1rem; padding: 0.6rem; box-shadow: 0 4px 0 var(--cream-d), 0 8px 12px rgba(20,40,20,0.2); display: flex; flex-direction: column; gap: 0.5rem; max-width: 22rem; }
.pb-text { font-size: 0.9rem; font-weight: 500; }
.pb-opts { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pb-opts:empty { display: none; }
.pb-opts button { background: #fff; border-radius: 0.7rem; padding: 0.35rem 0.6rem; font-weight: 600; box-shadow: 0 3px 0 var(--cream-d); min-height: 40px; }
.pb-opts button.ok { background: #e4f6d4; box-shadow: 0 3px 0 var(--green); }
.pb-opts button.bad { background: #e7e3dc; color: #9a948a; box-shadow: none; text-decoration: line-through; }
.pb-opts button.sel { outline: 3px solid var(--orange); }
.pb-btns { display: flex; gap: 0.5rem; justify-content: flex-end; }
.pad { position: relative; width: 9.6rem; height: 9.6rem; flex: none; }
.pad-hub { position: absolute; left: 50%; top: 50%; width: 2.6rem; height: 2.6rem; translate: -50% -50%; border-radius: 50%; background: rgba(255,248,230,0.85); box-shadow: 0 3px 0 var(--cream-d); display: grid; place-items: center; font-size: 0.65rem; font-weight: 700; color: var(--ink-soft); text-align: center; line-height: 1; }
.pad-btn { position: absolute; left: 50%; top: 50%; width: 3.3rem; height: 3.3rem; margin: -1.65rem 0 0 -1.65rem; border-radius: 1rem; background: var(--blue); color: #fff; font-size: 1.2rem;
  box-shadow: 0 4px 0 var(--blue-d), 0 7px 8px rgba(20,40,20,0.25); display: grid; place-items: center; }
.pad-btn svg { display: block; }
.pad-btn:active { filter: brightness(1.1); box-shadow: 0 1px 0 var(--blue-d); }
.pad-btn.hint { background: var(--orange); box-shadow: 0 4px 0 var(--orange-d); animation: pulse 0.8s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.2); } }

/* sheets */
.sheet-wrap { position: absolute; inset: 0; background: rgba(20,50,80,0.35); display: grid; place-items: center; padding: 1rem; z-index: 5; }
.sheet { background: var(--cream); border-radius: 1.4rem; padding: 1.2rem; width: min(26rem, 100%); max-height: calc(100% - 2rem); overflow-y: auto; box-shadow: 0 6px 0 var(--cream-d), 0 18px 30px rgba(10,30,50,0.35); display: flex; flex-direction: column; gap: 0.8rem; }
.sheet h2 { margin: 0; text-align: center; color: var(--ink); }
.sheet .toy { justify-content: center; }
.sheet ul { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.92rem; }
.gang { display: grid; gap: 0.5rem; }
.gang div { display: flex; gap: 0.6rem; align-items: center; font-size: 0.88rem; }
.gang i { width: 1.8rem; height: 1.8rem; border-radius: 0.5rem; flex: none; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.18); }
.win .stars { text-align: center; font-size: 2.6rem; letter-spacing: 0.15em; color: var(--orange); }
.win .stars .off { color: #d9cdb4; }
.win p { margin: 0; text-align: center; }
.win .earned { color: var(--green-d); font-weight: 600; }
.win-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.building { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.9rem; background: rgba(185,227,247,0.85); z-index: 6; font-weight: 600; }
.eb-cube { width: 3rem; height: 3rem; border-radius: 0.6rem; background: var(--red); box-shadow: inset 0 -5px 0 rgba(0,0,0,0.18); animation: eb 1s ease-in-out infinite; transform-origin: 100% 100%; }
@keyframes eb { 0% { transform: rotate(0); } 60%, 100% { transform: rotate(90deg); } }
.toast { position: absolute; left: 50%; top: 22%; translate: -50% 0; background: rgba(59,42,20,0.9); color: #fff; padding: 0.5rem 0.9rem; border-radius: 0.9rem; font-weight: 600; z-index: 7; font-size: 0.95rem; max-width: 90vw; text-align: center; }

/* small phones / foldable folded: tighten */
@media (max-height: 700px) and (orientation: portrait) {
  .pad { width: 8.4rem; height: 8.4rem; } .pad-btn { width: 2.9rem; height: 2.9rem; margin: -1.45rem 0 0 -1.45rem; }
  .power { min-height: 40px; min-width: 6.2rem; } .menu-play { height: 3.2rem; } .toy { min-height: 46px; }
}
/* wide (foldable unfolded / landscape): board on the left, controls in a right column */
@media (min-aspect-ratio: 6/5) {
  #board { width: 62%; }
  .game-screen { left: 62%; background: rgba(255,255,255,0.12); }
  .game-screen .board-spacer { flex: 1; }
  .hud-bottom { flex-direction: row; }
  .menu-screen { margin: 0 0 0 auto; width: 46%; max-width: none; }
  .menu-screen .menu-head { position: fixed; left: 0; width: 54%; top: max(1.2rem, var(--sat)); }
  .menu-screen .menu-spacer { flex: 0 0 0.5rem; }
  .menu-screen { justify-content: center; }
}
@media (min-aspect-ratio: 6/5) and (max-height: 520px) {
  .pad { width: 8rem; height: 8rem; } .pad-btn { width: 2.7rem; height: 2.7rem; margin: -1.35rem 0 0 -1.35rem; }
}
