/* Word Burst — ASD-Friendly Literacy Game
 *
 * Design principles:
 *   - No pure black (#000) or pure white (#fff). Muted tones throughout.
 *   - Rounded geometry everywhere to reduce visual sharpness.
 *   - Predictable, gentle animations. No sudden movement.
 *   - Generous spacing to reduce visual crowding.
 *   - High enough contrast for readability, low enough to avoid overstimulation.
 */

:root {
  --bg: #f0ece4;
  --bg-warm: #e8e2d8;
  --card-bg: #faf8f4;
  --text: #3d3832;
  --text-muted: #7a7268;
  --primary: #6b8f71;
  --primary-hover: #5a7d60;
  --accent: #8b7355;
  --accent-light: #c4b59a;
  --success: #6b8f71;
  --success-glow: rgba(107, 143, 113, 0.35);
  --incorrect: #b07d62;
  --incorrect-glow: rgba(176, 125, 98, 0.35);
  --border: #d4cec4;
  --box-stroke: #9e9688;
  --box-fill: #faf8f4;
  --letter-bg: #e8e2d8;
  --letter-text: #3d3832;
  --letter-shadow: rgba(0, 0, 0, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.1);
  --transition-smooth: 0.3s ease;
}

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

body {
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 1rem;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

main.container {
  padding-top: 2rem;
  padding-bottom: 3rem;
}

/* ── Header ── */

.site-header {
  background: var(--primary);
  padding: 0.75rem 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.site-header .container {
  display: flex;
  align-items: center;
}

.logo {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--card-bg);
  text-decoration: none;
  letter-spacing: -0.02em;
}

/* ── Footer ── */

.site-footer {
  text-align: center;
  padding: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ── Home Page ── */

.home-container {
  max-width: 680px;
  margin: 0 auto;
}

.hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

.hero h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--text-muted);
}

/* ── Word Form ── */

.word-form {
  max-width: 400px;
  margin: 0 auto;
}

.word-form-label {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.word-form-textarea {
  display: block;
  width: 100%;
  padding: 0.85rem 1rem;
  font-family: inherit;
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: border-color var(--transition-smooth);
}

.word-form-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.word-form-textarea::placeholder {
  color: var(--text-muted);
}

.btn-start {
  display: block;
  width: 100%;
  margin-top: 1rem;
  padding: 0.8rem;
  background: var(--primary);
  color: var(--card-bg);
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-smooth),
              transform var(--transition-smooth);
}

.btn-start:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

/* ── Loading state (shown while WASM initializes) ── */

.loading-text {
  text-align: center;
  padding: 4rem 0;
  color: var(--text-muted);
  font-size: 1.1rem;
}

/* ── Game Page ── */

.game-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 8px;
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Progress */

.game-progress {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  width: 0%;
  transition: width 0.5s ease;
}

.progress-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 4em;
  text-align: right;
}

/* Game area */

.game-area {
  position: relative;
  width: 100%;
  aspect-ratio: 800 / 420;
  background: var(--bg-warm);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  overflow: visible;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* SVG letter boxes (targets) */

.letter-box {
  fill: var(--box-fill);
  stroke: var(--box-stroke);
  stroke-width: 2;
  /* Corner radius is set via the rx/ry presentation attributes in View.hs;
     Firefox ignores rx/ry as CSS properties. */
}

.letter-box.filled {
  stroke: var(--primary);
  stroke-width: 2.5;
  fill: rgba(107, 143, 113, 0.08);
}

.box-label {
  fill: var(--text-muted);
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 42px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  opacity: 0.25;
}

.box-label.filled {
  opacity: 0;
}

/* Draggable letters */

.letter-tile {
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.letter-tile:active {
  cursor: grabbing;
}

.letter-tile-bg {
  fill: var(--letter-bg);
  stroke: var(--accent-light);
  stroke-width: 2;
  /* Corner radius is set via the rx/ry presentation attributes in View.hs;
     Firefox ignores rx/ry as CSS properties. */
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.08));
  transition: fill 0.2s ease, stroke 0.2s ease;
}

.letter-tile.dragging {
  transition: none;
}

.letter-tile.dragging .letter-tile-bg {
  fill: var(--card-bg);
  stroke: var(--primary);
  stroke-width: 2.5;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
}

/* Scale wrapper — animates the tile to 2× on pickup and back on release.
 *
 * The inner <g>'s children are centred at (0,0) and the outer <g> translates
 * to the tile centre, so a plain CSS scale() from the default origin expands
 * symmetrically. The scale value is set via inline style from Haskell;
 * this class just provides the transition.
 */
.letter-tile-scale {
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.letter-tile-text {
  fill: var(--letter-text);
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 42px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Explosion animation: letters transition from box positions to scattered positions */

.letter-tile {
  transition: transform 1.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.letter-tile.snapping {
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.letter-tile.snapped {
  opacity: 0.6;
}

.letter-tile.snapped .letter-tile-bg {
  fill: rgba(107, 143, 113, 0.12);
  stroke: var(--primary);
}

/* Feedback overlay */

.feedback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--radius);
  z-index: 100;
  gap: 1rem;
}

.feedback.hidden {
  display: none;
}

.feedback-icon {
  font-size: 3rem;
  line-height: 1;
}

.feedback-text {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.feedback.correct .feedback-icon { color: var(--success); }
.feedback.incorrect .feedback-icon { color: var(--incorrect); }

/* Completion screen */

.complete {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  padding: 3rem 1.5rem;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 2px solid var(--border);
}

.complete-content {
  text-align: center;
  max-width: 400px;
}

.complete-content h2 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.complete-content p {
  font-size: 1.15rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

/* Buttons */

.btn {
  display: inline-block;
  padding: 0.7rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition-smooth),
              transform var(--transition-smooth),
              box-shadow var(--transition-smooth);
}

.btn-next {
  background: var(--primary);
  color: var(--card-bg);
}

.btn-next:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}

.btn-home {
  background: var(--primary);
  color: var(--card-bg);
}

.btn-home:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}

/* ── Responsive ── */

@media (max-width: 600px) {
  .hero h1 {
    font-size: 1.6rem;
  }

  .phase-grid {
    grid-template-columns: 1fr;
  }
}
