/* ELG Wordfall — v1.0 */
:root {
  --wf-font: "DM Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --wf-font-display: "Fraunces", "Georgia", serif;
  --wf-bg: #FAFAF8;
  --wf-ink: #2C2C2A;
  --wf-muted: #7A7A76;
  --wf-border: #CDCDC6;
  --wf-green: #5E9E6E;
  --wf-red: #D4626E;
  --wf-blue: #4A94B0;
  --wf-yellow: #D4A843;
  --wf-board-bg: #6B6963;
  --wf-cell-bg: rgba(255,255,255,0.06);
  --wf-cell-border: rgba(255,255,255,0.08);
  --wf-tile-bg: #F5F4F0;
}

#elg-wordfall-root {
  max-width: 500px; margin: 0 auto; padding: 0 16px;
  font-family: var(--wf-font); color: var(--wf-ink);
  user-select: none;
}

/* --- Top bar --- */
.wf-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px solid var(--wf-border);
}
.wf-topbar-left { display: flex; align-items: baseline; gap: 10px; }
.wf-topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.wf-title {
  font-family: var(--wf-font-display);
  font-weight: 700; font-size: 22px; margin: 0; letter-spacing: -0.3px;
}
.wf-date { font-size: 13px; color: var(--wf-muted); font-weight: 500; }
.wf-score { font-weight: 700; font-size: 16px; }
.wf-words-cleared {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  background: rgba(94,158,110,0.1); color: var(--wf-green);
  padding: 3px 8px; border-radius: 4px;
}
.wf-streak { font-size: 14px; font-weight: 600; }

/* --- Game area --- */
.wf-game-area {
  display: flex; gap: 12px; margin-bottom: 12px;
}

/* --- Queue --- */
.wf-queue {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  flex-shrink: 0; padding-top: 4px;
}
.wf-queue-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--wf-muted);
}
.wf-queue-letters { display: flex; flex-direction: column; gap: 4px; }
.wf-queue-tile {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--wf-font-display); font-weight: 800; font-size: 18px;
  background: var(--wf-tile-bg); border-radius: 5px;
  border-bottom: 2px solid rgba(0,0,0,0.08);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  color: var(--wf-ink);
}

/* --- Board --- */
.wf-board-wrap {
  background: var(--wf-blue);
  border-radius: 12px;
  padding: 8px;
  flex: 1;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  position: relative;
}
.wf-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(12, 1fr);
  gap: 3px;
  background: var(--wf-board-bg);
  border-radius: 6px;
  padding: 6px;
  min-height: 400px;
}

/* Board cell */
.wf-cell {
  width: 100%;
  aspect-ratio: 1;
  min-width: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--wf-cell-bg);
  border: 1px solid var(--wf-cell-border);
  border-radius: 3px;
  font-family: var(--wf-font-display); font-weight: 800;
  font-size: clamp(12px, 2.2vw, 18px);
  color: transparent;
  transition: all 200ms ease;
  box-sizing: border-box;
}
/* Cell with a letter */
.wf-cell.has-letter {
  background: var(--wf-tile-bg);
  color: var(--wf-ink);
  border-color: rgba(255,255,255,0.4);
  border-bottom: 2px solid rgba(0,0,0,0.1);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
/* Active falling piece */
.wf-cell.is-active {
  background: var(--wf-yellow);
  color: #fff;
  border-color: rgba(255,255,255,0.5);
  box-shadow: 0 0 8px rgba(212,168,67,0.4);
  font-weight: 800;
}
/* Ghost/preview position */
.wf-cell.is-ghost {
  background: rgba(212,168,67,0.15);
  border-color: rgba(212,168,67,0.2);
}
/* Word clearing — Phase 1: word cells flash green */
.wf-cell.is-word-found {
  background: var(--wf-green);
  color: #fff;
  border-color: rgba(255,255,255,0.6);
  box-shadow: 0 0 14px rgba(94,158,110,0.6);
  transform: scale(1.1);
  transition: all 150ms ease;
  z-index: 2;
}
/* Phase 2: row/board cells marked for clearing */
.wf-cell.is-row-clear {
  background: rgba(94,158,110,0.35);
  border-color: rgba(94,158,110,0.4);
  transition: all 200ms ease;
}
/* Phase 3: vanish */
.wf-cell.is-vanish {
  animation: wf-vanish 350ms ease forwards;
}
@keyframes wf-vanish {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.05); opacity: 0.8; }
  100% { transform: scale(0.3); opacity: 0; }
}
/* Board wipe flash */
.wf-cell.is-board-wipe {
  background: rgba(74,148,176,0.4);
  border-color: rgba(74,148,176,0.5);
  transition: all 150ms ease;
}
.wf-cell.is-danger {
  background: rgba(212,98,110,0.2);
  border-color: rgba(212,98,110,0.3);
}

/* === Danger zone — board frame states === */
/* Warning: stack reaching row 5 */
.wf-board-wrap.is-warning {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12), inset 0 0 0 2px rgba(212,168,67,0.4);
  transition: all 300ms ease;
}
.wf-board-wrap.is-warning .wf-board {
  background: linear-gradient(180deg, rgba(212,168,67,0.15) 0%, var(--wf-board-bg) 30%);
}

/* Danger: stack reaching row 3 */
.wf-board-wrap.is-danger {
  box-shadow: 0 4px 16px rgba(212,98,110,0.25), inset 0 0 0 2px rgba(212,98,110,0.5);
  animation: wf-danger-pulse 1.2s ease-in-out infinite;
  transition: all 300ms ease;
}
.wf-board-wrap.is-danger .wf-board {
  background: linear-gradient(180deg, rgba(212,98,110,0.2) 0%, var(--wf-board-bg) 35%);
}
@keyframes wf-danger-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(212,98,110,0.2), inset 0 0 0 2px rgba(212,98,110,0.4); }
  50% { box-shadow: 0 4px 24px rgba(212,98,110,0.4), inset 0 0 0 3px rgba(212,98,110,0.7); }
}

/* Critical: stack at row 1 */
.wf-board-wrap.is-critical {
  box-shadow: 0 4px 20px rgba(212,98,110,0.4), inset 0 0 0 3px rgba(212,98,110,0.7);
  animation: wf-critical-pulse 0.6s ease-in-out infinite;
  transition: all 200ms ease;
}
.wf-board-wrap.is-critical .wf-board {
  background: linear-gradient(180deg, rgba(212,98,110,0.35) 0%, rgba(212,98,110,0.08) 40%, var(--wf-board-bg) 60%);
}
@keyframes wf-critical-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(212,98,110,0.3), inset 0 0 0 3px rgba(212,98,110,0.6); }
  50% { box-shadow: 0 4px 30px rgba(212,98,110,0.6), inset 0 0 0 4px rgba(212,98,110,0.9); }
}
/* Hint glow — 3-letter near-word sequence */
.wf-cell.is-hint {
  background: #F0DFB4;
  border-color: rgba(212,168,67,0.65);
  box-shadow: 0 0 10px rgba(212,168,67,0.4), inset 0 0 4px rgba(212,168,67,0.15);
  color: #7A5A10;
  animation: wf-hint-pulse 1.8s ease-in-out infinite;
}
@keyframes wf-hint-pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(212,168,67,0.3), inset 0 0 4px rgba(212,168,67,0.1); }
  50% { box-shadow: 0 0 14px rgba(212,168,67,0.55), inset 0 0 6px rgba(212,168,67,0.2); }
}

/* --- Controls --- */
.wf-controls {
  display: flex; gap: 8px; justify-content: center; margin-bottom: 12px;
}
.wf-ctrl-btn {
  font-family: var(--wf-font); font-size: 16px; font-weight: 700;
  padding: 12px 20px; border-radius: 10px;
  border: none; cursor: pointer;
  background: var(--wf-tile-bg); color: var(--wf-ink);
  border-bottom: 3px solid rgba(0,0,0,0.08);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  transition: all 100ms ease;
  -webkit-tap-highlight-color: transparent;
}
.wf-ctrl-btn:active { transform: translateY(2px); border-bottom-width: 0; }
.wf-ctrl-drop {
  flex: 1; max-width: 160px;
  background: var(--wf-ink); color: #fff;
  border-bottom-color: rgba(0,0,0,0.2);
}

/* --- Status --- */
.wf-status {
  text-align: center; font-size: 14px; font-weight: 600;
  color: var(--wf-muted); min-height: 24px; margin-bottom: 12px;
}
.wf-status.is-word {
  color: var(--wf-green); font-size: 16px;
}

/* --- Result --- */
.wf-result {
  text-align: center; padding: 24px; border-radius: 14px;
  background: #fff; border: 1px solid var(--wf-border);
  margin-bottom: 20px; box-shadow: 0 2px 12px rgba(0,0,0,0.04);
}
.wf-result h3 {
  font-family: var(--wf-font-display);
  font-size: 24px; font-weight: 700; margin: 0 0 16px;
}
.wf-result-stats { display: flex; gap: 28px; justify-content: center; margin-bottom: 16px; }
.wf-stat-value { font-size: 22px; font-weight: 700; display: block; color: var(--wf-ink); }
.wf-result-wordlist {
  font-size: 13px; color: var(--wf-muted); margin-bottom: 16px;
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
}
.wf-result-word {
  background: rgba(94,158,110,0.1); color: var(--wf-green);
  padding: 3px 10px; border-radius: 4px; font-weight: 700;
  font-size: 12px; text-transform: uppercase;
}
.wf-result-actions { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
.wf-result-extra {
  border-top: 1px solid var(--wf-border);
  padding-top: 16px; margin-top: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}

/* --- Buttons --- */
.wf-btn {
  font-family: var(--wf-font); font-size: 13px; font-weight: 600;
  padding: 8px 14px; border-radius: 6px; border: 1px solid var(--wf-border);
  background: #fff; color: var(--wf-ink); cursor: pointer;
}
.wf-btn:hover { background: #F3F3F0; }
.wf-share-btn {
  font-family: var(--wf-font); font-size: 14px; font-weight: 600;
  padding: 10px 24px; border-radius: 8px; border: none;
  background: var(--wf-ink); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: opacity 150ms;
}
.wf-share-btn:hover { opacity: 0.85; }
.wf-share-btn--secondary {
  background: #fff; color: var(--wf-ink); border: 1px solid var(--wf-border);
}

/* --- Modal --- */
.wf-overlay {
  position: fixed; inset: 0; z-index: 999999;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.wf-overlay[hidden] { display: none !important; }
.wf-modal {
  background: #fff; border-radius: 14px; padding: 28px;
  max-width: 420px; width: 100%; position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  max-height: 90vh; overflow-y: auto;
}
.wf-modal-close {
  position: absolute; top: 12px; right: 14px;
  font-size: 22px; background: none; border: none; cursor: pointer;
  color: var(--wf-muted); line-height: 1; z-index: 1;
}
.wf-modal-title {
  font-family: var(--wf-font-display);
  font-size: 22px; font-weight: 700; margin: 0 0 18px;
}
.wf-htp-steps { display: flex; flex-direction: column; gap: 16px; }
.wf-htp-step { display: flex; gap: 12px; align-items: flex-start; }
.wf-htp-icon { font-size: 28px; flex-shrink: 0; width: 40px; text-align: center; }
.wf-htp-step h3 { font-size: 15px; font-weight: 700; margin: 0 0 4px; }
.wf-htp-step p { font-size: 13px; color: var(--wf-muted); margin: 0; line-height: 1.4; }

/* --- Start screen --- */
.wf-start-overlay {
  position: absolute; inset: 0;
  background: rgba(44,44,42,0.85);
  border-radius: 6px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; z-index: 10;
}
.wf-start-overlay[hidden] { display: none !important; }
.wf-start-title {
  font-family: var(--wf-font-display);
  font-size: 28px; font-weight: 700; color: #fff;
  letter-spacing: -0.5px;
}
.wf-start-sub {
  font-size: 14px; color: rgba(255,255,255,0.6);
  text-align: center; max-width: 240px; line-height: 1.4;
}
.wf-start-btn {
  font-family: var(--wf-font); font-size: 18px; font-weight: 700;
  padding: 14px 40px; border-radius: 10px; border: none;
  background: var(--wf-green); color: #fff; cursor: pointer;
  box-shadow: 0 4px 12px rgba(94,158,110,0.4);
  transition: all 150ms ease;
}
.wf-start-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(94,158,110,0.5); }
.wf-start-speed {
  background: var(--wf-red);
  box-shadow: 0 4px 12px rgba(212,98,110,0.4);
  font-size: 15px;
  padding: 10px 28px;
}
.wf-start-speed:hover { box-shadow: 0 6px 16px rgba(212,98,110,0.5); }
/* Speed Demon badge */
.wf-speed-badge {
  display: inline-block;
  background: var(--wf-red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
}

/* --- Toast --- */
.wf-toast {
  position: fixed; top: 24px; left: 50%;
  transform: translateX(-50%) translateY(-60px);
  background: var(--wf-ink); color: #fff;
  font-family: var(--wf-font); font-size: 13px; font-weight: 600;
  padding: 10px 20px; border-radius: 8px;
  z-index: 1000000; pointer-events: none; opacity: 0;
  transition: transform 300ms ease, opacity 300ms ease;
}
.wf-toast.is-visible { transform: translateX(-50%) translateY(0); opacity: 1; }

/* --- Responsive --- */
@media (max-width: 500px) {
  #elg-wordfall-root { padding: 0 8px; }
  .wf-topbar { flex-wrap: wrap; gap: 6px; }
  .wf-title { font-size: 18px; }
  .wf-queue-tile { width: 28px; height: 28px; font-size: 14px; }
  .wf-board-wrap { padding: 6px; }
  .wf-board { gap: 2px; padding: 4px; }
  .wf-ctrl-btn { padding: 10px 14px; font-size: 14px; }
}
