/* Wool Sort — Sesame Street colour scheme: a neutral cosy base, then bold saturated
   primaries for everything you can tap. Red = the call to action, yellow = reward,
   blue = tools, green = go, orange = reset. Dark ink outlines keep it chunky and readable. */
:root {
  --ink: #1d1a2b;
  --cream: #fff6ea;
  --card: #fffdf8;
  --red: #e4002b;
  --red-dark: #9c0020;
  --yellow: #ffd23f;
  --yellow-dark: #d9a800;
  --blue: #1f75fe;
  --blue-dark: #0f47b3;
  --green: #3cb44b;
  --green-dark: #24802f;
  --orange: #ff7f11;
  --orange-dark: #c25a00;
  --purple: #7b2cbf;
  --pink: #ff5fa2;
  --shadow: 0 10px 24px rgba(50, 20, 40, 0.28);
  --font-head: 'Fredoka', 'Nunito', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Nunito', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #2b1f2e; color: var(--ink); font-family: var(--font-body); overflow: hidden; }
body { display: flex; justify-content: center; }

#app {
  position: relative; width: 100%; max-width: 520px; height: 100dvh;
  background: #3a2a3f url('../assets/bg.jpg') center / cover no-repeat;
  overflow: hidden; user-select: none; -webkit-user-select: none;
}
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; }
.hidden { display: none !important; }

/* ---------- loading ---------- */
#loading { justify-content: center; color: var(--cream); font-family: var(--font-head); font-size: 20px; }
#loading img { width: 90px; animation: spin 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- menu ---------- */
#menu { padding: max(14px, env(safe-area-inset-top)) 16px 18px; overflow-y: auto; }
#logo { width: min(80%, 370px); margin: 4px 0 4px; filter: drop-shadow(0 8px 14px rgba(40, 10, 30, 0.35)); }
#menu-buttons { display: flex; flex-direction: column; gap: 10px; align-items: center; width: 100%; max-width: 420px; }
.btn.btn-daily {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 8px 14px 8px 10px;
  background: var(--blue); color: #fff; box-shadow: 0 5px 0 var(--blue-dark), 0 8px 14px rgba(0,0,0,.22);
}
.btn.btn-daily:active { box-shadow: 0 2px 0 var(--blue-dark); }
.btn-daily img { height: 48px; width: 48px; object-fit: contain; }
.btn-daily > span { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.btn-daily b { font-size: 19px; }
.btn-daily small { font-family: var(--font-body); font-weight: 700; font-size: 12px; opacity: .95; }
.btn-daily .stars-inline { font-size: 12px; letter-spacing: 1px; }
.btn-daily .stars-inline .on { color: var(--yellow); }
.btn-daily .stars-inline span:not(.on) { color: rgba(255,255,255,.4); }
.btn-daily em { font-style: normal; font-family: var(--font-head); font-weight: 700; font-size: 16px; background: var(--yellow); color: var(--ink); padding: 4px 10px; border-radius: 999px; }
.btn-daily em:empty { display: none; }

#level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; width: 100%; max-width: 420px; margin: 12px 0 10px; }
.lvl {
  --ch: var(--red);
  aspect-ratio: 1; border: 3px solid var(--ink); border-radius: 16px; background: var(--card); color: var(--ink);
  font-family: var(--font-head); font-weight: 700; font-size: 22px; box-shadow: 0 4px 0 var(--ink), 0 8px 14px rgba(0,0,0,.18);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; cursor: pointer; transition: transform .08s;
  position: relative; overflow: hidden;
}
.lvl::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 7px; background: var(--ch); }
.lvl:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.lvl.done { background: var(--yellow); }
.lvl.current { background: #fff; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 4px 0 var(--ink), 0 0 0 0 rgba(228, 0, 43, .55); } 50% { box-shadow: 0 4px 0 var(--ink), 0 0 0 8px rgba(228, 0, 43, 0); } }
.lvl.locked { background: #d9d2cc; color: #8b8078; cursor: default; border-color: #8b8078; box-shadow: 0 4px 0 #8b8078; }
.lvl.locked::before { background: #b8ada4; }
.lvl small { font-size: 12px; letter-spacing: 1px; color: var(--yellow-dark); height: 14px; line-height: 14px; }
.lvl.done small { color: var(--red); }
.lvl.locked small { color: #a89a90; }
.lvl.hard { background: #ffe3e8; }
.lvl.hard.done { background: var(--yellow); }
.lvl.hard small { color: var(--red); font-size: 9px; letter-spacing: .5px; }
.chapter {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; margin-top: 10px;
  color: #fff; font-family: var(--font-head); font-weight: 600; font-size: 16px; text-shadow: 0 2px 4px rgba(0,0,0,.6);
}
.chapter .pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 2px solid var(--ink); text-shadow: none; }
.chapter b { flex: 1; font-weight: 600; }
.chapter em { font-style: normal; font-size: 12px; opacity: .9; }
#howto { width: 100%; max-width: 420px; background: var(--card); border: 3px solid var(--ink); border-radius: 16px; padding: 10px 14px; font-size: 14px; line-height: 1.45; }
#howto summary { font-family: var(--font-head); font-weight: 600; font-size: 17px; cursor: pointer; }
#howto ul { padding-left: 18px; margin: 8px 0 4px; }
.credit { color: rgba(255, 246, 234, .9); font-size: 12px; margin-top: 12px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.credit a { color: var(--yellow); }

/* ---------- buttons ---------- */
.btn {
  border: 3px solid var(--ink); border-radius: 999px; padding: 11px 26px; font-family: var(--font-head); font-weight: 700; font-size: 18px;
  background: var(--card); color: var(--ink); box-shadow: 0 5px 0 var(--ink), 0 8px 14px rgba(0,0,0,.18); cursor: pointer; transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-cta { background: var(--red); color: #fff; font-size: 22px; padding: 13px 44px; }
.btn-yellow { background: var(--yellow); color: var(--ink); }
.btn-green { background: var(--green); color: #fff; }
.btn-blue { background: var(--blue); color: #fff; }

/* ---------- game ---------- */
#game { justify-content: stretch; }
#hud { width: 100%; display: flex; align-items: center; gap: 8px; padding: max(10px, env(safe-area-inset-top)) 10px 6px; }
#hud-title {
  flex: 1; display: flex; flex-direction: column; line-height: 1.05; background: var(--card); border: 3px solid var(--ink);
  border-radius: 14px; padding: 5px 12px; min-width: 0; box-shadow: 0 3px 0 var(--ink);
}
#hud-level { font-family: var(--font-head); font-weight: 700; font-size: 18px; white-space: nowrap; }
#hud-name { font-size: 12px; font-weight: 700; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud-moves {
  text-align: center; line-height: 1; background: var(--yellow); border: 3px solid var(--ink); border-radius: 14px; padding: 4px 10px;
  box-shadow: 0 3px 0 var(--ink); min-width: 74px;
}
#hud-count { font-family: var(--font-head); font-weight: 700; font-size: 24px; display: block; }
#hud-moves small { display: block; font-size: 10px; font-weight: 800; margin-top: 1px; white-space: nowrap; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 3px solid var(--ink); background: var(--blue); color: #fff;
  font-size: 20px; cursor: pointer; box-shadow: 0 3px 0 var(--ink); flex: none;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.icon-btn.off { background: #cfc6c0; opacity: .7; }
#hud-moves { min-width: 70px; }

#stage { position: relative; flex: 1; width: 100%; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; }
#toast {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); max-width: 88%;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 14px; font-size: 14px; font-weight: 700; text-align: center;
  border: 2px solid var(--yellow); box-shadow: var(--shadow); pointer-events: none; animation: pop .25s ease-out;
}
@keyframes pop { from { transform: translateX(-50%) scale(.9); opacity: 0; } }

#toolbar {
  width: 100%; display: flex; justify-content: space-evenly; gap: 6px; padding: 6px 8px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(40, 20, 30, .55), rgba(40, 20, 30, 0));
}
.tool {
  position: relative; flex: 1; max-width: 96px; border: 3px solid var(--ink); border-radius: 18px; padding: 5px 4px 4px;
  color: #fff; font-family: var(--font-head); font-weight: 600; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; box-shadow: 0 4px 0 var(--ink), 0 6px 12px rgba(0,0,0,.2); cursor: pointer;
}
.tool img { height: 34px; width: auto; }
.tool:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.tool:disabled { opacity: .45; }
#btn-undo { background: var(--blue); }
#btn-hint { background: var(--yellow); color: var(--ink); }
#btn-spool { background: var(--green); }
#btn-restart { background: var(--orange); }
.tool .badge {
  position: absolute; top: -8px; right: -6px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--red); color: #fff;
  border: 2px solid var(--ink); font-size: 12px; line-height: 18px; text-align: center; padding: 0 5px;
}

/* ---------- modals ---------- */
.modal { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(30, 15, 30, .55); padding: 20px; z-index: 5; }
.card {
  width: 100%; max-width: 380px; background: var(--card); border: 4px solid var(--ink); border-radius: 26px; padding: 18px 18px 20px; text-align: center;
  box-shadow: var(--shadow); animation: pop-card .3s cubic-bezier(.2, 1.3, .4, 1);
}
@keyframes pop-card { from { transform: scale(.7); opacity: 0; } }
.card .banner { width: 92%; margin: -34px 0 -6px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.25)); }
.card .kitten { height: 150px; }
.card h2 { font-family: var(--font-head); margin: 4px 0 2px; font-size: 26px; color: var(--red); }
.card p { margin: 6px 0 14px; font-size: 15px; font-weight: 700; }
.stars { font-size: 42px; letter-spacing: 4px; color: #d9d2cc; line-height: 1; margin: 2px 0; }
.stars .on { color: var(--yellow); text-shadow: 0 3px 0 var(--yellow-dark); }
.card .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.card .row .btn { padding: 10px 18px; font-size: 16px; }
.card .row .btn-cta { padding: 10px 26px; font-size: 18px; }
