/* ============================================================
   style.css — Gridditch: Quidditch-themed word search game
   ============================================================ */

/* ── Google Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700;900&family=Lato:wght@300;400;700&display=swap');

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:    #0d0f1e;
  --dark:    #070910;
  --gold:    #f0c040;
  --gold2:   #d4a017;
  --crimson: #8b1a1a;
  --red:     #c0392b;
  --green:   #27ae60;
  --green2:  #1e8449;
  --parchment: #2a1f0e;
  --parch-light: #3a2a10;
  --text:    #e8d5a3;
  --text-dim: #9a8a6a;
  --white:   #ffffff;
  --cell-size: clamp(28px, 8vw, 48px);
  --font-magic: 'Cinzel', serif;
  --font-body:  'Lato', sans-serif;
}

html, body {
  width: 100%; height: 100%;
  overflow-x: hidden;
}

body {
  background: var(--navy);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  position: relative;
}

/* ── Stars Background ── */
.stars-bg {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(240,192,64,.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(139,26,26,.08) 0%, transparent 60%);
}
.stars-bg::before, .stars-bg::after {
  content: '';
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 35% 55%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 15%, rgba(255,255,255,.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 80% 40%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 75%, rgba(255,255,255,.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 50% 85%, rgba(255,255,255,.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 15% 70%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 90%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 25% 10%, rgba(240,192,64,.5) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 75% 5%, rgba(240,192,64,.4) 0%, transparent 100%);
}
.stars-bg::after {
  background-image:
    radial-gradient(1px 1px at 5% 50%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 45% 35%, rgba(255,255,255,.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 65%, rgba(255,255,255,.3) 0%, transparent 100%),
    radial-gradient(1px 1px at 85% 20%, rgba(255,255,255,.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 30% 80%, rgba(255,255,255,.4) 0%, transparent 100%),
    radial-gradient(2px 2px at 65% 50%, rgba(240,192,64,.3) 0%, transparent 100%);
  animation: twinkle 4s ease-in-out infinite alternate;
}
@keyframes twinkle {
  from { opacity: .6; }
  to   { opacity: 1; }
}

/* ── Snitch Animation ── */
.snitch {
  position: fixed;
  width: 28px; height: 28px;
  pointer-events: none;
  z-index: 1;
  top: 15%; left: 10%;
  animation: snitchFly 18s ease-in-out infinite;
}
.snitch-ball {
  width: 20px; height: 20px;
  background: radial-gradient(circle at 35% 35%, #ffe066, var(--gold2));
  border-radius: 50%;
  box-shadow: 0 0 8px 3px rgba(240,192,64,.6), 0 0 20px 6px rgba(240,192,64,.2);
  position: absolute; top: 4px; left: 4px;
}
.snitch-wing {
  position: absolute;
  width: 14px; height: 8px;
  background: radial-gradient(ellipse, rgba(240,192,64,.7), rgba(240,192,64,.1));
  border-radius: 50%;
  top: 8px;
  animation: wingFlap .3s ease-in-out infinite alternate;
}
.snitch-wing.left  { left: -12px; transform-origin: right center; }
.snitch-wing.right { right: -12px; transform-origin: left center; }
@keyframes wingFlap {
  from { transform: scaleY(1) rotate(-15deg); }
  to   { transform: scaleY(0.4) rotate(15deg); }
}
@keyframes snitchFly {
  0%   { top: 15%; left: 10%; }
  15%  { top: 8%;  left: 40%; }
  30%  { top: 20%; left: 75%; }
  45%  { top: 5%;  left: 60%; }
  60%  { top: 25%; left: 85%; }
  75%  { top: 10%; left: 20%; }
  90%  { top: 30%; left: 50%; }
  100% { top: 15%; left: 10%; }
}

/* ── Screens ── */
.screen { position: relative; z-index: 2; }
.screen.hidden { display: none !important; }

/* ============================================================
   SPLASH SCREEN
   ============================================================ */
#splash {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px 16px;
  text-align: center;
}

.splash-logo { margin-bottom: 8px; }
.splash-logo .broom-icon {
  font-size: clamp(48px, 12vw, 80px);
  animation: broomBob 3s ease-in-out infinite;
  display: block;
}
@keyframes broomBob {
  0%, 100% { transform: translateY(0) rotate(-10deg); }
  50%       { transform: translateY(-10px) rotate(10deg); }
}

.splash-title {
  font-family: var(--font-magic);
  font-size: clamp(42px, 12vw, 88px);
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-shadow:
    0 0 20px rgba(240,192,64,.8),
    0 0 60px rgba(240,192,64,.3),
    2px 2px 0 var(--crimson);
  line-height: 1;
  margin-bottom: 6px;
}

.splash-subtitle {
  font-family: var(--font-magic);
  font-size: clamp(11px, 3vw, 16px);
  color: var(--text-dim);
  letter-spacing: 0.25em;
  text-transform: uppercase;
  margin-bottom: 28px;
}

/* Stats bar on splash */
.splash-stats {
  display: flex; gap: 20px;
  margin-bottom: 32px;
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(240,192,64,.25);
  border-radius: 12px;
  padding: 14px 28px;
}
.stat-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.stat-value {
  font-family: var(--font-magic);
  font-size: clamp(22px, 6vw, 34px);
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
}
.stat-label {
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.stat-divider {
  width: 1px; background: rgba(240,192,64,.2); align-self: stretch;
}

/* Already-played message */
.already-played {
  background: rgba(240,192,64,.1);
  border: 1px solid rgba(240,192,64,.3);
  border-radius: 10px;
  padding: 14px 22px;
  margin-bottom: 24px;
  font-family: var(--font-magic);
  font-size: 13px;
  color: var(--gold);
  text-align: center;
  max-width: 320px;
}
.already-played .result-line {
  font-size: 17px;
  margin-bottom: 4px;
}
.already-played .comeback {
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 12px;
  margin-top: 6px;
}

/* Play button */
.btn-play {
  font-family: var(--font-magic);
  font-size: clamp(18px, 5vw, 26px);
  font-weight: 700;
  color: var(--navy);
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold2) 100%);
  border: none; border-radius: 50px;
  padding: 16px 56px;
  cursor: pointer;
  box-shadow:
    0 4px 20px rgba(240,192,64,.5),
    0 0 0 3px rgba(240,192,64,.15);
  transition: transform .15s, box-shadow .15s;
  letter-spacing: .06em;
  position: relative; overflow: hidden;
  margin-bottom: 28px;
}
.btn-play::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.25) 0%, transparent 60%);
  border-radius: inherit;
}
.btn-play:hover  { transform: scale(1.06); box-shadow: 0 6px 28px rgba(240,192,64,.7), 0 0 0 3px rgba(240,192,64,.25); }
.btn-play:active { transform: scale(.97); }
.btn-play:disabled {
  opacity: .5; cursor: not-allowed; transform: none;
}

.date-label {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: .1em;
  font-family: var(--font-magic);
}

/* ============================================================
   GAME SCREEN
   ============================================================ */
#game {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center;
  padding: 12px 12px 24px;
}

/* Header */
.game-header {
  width: 100%; max-width: 540px;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 4px;
}
.game-title {
  font-family: var(--font-magic);
  font-size: clamp(18px, 5vw, 26px);
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(240,192,64,.5);
  letter-spacing: .1em;
}
.game-date {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: .08em;
}

/* Timer */
.timer-wrap {
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}
#timer {
  font-family: var(--font-magic);
  font-size: clamp(28px, 8vw, 44px);
  font-weight: 900;
  color: var(--gold);
  letter-spacing: .08em;
  transition: color .3s, transform .3s;
  text-shadow: 0 0 10px rgba(240,192,64,.4);
}
#timer.urgent {
  color: var(--red);
  text-shadow: 0 0 12px rgba(192,57,43,.6);
  animation: timerPulse .7s ease-in-out infinite;
}
@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.18); }
}

/* Grid */
.grid-container {
  position: relative;
  background: linear-gradient(145deg, #1e1208, var(--parchment));
  border: 2px solid var(--gold2);
  border-radius: 10px;
  padding: 10px;
  box-shadow:
    0 0 0 1px rgba(240,192,64,.1),
    0 0 30px rgba(0,0,0,.6),
    inset 0 0 40px rgba(240,192,64,.04);
  margin-bottom: 14px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#grid {
  display: grid;
  grid-template-columns: repeat(10, var(--cell-size));
  grid-template-rows:    repeat(10, var(--cell-size));
  gap: 2px;
}

.cell {
  width: var(--cell-size); height: var(--cell-size);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-magic);
  font-size: clamp(13px, 3.5vw, 20px);
  font-weight: 600;
  color: var(--text);
  border-radius: 4px;
  border: 1px solid rgba(240,192,64,.1);
  background: rgba(255,255,255,.02);
  cursor: default;
  transition: background .1s, color .1s;
  position: relative;
}
.cell.selecting {
  background: rgba(240,192,64,.25);
  color: var(--white);
  border-color: rgba(240,192,64,.5);
}
.cell.found {
  background: rgba(39,174,96,.25) !important;
  color: #7aeb9a !important;
  border-color: rgba(39,174,96,.5) !important;
}
.cell.wrong-flash {
  background: rgba(192,57,43,.3) !important;
  color: #ff8a7a !important;
  border-color: rgba(192,57,43,.5) !important;
}

/* Sparkle effect on found cells */
@keyframes sparkle {
  0%   { transform: scale(0) rotate(0deg);   opacity: 1; }
  60%  { transform: scale(1.4) rotate(180deg); opacity: .8; }
  100% { transform: scale(0) rotate(360deg); opacity: 0; }
}
.sparkle-particle {
  position: absolute;
  width: 6px; height: 6px;
  pointer-events: none;
  z-index: 10;
  border-radius: 50%;
  animation: sparkle .7s ease-out forwards;
}

/* Word list */
.word-list-wrap {
  width: 100%; max-width: 540px;
}
.word-list-title {
  font-family: var(--font-magic);
  font-size: 11px;
  letter-spacing: .15em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 8px;
  text-align: center;
}
.word-list {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center;
}
.word-chip {
  font-family: var(--font-magic);
  font-size: clamp(10px, 2.8vw, 14px);
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--text);
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(240,192,64,.2);
  border-radius: 20px;
  padding: 5px 12px;
  transition: all .3s;
}
.word-chip.found {
  background: rgba(39,174,96,.2);
  border-color: rgba(39,174,96,.5);
  color: #7aeb9a;
  text-decoration: line-through;
  text-decoration-color: rgba(122,235,154,.6);
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.hidden { display: none !important; }

.modal {
  background: linear-gradient(160deg, #111628, #0d0f1e 60%, #1a0d0d);
  border: 2px solid var(--gold2);
  border-radius: 16px;
  padding: 32px 28px;
  max-width: 380px; width: 100%;
  text-align: center;
  box-shadow: 0 0 60px rgba(240,192,64,.2), 0 20px 60px rgba(0,0,0,.6);
  position: relative;
  overflow: hidden;
  animation: modalIn .4s cubic-bezier(.34,1.56,.64,1);
}
@keyframes modalIn {
  from { transform: scale(.7); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}
.modal::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(240,192,64,.08) 0%, transparent 70%);
  pointer-events: none;
}

.modal-icon {
  font-size: 56px;
  margin-bottom: 10px;
  display: block;
  animation: popIn .5s cubic-bezier(.34,1.56,.64,1) .1s both;
}
@keyframes popIn {
  from { transform: scale(0) rotate(-20deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}
.modal-title {
  font-family: var(--font-magic);
  font-size: clamp(18px, 6vw, 26px);
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 16px rgba(240,192,64,.5);
  margin-bottom: 8px;
  line-height: 1.2;
}
.modal-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 20px;
  line-height: 1.5;
  font-style: italic;
}
.modal-stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: rgba(0,0,0,.3);
  border-radius: 10px;
  padding: 14px 8px;
  margin-bottom: 16px;
  border: 1px solid rgba(240,192,64,.1);
}
.modal-stat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.modal-stat-value {
  font-family: var(--font-magic);
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
}
.modal-stat-label {
  font-size: 9px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1.2;
  text-align: center;
}
.modal-result-line {
  font-family: var(--font-magic);
  font-size: 14px;
  color: var(--text);
  margin-bottom: 16px;
}
.modal-result-line span {
  color: var(--gold);
  font-weight: 700;
}
.modal-buttons {
  display: flex; flex-direction: column; gap: 10px;
}
.btn-share {
  font-family: var(--font-magic);
  font-size: 14px; font-weight: 700;
  color: var(--navy);
  background: linear-gradient(135deg, var(--gold), var(--gold2));
  border: none; border-radius: 50px;
  padding: 13px 24px; cursor: pointer;
  letter-spacing: .06em;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 3px 14px rgba(240,192,64,.4);
}
.btn-share:hover  { transform: scale(1.04); box-shadow: 0 5px 20px rgba(240,192,64,.6); }
.btn-share:active { transform: scale(.97); }

.btn-tomorrow {
  font-family: var(--font-magic);
  font-size: 13px;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid rgba(240,192,64,.2);
  border-radius: 50px;
  padding: 11px 24px; cursor: pointer;
  letter-spacing: .06em;
  transition: all .15s;
}
.btn-tomorrow:hover { color: var(--text); border-color: rgba(240,192,64,.5); }

.countdown-next {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 10px;
  letter-spacing: .06em;
}
.countdown-next span {
  color: var(--gold);
  font-family: var(--font-magic);
  font-weight: 700;
}

/* ── Confetti canvas (win) ── */
#confettiCanvas {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 99;
}

/* ── Toast ── */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: rgba(39,174,96,.9);
  color: #fff;
  font-family: var(--font-magic);
  font-size: 13px; letter-spacing: .06em;
  padding: 10px 22px;
  border-radius: 50px;
  z-index: 200;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ── Responsive ── */
@media (max-width: 420px) {
  :root { --cell-size: clamp(26px, 8.5vw, 36px); }
  .splash-stats { padding: 10px 14px; gap: 12px; }
  .modal { padding: 24px 18px; }
  .modal-stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 640px) {
  :root { --cell-size: 46px; }
}
