/* ── Category Cauldron — Styles ─────────────────────────────────────────────── */

/* ── Google Fonts ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700;900&family=IM+Fell+English:ital@0;1&display=swap');

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

:root {
  --bg:         #0d0a1a;
  --bg2:        #160f30;
  --gold:       #c9a227;
  --gold-light: #f0d060;
  --purple:     #6a2fa0;
  --purple-light: #9b59b6;
  --text:       #e8dfc8;
  --text-dim:   #a09070;
  --card:       #1e1535;
  --card2:      #261c44;
  --danger:     #e84040;
  --radius:     12px;
  --font-head:  'Cinzel', serif;
  --font-body:  'IM Fell English', serif;
}

html, body {
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

/* Starfield background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(106,47,160,0.18) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(15,50,120,0.18) 0%, transparent 60%),
    var(--bg);
  pointer-events: none;
  z-index: 0;
}

/* Tiny star dots */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 15%, rgba(255,255,255,0.8) 0%, transparent 100%),
    radial-gradient(1px 1px at 25% 40%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 50% 10%, rgba(255,255,255,0.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 70% 25%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 85% 55%, rgba(255,255,255,0.8) 0%, transparent 100%),
    radial-gradient(1px 1px at 35% 80%, rgba(255,255,255,0.4) 0%, transparent 100%),
    radial-gradient(1px 1px at 60% 65%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 90% 85%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 15% 92%, rgba(255,255,255,0.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 45% 50%, rgba(255,255,255,0.3) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.screen {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.container {
  width: 100%;
  max-width: 480px;
}

.hidden {
  display: none !important;
}

/* ── Splash Screen ────────────────────────────────────────────────────────── */
#splash {
  text-align: center;
}

#splash .container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

.cauldron-wrap {
  font-size: 5rem;
  line-height: 1;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(106,47,160,0.8));
}

@keyframes float {
  0%, 100% { transform: translateY(0);   }
  50%       { transform: translateY(-10px); }
}

/* Steam wisps */
.steam {
  display: inline-flex;
  gap: 0.5rem;
  font-size: 1.4rem;
  opacity: 0.7;
  animation: steam 2s ease-in-out infinite alternate;
}

@keyframes steam {
  from { transform: translateY(0) scaleX(1);   opacity: 0.5; }
  to   { transform: translateY(-6px) scaleX(1.1); opacity: 0.9; }
}

.game-title {
  font-family: var(--font-head);
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 50%, #e8a020 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  line-height: 1.1;
}

.game-subtitle {
  font-family: var(--font-body);
  font-style: italic;
  color: var(--text-dim);
  font-size: 1rem;
}

#splash-date {
  font-family: var(--font-head);
  font-size: 0.9rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

.instructions {
  background: rgba(30, 21, 53, 0.8);
  border: 1px solid rgba(201,162,39,0.25);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  font-size: 0.9rem;
  color: var(--text-dim);
  text-align: left;
  line-height: 1.6;
}

.instructions strong {
  color: var(--gold);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  background: linear-gradient(135deg, #7c3fd0 0%, #4a1a80 100%);
  color: var(--gold-light);
  border: 2px solid var(--gold);
  border-radius: 50px;
  padding: 0.8rem 2.5rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 0 20px rgba(201,162,39,0.3), 0 4px 15px rgba(0,0,0,0.5);
}

.btn-primary:hover,
.btn-primary:focus-visible {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 0 30px rgba(201,162,39,0.5), 0 6px 20px rgba(0,0,0,0.5);
  outline: none;
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
}

.btn-secondary {
  font-family: var(--font-head);
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50px;
  padding: 0.55rem 1.5rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.btn-secondary:hover,
.btn-secondary:focus-visible {
  color: var(--text);
  border-color: var(--gold);
  outline: none;
}

/* ── Game Screen ─────────────────────────────────────────────────────────── */
#game {
  padding-top: 0.5rem;
}

#game .container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ── HUD (timer + lives) ─────────────────────────────────────────────────── */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: rgba(30,21,53,0.7);
  border: 1px solid rgba(201,162,39,0.2);
  border-radius: var(--radius);
}

#timer {
  font-family: var(--font-head);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gold);
  min-width: 3.5rem;
  letter-spacing: 0.05em;
  transition: color 0.3s;
}

#timer.danger {
  color: var(--danger);
  animation: pulse 0.7s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%       { opacity: 0.7; transform: scale(1.08); }
}

#lives {
  display: flex;
  gap: 0.4rem;
  font-size: 1.4rem;
}

.hud-title {
  font-family: var(--font-head);
  font-size: 0.85rem;
  color: var(--text-dim);
  letter-spacing: 0.08em;
}

/* ── 3×3 Grid ───────────────────────────────────────────────────────────── */
#grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  min-height: 10rem; /* keeps space when words are dragged out */
}

/* ── Word Boxes ──────────────────────────────────────────────────────────── */
.word-box {
  font-family: var(--font-body);
  font-size: clamp(0.75rem, 3vw, 1rem);
  color: var(--text);
  background: var(--card2);
  border: 1.5px solid rgba(201,162,39,0.3);
  border-radius: var(--radius);
  padding: 0.65rem 0.4rem;
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  user-select: none;
  touch-action: none;
  -webkit-user-select: none;
  word-break: break-word;
  hyphens: auto;
  line-height: 1.25;
}

.word-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  border-color: var(--gold);
}

.word-box:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.word-box.selected {
  background: var(--purple);
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201,162,39,0.35), 0 4px 12px rgba(0,0,0,0.5);
  transform: translateY(-2px) scale(1.04);
}

.word-box.locked {
  cursor: default;
  opacity: 0.95;
}

.word-box.dragging {
  opacity: 0.4;
}

/* ── Stack Area ──────────────────────────────────────────────────────────── */
.stacks-section {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stacks-heading {
  font-family: var(--font-head);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  text-align: center;
}

#stacks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.stack-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.stack-slots {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
  border: 1.5px solid rgba(201,162,39,0.2);
  border-radius: var(--radius);
  padding: 0.35rem;
  background: rgba(20,14,40,0.6);
  transition: box-shadow 0.4s;
}

.stack-slots.locked {
  border-color: var(--gold);
  box-shadow: 0 0 18px 2px rgba(var(--glow-color, 150,100,200), 0.5),
              0 0 35px 5px rgba(var(--glow-color, 150,100,200), 0.2);
  background: rgba(30,20,55,0.8);
}

.stack-slot {
  width: 100%;
  min-height: 2.5rem;
  border-radius: calc(var(--radius) - 4px);
  border: 1px dashed rgba(201,162,39,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.02);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.stack-slot:empty:hover,
.stack-slot:not(:has(.word-box)):hover {
  border-color: rgba(201,162,39,0.5);
  background: rgba(201,162,39,0.06);
}

.stack-slot .word-box {
  width: 100%;
  margin: 0;
}

.stack-label {
  font-family: var(--font-head);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-align: center;
  min-height: 1rem;
  color: var(--gold);
  word-break: break-word;
}

/* ── Animations ──────────────────────────────────────────────────────────── */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  15%     { transform: translateX(-8px); }
  30%     { transform: translateX(8px); }
  45%     { transform: translateX(-6px); }
  60%     { transform: translateX(6px); }
  75%     { transform: translateX(-3px); }
  90%     { transform: translateX(3px); }
}

.shake {
  animation: shake 0.55s cubic-bezier(.36,.07,.19,.97) both;
  border-color: var(--danger) !important;
  box-shadow: 0 0 12px rgba(232,64,64,0.5) !important;
}

@keyframes correctFlash {
  0%   { box-shadow: 0 0 0px transparent; }
  40%  { box-shadow: 0 0 30px 8px rgba(255,215,0,0.6); }
  100% { box-shadow: 0 0 18px 2px rgba(var(--glow-color,150,100,200),0.5); }
}

.correct-flash {
  animation: correctFlash 0.9s ease-out forwards;
}

/* ── Modal ────────────────────────────────────────────────────────────────── */
#modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  background: rgba(5, 2, 15, 0.75);
  backdrop-filter: blur(4px);
}

@media (min-height: 600px) {
  #modal {
    align-items: center;
  }
}

.modal-inner {
  width: 100%;
  max-width: 480px;
  background: linear-gradient(160deg, #1e1540 0%, #130d2e 100%);
  border: 1.5px solid var(--gold);
  border-radius: 20px;
  padding: 1.5rem 1.25rem;
  box-shadow: 0 0 40px rgba(201,162,39,0.25), 0 20px 60px rgba(0,0,0,0.7);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 90dvh;
  overflow-y: auto;
}

#modal-title {
  font-family: var(--font-head);
  font-size: 1.8rem;
  font-weight: 900;
  text-align: center;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  color: var(--text-dim);
  gap: 0.5rem;
  flex-wrap: wrap;
}

#modal-categories {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#modal-categories li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1.4;
}

#modal-categories li.unsolved {
  opacity: 0.55;
}

.cat-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 0.25rem;
}

#modal-countdown {
  font-family: var(--font-head);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  text-align: center;
}

.modal-buttons {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── Word placeholder (empty grid slot after word is dragged to stack) ──────── */
.word-placeholder {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  pointer-events: none;
  cursor: default;
}

.word-placeholder:hover {
  transform: none;
  box-shadow: none;
  border-color: transparent;
}

/* ── Modal streak ─────────────────────────────────────────────────────────── */
.modal-streak {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.streak-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.streak-item strong {
  color: var(--gold);
  font-size: 1.05rem;
}

/* ── Splash countdown ─────────────────────────────────────────────────────── */
.splash-countdown {
  font-family: var(--font-head);
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  text-align: center;
  margin-top: 0.5rem;
}

/* ── Reduced Motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Responsive tweaks ────────────────────────────────────────────────────── */
@media (max-width: 360px) {
  .word-box {
    padding: 0.5rem 0.25rem;
    font-size: 0.7rem;
  }
  .game-title {
    font-size: 1.8rem;
  }
}

@media (min-width: 600px) {
  /* Desktop: centered card with magical backdrop visible */
  body::before {
    background:
      radial-gradient(ellipse at 20% 30%, rgba(106,47,160,0.3) 0%, transparent 50%),
      radial-gradient(ellipse at 80% 70%, rgba(15,50,120,0.3) 0%, transparent 50%),
      var(--bg);
  }
}
