/* ============================================================
   LinkLot — Weaving Pulse Theme
   Nature-inspired calm UI for a word-chain game.
   Fonts: DM Sans (body), Outfit (headings), Space Mono (letters)
   ============================================================ */

/* ---------------------------------------------------------
   0. CUSTOM PROPERTIES
   --------------------------------------------------------- */
:root {
  /* NATURE THEME */
  --bg-primary: #f2f5f3;
  --bg-secondary: #e6ebe8;
  --bg-surface: rgba(255, 255, 255, 0.5);
  --bg-surface-solid: #ffffff;

  /* Typography */
  --text-primary: #2c3e35;
  --text-secondary: #53695c;
  --text-muted: #859c8e;

  /* Accents */
  --accent-teal: #4a8260;
  --accent-lavender: #6b9679;
  --accent-mint: #3d8a57;
  --accent-rose: #c76f6f;
  --accent-gold: #d6ad45;
  --accent-silver: #a0acab;
  --accent-bronze: #b87a4a;

  /* Glass & surfaces */
  --glass-bg: rgba(242, 245, 243, 0.85);
  --glass-border: rgba(74, 130, 96, 0.15);

  /* Pill states */
  --pill-border: rgba(74, 130, 96, 0.2);
  --pill-active-glow: rgba(74, 130, 96, 0.25);
  --pill-complete: rgba(61, 138, 87, 0.12);
  --pill-complete-border: rgba(61, 138, 87, 0.3);

  /* Keyboard */
  --key-bg: #ffffff;
  --key-text: #2c3e35;

  /* Toast & modal */
  --toast-bg: rgba(44, 62, 53, 0.95);
  --modal-backdrop: rgba(18, 28, 23, 0.4);
}

/* ---------------------------------------------------------
   1. RESET & BASE
   --------------------------------------------------------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
  height: -webkit-fill-available;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: linear-gradient(160deg, #f2f5f3 0%, #e6ebe8 50%, #f2f5f3 100%);
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, rgba(126, 200, 227, 0.03) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ---------------------------------------------------------
   2. LOADING SCREEN
   --------------------------------------------------------- */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loading-screen.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.loader-ring {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(126, 200, 227, 0.12);
  border-top-color: var(--accent-teal);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.loader-text {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.06em;
}

/* ---------------------------------------------------------
   3. START SCREEN
   --------------------------------------------------------- */
#start-screen {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #f2f5f3 0%, #e6ebe8 50%, #f2f5f3 100%);
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

#start-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.start-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: start-fade-in 0.8s ease;
}

.start-logo {
  color: var(--accent-teal);
  margin-bottom: 4px;
}

.start-title {
  font-family: 'Outfit', sans-serif;
  font-size: 3rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-teal), var(--accent-lavender));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}

.start-puzzle-number {
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.start-tagline {
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* Start Screen Ad Container */
.start-ad-container {
  display: none; /* Hidden for launch. Change this to 'flex' when you are ready to enable Google AdSense */
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 320px;
  margin: 16px 0 36px 0; /* Generous bottom margin to prevent accidental clicks near the Start button */
  min-height: 122px; /* Reserves space to prevent Layout Shifts (CLS) when the ad loads, keeping the Start button stable */
}

.ad-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.ad-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 320px;
  height: 100px;
  border-radius: 12px;
  background: var(--bg-secondary);
  border: 1px dashed var(--pill-border);
  color: var(--text-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  transition: all 0.3s ease;
}

.start-button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 48px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent-teal), var(--accent-lavender));
  color: #fff;
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 20px rgba(74, 130, 96, 0.3);
  animation: start-pulse 2s ease-in-out infinite;
}

.start-button:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 6px 30px rgba(74, 130, 96, 0.4);
}

.start-button:active {
  transform: scale(0.97);
}

.start-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
}

.start-footer-link {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.start-footer-link:hover {
  color: var(--accent-teal);
}

.start-footer-sep {
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.5;
}

@keyframes start-fade-in {
  0% { opacity: 0; transform: translateY(20px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes start-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(74, 130, 96, 0.3); }
  50% { box-shadow: 0 6px 35px rgba(74, 130, 96, 0.45); }
}

/* ---------------------------------------------------------
   4. APP SHELL
   --------------------------------------------------------- */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  height: var(--viewport-height, 100vh);
  max-width: 520px;
  margin: 0 auto;
  padding: 0 16px;
  overflow: hidden;
}

/* ---------------------------------------------------------
   5. HEADER
   --------------------------------------------------------- */
#main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 0;
  flex-shrink: 0;
}

#logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-teal), var(--accent-lavender));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}

.logo-icon {
  display: inline-flex;
  color: var(--accent-teal);
  flex-shrink: 0;
}

.logo-icon svg {
  width: 22px;
  height: 22px;
}

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

.header-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}

.header-btn svg {
  width: 18px;
  height: 18px;
}

.header-btn:hover {
  color: var(--accent-teal);
  border-color: rgba(74, 130, 96, 0.3);
  background: rgba(74, 130, 96, 0.06);
}

.header-btn:focus-visible {
  outline: 2px solid var(--accent-teal);
  outline-offset: 2px;
}

/* Streak Badge */
.streak-badge {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(214, 173, 69, 0.12);
  border: 1px solid rgba(214, 173, 69, 0.25);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-gold);
  line-height: 1;
}

.streak-fire {
  font-size: 0.9rem;
}

.streak-count {
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------
   6. PUZZLE INFO
   --------------------------------------------------------- */
#puzzle-info {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 6px 0 10px;
  flex-shrink: 0;
}

.puzzle-hint {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-secondary);
  text-align: center;
}

.puzzle-hint strong {
  color: var(--accent-teal);
  font-weight: 600;
}

.puzzle-divider {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.5;
  flex-shrink: 0;
}

.puzzle-number {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* ---------------------------------------------------------
   7. WEAVE CONTAINER (Main Game Area)
   --------------------------------------------------------- */
#weave-container {
  width: 100%;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  -ms-overflow-style: none;
  scrollbar-width: none;
  transition: flex-direction 0s;
}

#weave-container::-webkit-scrollbar {
  display: none;
}

/* ---------------------------------------------------------
   8. WORD NODE — Weave Alignment
   --------------------------------------------------------- */
.word-node {
  display: flex;
  justify-content: center;
  width: 100%;
  transition: transform 0.6s cubic-bezier(0.34, 1.1, 0.64, 1), opacity 0.6s ease;
  transform: translateX(var(--node-x, 0px)) translateY(var(--node-y, 0px)) scale(var(--node-scale, 1));
  opacity: var(--node-opacity, 1);
  z-index: var(--node-z, 10);
  transform-origin: center center;
  flex-shrink: 0;
}

/* Default vertical weaving offsets */
.word-node[data-row="1"], .word-node[data-row="3"] { --node-x: 25px; }
.word-node[data-row="2"], .word-node[data-row="4"] { --node-x: -25px; }

/* ---------------------------------------------------------
   9. NODE PILL
   --------------------------------------------------------- */
.node-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1.5px solid var(--pill-border);
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  min-width: 280px;
  transition: all 0.4s ease;
  gap: 0;
}

.word-node.active .node-pill {
  border-color: var(--accent-teal);
  box-shadow: 0 0 20px var(--pill-active-glow);
  animation: breathe 3s ease-in-out infinite;
}

.word-node.complete .node-pill {
  background: var(--pill-complete);
  border-color: var(--pill-complete-border);
}

.word-node.complete .node-pill.ripple {
  animation: ripple-out 0.6s ease-out;
}

.word-node.invalid .node-pill {
  border-color: var(--accent-rose);
  animation: gentle-pulse 0.6s ease;
}

/* ---------------------------------------------------------
   10. LETTERS
   --------------------------------------------------------- */
.letter {
  display: inline-block;
  font-family: 'Space Mono', monospace;
  font-size: 1.6rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-primary);
  width: 32px;
  text-align: center;
  line-height: 1;
  transition: color 0.3s ease, transform 0.2s ease;
}

.letter.locked {
  color: var(--accent-teal);
}

.letter.ghost {
  color: var(--text-muted);
  opacity: 0.3;
}

.word-node.complete .letter {
  color: var(--accent-mint);
}

.letter.pop {
  animation: letter-pop 0.15s ease;
}

/* ---------------------------------------------------------
   11. LETTER SEPARATOR
   --------------------------------------------------------- */
.letter-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.2;
  margin: 0 2px;
  flex-shrink: 0;
  transition: opacity 0.3s ease, background 0.3s ease;
}

.word-node.active .letter-sep {
  opacity: 0.35;
}

.word-node.complete .letter-sep {
  background: var(--accent-mint);
  opacity: 0.3;
}

/* ---------------------------------------------------------
   12. CHAIN CONNECTOR
   --------------------------------------------------------- */
.chain-connector {
  height: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: var(--conn-opacity, 0.3);
  transition: opacity 0.6s ease, transform 0.6s ease;
  transform: scaleY(var(--node-scale, 1));
  z-index: 1;
  flex-shrink: 0;
}

/* Link letter badge (hidden on mobile, shown on desktop) */
.link-letter {
  display: none;
}

.connector-line {
  width: 2px;
  height: 100%;
  background: linear-gradient(to bottom, var(--accent-teal), var(--accent-lavender));
  border-radius: 1px;
  position: relative;
}

.chain-connector.active .connector-line {
  opacity: 1;
}

/* ---------------------------------------------------------
   13. PULSE DOT
   --------------------------------------------------------- */
.pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-teal);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  top: 0;
}

.chain-connector.active .pulse-dot {
  animation: pulse-travel 1.5s ease-in-out infinite;
  opacity: 1;
}

/* ---------------------------------------------------------
   14. GAME ACTION BUTTONS (Go-Back / Forfeit)
   --------------------------------------------------------- */
#game-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 0;
  flex-shrink: 0;
  min-height: 36px;
}

.game-action-btn {
  padding: 6px 16px;
  border-radius: 999px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  gap: 5px;
}

.goback-btn {
  background: rgba(74, 130, 96, 0.08);
  border: 1px solid rgba(74, 130, 96, 0.2);
  color: var(--accent-teal);
}

.goback-btn:hover {
  background: rgba(74, 130, 96, 0.15);
  border-color: rgba(74, 130, 96, 0.35);
}

.goback-btn svg {
  width: 14px;
  height: 14px;
}

.forfeit-btn {
  background: rgba(199, 111, 111, 0.08);
  border: 1px solid rgba(199, 111, 111, 0.2);
  color: var(--accent-rose);
}

.forfeit-btn:hover {
  background: rgba(199, 111, 111, 0.15);
  border-color: rgba(199, 111, 111, 0.35);
}

/* ---------------------------------------------------------
   15. TYPING HINT (Desktop Only)
   --------------------------------------------------------- */
#typing-hint.desktop-only {
  text-align: center;
  padding: 12px 0;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

/* ---------------------------------------------------------
   16. VIRTUAL KEYBOARD
   --------------------------------------------------------- */
#keyboard {
  display: none;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 8px 4px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg-primary) 60%, transparent);
  flex-shrink: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Hide keyboard on mobile when game is done */
body.game-complete #keyboard {
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
}

.keyboard-row {
  display: flex;
  gap: 5px;
  justify-content: center;
  width: 100%;
}

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 52px;
  max-width: 42px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--key-bg);
  color: var(--key-text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.key:active,
.key.key-active {
  background: var(--accent-teal);
  color: #ffffff;
  transform: scale(0.96);
}

.key:focus-visible {
  outline: 2px solid var(--accent-teal);
  outline-offset: 1px;
}

.key-wide {
  flex: 1.5;
  max-width: 65px;
  font-size: 0.7rem;
  letter-spacing: 0.02em;
}

.key-wide svg {
  width: 20px;
  height: 20px;
}

.spacer-half {
  flex: 0.5;
  visibility: hidden;
  pointer-events: none;
}

/* ---------------------------------------------------------
   17. MODAL SYSTEM
   --------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: var(--modal-backdrop);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-content {
  position: relative;
  z-index: 1;
  width: calc(100% - 40px);
  max-width: 400px;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  padding: 32px 24px;
  animation: modal-slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  -ms-overflow-style: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(126, 200, 227, 0.1) transparent;
}

.modal-content::-webkit-scrollbar { width: 4px; }
.modal-content::-webkit-scrollbar-track { background: transparent; }
.modal-content::-webkit-scrollbar-thumb {
  background: rgba(126, 200, 227, 0.1);
  border-radius: 4px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.modal-close:hover {
  color: var(--text-primary);
  background: rgba(74, 130, 96, 0.06);
}

.modal-close:focus-visible {
  outline: 2px solid var(--accent-teal);
  outline-offset: 2px;
}

.modal-close svg {
  width: 16px;
  height: 16px;
}

.modal-content h2 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 16px;
}

.modal-body p {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.88rem;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: 1.6;
}

.modal-body h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  margin: 20px 0 12px;
}

/* ---------------------------------------------------------
   18. HELP MODAL — Rules
   --------------------------------------------------------- */
.rule-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 20px 0;
  list-style: none;
}

.rule {
  display: flex;
  flex-direction: row;
  gap: 12px;
  align-items: flex-start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--glass-border);
}

.rule:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.rule-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rule-icon svg {
  width: 20px;
  height: 20px;
  color: var(--accent-teal);
}

.rule p { margin: 0; }

.example-chain {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px;
  background: rgba(74, 130, 96, 0.04);
  border-radius: 14px;
  margin: 12px 0;
}

.example-label {
  font-family: 'Outfit', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-teal);
  margin-bottom: 6px;
}

.example-node { display: flex; gap: 3px; }

.ex-l {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--bg-surface-solid);
  font-family: 'Space Mono', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-primary);
}

.ex-l.accent {
  color: var(--accent-teal);
  border: 1px solid rgba(74, 130, 96, 0.3);
}

.ex-l.link {
  color: var(--accent-lavender);
  border: 1px solid rgba(107, 150, 121, 0.3);
}

.example-connector {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.4;
  padding: 2px 0;
}

.example-dots {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.4;
  padding: 2px 0;
  letter-spacing: 0.15em;
}

.example-word-count {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  opacity: 0.5;
  margin-bottom: 4px;
}

.example-note {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--accent-lavender);
  margin-top: 6px;
  opacity: 0.85;
}

.help-footer {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-muted);
  text-align: center;
  margin-top: 16px;
  line-height: 1.5;
}

/* ---------------------------------------------------------
   19. STATS MODAL
   --------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-number {
  font-family: 'Outfit', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.stat-label {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  text-align: center;
}

.medal-distribution h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 14px;
}

.medal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.medal-row:last-child { margin-bottom: 0; }

.medal-icon {
  font-size: 1.2rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
}

.medal-bar-track {
  flex: 1;
  height: 22px;
  background: var(--bg-surface-solid);
  border-radius: 6px;
  overflow: hidden;
}

.medal-bar {
  height: 100%;
  border-radius: 6px;
  min-width: 0;
  transition: width 0.6s ease;
}

#bar-gold { background: linear-gradient(90deg, #f0d68a, #e6c060); }
#bar-silver { background: linear-gradient(90deg, #c0c8d4, #a8b0bc); }
#bar-bronze { background: linear-gradient(90deg, #cd9b6a, #b8864e); }
#bar-complete { background: linear-gradient(90deg, var(--accent-teal), var(--accent-lavender)); }

.medal-count {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  width: 28px;
  text-align: right;
  flex-shrink: 0;
}

/* ---------------------------------------------------------
   20. RESULT MODAL
   --------------------------------------------------------- */
.medal-display {
  text-align: center;
  margin-bottom: 8px;
}

.medal-emoji {
  font-size: 3.5rem;
  display: block;
  line-height: 1.2;
  animation: medal-appear 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.result-subtitle {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.5;
}

.result-chain {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 14px;
  background: rgba(74, 130, 96, 0.04);
  border-radius: 14px;
  margin-bottom: 20px;
}

.result-word {
  display: flex;
  gap: 3px;
}

.result-letter {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.result-letter.valid {
  background: var(--pill-complete);
  color: var(--accent-mint);
  border: 1px solid var(--pill-complete-border);
}

.result-letter.empty {
  background: var(--bg-surface-solid);
  color: var(--text-muted);
}

.result-connector {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.4;
  padding: 1px 0;
}

.btn-share {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-teal), var(--accent-lavender));
  color: var(--bg-primary);
  font-family: 'Outfit', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 20px rgba(74, 130, 96, 0.2);
}

.btn-share svg { width: 18px; height: 18px; }

.btn-share:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(74, 130, 96, 0.3);
}

.btn-share:active { transform: translateY(0); }

.btn-share:focus-visible {
  outline: 2px solid var(--accent-teal);
  outline-offset: 3px;
}

.next-puzzle {
  border-top: 1px solid var(--glass-border);
  margin-top: 20px;
  padding-top: 16px;
  text-align: center;
}

.next-label {
  display: block;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.next-countdown {
  font-family: 'Space Mono', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ---------------------------------------------------------
   21. FORFEIT CONFIRMATION MODAL
   --------------------------------------------------------- */
.forfeit-content {
  text-align: center;
}

.forfeit-content .modal-body p {
  text-align: center;
  margin-bottom: 20px;
}

.forfeit-actions {
  display: flex;
  gap: 10px;
}

.forfeit-cancel-btn,
.forfeit-confirm-btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.forfeit-cancel-btn {
  background: var(--bg-surface-solid);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}

.forfeit-cancel-btn:hover {
  background: rgba(74, 130, 96, 0.06);
  border-color: rgba(74, 130, 96, 0.3);
}

.forfeit-confirm-btn {
  background: rgba(199, 111, 111, 0.12);
  border: 1px solid rgba(199, 111, 111, 0.3);
  color: var(--accent-rose);
}

.forfeit-confirm-btn:hover {
  background: rgba(199, 111, 111, 0.2);
}

/* Storage warning */
.storage-warning {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  margin-top: 16px;
  border-radius: 10px;
  background: rgba(214, 173, 69, 0.08);
  border: 1px solid rgba(214, 173, 69, 0.2);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

.storage-warning-icon {
  flex-shrink: 0;
  font-size: 0.85rem;
  line-height: 1;
  margin-top: 1px;
}

/* ---------------------------------------------------------
   22. TOAST SYSTEM
   --------------------------------------------------------- */
#toast-container {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 22px;
  border-radius: 999px;
  background: var(--toast-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  color: #ffffff;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(12px) scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: auto;
}

.toast.toast-visible { opacity: 1; transform: translateY(0) scale(1); }
.toast.toast-exit { opacity: 0; transform: translateY(-8px) scale(0.95); }

/* Warning toast variant */
.toast.toast-warning {
  background: rgba(214, 173, 69, 0.95);
  color: #3d3015;
  border-color: rgba(214, 173, 69, 0.3);
}

/* ---------------------------------------------------------
   23. KEYFRAME ANIMATIONS
   --------------------------------------------------------- */
@keyframes breathe {
  0%, 100% {
    box-shadow: 0 0 15px var(--pill-active-glow);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 25px rgba(74, 130, 96, 0.2);
    transform: scale(1.008);
  }
}

@keyframes letter-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes gentle-pulse {
  0%, 100% { border-color: var(--accent-rose); }
  50%      { border-color: var(--pill-border); }
}

@keyframes pulse-travel {
  0%   { top: 0; opacity: 0; }
  20%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { top: calc(100% - 6px); opacity: 0; }
}

@keyframes ripple-out {
  0%   { box-shadow: 0 0 0 0 rgba(74, 130, 96, 0.3); }
  100% { box-shadow: 0 0 0 15px rgba(74, 130, 96, 0); }
}

@keyframes modal-slide-up {
  0% { opacity: 0; transform: translateY(20px) scale(0.97); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes medal-appear {
  0%   { transform: scale(0); }
  100% { transform: scale(1); }
}

@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ---------------------------------------------------------
   24. ACCESSIBILITY — Reduced Motion
   --------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  body { animation: none; }
}

:focus-visible { outline: 2px solid var(--accent-teal); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

/* ---------------------------------------------------------
   25. RESPONSIVE — Mobile (≤768px)
   --------------------------------------------------------- */
@media (max-width: 768px) {
  #app {
    max-width: 100%;
    padding: 0 12px;
  }

  #main-header { padding: 10px 0; }
  #logo { font-size: 1.4rem; }

  #typing-hint.desktop-only { display: none !important; }

  #keyboard {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
  }

  #toast-container { bottom: 90px; }

  /* Mobile keeps vertical weaving */
  .word-node[data-row="1"], .word-node[data-row="3"] { --node-x: 15px; }
  .word-node[data-row="2"], .word-node[data-row="4"] { --node-x: -15px; }

  .node-pill { padding: 8px 16px; min-width: 240px; }
  .letter { font-size: 1.35rem; width: 26px; }
  .chain-connector { height: 24px; }
  #weave-container { padding-bottom: 180px; }
  #puzzle-info { padding: 4px 0 8px; }
  .puzzle-hint { font-size: 0.8rem; }
}

/* ---------------------------------------------------------
   26. RESPONSIVE — Small Mobile (≤400px)
   --------------------------------------------------------- */
@media (max-width: 400px) {
  #logo { font-size: 1.25rem; }
  .header-btn { width: 34px; height: 34px; }
  .header-btn svg { width: 16px; height: 16px; }
  .node-pill { padding: 7px 12px; min-width: 210px; }
  .letter { font-size: 1.15rem; width: 22px; }
  .letter-sep { width: 2px; height: 2px; margin: 0 1px; }
  .chain-connector { height: 20px; }
  .key { min-height: 44px; font-size: 0.75rem; border-radius: 6px; }
  .key-wide { font-size: 0.65rem; }
  .modal-content { padding: 24px 18px; border-radius: 16px; }
  .modal-content h2 { font-size: 1.2rem; }
  .stat-number { font-size: 1.5rem; }
  .result-letter { width: 24px; height: 24px; font-size: 0.65rem; }
  .ex-l { width: 26px; height: 26px; font-size: 0.7rem; }
}

/* ---------------------------------------------------------
   27. RESPONSIVE — Desktop (≥769px) — HORIZONTAL CHAIN
   --------------------------------------------------------- */
@media (min-width: 769px) {
  #keyboard { display: none !important; }
  #typing-hint.desktop-only { display: block; }

  #app {
    max-width: 100%;
    padding: 0 40px;
    justify-content: center;
  }

  /* Horizontal chain layout (Absolute Carousel) */
  #weave-container {
    position: relative;
    height: 140px;
    display: block;
    width: 100%;
    overflow: hidden;
    padding: 0;
  }

  .word-node {
    width: auto;
    position: absolute;
    left: 50%;
    top: 50%;
    margin: 0;
  }
  
  /* Weaving Y offsets */
  .word-node[data-row="1"], .word-node[data-row="3"] { --node-y: -15px; }
  .word-node[data-row="2"], .word-node[data-row="4"] { --node-y: 15px; }
  .word-node[data-row="0"], .word-node[data-row="5"] { --node-y: 0px; }

  /* Desktop connectors: hide lines, show link-letter badges */
  .chain-connector {
    position: absolute;
    left: 50%;
    top: 50%;
    height: auto;
    width: auto;
    min-width: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    /* JS sets transform for positioning */
  }

  .chain-connector .connector-line,
  .chain-connector .pulse-dot {
    display: none !important;
  }

  .chain-connector .link-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(74, 130, 96, 0.12);
    border: 1.5px solid rgba(74, 130, 96, 0.3);
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-teal);
    text-transform: uppercase;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: all 0.4s ease;
  }

  .chain-connector.active .link-letter {
    background: rgba(74, 130, 96, 0.2);
    border-color: var(--accent-teal);
    box-shadow: 0 0 12px rgba(74, 130, 96, 0.3);
    animation: badge-pulse 2s ease-in-out infinite;
  }

  @keyframes badge-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(74, 130, 96, 0.2); }
    50%      { box-shadow: 0 0 16px rgba(74, 130, 96, 0.45); }
  }

  /* Smaller pills on desktop horizontal */
  .node-pill {
    padding: 8px 14px;
    min-width: 120px;
  }

  .letter {
    font-size: 1.2rem;
    width: 24px;
  }

  .letter-sep {
    width: 2px;
    height: 2px;
    margin: 0 1px;
  }

  /* Completion: horizontal → vertical transition */
  #weave-container.chain-vertical {
    display: flex;
    flex-direction: column;
    height: auto;
    transition: none;
  }

  #weave-container.chain-vertical .word-node,
  #weave-container.chain-vertical .chain-connector {
    position: relative;
    left: auto; top: auto;
    transform: none !important;
  }

  #weave-container.chain-vertical .word-node {
    --node-x: 0px !important;
    --node-y: 0px !important;
    --node-scale: 0.85 !important;
    --node-opacity: 1 !important;
    width: 100%;
    justify-content: center;
  }

  #weave-container.chain-vertical .chain-connector {
    width: auto;
    height: 20px;
    min-width: auto;
  }

  /* In vertical stack: show lines, hide badges */
  /* In vertical stack: show lines and dots, hide badges */
  #weave-container.chain-vertical .connector-line,
  #weave-container.chain-vertical .pulse-dot {
    display: block !important;
  }
  
  #weave-container.chain-vertical .connector-line {
    width: 2px;
    height: 100%;
    background: linear-gradient(to bottom, var(--accent-teal), var(--accent-lavender));
  }

  #weave-container.chain-vertical .link-letter {
    display: none !important;
  }

  /* Stagger animation for each node */
  #weave-container.chain-transitioning .word-node {
    transition: transform 0.8s cubic-bezier(0.34, 1.1, 0.64, 1), opacity 0.6s ease;
  }

  #weave-container.chain-transitioning .word-node[data-row="0"] { transition-delay: 0s; }
  #weave-container.chain-transitioning .word-node[data-row="1"] { transition-delay: 0.08s; }
  #weave-container.chain-transitioning .word-node[data-row="2"] { transition-delay: 0.16s; }
  #weave-container.chain-transitioning .word-node[data-row="3"] { transition-delay: 0.24s; }
  #weave-container.chain-transitioning .word-node[data-row="4"] { transition-delay: 0.32s; }
  #weave-container.chain-transitioning .word-node[data-row="5"] { transition-delay: 0.4s; }

  #weave-container.chain-transitioning .chain-connector {
    transition: all 0.6s ease;
  }
}

/* Horizontal pulse dot animation (desktop) */
@keyframes pulse-travel-h {
  0%   { left: 0; opacity: 0; }
  20%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { left: calc(100% - 6px); opacity: 0; }
}

/* ---------------------------------------------------------
   28. RESPONSIVE — Large Desktop (≥1025px)
   --------------------------------------------------------- */
@media (min-width: 1025px) {
  #main-header { padding: 18px 0; }
  #logo { font-size: 1.7rem; }

  /* Slightly larger pills on big screens */
  .node-pill { padding: 10px 16px; min-width: 140px; }
  .letter { font-size: 1.3rem; width: 26px; }
  .chain-connector { width: 36px; min-width: 36px; }
}

/* ---------------------------------------------------------
   29. SAFE AREA INSETS (Notched devices)
   --------------------------------------------------------- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #keyboard {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
}
