/* ============================================================
   Love Tetris — warm light-pink theme
   Palette lives here and is mirrored in js/config.js for canvas
   drawing (canvas can't read CSS custom properties).
   ============================================================ */

:root {
  --bg:            #FFF5F0;  /* warm blush page */
  --bg-deep:       #FFEDE5;
  --surface:       #FFFAF7;  /* cream cards */
  --board-bg:      #FFEDE7;
  --grid:          #FFE0D6;
  --accent:        #F49AA8;  /* coral pink */
  --accent-deep:   #E87F91;
  --accent-soft:   #F7C6C7;
  --glow:          #FFE0B2;  /* warm gold */
  --text:          #7A3B4A;  /* deep rose, readable on blush */
  --text-muted:    #A9737F;
  --shadow:        0 10px 30px rgba(200, 120, 130, 0.18);
  --shadow-soft:   0 4px 14px rgba(200, 120, 130, 0.13);
  --radius:        18px;
  --radius-sm:     12px;
  --font-display:  'Quicksand', 'Nunito', 'Segoe UI', system-ui, sans-serif;
  --font-body:     'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, #FFE8DE 0%, transparent 55%),
    radial-gradient(circle at 85% 85%, #FFEAF0 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- drifting hearts ---------- */
.petals {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.petal {
  position: absolute;
  color: var(--accent-soft);
  opacity: 0;
  animation: drift linear infinite;
  user-select: none;
}
@keyframes drift {
  0%   { transform: translateY(105vh) rotate(0deg)   scale(.8); opacity: 0; }
  10%  { opacity: .55; }
  90%  { opacity: .35; }
  100% { transform: translateY(-12vh) rotate(320deg) scale(1.1); opacity: 0; }
}

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: .02em;
  border: none;
  border-radius: 999px;
  padding: 13px 34px;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
  touch-action: manipulation;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #F7B79E 100%);
  color: #fff;
  box-shadow: 0 6px 18px rgba(244, 154, 168, .45);
}
.btn-primary:hover  { transform: translateY(-2px); box-shadow: 0 9px 24px rgba(244, 154, 168, .55); }
.btn-primary:active { transform: translateY(0); }
.btn-soft {
  background: var(--surface);
  color: var(--accent-deep);
  box-shadow: var(--shadow-soft);
}
.btn-soft:hover { transform: translateY(-2px); }
.btn-ghost {
  background: rgba(255, 255, 255, .7);
  color: var(--text-muted);
  border: 1.5px solid var(--accent-soft);
}
.btn-ghost:hover { background: #fff; color: var(--accent-deep); }
.btn-small { padding: 9px 22px; font-size: .85rem; width: 100%; }

/* ---------- generic screens / overlays ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.screen[hidden] { display: none; }
.screen-dim  { background: rgba(255, 232, 226, .82); backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px); }
.screen-dark { background: rgba(70, 40, 46, .92);  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

/* ---------- title screen ---------- */
#titleScreen {
  background:
    radial-gradient(circle at 30% 20%, #FFE6DC 0%, transparent 60%),
    radial-gradient(circle at 70% 80%, #FFE7EE 0%, transparent 60%),
    var(--bg);
}
.title-card {
  text-align: center;
  animation: rise .7s cubic-bezier(.2, .8, .3, 1) both;
  max-width: 520px;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(22px); }
  to   { opacity: 1; transform: translateY(0); }
}
.title-heart {
  font-size: 3.2rem;
  color: var(--accent);
  animation: beat 2.1s ease-in-out infinite;
  line-height: 1;
}
@keyframes beat {
  0%, 100% { transform: scale(1); }
  14%      { transform: scale(1.16); }
  28%      { transform: scale(1); }
  42%      { transform: scale(1.1); }
}
.title-name {
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 11vw, 4.4rem);
  font-weight: 700;
  margin: .12em 0 .1em;
  background: linear-gradient(120deg, var(--accent-deep), #F5A77F);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.1;
}
.title-sub {
  color: var(--text-muted);
  font-size: 1.02rem;
  margin: 0 0 2rem;
}
.title-hint {
  margin-top: 1.9rem;
  font-size: .78rem;
  color: var(--text-muted);
  opacity: .85;
  line-height: 1.7;
}
.mobile-hint  { display: none; }
@media (hover: none) and (pointer: coarse) {
  .desktop-hint { display: none; }
  .mobile-hint  { display: inline; }
}

/* ---------- game layout ---------- */
.game {
  display: flex;
  gap: 26px;
  align-items: flex-start;
  position: relative;
  z-index: 1;
  animation: rise .5s ease both;
}
.game[aria-hidden="true"] { display: none; }

.board-wrap { display: flex; flex-direction: column; gap: 14px; }

/* Sits in the flow above the board rather than floating over it, so it can
   never overlap the play area on a narrow screen. */
.back-link {
  align-self: flex-start;
  font-family: var(--font-display);
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  background: var(--surface);
  border: 1.5px solid var(--accent-soft);
  border-radius: 999px;
  padding: 8px 17px;
  box-shadow: var(--shadow-soft);
  transition: color .18s ease, border-color .18s ease, transform .18s ease;
  white-space: nowrap;
}
.back-link:hover {
  color: var(--accent-deep);
  border-color: var(--accent);
  transform: translateX(-3px);
}

.board-stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--board-bg);
  border: 3px solid #fff;
}
#board {
  display: block;
  touch-action: none;
  max-width: 100%;
  height: auto;
}

.board-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 240, 236, .88);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.board-overlay[hidden] { display: none; }
.pause-text {
  font-family: var(--font-display);
  font-size: 1.7rem;
  color: var(--accent-deep);
  letter-spacing: .06em;
}

/* ---------- side panel ---------- */
.side {
  width: 210px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
.stat {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.stat-label {
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-muted);
}
.stat-value {
  font-family: var(--font-display);
  font-size: 1.28rem;
  font-weight: 700;
  color: var(--accent-deep);
  font-variant-numeric: tabular-nums;
}

.previews { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.preview {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px;
  box-shadow: var(--shadow-soft);
  text-align: center;
}
.preview-label {
  display: block;
  font-size: .62rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.preview canvas { display: block; width: 100%; height: auto; }

/* ---------- memory shelf ---------- */
.shelf {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px;
  box-shadow: var(--shadow-soft);
}
.shelf-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 9px;
}
.shelf-title {
  font-family: var(--font-display);
  font-size: .82rem;
  font-weight: 700;
  color: var(--accent-deep);
}
.shelf-count { font-size: .72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.shelf-slots { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }

.slot {
  aspect-ratio: 1;
  border-radius: 9px;
  border: none;
  padding: 0;
  overflow: hidden;
  position: relative;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition: transform .18s ease, box-shadow .18s ease;
}
.slot.locked::after {
  content: '♡';
  font-size: 1rem;
  color: var(--accent-soft);
}
.slot.unlocked { cursor: pointer; box-shadow: 0 0 0 2px var(--accent-soft); }
.slot.unlocked:hover { transform: scale(1.12); box-shadow: 0 0 0 2px var(--accent), var(--shadow-soft); }
.slot img, .slot video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.slot.just-unlocked { animation: pop .6s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes pop {
  0%   { transform: scale(.5); }
  60%  { transform: scale(1.22); }
  100% { transform: scale(1); }
}
.shelf-hint {
  margin: 9px 0 0;
  font-size: .68rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- memory unlock card ---------- */
.memory-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 18px;
  box-shadow: 0 24px 60px rgba(190, 110, 120, .3);
  max-width: min(560px, 92vw);
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  position: relative;
  animation: cardIn .55s cubic-bezier(.2, 1.1, .3, 1) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: scale(.82) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.memory-media {
  width: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  position: relative;
}
.memory-media img,
.memory-media video {
  width: 100%;
  max-height: 62dvh;
  object-fit: contain;
  display: block;
}
.memory-caption {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text);
  text-align: center;
}
.memory-caption[hidden] { display: none; }

/* unmute button on video memories */
.unmute-btn {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(255, 255, 255, .92);
  color: var(--accent-deep);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: .8rem;
  font-weight: 700;
  font-family: var(--font-display);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  z-index: 2;
}
.unmute-btn:hover { background: #fff; }

.memory-sparkle { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 24px; }
.spark {
  position: absolute;
  font-size: 1rem;
  color: var(--accent);
  animation: sparkUp 1.5s ease-out forwards;
}
@keyframes sparkUp {
  0%   { transform: translateY(0) scale(.4); opacity: 0; }
  25%  { opacity: 1; }
  100% { transform: translateY(-130px) scale(1.15); opacity: 0; }
}

/* missing-file placeholder */
.media-fallback {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, #FFE8E0, #FFEEF2);
  color: var(--text-muted);
  font-size: .8rem;
  text-align: center;
  padding: 14px;
}
.media-fallback::before { content: '♡'; font-size: 2rem; color: var(--accent-soft); }

/* ---------- game over ---------- */
.over-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(190, 110, 120, .3);
  max-width: min(620px, 94vw);
  max-height: 92dvh;
  overflow-y: auto;
  text-align: center;
  animation: cardIn .5s cubic-bezier(.2, 1.1, .3, 1) both;
}
.over-title {
  font-family: var(--font-display);
  font-size: 1.7rem;
  margin: 0 0 18px;
  background: linear-gradient(120deg, var(--accent-deep), #F5A77F);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.over-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  margin-bottom: 20px;
}
.over-stats .stat { background: var(--bg-deep); box-shadow: none; align-items: center; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 9px;
  margin-bottom: 18px;
}
.gallery-item {
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  border: none;
  padding: 0;
  background: var(--bg-deep);
  position: relative;
  transition: transform .2s ease, box-shadow .2s ease;
}
.gallery-item:hover { transform: translateY(-3px) scale(1.03); box-shadow: var(--shadow-soft); }
.gallery-item img, .gallery-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item .play-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .45);
  pointer-events: none;
}
.over-note { font-size: 1.5rem; color: var(--accent); margin: 6px 0 18px; }

/* ---------- lightbox ---------- */
.lb-stage {
  max-width: 92vw;
  max-height: 86dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-stage img, .lb-stage video {
  max-width: 92vw;
  max-height: 86dvh;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  display: block;
}
.lb-nav, .lb-close {
  position: absolute;
  background: rgba(255, 255, 255, .16);
  color: #fff;
  border: none;
  cursor: pointer;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  transition: background .18s ease;
}
.lb-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  font-size: 2rem;
  line-height: 1;
}
.lb-nav:hover, .lb-close:hover { background: rgba(255, 255, 255, .3); }
.lb-prev  { left: 16px; }
.lb-next  { right: 16px; }
.lb-close { top: 18px; right: 18px; width: 44px; height: 44px; font-size: 1.6rem; line-height: 1; }

/* ---------- touch controls ---------- */
.touch-controls { display: none; }
.tbtn {
  background: var(--surface);
  border: 1.5px solid var(--accent-soft);
  color: var(--accent-deep);
  border-radius: 14px;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: var(--font-display);
  padding: 15px 0;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.tbtn:active { background: var(--accent-soft); transform: scale(.95); }
.tbtn-wide { grid-column: span 2; font-size: .9rem; letter-spacing: .1em; }

/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 760px) {
  body { padding: 10px; align-items: flex-start; }

  .game {
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
  }

  /* Cap the wrap at the board's width so the back link's left edge lines up
     with the board instead of floating out at the screen edge. */
  .board-wrap { width: 100%; max-width: 340px; align-items: center; gap: 10px; }
  .board-stage { width: 100%; max-width: 340px; }

  /* Compact, so it costs as little vertical space as possible on a phone. */
  .back-link { font-size: .75rem; padding: 6px 13px; }

  .side { width: 100%; max-width: 340px; }

  .stats { grid-template-columns: repeat(4, 1fr); }
  .stat { padding: 7px 8px; align-items: center; }
  .stat-value { font-size: 1.05rem; }
  .stat-label { font-size: .58rem; }

  .previews { grid-template-columns: 1fr 1fr; }

  .touch-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 340px;
  }

  #pauseBtn { order: 5; }

  .lb-nav { width: 44px; height: 44px; font-size: 1.6rem; }
  .lb-prev { left: 8px; }
  .lb-next { right: 8px; }
}

/* stop scroll-bounce while playing on touch devices */
body.playing { overscroll-behavior: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .petals { display: none; }
}
