/* ── Connections Styles ────────────────────────────────────────── */
:root {
  --bg: #1a1a2e;
  --bg-2: #16213e;
  --ink: #0a0a1a;
  --cream: #e8e6f0;
  --dim: #8888aa;
  --accent: #7c6df0;
  --accent-glow: rgba(124,109,240,0.3);
  --gold: #ffe46b;
  --rose: #ff5d5d;
  --card-bg: #2a2a44;
  --card-hover: #33335a;
  --card-selected: #4a3a8a;
  --card-border: rgba(120,120,200,0.15);
  --card-selected-border: rgba(160,140,255,0.7);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.5vh, 16px);
  padding: clamp(10px, 2vh, 24px) 12px;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 40% 30%, rgba(124,109,240,0.06) 0%, transparent 50%),
    radial-gradient(circle at 60% 70%, rgba(255,228,107,0.04) 0%, transparent 50%);
  font-family: 'Press Start 2P', monospace;
  color: var(--cream);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── HUD ─────────────────────────────────────────────────────── */
.hud {
  width: 100%;
  max-width: 560px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  z-index: 5;
}

.hud-mistakes {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.5em;
  color: var(--dim);
}

.mistake-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255,93,93,0.2);
  border: 1px solid rgba(255,93,93,0.3);
  transition: background 0.3s, border-color 0.3s;
}

.mistake-dot.used {
  background: var(--rose);
  border-color: var(--rose);
  box-shadow: 0 0 8px rgba(255,93,93,0.5);
}

.hud-label {
  font-size: 0.45em;
  letter-spacing: 0.2em;
  color: var(--dim);
}

/* ── Game Area ───────────────────────────────────────────────── */
#game-area {
  width: 100%;
  max-width: 560px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Solved Groups ───────────────────────────────────────────── */
.solved-area {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.solved-row {
  border-radius: 12px;
  padding: 14px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.solved-category {
  font-size: 0.6em;
  font-weight: bold;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.solved-words {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.75em;
  opacity: 0.85;
}

@keyframes solvedSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px) scaleY(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(0) scaleY(1);
  }
}

/* ── Word Grid ───────────────────────────────────────────────── */
.word-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.word-card {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.4em, 1.8vw, 0.6em);
  line-height: 1.3;
  color: var(--cream);
  background: var(--card-bg);
  border: 2px solid var(--card-border);
  border-radius: 10px;
  padding: clamp(10px, 2.5vw, 18px) 6px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  text-align: center;
  word-break: break-word;
  transition: transform 0.15s, background 0.15s, border-color 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}

.word-card:hover {
  background: var(--card-hover);
  transform: translateY(-2px);
}

.word-card:active {
  transform: translateY(0) scale(0.97);
}

.word-card.selected {
  background: var(--card-selected);
  border-color: var(--card-selected-border);
  box-shadow: 0 0 16px var(--accent-glow), inset 0 0 20px rgba(124,109,240,0.1);
  transform: translateY(-2px) scale(1.02);
}

.word-card.selected:hover {
  background: #554aa0;
}

/* Shake animation for wrong guess */
@keyframes cardShake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
  90% { transform: translateX(2px); }
}

.word-card.shake {
  animation: cardShake 0.4s ease-in-out;
}

/* ── Actions Bar ─────────────────────────────────────────────── */
.actions-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 0;
  flex-wrap: wrap;
}

.conn-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.45em;
  line-height: 1.4;
  letter-spacing: 0.04em;
  color: var(--cream);
  background: rgba(124,109,240,0.15);
  border: 1px solid rgba(124,109,240,0.3);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: background 0.15s, border-color 0.15s, transform 0.08s, opacity 0.15s;
}

.conn-btn:hover:not(:disabled) {
  background: rgba(124,109,240,0.3);
  border-color: rgba(124,109,240,0.5);
}

.conn-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.conn-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.submit-btn {
  background: rgba(106,170,100,0.2);
  border-color: rgba(106,170,100,0.4);
  color: #a8e6a3;
}

.submit-btn:hover:not(:disabled) {
  background: rgba(106,170,100,0.35);
  border-color: rgba(106,170,100,0.6);
}

/* ── Footer ──────────────────────────────────────────────────── */
.footer {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.5em;
  color: var(--dim);
  z-index: 5;
}

.seed-display {
  letter-spacing: 0.05em;
}

/* ── Buttons (shared) ────────────────────────────────────────── */
.btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.55em;
  line-height: 1.4;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(124,109,240,0.28);
  border: 1px solid rgba(160,140,255,0.55);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-shadow:
    inset 0 2px rgba(255,255,255,0.1),
    0 3px 0 0 #1a1040,
    0 3px 0 2px var(--ink);
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

.btn:hover {
  background: rgba(124,109,240,0.42);
  border-color: rgba(160,140,255,0.8);
}

.btn:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 2px rgba(255,255,255,0.1),
    0 1px 0 0 #1a1040,
    0 1px 0 2px var(--ink);
}

.help-btn,
.back-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7em;
  border-radius: 50%;
  text-decoration: none;
}

.back-btn {
  font-size: 1em;
  line-height: 1;
  padding-bottom: 2px;
}

/* ── Overlays ────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,10,26,0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.overlay.visible, .overlay.start-overlay {
  opacity: 1;
  pointer-events: auto;
}

.overlay.gone {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}

/* ── Start Screen ────────────────────────────────────────────── */
.start-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  cursor: pointer;
}

.start-title {
  font-size: clamp(1.4em, 5vw, 2.5em);
  line-height: 1.2;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--ink);
}

.start-sub {
  font-size: clamp(0.6em, 2vw, 0.9em);
  color: var(--dim);
  letter-spacing: 0.1em;
}

.start-bar {
  width: 200px;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.start-bar-fill {
  width: 100%;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  animation: barPulse 1.5s ease-in-out infinite;
}

@keyframes barPulse {
  0%, 100% { transform: scaleX(0.3); opacity: 0.5; }
  50% { transform: scaleX(1); opacity: 1; }
}

.start-prompt {
  font-size: 0.5em;
  color: var(--accent);
  letter-spacing: 0.15em;
  animation: blink 1.2s step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Panel (Game Over, Tutorial) ─────────────────────────────── */
.panel {
  background: #1e1e32;
  border: 1px solid rgba(120,120,200,0.2);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 420px;
  width: 90%;
  text-align: center;
}

.panel-title {
  font-size: 1.1em;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--ink);
  margin-bottom: 16px;
}

/* ── Game Over ───────────────────────────────────────────────── */
.go-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.go-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.55em;
  padding: 4px 12px;
}

.go-label { color: var(--dim); }
.go-val { color: var(--gold); }

.go-msg {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.8em;
  color: var(--dim);
  margin-bottom: 16px;
  line-height: 1.5;
}

.go-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

/* ── One Away Toast ──────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: #2a2a44;
  border: 1px solid rgba(255,228,107,0.4);
  border-radius: 10px;
  padding: 10px 20px;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.5em;
  color: var(--gold);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Tutorial ────────────────────────────────────────────────── */
.tut-panel {
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

.tut-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  color: var(--dim);
  font-size: 1.2em;
  cursor: pointer;
  font-family: 'Press Start 2P', monospace;
}

.tut-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}

.tut-card {
  text-align: left;
  padding: 12px;
  background: rgba(124,109,240,0.06);
  border: 1px solid rgba(124,109,240,0.12);
  border-radius: 10px;
}

.tut-icon {
  font-size: 1.4em;
  margin-bottom: 6px;
}

.tut-heading {
  font-size: 0.55em;
  color: var(--gold);
  margin-bottom: 6px;
}

.tut-body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.78em;
  line-height: 1.6;
  color: var(--dim);
}

.tut-close-btn {
  font-size: 0.5em;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 480px) {
  body { padding: 12px 8px; }
  .word-card { padding: 8px 4px; font-size: 0.38em; }
  .word-grid { gap: 4px; }
  .solved-row { padding: 10px 12px; }
  .solved-category { font-size: 0.5em; }
  .solved-words { font-size: 0.65em; }
}

@media (max-width: 360px) {
  .word-card { font-size: 0.32em; padding: 7px 3px; }
}

/* ── FX Canvas (confetti) ────────────────────────────────────── */
#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 150;
}

/* ── Screen Shake (wrong guess) ──────────────────────────────── */
@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-4px, 2px); }
  20% { transform: translate(4px, -2px); }
  30% { transform: translate(-3px, -1px); }
  40% { transform: translate(3px, 1px); }
  50% { transform: translate(-2px, 2px); }
  60% { transform: translate(2px, -2px); }
  70% { transform: translate(-1px, 1px); }
  80% { transform: translate(1px, -1px); }
  90% { transform: translate(-1px, 0); }
}

.screen-shake {
  animation: screenShake 0.5s ease-in-out;
}

/* ── Card juice ──────────────────────────────────────────────── */
.word-card.selected {
  animation: cardPop 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardPop {
  0% { transform: scale(0.94); }
  60% { transform: scale(1.06); }
  100% { transform: translateY(-2px) scale(1.02); }
}

/* Solved row entrance pop */
.solved-row {
  animation: solvedSlideIn 0.4s ease-out, solvedGlow 1.2s ease-out;
}

@keyframes solvedGlow {
  0% { box-shadow: 0 0 0 0 rgba(255,228,107,0); }
  40% { box-shadow: 0 0 24px 4px rgba(255,228,107,0.4); }
  100% { box-shadow: 0 0 0 0 rgba(255,228,107,0); }
}

/* ── Mute Button ─────────────────────────────────────────────── */
.mute-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9em;
  border-radius: 50%;
}

/* ── Win panel glow ──────────────────────────────────────────── */
.overlay.visible .panel {
  animation: panelIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes panelIn {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.go-msg {
  text-shadow: 1px 1px 0 var(--ink);
}

/* ── Submit button ready pulse ──────────────────────────────── */
.submit-btn:not(:disabled) {
  animation: submitReady 1.5s ease-in-out infinite;
}

@keyframes submitReady {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168,230,163,0.4); }
  50% { box-shadow: 0 0 12px 2px rgba(168,230,163,0.5); }
}

/* ── Mistake dot pop on use ──────────────────────────────────── */
.mistake-dot.used {
  animation: dotPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dotPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

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