:root {
  color-scheme: light;
  --ink: #0b1326;
  --ink-soft: #2a3450;
  --muted: #94a0b4;
  --line: #e6eaf1;
  --surface: #ffffff;
  --accent: #ff3d68;       /* cardiac red */
  --accent-2: #ff8a5b;     /* coral */
  --accent-soft: #ffeef1;
  --indigo: #6a6ff4;
  --purple: #8b51f5;
  --good: #19c47a;
  --danger: #e11d48;
  --amber: #ffb547;
  --grad-hero: linear-gradient(120deg, #ff8a5b 0%, #ff3d68 45%, #8b51f5 100%);
  --grad-cta:  linear-gradient(120deg, #6a6ff4 0%, #8b51f5 60%, #ff3d68 100%);
  font-family: "Inter", "SF Pro Display", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: #f3f5f9;
  color: var(--ink);
  overflow: hidden;
}

button { font: inherit; }

.app-shell {
  min-height: 100svh;
  display: grid;
  place-items: stretch;
}

.game-panel {
  width: 100%;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: #fff;
}

/* ---------- Top bar ---------- */

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  background: #0b1326;
  color: #fff;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  transition: transform .12s ease, background .2s ease;
}

.pill-btn:active { transform: scale(.96); }
.pill-btn:hover { background: rgba(255, 255, 255, .18); }

.exit-btn {
  background: linear-gradient(120deg, #8b51f5, #6a6ff4);
  box-shadow: 0 4px 12px rgba(139, 81, 245, .45);
}

.exit-btn:hover { background: linear-gradient(120deg, #9462ff, #7079ff); }

.restart-btn {
  background: linear-gradient(120deg, #ff3d68, #ff8a5b);
  box-shadow: 0 4px 12px rgba(255, 61, 104, .4);
}

.restart-btn:hover { background: linear-gradient(120deg, #ff5478, #ff9a6e); }

.streak {
  display: flex;
  justify-content: center;
}

.level-dots {
  display: flex;
  align-items: center;
  gap: 6px;
}

.level-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .25);
  transition: width .25s ease, background .25s ease, transform .25s ease;
}

.level-dot.done {
  background: var(--good);
}

.level-dot.active {
  width: 28px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 0 12px rgba(255, 255, 255, .6);
}

/* ---------- Hero (level header) ---------- */

.hero {
  position: relative;
  padding: 18px 18px 16px;
  background: var(--grad-hero);
  color: #fff;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  inset: -40% -20% auto auto;
  width: 240px;
  height: 240px;
  background: radial-gradient(circle, rgba(255, 255, 255, .35), transparent 60%);
  pointer-events: none;
}

.hero-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  position: relative;
  z-index: 1;
}

.hero-badge {
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .22);
  backdrop-filter: blur(8px);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
}

.hero-shape {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.01em;
  text-shadow: 0 2px 6px rgba(11, 19, 38, .18);
}

.hero-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.hearts {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .22);
  backdrop-filter: blur(8px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3);
}

.heart {
  width: 22px;
  height: 22px;
  background: url("/assets/heart-icon.svg") center / contain no-repeat;
  filter:
    drop-shadow(0 0 1px #fff)
    drop-shadow(0 2px 4px rgba(11, 19, 38, .35));
  animation: heartPop .4s cubic-bezier(.22, 1.2, .36, 1);
}

.heart.empty {
  opacity: .35;
  filter: grayscale(1) brightness(1.6) drop-shadow(0 0 1px rgba(255, 255, 255, .6));
}

@keyframes heartPop {
  0%   { transform: scale(.6); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

.hero-pills {
  display: flex;
  gap: 6px;
}

.stat-pill {
  min-width: 64px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .22);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .02em;
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3);
}

.timer-pill {
  background: rgba(11, 19, 38, .42);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);
}

.timer-pill.danger {
  background: #fff;
  color: var(--accent);
  animation: timerPulse .85s ease-in-out infinite;
}

/* ---------- Board ---------- */

.board-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 8px 4px;
  background: #fff;
  overflow: hidden;
}

.board {
  width: min(96vw, calc(100svh - 300px), 720px);
  aspect-ratio: 1;
  display: block;
  overflow: visible;
}

.grid-dot {
  fill: #c5cdd9;
  opacity: .7;
}

.arrow-piece {
  cursor: pointer;
  outline: none;
  color: var(--ink);
  transform-box: fill-box;
  transition: opacity .25s ease, transform .28s cubic-bezier(.22, .9, .2, 1.02);
}

.arrow-piece:focus-visible .arrow-stem,
.arrow-piece:focus-visible .arrow-head {
  stroke: var(--indigo);
}

.arrow-hit {
  fill: transparent;
  pointer-events: all;
}

.arrow-stem,
.arrow-head {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.arrow-piece.good { color: var(--good); }
.arrow-piece.blocked { color: var(--accent); animation: blockedShake .3s ease; }
.arrow-piece.hint { color: var(--good); animation: hintPulse .7s ease-in-out 2; }

.arrow-piece.good.exit-up    { transform: translateY(-760px); opacity: 0; }
.arrow-piece.good.exit-down  { transform: translateY( 760px); opacity: 0; }
.arrow-piece.good.exit-left  { transform: translateX(-760px); opacity: 0; }
.arrow-piece.good.exit-right { transform: translateX( 760px); opacity: 0; }

.confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

.level-intro {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  z-index: 10;
  animation: introBackdropIn .25s ease-out;
}

.level-intro[hidden] { display: none; }

.level-intro.leaving { animation: introBackdropOut .35s ease-in forwards; }

.level-intro-card {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 28px 36px;
  border-radius: 22px;
  background: #fff;
  box-shadow:
    0 24px 60px rgba(11, 19, 38, .15),
    0 0 0 1px var(--line);
  text-align: center;
  animation: introCardIn .45s cubic-bezier(.22, 1.2, .36, 1);
}

.level-intro.leaving .level-intro-card { animation: introCardOut .3s ease-in forwards; }

.level-intro-eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.level-intro-number {
  margin: 0;
  background: var(--grad-cta);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 46px;
  font-weight: 900;
  letter-spacing: -.02em;
  line-height: 1;
}

.level-intro-title {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .01em;
}

.level-intro-meta {
  margin-top: 8px;
  display: flex;
  gap: 8px;
}

.intro-chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: #f1f4fa;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .02em;
}

.intro-chip + .intro-chip {
  background: #0b1326;
  color: #fff;
}

.message {
  position: absolute;
  inset: auto 24px 18px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(11, 19, 38, .94);
  color: #fff;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 14px 32px rgba(11, 19, 38, .25);
}

/* ---------- Control dock ---------- */

.control-dock {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
}

.dock-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(11, 19, 38, .06);
  transition: transform .14s ease, color .2s ease, border-color .2s ease, box-shadow .2s ease;
}

.dock-button:hover { box-shadow: 0 6px 14px rgba(11, 19, 38, .1); }
.dock-button:active { transform: scale(.94); }
.dock-button:disabled { opacity: .4; cursor: not-allowed; }

.dock-button.hint {
  color: #fff;
  background: linear-gradient(135deg, #ffb547, #ff8a5b);
  border-color: transparent;
  box-shadow: 0 6px 14px rgba(255, 138, 91, .4);
}

.dock-button.hint .hint-count {
  position: absolute;
  right: -3px;
  bottom: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #fff;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(11, 19, 38, .18);
}

.dock-button.grid-toggle.active {
  color: var(--indigo);
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px rgba(106, 111, 244, .18);
}

.next-button {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 14px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--grad-cta);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .02em;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(139, 81, 245, .4);
  transition: transform .14s ease, box-shadow .2s ease, filter .2s ease;
}

.next-button:hover { filter: brightness(1.05); }
.next-button:active { transform: scale(.96); }
.next-button:disabled {
  opacity: .35;
  cursor: not-allowed;
  filter: grayscale(.5);
  box-shadow: none;
}

.next-button:not(:disabled) {
  animation: nextGlow 1.6s ease-in-out infinite;
}

/* ---------- Animations ---------- */

@keyframes blockedShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-14px); }
  75% { transform: translateX(14px); }
}

@keyframes hintPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@keyframes nextGlow {
  0%, 100% { box-shadow: 0 8px 22px rgba(139, 81, 245, .4); }
  50%      { box-shadow: 0 10px 28px rgba(255, 61, 104, .5); }
}

@keyframes introBackdropIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes introBackdropOut { from { opacity: 1; } to { opacity: 0; } }

@keyframes introCardIn {
  0%   { opacity: 0; transform: scale(.7) translateY(20px); }
  60%  { opacity: 1; transform: scale(1.04) translateY(0); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes introCardOut {
  to { opacity: 0; transform: scale(.94) translateY(-8px); }
}

/* ---------- Responsive ---------- */

@media (max-width: 380px) {
  .pill-btn span { display: none; }
  .pill-btn { padding: 9px; }
}

@media (max-width: 460px) {
  .board { width: min(96vw, calc(100svh - 320px)); }
  .heart { width: 20px; height: 20px; }
  .dock-button { width: 48px; height: 48px; }
  .hero-shape { font-size: 19px; }
}
