@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,300;1,400&family=Lora:ital,wght@0,400;0,500;1,400&display=swap');

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --cell-size: 50px;
  --wall-color: rgba(255, 255, 255, 0.92);
}

html, body {
  width: 100%; height: 100%; height: 100dvh;
  overflow: hidden;
  font-family: 'Cormorant Garamond', serif;
  background: #000;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ── LAVA LAMP BACKGROUND ── */
#lava-bg {
  position: fixed; inset: 0;
  z-index: 0;
  overflow: hidden;
  transition: filter 1.5s ease;
}

#lava-bg canvas {
  width: 100%; height: 100%;
}

/* ── GAME CONTAINER ── */
#game-container {
  position: relative;
  z-index: 1;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ── HUD ── */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  font-family: 'Cormorant Garamond', serif;
  color: rgba(255, 255, 255, 0.85);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s ease;
}

#hud.visible {
  opacity: 1;
}

#hud .level-label {
  font-size: clamp(14px, 2.5vw, 18px);
  font-weight: 300;
  letter-spacing: 0.15em;
  text-transform: lowercase;
}

#hud .move-counter {
  font-size: clamp(14px, 2.5vw, 18px);
  font-weight: 300;
  letter-spacing: 0.1em;
  font-style: italic;
}

/* ── GRID ── */
#grid-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#grid {
  position: relative;
  display: grid;
  gap: 0;
  border-radius: 4px;
  overflow: visible;
  transition: opacity 0.3s ease;
}

#grid.fading { opacity: 0; }

.cell {
  position: relative;
  width: var(--cell-size);
  height: var(--cell-size);
  background: transparent;
  transition: background 0.3s;
}

.cell.wall {
  background: transparent;
  border: clamp(1.5px, 0.4vw, 2.5px) solid rgba(255, 255, 255, 0.5);
  border-radius: clamp(4px, 1vw, 8px);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.1);
}

/* ── HEART HALVES ── */
.heart-piece {
  position: absolute;
  z-index: 5;
  transition: left 0.2s cubic-bezier(0.22, 1, 0.36, 1),
              top 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.heart-top svg, .heart-bottom svg {
  width: 80%;
  height: 80%;
  filter: drop-shadow(0 0 12px rgba(220, 40, 80, 0.6));
}

.heart-top svg path { fill: #e8435a; stroke: rgba(255,255,255,0.7); stroke-width: 3; }
.heart-bottom svg path { fill: #d63a50; stroke: rgba(255,255,255,0.7); stroke-width: 3; }

.heart-top.no-outline svg path,
.heart-bottom.no-outline svg path {
  stroke: none;
}

.heart-full svg {
  width: 80%;
  height: 80%;
  filter: drop-shadow(0 0 16px rgba(220, 40, 80, 0.7));
}

.heart-full svg path { fill: #e8435a; stroke: rgba(255,255,255,0.7); stroke-width: 3; }

/* ── SPEECH BUBBLES ── */
/* These are positioned absolutely within the grid, NOT as children
   of heart pieces, so they sit above everything. */
.speech-bubble {
  position: absolute;
  z-index: 999;
  background: rgba(0, 0, 0, 0.8);
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  color: #fff;
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: clamp(12px, 2vw, 16px);
  padding: 8px 14px;
  border-radius: 12px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
}

.speech-bubble.visible { opacity: 1; }

/* Tail pointing down-left toward the heart piece */
.speech-bubble::before {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 15px;
  width: 0; height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 8px solid rgba(255, 255, 255, 0.6);
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 16px;
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid rgba(0, 0, 0, 0.8);
}

/* ── TITLE SCREEN ── */
#title-screen {
  position: fixed; inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#title-screen h1 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 300;
  font-size: clamp(42px, 10vw, 80px);
  color: rgba(255, 255, 255, 0.95);
  letter-spacing: 0.2em;
  text-transform: lowercase;
  margin-bottom: 20px;
  text-shadow: 0 0 20px rgba(0, 0, 0, 0.9), 0 0 50px rgba(0, 0, 0, 0.5);
  animation: titlePulse 3s ease-in-out infinite;
}

#title-screen .subtitle {
  font-family: 'Lora', serif;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(14px, 3vw, 20px);
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: 0.15em;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.9), 0 0 30px rgba(0, 0, 0, 0.6);
  animation: subtitleFade 2s ease-in-out infinite alternate;
}

@keyframes titlePulse {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.02); }
}

@keyframes subtitleFade {
  0% { opacity: 0.35; }
  100% { opacity: 0.6; }
}

/* ── LEVEL TRANSITION ── */
#level-transition {
  position: fixed; inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}

#level-transition.active {
  opacity: 1;
  pointer-events: all;
}

#level-transition .level-text {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 300;
  font-size: clamp(28px, 7vw, 56px);
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: 0.25em;
  text-transform: lowercase;
}

/* ── FADE OVERLAY ── */
#fade-overlay {
  position: fixed; inset: 0;
  z-index: 200;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 3s ease;
}

#fade-overlay.active {
  opacity: 1;
  pointer-events: all;
}

/* ── END SCREEN ── */
#end-screen {
  position: fixed; inset: 0;
  z-index: 300;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  gap: 10px;
  padding: 24px;
}

#end-screen.active {
  display: flex;
}

#end-screen .end-title {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 300;
  font-size: clamp(28px, 6vw, 48px);
  color: rgba(255, 255, 255, 0.3);
  letter-spacing: 0.2em;
  text-transform: lowercase;
  margin-bottom: 0;
}

#end-screen .end-moves {
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: clamp(16px, 3vw, 22px);
  color: rgba(255, 255, 255, 0.35);
  letter-spacing: 0.1em;
  margin: 14px 0;
}

#end-screen .links {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 32px;
}

#end-screen .links a {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.3);
  text-decoration: none;
  transition: color 0.4s ease;
}

#end-screen .links a:hover {
  color: rgba(255, 255, 255, 0.5);
}

#end-screen .links a svg {
  flex-shrink: 0;
  stroke: currentColor;
}

/* ── RESTART HINT ── */
#restart-hint {
  position: fixed;
  bottom: 20px;
  left: 24px;
  z-index: 10;
  font-family: 'Lora', serif;
  font-style: italic;
  font-size: clamp(14px, 2.5vw, 18px);
  color: rgba(255, 255, 255, 0.25);
  pointer-events: none;
  opacity: 0;
  transition: opacity 1s ease;
}

#restart-hint.visible {
  opacity: 1;
}

#restart-hint .mobile-only { display: none; }
#restart-hint .desktop-only { display: inline; }

@media (hover: none) and (pointer: coarse) {
  #restart-hint .mobile-only { display: inline; }
  #restart-hint .desktop-only { display: none; }
}

/* ── DEV PANEL ── */
#dev-tap-zone {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 60px;
  height: 60px;
  z-index: 15;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}

#dev-panel {
  position: fixed;
  bottom: 0; right: 0;
  z-index: 400;
  background: rgba(0, 0, 0, 0.92);
  border-top-left-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-bottom: none;
  border-right: none;
  padding: 16px 20px;
  display: none;
  flex-direction: column;
  gap: 8px;
  max-height: 70vh;
  overflow-y: auto;
}

#dev-panel.active {
  display: flex;
}

#dev-panel .dev-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.1em;
  text-transform: lowercase;
  margin-bottom: 4px;
}

#dev-panel button {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.7);
  font-family: 'Lora', serif;
  font-size: 14px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  text-align: left;
}

#dev-panel button:hover {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.95);
}

#dev-panel .dev-close {
  margin-top: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.35);
  text-align: center;
}
