:root {
  --bg: #07111f;
  --bg-soft: rgba(12, 24, 44, 0.72);
  --line: rgba(146, 184, 255, 0.18);
  --text: #eaf2ff;
  --muted: #9cb2cf;
  --accent: #67c2ff;
  --accent-2: #9c6fff;
  --success: #6ef0b0;
  --warning: #ffdb74;
  --danger: #ff7b9c;
  --track-red: #ff4545;
  --track-red-soft: rgba(255, 69, 69, 0.2);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: radial-gradient(circle at top, #122441 0%, #07111f 55%, #040b14 100%);
  color: var(--text);
  overflow-x: hidden;
}

.bg-grid,
.bg-orb {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.bg-grid {
  background-image: linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 90%);
}

.bg-orb {
  filter: blur(80px);
  opacity: 0.35;
  will-change: transform;
  animation: orbFloat 16s ease-in-out infinite alternate;
}

.orb-1 {
  background: #1454ff;
  width: 380px;
  height: 380px;
  inset: 4% auto auto 6%;
}

.orb-2 {
  background: #7c3aed;
  width: 280px;
  height: 280px;
  inset: auto 8% 10% auto;
  animation-duration: 18s;
}

.app-shell {
  width: min(1400px, calc(100% - 24px));
  margin: 18px auto 32px;
  position: relative;
  z-index: 1;
}

.card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.glow {
  box-shadow: 0 0 0 1px rgba(103, 194, 255, 0.15), 0 30px 90px rgba(3, 10, 22, 0.6), inset 0 1px 0 rgba(255,255,255,0.08);
}

.hero {
  padding: 28px;
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 22px;
  align-items: center;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  font-size: 0.75rem;
  margin: 0 0 10px;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(2rem, 4vw, 3.4rem); line-height: 0.98; }
.hero-copy { color: var(--muted); margin-top: 12px; max-width: 60ch; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.stat-pill,
.session-item {
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  border-radius: 18px;
  padding: 16px;
}

.stat-pill span,
.session-item strong {
  display: block;
  font-size: 1.5rem;
  font-weight: 800;
}

.stat-pill small,
.session-item span,
.legend {
  color: var(--muted);
}

.control-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 18px;
  margin-top: 18px;
}

.panel,
.board-panel,
.words-panel {
  padding: 22px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-head.compact { margin-bottom: 14px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

label span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

select,
input {
  width: 100%;
  background: rgba(255,255,255,0.05);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 14px;
  padding: 14px 14px;
  outline: none;
  font: inherit;
}

.button {
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: transform 140ms ease, box-shadow 180ms ease, filter 180ms ease;
  will-change: transform;
}

.button:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 32px rgba(75, 140, 255, 0.28);
}

.button.ghost {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
}

.search-results {
  min-height: 56px;
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.search-chip,
.seed-pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 0.9rem;
}

.seed-pill.secondary { color: var(--warning); }
.seed-pill { color: var(--accent); }

.progress-panel .session-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 18px;
  font-size: 0.9rem;
}

.dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 8px;
}
.dot.live { background: var(--track-red); }
.dot.solved { background: var(--success); }
.dot.hint { background: var(--warning); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) 340px;
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.board-stage {
  position: relative;
  isolation: isolate;
  transform-style: preserve-3d;
  transform: perspective(1200px) rotateX(var(--tilt-y, 0deg)) rotateY(var(--tilt-x, 0deg)) translateZ(0);
  transition: transform 140ms ease, box-shadow 200ms ease;
  border-radius: 24px;
  padding: 4px;
}

.board-stage::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at var(--glow-x, 50%) var(--glow-y, 50%), rgba(255, 72, 72, 0.18), transparent 26%),
    linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0));
  pointer-events: none;
  z-index: 0;
}

.board-stage.word-hit {
  animation: boardHit 420ms ease-out;
}

.board-stage.board-cleared {
  animation: boardClear 950ms cubic-bezier(.16,.84,.19,1.01);
}

.fx-canvas,
.fx-status {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.fx-canvas {
  z-index: 3;
  width: 100%;
  height: 100%;
}

.fx-status {
  display: grid;
  place-items: center;
  z-index: 4;
  font-size: clamp(1.2rem, 3vw, 2.4rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0;
  transform: scale(0.88);
  text-shadow: 0 12px 44px rgba(0,0,0,0.45);
}

.fx-status.show {
  animation: statusPop 1100ms ease-out;
}

.board {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 4px;
  user-select: none;
  touch-action: none;
  transform: translateZ(0);
}

.board-cell {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  min-height: 34px;
  display: grid;
  place-items: center;
  font-weight: 800;
  border-radius: 12px;
  background: rgba(255,255,255,0.045);
  border: 1px solid rgba(255,255,255,0.06);
  transition: transform 100ms ease, background 110ms ease, box-shadow 110ms ease, border-color 110ms ease;
  will-change: transform, background, box-shadow;
  backface-visibility: hidden;
}

.board-cell::after {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.22), transparent 58%);
  transition: opacity 120ms ease;
}

.board-cell:hover::after,
.board-cell.live::after,
.board-cell.head::after {
  opacity: 1;
}

.board-cell.live,
.board-cell.head {
  background: rgba(255, 69, 69, 0.18);
  border-color: rgba(255, 85, 85, 0.42);
  box-shadow: inset 0 0 0 1px rgba(255, 96, 96, 0.5), 0 0 22px rgba(255, 69, 69, 0.16);
  transform: translateY(-1px) scale(1.01);
}

.board-cell.head {
  box-shadow: inset 0 0 0 1px rgba(255, 125, 125, 0.7), 0 0 26px rgba(255, 69, 69, 0.28), 0 0 42px rgba(255, 118, 118, 0.14);
}

.board-cell.found {
  background: rgba(110, 240, 176, 0.2);
  border-color: rgba(110,240,176,0.28);
  box-shadow: inset 0 0 0 1px rgba(110,240,176,0.45), 0 0 20px rgba(110,240,176,0.09);
}

.board-cell.hint {
  background: rgba(255, 219, 116, 0.18);
  border-color: rgba(255,219,116,0.3);
  box-shadow: inset 0 0 0 1px rgba(255,219,116,0.45), 0 0 18px rgba(255,219,116,0.12);
}

.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.word-pill {
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 0.92rem;
  transition: transform 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.word-pill.found {
  text-decoration: line-through;
  color: var(--success);
  border-color: rgba(110,240,176,0.35);
  box-shadow: 0 8px 28px rgba(110,240,176,0.09);
  transform: translateY(-1px);
}

.hidden { display: none !important; }

@keyframes orbFloat {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(12px, -18px, 0) scale(1.08); }
}

@keyframes boardHit {
  0% { transform: perspective(1200px) scale(1) rotateX(var(--tilt-y, 0deg)) rotateY(var(--tilt-x, 0deg)); }
  32% { transform: perspective(1200px) scale(1.018) rotateX(var(--tilt-y, 0deg)) rotateY(var(--tilt-x, 0deg)); }
  100% { transform: perspective(1200px) scale(1) rotateX(var(--tilt-y, 0deg)) rotateY(var(--tilt-x, 0deg)); }
}

@keyframes boardClear {
  0% { transform: perspective(1200px) scale(1) rotateX(var(--tilt-y, 0deg)) rotateY(var(--tilt-x, 0deg)); filter: saturate(1); }
  28% { transform: perspective(1200px) scale(1.025) rotateX(var(--tilt-y, 0deg)) rotateY(var(--tilt-x, 0deg)); filter: saturate(1.25); }
  100% { transform: perspective(1200px) scale(1) rotateX(var(--tilt-y, 0deg)) rotateY(var(--tilt-x, 0deg)); filter: saturate(1); }
}

@keyframes statusPop {
  0% { opacity: 0; transform: scale(0.84); }
  18% { opacity: 1; transform: scale(1); }
  72% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.08); }
}

@media (max-width: 1120px) {
  .hero,
  .control-grid,
  .game-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell { width: min(100% - 16px, 1400px); margin-top: 10px; }
  .hero,
  .panel,
  .board-panel,
  .words-panel { padding: 16px; border-radius: 18px; }
  .stats-row,
  .form-grid,
  .progress-panel .session-grid { grid-template-columns: 1fr; }
  .board-cell { min-height: 26px; font-size: 0.86rem; border-radius: 8px; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .button { width: 100%; }
  .board-stage { border-radius: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg-orb,
  .board-stage,
  .button,
  .board-cell,
  .word-pill,
  .fx-status {
    animation: none !important;
    transition: none !important;
  }
}
