/* css/game.css - Leo's Owl Maze */
:root {
  --ink: #2b3f9e;
  --ink-dark: #1d2f8f;
  --paper: #f7f1e3;
  --accent: #e05b7a;
  --gold: #f0a500;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  font-family: ui-rounded, "SF Pro Rounded", "Comic Sans MS", "Segoe Print", "Chalkboard SE", "Marker Felt", system-ui, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#loading {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper);
  font-size: 20px; font-weight: 700; z-index: 99;
}
#toast {
  position: fixed;
  left: 50%; bottom: calc(70px + var(--safe-bottom));
  transform: translateX(-50%) translateY(12px);
  max-width: min(92vw, 480px);
  background: rgba(29,47,143,.94);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 20px rgba(0,0,0,.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 60;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.hidden { display: none !important; }

#app { height: 100dvh; }

.screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- title ---------- */
.title-screen { position: relative; }
.title-bg {
  position: absolute; inset: 0;
  background: url("../assets/title-bg.png") center / cover no-repeat;
  filter: saturate(1.05);
}
.title-content {
  position: relative;
  z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(16px + var(--safe-top)) 18px calc(16px + var(--safe-bottom));
  height: 100%;
  text-align: center;
}
.game-title {
  font-size: clamp(44px, 13vw, 88px);
  margin: 0;
  letter-spacing: 2px;
  color: var(--ink-dark);
  text-shadow: 0 2px 0 rgba(255,255,255,.8), 0 6px 18px rgba(43,63,158,.25);
  line-height: .95;
}
.title-2 { color: var(--accent); }
.tagline {
  max-width: 430px;
  margin: 0;
  font-size: clamp(14px, 3.6vw, 19px);
  font-weight: 700;
  background: rgba(255,255,255,.82);
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(43,63,158,.12);
}
.mascot-wrap { position: relative; }
#owl-mascot {
  width: 132px;
  animation: bob 2.6s ease-in-out infinite;
  cursor: pointer;
  filter: drop-shadow(0 8px 10px rgba(43,63,158,.25));
}
.mascot-hint {
  font-size: 12px; font-weight: 700; opacity: .65;
  background: #fff; border-radius: 999px; padding: 3px 10px;
  margin-top: 6px;
}
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg);} 50% { transform: translateY(-9px) rotate(2deg);} }

.btn {
  border: none;
  font-family: inherit;
  cursor: pointer;
  border-radius: 999px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, #4a63d8, var(--ink-dark));
  box-shadow: 0 5px 0 #16225f, 0 10px 18px rgba(29,47,143,.35);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #16225f, 0 4px 8px rgba(29,47,143,.3); }
.btn.big { font-size: clamp(24px, 7vw, 40px); padding: 14px 52px; }
.btn.small { font-size: 16px; padding: 10px 26px; background: #fff; color: var(--ink-dark); box-shadow: 0 4px 0 #d8cbb2, 0 8px 14px rgba(43,63,158,.15); }
.btn.small:active { box-shadow: 0 1px 0 #d8cbb2; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: none; text-decoration: underline; }
.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1);} 50% { transform: scale(1.05);} }

.howto {
  max-width: 430px;
  background: rgba(255,255,255,.92);
  border-radius: var(--radius);
  padding: 12px 18px;
  text-align: left;
  font-size: 15px;
  box-shadow: 0 6px 16px rgba(43,63,158,.15);
}
.howto ul { margin: 6px 0; padding-left: 20px; }
.howto li { margin: 4px 0; }

.title-buttons { display: flex; gap: 12px; }
.credit { font-size: 13px; font-weight: 700; opacity: .7; margin: 0; }
.shake { animation: shake .5s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* ---------- shared hud / buttons ---------- */
.icon-btn {
  position: relative;
  border: none;
  background: #fff;
  border-radius: 12px;
  min-width: 44px; min-height: 44px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(43,63,158,.18);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink);
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { transform: scale(.92); }
.icon-btn.off { opacity: .5; }
.icon-btn.off::after {
  content: "";
  position: absolute;
  left: 45%; top: 8%;
  width: 10%; height: 84%;
  background: var(--accent);
  border-radius: 3px;
  transform: rotate(40deg);
}

.hud-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  background: rgba(255,255,255,.9);
  border-bottom: 2px solid #e3d9c2;
  z-index: 5;
}
.hud-bar h2 { margin: 0; font-size: 22px; flex: 1; text-align: center; }
.hud-title { font-size: 17px; font-weight: 800; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; }
.hud-stat {
  display: inline-flex; align-items: center; gap: 3px;
  background: #fff; border-radius: 999px; padding: 4px 10px;
  font-weight: 800; font-size: 15px;
  box-shadow: 0 2px 5px rgba(43,63,158,.15);
  white-space: nowrap;
}
.hud-stat svg { width: 16px; height: 16px; }
.hud-ico { width: 20px; height: 20px; object-fit: contain; }
.timer span { font-variant-numeric: tabular-nums; }

/* ---------- level select ---------- */
.select-screen { background: var(--paper); }
.cards {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  padding: 16px;
  align-content: start;
}
.level-card {
  border: 3px solid transparent;
  background: #fff;
  border-radius: var(--radius);
  padding: 10px 10px 12px;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  box-shadow: 0 6px 16px rgba(43,63,158,.15);
  transition: transform .1s ease;
}
.level-card:active { transform: scale(.97); }
.level-card.locked { opacity: .75; background: #efe9da; }
.level-card.shake { animation: shake .5s; }
.level-card canvas {
  width: 100%; height: auto; border-radius: 12px;
  background: #fbf7ec; display: block;
}
.level-name { font-size: 21px; font-weight: 800; margin-top: 6px; }
.level-stars { color: var(--gold); font-size: 19px; letter-spacing: 2px; }
.level-best { font-size: 13px; opacity: .7; font-weight: 700; }
.select-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px calc(8px + var(--safe-bottom));
  background: rgba(255,255,255,.9);
  border-top: 2px solid #e3d9c2;
  font-weight: 800;
}

/* ---------- game ---------- */
.game-screen { background: var(--paper); }
#game-wrap { position: relative; flex: 1; min-height: 0; }
#game-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  touch-action: none;
  display: block;
}
.zoom-ctrl {
  position: absolute; right: 10px; bottom: 14px;
  display: flex; flex-direction: column; gap: 8px;
  opacity: .85;
}
.zoom-ctrl .zoom { width: 52px; height: 52px; font-size: 26px; border-radius: 50%; }
#hint {
  min-height: 34px;
  text-align: center;
  padding: 6px 14px calc(8px + var(--safe-bottom));
  font-weight: 800;
  font-size: 15px;
  background: rgba(255,255,255,.92);
  border-top: 2px dashed #e3d9c2;
  opacity: 0;
  transition: opacity .25s;
}
#hint.show { opacity: 1; }

/* ---------- win overlay ---------- */
#overlay-win {
  position: fixed; inset: 0;
  background: rgba(29,47,143,.55);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 50;
  padding: 20px;
}
#overlay-win.show { display: flex; animation: fadein .3s ease; }
@keyframes fadein { from { opacity: 0;} to { opacity: 1;} }
.win-card {
  background: var(--paper);
  border-radius: 24px;
  max-width: 420px;
  width: 100%;
  padding: 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
  animation: pop .35s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: scale(.7); opacity: 0;} to { transform: scale(1); opacity: 1;} }
#win-daddy { width: 150px; margin: -58px auto 0; display: block; filter: drop-shadow(0 8px 12px rgba(0,0,0,.2)); animation: bob 3s ease-in-out infinite; }
.win-card h3 { margin: 10px 0 4px; font-size: 34px; color: var(--ink-dark); }
#win-stars { font-size: 44px; color: #cfc4a8; letter-spacing: 6px; }
#win-stars .star { display: inline-block; opacity: 0; animation: starpop .45s forwards; color: var(--gold); text-shadow: 0 3px 0 #b57e00; }
@keyframes starpop { from { transform: scale(2.2) rotate(-30deg); opacity: 0;} to { transform: scale(1) rotate(0); opacity: 1;} }
#win-msg { font-size: 17px; font-weight: 700; margin: 8px 0; }
#win-stats {
  display: flex; justify-content: space-around; flex-wrap: wrap; gap: 6px;
  background: #fff; border-radius: 14px; padding: 10px;
  font-weight: 800; font-size: 15px;
  margin-bottom: 16px;
}
.win-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#btn-map { display: block; margin: 12px auto 0; }

/* landscape phones */
@media (max-height: 480px) {
  #owl-mascot { width: 90px; }
  .game-title { font-size: 40px; }
  .tagline { display: none; }
  .mascot-hint { display: none; }
}
