/* Root and reset */
:root {
  --brand:#0C1756;
  --brand-mid:#1b2c7e;
  --brand-dark:#070d2e;
  --brand-light:#f1f4ff;
  --brand-glow:rgba(12,23,86,0.55);
  --accent:#2f4fe0;
  --accent-light:#4f6bf5;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: radial-gradient(120% 120% at 50% 0%, #2e448f 0%, rgba(12,23,86,0.95) 45%, #050921 100%);
  color: #fff;
  user-select: none;
  overflow: hidden;
}

#game { position: relative; overflow: hidden; height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
#game > * { position: relative; z-index: 1; }
#game::before,
#game::after {
  content: "";
  position: absolute;
  inset: -45%;
  background: radial-gradient(ellipse at center, rgba(79,107,245,0.18), rgba(12,23,86,0));
  filter: blur(60px);
  opacity: 0.55;
  animation: backdrop-drift 18s ease-in-out infinite;
  mix-blend-mode: screen;
  pointer-events: none;
  z-index: 0;
}
#game::after {
  animation-duration: 24s;
  animation-direction: reverse;
  opacity: 0.4;
}
/* Fine-tune for small iframe embeds (phone mockup in examples) */
@media (max-width: 460px){
  /* Tighten spacing inside the frame on small embeds */
  .topbar{ padding: 10px clamp(8px, 4vw, 10px); }
  .brand{ display:none; }
  /* Shrink the letter tray a bit more so it fully fits */
  .tray{ width: min(50vw, 220px); height: min(50vw, 220px); }
}

@media (max-width: 360px){
  .tray{ width: min(48vw, 204px); height: min(48vw, 204px); }
}

@media (max-height: 560px){
  .tray-wrap{ padding-bottom: 10px; }
}

/* Top */
.topbar {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  padding: 12px 16px;
}
.badge {
  position: relative;
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,0.06);
  box-shadow: inset 0 0 0 1.6px rgba(255,255,255,0.45), 0 4px 12px rgba(0,0,0,0.35);
  overflow: hidden;
}
.timer-svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.timer-track { stroke: rgba(255,255,255,0.25); stroke-width: 4; fill: none; }
.timer-progress { stroke: #ffffff; stroke-width: 4; fill: none; stroke-linecap: round; }
#progress { text-align: center; font-weight: 800; font-size: 28px; letter-spacing: 1px; }
.brand {
  justify-self: end;
  width: 36px; height: 36px; border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(255,255,255,0.92) 0 20%, rgba(255,255,255,0.4) 20% 45%, rgba(255,255,255,0.92) 45% 60%, rgba(255,255,255,0.4) 60% 80%, rgba(255,255,255,0.92) 80% 100%);
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

/* Stage */
.stage { display: grid; grid-template-rows: auto 1fr; padding: 0 clamp(10px, 3vw, 16px); }
.hint { text-align: center; opacity: .85; font-weight: 600; padding: 6px 0 2px; font-size: 14px; }

.board { display: grid; gap: clamp(4px, 1.2vw, 6px); justify-content: center; align-content: start; padding: 28px 0 0; grid-template-columns: repeat(13, clamp(15px, 5.2vw, 32px)); grid-auto-rows: clamp(15px, 5.2vw, 32px); }
.word-row { display: contents; }
.cell {
  width: 100%; height: 100%;
  border-radius: 10px;
  background: rgba(12,23,86,0.38);
  box-shadow: inset 0 -2px 0 rgba(255,255,255,0.05);
  display: grid; place-items: center;
  font-weight: 800; font-size: clamp(14px, 2.8vw, 18px);
  text-transform: uppercase;
}
.cell.revealed { background: rgba(241,244,255,0.98); color: var(--brand); box-shadow: 0 6px 14px rgba(7,13,46,0.28); }
.cell.active { outline: 2px solid rgba(79,107,245,0.35); background: rgba(12,23,86,0.28); }
.cell.revealed.active { background: rgba(241,244,255,0.98) !important; color: var(--brand); outline: none; }
.word-row.solved .cell { transform: translateY(-1px); }

/* Tray */
.tray-wrap { position: relative; padding: 10px 14px 18px; }
.current-word { text-align: center; font-weight: 700; min-height: 24px; opacity: .9; }
.tray-controls { display: none; }
.shuffle {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: transparent; border: none; width: auto; height: auto; border-radius: 0;
  color: rgba(255,255,255,0.9); font-weight: 900; font-size: clamp(24px, 5.2vw, 30px);
  text-shadow: 0 4px 12px rgba(5,9,33,0.6);
  z-index: 3; cursor: pointer; padding: 0; line-height: 1;
}
.shuffle:active { transform: translate(-50%, -50%) scale(.96); }

.tray {
  position: relative;
  width: min(68vw, 280px);
  height: min(68vw, 280px);
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(120% 120% at 50% 10%, rgba(47,79,224,0.22) 0%, rgba(12,23,86,0.18) 65%, rgba(7,13,46,0.4) 100%);
  box-shadow: inset 0 0 0 1px rgba(79,107,245,0.28), 0 16px 36px rgba(5,9,33,0.55);
  transition: background .2s ease, box-shadow .2s ease;
}

.tile {
  position: absolute;
  width: clamp(38px, 11vw, 56px);
  height: clamp(38px, 11vw, 56px);
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: clamp(22px, 5.4vw, 32px);
  color: #f7f9ff;
  background: transparent;
  box-shadow: none;
  touch-action: none;
  transform: translate(-50%, -50%);
  z-index: 1;
  text-shadow: 0 4px 14px rgba(5,9,33,0.6);
}
.tile.selected { outline: none; box-shadow: none; color: #ffcc4d; text-shadow: 0 4px 14px rgba(5,9,33,0.65); }
/* .tile.hit animation removed as per request */

@keyframes pop { from { transform: scale(.96); } to { transform: scale(1); } }

.tray.shake { animation: shake .55s cubic-bezier(.36,.07,.19,.97); transform-origin: 50% 55%; }
@keyframes shake {
  0% { transform: translateX(0) rotate(0deg); }
  8% { transform: translate(-18px, -2px) rotate(-5deg); }
  16% { transform: translate(22px, 2px) rotate(5deg); }
  24% { transform: translate(-26px, -4px) rotate(-6deg); }
  32% { transform: translate(26px, 4px) rotate(6deg); }
  40% { transform: translate(-22px, 2px) rotate(-5deg); }
  48% { transform: translate(20px, -2px) rotate(4deg); }
  56% { transform: translate(-18px, 1px) rotate(-4deg); }
  64% { transform: translate(16px, -1px) rotate(3deg); }
  72% { transform: translate(-12px, 1px) rotate(-3deg); }
  80% { transform: translate(12px, -1px) rotate(2deg); }
  88% { transform: translate(-6px, 0) rotate(-1deg); }
  100% { transform: translateX(0) rotate(0deg); }
}

.tray.error {
  background: radial-gradient(120% 120% at 50% 10%, rgba(255, 90, 90, 0.30) 0%, rgba(255, 90, 90, 0.18) 65%, rgba(7,13,46,0.4) 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 120, 120, 0.92), 0 0 24px rgba(255, 120, 120, 0.45), 0 16px 36px rgba(5,9,33,0.55);
}

/* Overlays (start + win) */
.hidden { display: none; }
.overlay.hidden { display: none !important; }
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center; backdrop-filter: blur(8px) saturate(120%);
  background: rgba(7,13,46,0.55);
  z-index: 1000;
}
.win-card {
  position: relative;
  overflow: hidden;
  width: min(88vw, 640px);
  padding: 28px 28px 32px;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(180deg, rgba(241,244,255,0.96), rgba(221,230,255,0.94));
  color: var(--brand);
  box-shadow: 0 24px 60px rgba(7,13,46,0.45);
}
.win-card::before {
  content: "";
  position: absolute;
  inset: -45%;
  background: conic-gradient(from 0deg, rgba(79,107,245,0.55), rgba(12,23,86,0.0) 55%, rgba(79,107,245,0.45));
  filter: blur(70px);
  opacity: .65;
  animation: aurora-spin 10s linear infinite;
  z-index: -1;
}
.win-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(12,23,86,0.08);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.4);
  pointer-events: none;
}
.win-card {
  animation: none;
}
.win-card.enter {
  animation: pop-in .45s ease both;
}
.win-card h2 {
  font-size: clamp(24px, 6.5vw, 40px);
  font-weight: 900;
  animation: breathe 3s ease-in-out infinite, title-glow 3.6s ease-in-out alternate infinite;
}
.win-card p {
  font-size: clamp(14px, 3.5vw, 18px);
  opacity: .75;
  animation: floaty 4s ease-in-out infinite, subtitle-glow 6s ease-in-out infinite;
  color: rgba(12,23,86,0.76);
}
.cta, .replay, .secondary {
  width: 100%; border: 0; border-radius: 14px; padding: 16px 18px; font-size: 18px; font-weight: 800; margin-top: 12px;
}
.cta { background: linear-gradient(120deg, var(--accent-light), var(--brand)); color: #fff; box-shadow: 0 10px 22px rgba(12,23,86,0.28); }
.replay { background: rgba(12,23,86,0.08); color: var(--brand); }
.secondary { background: rgba(12,23,86,0.12); color: var(--brand); }

@media (min-width: 540px) {
  .tile { font-size: 32px; width: 64px; height: 64px; }
}

/* Drag path */
.path-svg { position: absolute; inset: 0; pointer-events: none; z-index: 0; }

/* Active word highlight */
.word-row.active .cell { outline: 2px solid rgba(79,107,245,0.35); background: rgba(12,23,86,0.26); }

/* Breathing letters */
.tile.breathe { animation: tile-breathe 1.8s ease-in-out infinite; }
@keyframes tile-breathe { 0% { transform: translate(-50%, -50%) scale(1);} 50% { transform: translate(-50%, -50%) scale(1.06);} 100% { transform: translate(-50%, -50%) scale(1);} }

/* Overlay animations */
@keyframes pop-in { from { transform: translateY(12px) scale(.96); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
@keyframes breathe { 0%,100% { transform: scale(0.96);} 50% { transform: scale(1.08);} }
@keyframes floaty { 0%,100% { transform: translateY(0);} 50% { transform: translateY(12px);} }
@keyframes aurora-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes win-float { 0%,100% { transform: translateY(0) scale(1); } 45% { transform: translateY(-12px) scale(1.015); } 75% { transform: translateY(9px) scale(0.992); } }
@keyframes title-glow { 0% { text-shadow: 0 6px 18px rgba(12,23,86,0.25); } 40% { text-shadow: 0 16px 36px rgba(79,107,245,0.55); } 100% { text-shadow: 0 6px 18px rgba(12,23,86,0.25); } }
@keyframes subtitle-glow { 0%,100% { color: rgba(12,23,86,0.68); } 50% { color: rgba(79,107,245,0.95); } }
@keyframes backdrop-drift {
  0% { transform: translate3d(-12%, -8%, 0) scale(1); }
  38% { transform: translate3d(10%, 12%, 0) scale(1.08) rotate(4deg); }
  68% { transform: translate3d(-6%, 16%, 0) scale(1.04) rotate(-3deg); }
  100% { transform: translate3d(-12%, -8%, 0) scale(1); }
}

/* Celebration */
.celebrate-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 900; }
.cell.burst { animation: cell-burst .35s ease; }
@keyframes cell-burst {
  0% { transform: scale(0.96); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* Hand hint */
.hand-hint {
  position: absolute; width: 40px; height: 40px; transform: translate(-50%, -50%);
  display: grid; place-items: center; font-size: 28px; line-height: 1; pointer-events: none; z-index: 4;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.35));
  transition: opacity .2s ease;
}
