/* Word Garden — Styles */
/* ========================================================================== */
/* CSS Custom Properties */
:root {
  --bg: #f1f8e9;
  --bg-alt: #e8f5e9;
  --card: #ffffff;
  --card-hover: #f9fbe7;
  --text: #2e3d2e;
  --text-muted: #5a6b5a;
  --text-light: #7a8b7a;
  --accent: #8fd694;
  --accent-dark: #66bb6a;
  --accent-deep: #388e3c;
  --warm: #ffb347;
  --warm-dark: #ffa000;
  --warm-light: #fff3e0;
  --petal: #ffccbc;
  --petal-dark: #ff8a65;
  --berry: #f06292;
  --berry-dark: #ec407a;
  --sky: #81d4fa;
  --sky-dark: #4fc3f7;
  --lavender: #ce93d8;
  --shadow: rgba(46, 61, 46, 0.08);
  --shadow-strong: rgba(46, 61, 46, 0.15);
  --focus: #388e3c;
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 22px;
  --radius-xl: 32px;
  --transition: 180ms cubic-bezier(0.2, 0.6, 0.3, 1);
  --transition-bouncy: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
  --header-h: 64px;
  --panel-w: 260px;
  --guide-w: 280px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b2a1b;
    --bg-alt: #233523;
    --card: #2a3d2a;
    --card-hover: #314831;
    --text: #e8f0e8;
    --text-muted: #a8b8a8;
    --text-light: #8a9a8a;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-strong: rgba(0, 0, 0, 0.5);
    --warm-light: #3d2a0a;
  }
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Nunito', 'Quicksand', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&family=Quicksand:wght@500;600;700&display=swap');

/* ========================================================================== */
/* Background Decorations */
.bg-decor { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }

.float-petal {
  position: absolute;
  width: var(--size, 12px);
  height: var(--size, 12px);
  border-radius: 50% 0 50% 50%;
  background: linear-gradient(135deg, var(--petal), var(--lavender));
  opacity: 0.4;
  animation: floatPetal 20s infinite ease-in-out;
  transform-origin: center;
}
.float-petal:nth-child(odd) { background: linear-gradient(135deg, var(--sky), var(--accent)); }
.float-petal:nth-child(3n) { background: linear-gradient(135deg, var(--warm), var(--petal)); border-radius: 0 50% 50% 50%; }

@keyframes floatPetal {
  0%, 100% { transform: translate(var(--tx0, 0), var(--ty0, 0)) rotate(var(--r0, 0deg)); }
  25% { transform: translate(var(--tx1, 50px), var(--ty1, -30px)) rotate(var(--r1, 90deg)); }
  50% { transform: translate(var(--tx2, -20px), var(--ty2, 40px)) rotate(var(--r2, 180deg)); }
  75% { transform: translate(var(--tx3, 60px), var(--ty3, 20px)) rotate(var(--r3, 270deg)); }
}

/* ========================================================================== */
/* App Shell */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: 0 clamp(16px, 3vw, 32px);
}

/* ========================================================================== */
/* Header */
.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.brand-mark { flex-shrink: 0; width: 40px; height: 40px; }

.brand-name {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: clamp(1.1rem, 2.5vw, 1.4rem);
  letter-spacing: -0.02em;
}
.brand-name span { font-weight: 500; color: var(--accent-dark); }

.top-actions { display: flex; align-items: center; gap: 8px; }

.icon-button,
.quiet-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--card);
  border: 2px solid transparent;
  border-radius: var(--radius-m);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 8px var(--shadow);
}
.icon-button { padding: 10px; }
.icon-button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; }
.icon-button .sound-off-icon { display: none; }
.icon-button[aria-pressed="true"] .sound-on-icon { display: none; }
.icon-button[aria-pressed="true"] .sound-off-icon { display: block; }

.icon-button:hover,
.quiet-button:hover {
  background: var(--card-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
}
.icon-button:focus-visible,
.quiet-button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ========================================================================== */
/* Hero */
.hero {
  text-align: center;
  padding: clamp(24px, 5vw, 40px) 0;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent-dark);
  margin-bottom: 10px;
}
.eyebrow span { font-size: 1.2em; animation: sprout 2s infinite ease-in-out; }
@keyframes sprout { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-4px) scale(1.1); } }

.hero h1 {
  font-family: 'Quicksand', sans-serif;
  font-weight: 800;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.2;
  color: var(--text);
  max-width: 600px;
  margin: 0 auto;
}
.hero h1 em { font-style: italic; color: var(--accent-dark); font-weight: 600; }

.hero-progress {
  max-width: 400px;
  margin: 24px auto 0;
}
.progress-copy { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 0.9rem; color: var(--text-muted); }
.progress-copy strong { color: var(--text); }
.progress-track {
  height: 10px;
  background: var(--bg-alt);
  border-radius: 999px;
  overflow: hidden;
}
.progress-track span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--warm));
  border-radius: 999px;
  transition: width 500ms cubic-bezier(0.2, 0.6, 0.3, 1);
  width: 0%;
}

/* ========================================================================== */
/* Game Layout */
.game-layout {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr var(--guide-w);
  gap: 20px;
  flex: 1;
  align-content: start;
}

/* Panels */
.panel {
  background: var(--card);
  border-radius: var(--radius-l);
  padding: 20px;
  box-shadow: 0 4px 20px var(--shadow);
  height: fit-content;
  max-height: calc(100vh - var(--header-h) - 100px);
  overflow-y: auto;
  position: sticky;
  top: calc(var(--header-h) + 20px);
}

.panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.panel-kicker { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent-dark); }
.panel-heading h2 { font-family: 'Quicksand', sans-serif; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.count-badge {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}

.level-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.level-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: var(--radius-m);
  cursor: pointer;
  transition: var(--transition);
  border: 2px solid transparent;
}
.level-item:hover { background: var(--card-hover); transform: translateX(4px); }
.level-item:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.level-item.completed { background: linear-gradient(135deg, var(--bg-alt), var(--accent-light)); border-color: var(--accent); }
.level-item.locked { opacity: 0.5; cursor: not-allowed; }
.level-item.current { border-color: var(--warm); background: var(--warm-light); }

.level-info { display: flex; flex-direction: column; gap: 2px; }
.level-num { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.level-name { font-weight: 600; color: var(--text); font-size: 0.9rem; }
.level-stars { display: flex; gap: 3px; }
.star { width: 18px; height: 18px; background: var(--bg); border-radius: 3px; display: flex; align-items: center; justify-content: center; font-size: 10px; color: transparent; transition: var(--transition); }
.star.filled { background: linear-gradient(135deg, var(--warm), var(--warm-dark)); color: white; animation: starPop 400ms cubic-bezier(0.34, 1.56, 0.64, 1) backwards; }
@keyframes starPop { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }

.level-tip { margin-top: 16px; padding: 12px; background: var(--bg); border-radius: var(--radius-m); display: flex; align-items: flex-start; gap: 10px; font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; }
.tip-sprout { flex-shrink: 0; width: 24px; height: 24px; background: linear-gradient(135deg, var(--accent), var(--accent-dark)); border-radius: 50% 0 50% 50%; animation: sprout 2s infinite ease-in-out; }
.tip-orbit { flex-shrink: 0; width: 24px; height: 24px; border: 2px solid var(--accent); border-radius: 50%; animation: orbit 4s linear infinite; }
@keyframes orbit { to { transform: rotate(360deg); } }

#endless-button {
  margin-top: 16px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--berry), var(--berry-dark));
  color: white;
  border: none;
  padding: 14px;
  font-weight: 700;
}
#endless-button:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(240, 98, 146, 0.4); }
#endless-button svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ========================================================================== */
/* Board Area */
.board-area { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.board-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 16px; }
.level-heading { display: flex; flex-direction: column; gap: 4px; }
.level-heading .panel-kicker { color: var(--warm-dark); }
#level-title { font-family: 'Quicksand', sans-serif; font-weight: 700; font-size: 1.3rem; color: var(--text); }

.metrics { display: flex; gap: 16px; flex-wrap: wrap; }
.metric { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; padding: 8px 14px; background: var(--card); border-radius: var(--radius-m); box-shadow: 0 2px 8px var(--shadow); min-width: 90px; }
.metric span { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.metric strong { font-family: 'Quicksand', sans-serif; font-weight: 700; font-size: 1.4rem; color: var(--text); }
.metric-words strong { color: var(--accent-dark); }

/* Board Frame */
.board-frame { position: relative; background: var(--card); border-radius: var(--radius-xl); box-shadow: 0 8px 32px var(--shadow), inset 0 1px 0 rgba(255,255,255,0.6); overflow: hidden; aspect-ratio: 1 / 1; max-width: 100%; }
.board-corner { position: absolute; width: 24px; height: 24px; background: radial-gradient(circle at var(--cx, 0) var(--cy, 0), var(--accent) 0%, transparent 70%); opacity: 0.15; pointer-events: none; }
.corner-tl { top: 0; left: 0; --cx: 100%; --cy: 100%; }
.corner-tr { top: 0; right: 0; --cx: 0; --cy: 100%; }
.corner-bl { bottom: 0; left: 0; --cx: 100%; --cy: 0; }
.corner-br { bottom: 0; right: 0; --cx: 0; --cy: 0; }

/* Board Grid */
.board { display: grid; gap: 8px; padding: 16px; width: 100%; height: 100%; }
.board[data-size="4"] { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }
.board[data-size="5"] { grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(5, 1fr); }
.board[data-size="6"] { grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(6, 1fr); }
.board[data-size="7"] { grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(7, 1fr); }

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, #fff, #f0f4f0);
  border: 2px solid #e0e8e0;
  border-radius: var(--radius-m);
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: clamp(1rem, 3vw, 1.5rem);
  color: var(--text);
  cursor: pointer;
  transition: var(--transition-bouncy);
  user-select: none;
  position: relative;
  box-shadow: 0 2px 6px var(--shadow), inset 0 1px 0 rgba(255,255,255,0.8);
}
.tile:hover { transform: scale(1.05) translateY(-2px); box-shadow: 0 6px 16px var(--shadow-strong); border-color: var(--accent); }
.tile:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; z-index: 1; }
.tile:active { transform: scale(0.98); transition-duration: 50ms; }

.tile.selected { background: linear-gradient(135deg, var(--warm-light), #fff8e1); border-color: var(--warm); box-shadow: 0 0 0 3px rgba(255, 179, 71, 0.3), 0 4px 12px var(--shadow); transform: scale(1.08); z-index: 2; }
.tile.found { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); border-color: var(--accent-dark); color: white; animation: tileBloom 500ms cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes tileBloom { 0% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }
.tile.hint { animation: pulseHint 1s infinite ease-in-out; box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.4); }
@keyframes pulseHint { 0%, 100% { box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.4); } 50% { box-shadow: 0 0 0 6px rgba(76, 175, 80, 0.2); } }

.tile-letter { position: relative; z-index: 1; }
.tile::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: var(--radius-m);
  background: radial-gradient(circle at center, var(--petal) 0%, transparent 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms;
}
.tile.selected::before { opacity: 0.6; animation: petalGlow 1.5s infinite ease-in-out; }
@keyframes petalGlow { 0%, 100% { transform: scale(1); opacity: 0.4; } 50% { transform: scale(1.15); opacity: 0.7; } }

/* Selection Trail */
.selection-trail { position: absolute; inset: 16px; pointer-events: none; z-index: 1; overflow: visible; }
.trail-segment {
  position: absolute;
  background: linear-gradient(90deg, var(--warm), var(--warm-dark));
  height: 6px;
  border-radius: 3px;
  transform-origin: left center;
  opacity: 0.8;
  animation: trailIn 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes trailIn { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* Overlays */
.win-overlay, .lose-overlay { position: absolute; inset: 0; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 10; animation: overlayIn 300ms cubic-bezier(0.2, 0.6, 0.3, 1); }
.win-overlay[hidden], .lose-overlay[hidden] { display: none !important; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.win-card, .lose-card {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: 32px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 16px 48px var(--shadow-strong);
  animation: cardPop 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cardPop { from { opacity: 0; transform: scale(0.9) translateY(20px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.win-symbol, .lose-symbol { width: 80px; height: 80px; margin: 0 auto 16px; animation: symbolFloat 3s infinite ease-in-out; }
@keyframes symbolFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

.win-card .panel-kicker { color: var(--accent-dark); }
.lose-card .panel-kicker { color: var(--petal-dark); }

.win-card h3, .lose-card h3 { font-family: 'Quicksand', sans-serif; font-weight: 700; font-size: 1.4rem; margin-bottom: 16px; color: var(--text); }

.visitors { display: flex; justify-content: center; gap: 12px; margin: 16px 0; flex-wrap: wrap; }
.visitor { width: 56px; height: 56px; background: var(--bg); border-radius: var(--radius-m); display: flex; align-items: center; justify-content: center; font-size: 28px; animation: visitorHop 2s infinite ease-in-out; }
.visitor:nth-child(2) { animation-delay: 0.3s; }
.visitor:nth-child(3) { animation-delay: 0.6s; }
@keyframes visitorHop { 0%, 100% { transform: translateY(0) rotate(-5deg); } 50% { transform: translateY(-10px) rotate(5deg); } }

.win-summary, .lose-summary { color: var(--text-muted); margin-bottom: 24px; font-size: 0.95rem; line-height: 1.6; }
.win-summary strong, .lose-summary strong { color: var(--text); }

.win-actions, .lose-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ========================================================================== */
/* Buttons */
.primary-button, .secondary-button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-m);
  border: none;
  cursor: pointer;
  transition: var(--transition);
}
.primary-button, .btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
  box-shadow: 0 4px 14px rgba(102, 187, 106, 0.4);
}
.primary-button:hover, .btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(102, 187, 106, 0.5); }
.secondary-button, .btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 2px solid #e0e8e0;
  box-shadow: 0 2px 8px var(--shadow);
}
.secondary-button:hover, .btn-secondary:hover { background: var(--card-hover); border-color: var(--accent); transform: translateY(-1px); }
.primary-button:focus-visible, .secondary-button:focus-visible, .btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.primary-button:disabled, .secondary-button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.primary-button svg, .secondary-button svg, .btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.5; }

/* Board Controls */
.board-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 8px 4px; }
.control-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.keyboard-hint { font-size: 0.75rem; color: var(--text-light); display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.keyboard-hint kbd { background: var(--bg); border: 1px solid #d0d8d0; padding: 2px 6px; border-radius: 4px; font-family: inherit; font-size: 0.7rem; font-weight: 600; color: var(--text-muted); }

/* ========================================================================== */
/* Guide Panel */
.guide-panel { display: flex; flex-direction: column; }
.guide-icon { width: 32px; height: 32px; color: var(--accent-dark); flex-shrink: 0; }

.steps { list-style: none; display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }
.steps li { display: flex; gap: 12px; }
.step-number { flex-shrink: 0; width: 28px; height: 28px; background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700; }
.steps li > div { display: flex; flex-direction: column; gap: 4px; }
.steps strong { font-size: 0.9rem; color: var(--text); }
.steps p { font-size: 0.8rem; color: var(--text-muted); line-height: 1.5; }

.scoring { margin-bottom: 20px; padding: 16px; background: var(--bg); border-radius: var(--radius-m); }
.scoring h3 { font-size: 0.85rem; font-weight: 700; color: var(--text-muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.score-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.score-list li { display: flex; justify-content: space-between; padding: 6px 10px; background: var(--card); border-radius: var(--radius-s); font-size: 0.8rem; }
.score-list span { color: var(--text-muted); }
.score-list strong { color: var(--accent-dark); font-family: 'Quicksand', sans-serif; }

.keyboard-card { padding: 16px; background: var(--bg); border-radius: var(--radius-m); }
.keyboard-card p { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
.keyboard-card > div { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 0.8rem; color: var(--text); }
.keyboard-card kbd { background: var(--card); border: 1px solid #d0d8d0; padding: 3px 8px; border-radius: 4px; font-family: inherit; font-size: 0.7rem; font-weight: 700; color: var(--accent-dark); min-width: 48px; text-align: center; }
.keyboard-card span { color: var(--text-muted); flex: 1; }

/* ========================================================================== */
/* Footer */
footer { margin-top: auto; padding: 24px 0; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-light); font-size: 0.85rem; }
.footer-status { display: inline-flex; align-items: center; gap: 6px; }
.footer-status i { width: 8px; height: 8px; background: var(--accent); border-radius: 50%; animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ========================================================================== */
/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: var(--bg);
  padding: 14px 24px;
  border-radius: var(--radius-m);
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 8px 32px var(--shadow-strong);
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  transition: var(--transition-bouncy);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); }
.toast.error { background: linear-gradient(135deg, var(--petal-dark), #e57373); }
.toast.info { background: linear-gradient(135deg, var(--sky), var(--sky-dark)); }

/* ========================================================================== */
/* Help Dialog */
.help-dialog { border: none; border-radius: var(--radius-xl); padding: 0; max-width: 480px; width: 90vw; box-shadow: 0 24px 64px var(--shadow-strong); background: var(--card); overflow: hidden; }
.help-dialog::backdrop { background: rgba(30, 40, 30, 0.6); backdrop-filter: blur(4px); }
.dialog-close { position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--bg); color: var(--text-muted); font-size: 1.4rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition); z-index: 1; }
.dialog-close:hover { background: var(--accent); color: white; transform: rotate(90deg); }

.help-dialog > *:not(.dialog-close) { padding: 0 28px; }
.help-dialog .panel-kicker { margin: 28px 0 8px; display: block; }
.help-dialog h2 { font-family: 'Quicksand', sans-serif; font-weight: 700; font-size: 1.5rem; margin-bottom: 16px; color: var(--text); }
.help-dialog p { color: var(--text-muted); margin-bottom: 16px; line-height: 1.7; }
.help-dialog h3 { font-size: 1rem; font-weight: 700; color: var(--text); margin: 20px 0 10px; }
.help-dialog ul { margin-left: 18px; margin-bottom: 16px; color: var(--text-muted); line-height: 1.8; }
.help-dialog li { margin-bottom: 6px; }
.help-dialog strong { color: var(--text); }
.help-tip { background: var(--warm-light); border-radius: var(--radius-m); padding: 12px 16px; margin: 20px 0; font-size: 0.9rem; color: var(--text); border-left: 4px solid var(--warm); }
.help-tip strong { color: var(--warm-dark); }
#start-playing-button { margin: 8px 0 28px; width: 100%; }

/* ========================================================================== */
/* Responsive */
@media (max-width: 1100px) {
  .game-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .panel { position: static; max-height: none; top: auto; }
  .level-panel { order: 1; }
  .board-area { order: 2; }
  .guide-panel { order: 3; }
  .board-frame { max-width: 480px; margin: 0 auto; }
}

@media (max-width: 600px) {
  :root { --header-h: 56px; }
  .app-shell { padding: 0 16px; }
  .brand-name span { display: none; }
  .quiet-button span { display: none; }
  .quiet-button { padding: 10px; }
  .metrics { gap: 8px; }
  .metric { min-width: 0; padding: 6px 10px; }
  .metric strong { font-size: 1.1rem; }
  .board { gap: 6px; padding: 12px; }
  .tile { font-size: clamp(0.9rem, 3.5vw, 1.2rem); }
  .win-card, .lose-card { padding: 24px 20px; }
  .control-buttons { width: 100%; justify-content: center; }
  .keyboard-hint { width: 100%; justify-content: center; font-size: 0.7rem; }
}

@media (max-width: 400px) {
  .help-dialog { margin: 16px; width: calc(100% - 32px); }
}

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

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ========================================================================== */
/* Word Submission Animation */
@keyframes wordBurst {
  0% { transform: scale(1) translateY(0); opacity: 1; }
  100% { transform: scale(1.5) translateY(-60px); opacity: 0; }
}

.word-pop {
  position: absolute;
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--accent-dark);
  pointer-events: none;
  z-index: 20;
  animation: wordBurst 1s cubic-bezier(0.2, 0.6, 0.3, 1) forwards;
}

.nectar-pop {
  position: absolute;
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--warm-dark);
  pointer-events: none;
  z-index: 20;
  animation: wordBurst 1s cubic-bezier(0.2, 0.6, 0.3, 1) forwards;
}

/* Shuffle animation */
@keyframes shuffleSpin {
  0% { transform: rotate(0) scale(1); }
  50% { transform: rotate(180deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}
.board.shuffling .tile { animation: shuffleSpin 400ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.board.shuffling .tile:nth-child(odd) { animation-delay: 50ms; }
.board.shuffling .tile:nth-child(3n) { animation-delay: 100ms; }

/* Level complete celebration */
@keyframes confettiFall {
  0% { transform: translateY(-100vh) rotate(0); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
.confetti {
  position: fixed;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 50;
  animation: confettiFall 3s linear forwards;
}