/* Draw to Save the Cat — styles */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #16181d;
  --accent: #ffce3a;
  --accent2: #ff7a3d;
  --good: #43d67a;
  --bad: #ff4d5e;
  --panel: rgba(20, 24, 34, 0.72);
  --font: 'Baloo 2', 'Comic Sans MS', 'Chalkboard SE', 'Segoe UI', system-ui, sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b1020;
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
#ui > * { pointer-events: auto; }

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.pill.name { font-weight: 900; }
.progwrap {
  flex: 1;
  height: 12px;
  min-width: 40px;
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.progfill {
  height: 100%;
  width: 0%;
  border-radius: 8px;
  background: linear-gradient(90deg, #4fd07a, #ffd21f);
  transition: width .12s linear;
}

.pill {
  background: var(--panel);
  color: #fff;
  border-radius: 14px;
  padding: 7px 12px;
  font-weight: 800;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  white-space: nowrap;
}
.pill .lbl { opacity: .7; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.pill .val { font-variant-numeric: tabular-nums; }

.iconbtn {
  width: 44px; height: 44px;
  border: none;
  border-radius: 14px;
  background: var(--panel);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  transition: transform .08s ease, background .15s ease;
}
.iconbtn:active { transform: scale(.92); }

/* ---------- bottom bar: ink + clear ---------- */
.bottombar {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(560px, calc(100% - 24px));
}
.ink {
  flex: 1;
  background: var(--panel);
  border-radius: 16px;
  padding: 9px 12px 11px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.ink .top {
  display: flex; justify-content: space-between; align-items: baseline;
  color: #fff; font-weight: 800; font-size: 13px; margin-bottom: 6px;
}
.ink .top .hint { font-weight: 700; opacity: .65; font-size: 11px; }
.ink .bar {
  height: 12px;
  border-radius: 8px;
  background: rgba(255,255,255,.18);
  overflow: hidden;
}
.ink .fill {
  height: 100%;
  width: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, #4fc3ff, #7a5cff);
  transition: width .08s linear;
}
.ink.low .fill { background: linear-gradient(90deg, #ff9d3d, #ff4d5e); }

.bigbtn {
  border: none;
  border-radius: 16px;
  padding: 12px 16px;
  font-family: var(--font);
  font-weight: 900;
  font-size: 15px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,.22), 0 8px 18px rgba(0,0,0,.25);
  transition: transform .06s ease, box-shadow .06s ease;
  display: flex; align-items: center; gap: 7px;
}
.bigbtn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.22); }
.bigbtn.clear { background: linear-gradient(180deg, #ff6b7d, #e23b52); }
.bigbtn.play  { background: linear-gradient(180deg, #4fd07a, #22b25a); font-size: 20px; padding: 15px 28px; }
.bigbtn.ghost { background: linear-gradient(180deg, #5a6274, #414859); font-size: 16px; }

/* ---------- level select grid ---------- */
.card.wide { max-width: 560px; }
.title.small { font-size: clamp(22px, 6vw, 32px); margin-bottom: 16px; }
.levelgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.levelcard {
  border: none;
  border-radius: 18px;
  padding: 14px 10px 12px;
  background: linear-gradient(180deg, #3a86ff, #2f6fe0);
  color: #fff;
  cursor: pointer;
  font-family: var(--font);
  box-shadow: 0 5px 0 rgba(0,0,0,.22);
  transition: transform .06s ease, box-shadow .06s ease;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.levelcard:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.22); }
.levelcard .ln { font-size: 26px; font-weight: 900; line-height: 1; }
.levelcard .lt { font-size: 13px; font-weight: 800; opacity: .95; }
.levelcard .ls { font-size: 14px; margin-top: 2px; }
.levelcard.locked { background: linear-gradient(180deg, #3a3f4c, #2b2f3a); opacity: .7; cursor: not-allowed; }

/* ---------- toast ---------- */
#toast {
  position: absolute;
  top: 64px; left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: rgba(20,24,34,.9);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 14px;
  max-width: 88%;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 30%, rgba(10,14,28,.35), rgba(6,9,20,.82));
  backdrop-filter: blur(3px);
  color: #fff;
}
.overlay.hidden { display: none; }

.card {
  background: rgba(24, 28, 40, .82);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 24px;
  padding: 26px 26px 30px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}

.title {
  font-size: clamp(30px, 8vw, 46px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: .5px;
  background: linear-gradient(180deg, #ffe27a, #ffb03a);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.25));
  margin-bottom: 2px;
}
.subtitle { font-size: 16px; font-weight: 800; opacity: .85; margin-bottom: 14px; }

.how {
  text-align: left;
  font-size: 15px;
  line-height: 1.5;
  font-weight: 600;
  opacity: .92;
  background: rgba(255,255,255,.06);
  border-radius: 16px;
  padding: 14px 16px;
  margin: 6px 0 18px;
}
.how li { margin: 4px 0; list-style: none; display: flex; gap: 8px; align-items: flex-start; }
.how li b { color: var(--accent); }

.stats {
  display: flex; gap: 12px; justify-content: center; margin: 8px 0 18px; flex-wrap: wrap;
}
.stat {
  background: rgba(255,255,255,.06);
  border-radius: 16px;
  padding: 12px 18px;
  min-width: 96px;
}
.stat .n { font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; opacity: .7; font-weight: 800; }
.stat.best .n { color: var(--accent); }

.gameover-emoji { font-size: 54px; }
.center-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

.credit { position: absolute; bottom: 8px; width: 100%; text-align: center; font-size: 11px; opacity: .5; font-weight: 700; }

@media (max-height: 560px) {
  .how { display: none; }
  .subtitle { margin-bottom: 8px; }
}
