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

:root {
  --bg: #0a1410;
  --surface: rgba(255,255,255,0.04);
  --surface-hover: rgba(255,255,255,0.08);
  --border: rgba(255,255,255,0.08);
  --accent: #22c55e;
  --accent-dark: #16a34a;
  --accent2: #06b6d4;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --correct: #34d399;
  --incorrect: #f87171;
  --pending: rgba(255,255,255,0.18);
  --font-ui: 'Inter', sans-serif;
  --font-mono: 'Lexend', 'Arial', sans-serif;
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.2s ease;
}

html, body { height: 100%; overflow: hidden; overscroll-behavior: none; touch-action: pan-y; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}

/* ===== ORBS ===== */
.bg-orbs { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.orb { position: absolute; border-radius: 50%; filter: blur(100px); opacity: 0.18; animation: orbFloat 8s ease-in-out infinite; }
.orb-1 { width: 600px; height: 600px; background: radial-gradient(circle, #22c55e, transparent); top: -200px; left: -100px; }
.orb-2 { width: 500px; height: 500px; background: radial-gradient(circle, #06b6d4, transparent); bottom: -150px; right: -100px; animation-delay: -3s; }
.orb-3 { width: 400px; height: 400px; background: radial-gradient(circle, #86efac, transparent); top: 50%; left: 50%; transform: translate(-50%,-50%); animation-delay: -6s; opacity: 0.06; }
@keyframes orbFloat { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-30px) scale(1.05); } }

/* ===== SCREENS ===== */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 1; opacity: 0; pointer-events: none;
  transform: translateY(20px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.screen.active { opacity: 1; pointer-events: all; transform: translateY(0); }

/* ===== FULLSCREEN BUTTON (shared style) ===== */
.fullscreen-btn {
  position: absolute;
  top: 20px; right: 20px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 50px;
  padding: 10px 16px;
  color: var(--text-muted);
  font-size: 0.8rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
  font-family: var(--font-ui); z-index: 10;
}
.fullscreen-btn:hover { color: var(--text); border-color: rgba(34,197,94,0.4); background: var(--surface-hover); }

/* ===== START SCREEN ===== */
.start-container { width: 100%; max-width: 960px; padding: 20px 32px; display: flex; flex-direction: column; gap: 20px; }
.logo-area { text-align: center; }
.logo-icon { font-size: 5.5rem; display: block; margin-bottom: 10px; animation: iconPulse 2s ease-in-out infinite; }
@keyframes iconPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1) rotate(5deg); } }
.logo-text { font-size: 3.8rem; font-weight: 900; background: linear-gradient(135deg,#22c55e,#06b6d4); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; letter-spacing: -1px; }
.logo-sub { color: var(--text-muted); font-size: 1.1rem; margin-top: 6px; }
.section-label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); margin-bottom: 10px; }

.mode-grid { display: grid; grid-template-columns: repeat(6,1fr); gap: 8px; }
.mode-btn {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 18px 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center;
  gap: 6px; transition: all var(--transition); color: var(--text-dim);
}
.mode-btn:hover { background: var(--surface-hover); border-color: rgba(34,197,94,0.3); transform: translateY(-2px); }
.mode-btn.active { background: rgba(34,197,94,0.12); border-color: var(--accent); color: var(--text); box-shadow: 0 0 20px rgba(34,197,94,0.2); }
.mode-icon { font-size: 1.8rem; }
.mode-name { font-size: 0.9rem; font-weight: 600; text-align: center; line-height: 1.2; }
.mode-desc { font-size: 0.7rem; color: var(--text-muted); text-align: center; }

.time-grid { display: grid; grid-template-columns: repeat(6,1fr); gap: 8px; }
.time-btn {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 8px; cursor: pointer; font-size: 1rem; font-weight: 600;
  color: var(--text-dim); transition: all var(--transition); font-family: var(--font-ui);
}
.time-btn:hover { background: var(--surface-hover); border-color: rgba(34,197,94,0.3); transform: translateY(-2px); }
.time-btn.active { background: rgba(34,197,94,0.12); border-color: var(--accent); color: var(--text); box-shadow: 0 0 20px rgba(34,197,94,0.2); }

.start-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 20px;
  background: linear-gradient(135deg,#22c55e,#16a34a); border: none; border-radius: var(--radius);
  color: white; font-size: 1.3rem; font-weight: 700; cursor: pointer;
  transition: all var(--transition); box-shadow: 0 8px 32px rgba(34,197,94,0.35); font-family: var(--font-ui);
}
.start-btn:hover { transform: translateY(-3px); box-shadow: 0 12px 40px rgba(34,197,94,0.5); }
.start-btn:active { transform: translateY(-1px); }
.start-btn svg { width: 20px; height: 20px; }

/* ===== GAME SCREEN ===== */
.game-container {
  width: 100%; max-width: 960px; padding: 24px;
  display: flex; flex-direction: column; gap: 20px; align-items: center;
}

.hud {
  display: flex; align-items: center;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 50px; padding: 8px 24px; gap: 20px;
}
.hud-stat { display: flex; flex-direction: column; align-items: center; min-width: 60px; }
.hud-value { font-family: var(--font-ui); font-size: 1.4rem; font-weight: 700; color: var(--text); line-height: 1; transition: color 0.3s; }
#hud-timer .hud-value { color: var(--accent); }
#hud-timer.warning .hud-value { color: var(--incorrect); animation: timerPulse 1s ease infinite; }
@keyframes timerPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.hud-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-top: 2px; }
.hud-divider { width: 1px; height: 28px; background: var(--border); }

.progress-bar-wrap { width: 100%; height: 4px; background: var(--surface); border-radius: 2px; overflow: hidden; }
.progress-bar { height: 100%; width: 100%; background: linear-gradient(90deg,#22c55e,#06b6d4); border-radius: 2px; transform-origin: left; transition: transform 1s linear; }

/* ===== TARGET AREA ===== */
.target-area {
  width: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 28px; min-height: 320px; padding: 16px;
  flex: 1;
}
.target-display {
  display: flex; flex-wrap: wrap; justify-content: center;
  align-items: baseline; text-align: center;
  line-height: 1.4; font-family: var(--font-mono); max-width: 100%;
}

/* Character states */
.tchar { display: inline-block; position: relative; color: var(--pending); transition: color 0.06s, text-shadow 0.08s; }
.tchar.done { color: var(--correct); }
.tchar.active {
  color: #ffffff;
  text-shadow: 0 0 24px rgba(34,197,94,0.9), 0 0 48px rgba(34,197,94,0.4);
}
.tchar.active::after {
  content: ''; position: absolute; bottom: -4px; left: 0; right: 0;
  height: 3px; background: var(--accent); border-radius: 2px;
  animation: caretPulse 0.7s ease-in-out infinite;
  box-shadow: 0 0 10px rgba(34,197,94,0.9);
}
@keyframes caretPulse { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

.tchar.space-char { width: 0.4em; height: 1em; vertical-align: bottom; }
.tchar.space-char.active::after { bottom: 0; height: 3px; }

.tchar.error-flash {
  color: var(--incorrect) !important;
  text-shadow: 0 0 20px rgba(248,113,113,0.9) !important;
  animation: errShake 0.22s ease;
}
@keyframes errShake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }

.target-display.item-complete { animation: successPop 0.3s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes successPop { 0% { transform: scale(1); } 50% { transform: scale(1.07); } 100% { transform: scale(1); } }

/* Font sizes per mode — big and clear for SEN pupils */
.target-display.mode-lowercase,
.target-display.mode-uppercase  { font-size: 16rem; font-weight: 700; }
.target-display.mode-cvc        { font-size: 9rem;  font-weight: 700; }
.target-display.mode-words      { font-size: 7rem;  font-weight: 700; }
.target-display.mode-sentences,
.target-display.mode-punctuation { font-size: 3.5rem; font-weight: 500; line-height: 1.5; }

/* Next preview */
.next-preview { display: flex; align-items: center; gap: 10px; opacity: 0.45; }
.next-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); white-space: nowrap; }
.next-text { font-family: var(--font-mono); font-size: 1.1rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 560px; }

/* Key hint */
.key-hint {
  font-size: 0.85rem; color: var(--text-muted); letter-spacing: 0.04em;
  padding: 8px 20px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 50px; transition: opacity 0.4s;
}
.key-hint.hidden { opacity: 0; pointer-events: none; }

/* Game top-left toolbar */
.game-topbar {
  position: absolute; top: 20px; left: 20px;
  display: flex; gap: 8px; z-index: 10;
}
.topbar-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 50px;
  padding: 9px 16px; color: var(--text-muted); font-size: 0.82rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition); font-family: var(--font-ui);
}
.topbar-btn:hover { color: var(--text); border-color: rgba(34,197,94,0.4); background: var(--surface-hover); }

.finish-btn {
  display: flex; align-items: center; gap: 8px;
  background: rgba(34,197,94,0.12); border: 1.5px solid var(--correct); border-radius: 50px;
  padding: 10px 20px; color: var(--correct); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: all var(--transition); font-family: var(--font-ui);
}
.finish-btn:hover { background: rgba(34,197,94,0.2); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(34,197,94,0.2); }
.finish-btn.hidden { display: none; }

/* ===== MASCOT ===== */
.mascot {
  position: absolute;
  bottom: 20px; right: 20px;
  z-index: 5; user-select: none; pointer-events: none;
  width: 160px; height: 195px;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.3));
}

/* Eye state defaults — only normal visible */
#eyes-happy, #eyes-shocked, #eyes-wow { display: none; }
#mouth-happy { display: none; }

/* Bounce = correct keypress */
.mascot.bounce #eyes-normal  { display: none; }
.mascot.bounce #eyes-happy   { display: block; }
.mascot.bounce #mouth-normal { display: none; }
.mascot.bounce #mouth-happy  { display: block; }

/* Shake = wrong keypress */
.mascot.shake #eyes-normal  { display: none; }
.mascot.shake #eyes-shocked { display: block; }

/* Wow = word / sentence complete */
.mascot.wow #eyes-normal  { display: none; }
.mascot.wow #eyes-wow     { display: block; }
.mascot.wow #mouth-normal { display: none; }
.mascot.wow #mouth-happy  { display: block; }

/* Tail wag — idle */
#cat-tail {
  transform-box: fill-box;
  transform-origin: 76px 112px;
  animation: tailWag 2.2s ease-in-out infinite;
}
@keyframes tailWag {
  0%,100% { transform: rotate(0deg); }
  50%     { transform: rotate(-14deg); }
}

/* Blink on normal eyes */
#eyes-normal ellipse {
  transform-box: fill-box;
  transform-origin: center;
  animation: catBlink 4.5s ease-in-out infinite;
}
@keyframes catBlink {
  0%,87%,100% { transform: scaleY(1); }
  91%         { transform: scaleY(0.06); }
}

/* Reaction animations on the whole SVG */
.mascot.bounce #mascot-svg { animation: mascotBounce 0.45s cubic-bezier(0.34,1.56,0.64,1); }
.mascot.shake  #mascot-svg { animation: mascotShake  0.35s ease; }
.mascot.wow    #mascot-svg { animation: mascotWow    0.55s cubic-bezier(0.34,1.56,0.64,1); }

@keyframes mascotBounce {
  0%,100% { transform: translateY(0) scale(1); }
  40%     { transform: translateY(-20px) scale(1.15); }
}
@keyframes mascotShake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-10px) rotate(-5deg); }
  60%     { transform: translateX(10px)  rotate( 5deg); }
}
@keyframes mascotWow {
  0%   { transform: scale(1) rotate(0); }
  45%  { transform: scale(1.35) rotate(12deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ===== CONFETTI ===== */
@keyframes confettiFall {
  0%   { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

/* ===== RESULTS ===== */
.results-container { width: 100%; max-width: 700px; padding: 24px; display: flex; flex-direction: column; gap: 24px; overflow-y: auto; max-height: 100vh; }
.results-header { text-align: center; }

/* Star rating */
.star-rating { display: flex; justify-content: center; align-items: center; gap: 12px; margin-bottom: 16px; }
.star {
  font-size: 5rem; display: inline-block;
  color: rgba(255,255,255,0.08);
  transform: scale(0.3);
  transition: color 0.2s;
  line-height: 1;
  filter: drop-shadow(0 0 0px transparent);
}
.star.empty  { transform: scale(1); color: rgba(255,255,255,0.1); }
.star.filled { color: #fbbf24; filter: drop-shadow(0 0 16px rgba(251,191,36,0.7)); animation: starPop 0.5s cubic-bezier(0.34,1.56,0.64,1) forwards; }
@keyframes starPop { from { transform: scale(0) rotate(-25deg); } to { transform: scale(1) rotate(0deg); } }

.results-title { font-size: 2.2rem; font-weight: 900; background: linear-gradient(135deg,#22c55e,#06b6d4); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.results-sub { color: var(--text-muted); margin-top: 4px; font-size: 0.95rem; }

.stats-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; }
.stat-card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 20px 16px; display: flex; flex-direction: column; align-items: center; gap: 4px; animation: statCardIn 0.4s ease both; }
.stat-card:nth-child(1){animation-delay:0.1s} .stat-card:nth-child(2){animation-delay:0.15s} .stat-card:nth-child(3){animation-delay:0.2s}
.stat-card:nth-child(4){animation-delay:0.25s} .stat-card:nth-child(5){animation-delay:0.3s} .stat-card:nth-child(6){animation-delay:0.35s}
@keyframes statCardIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.stat-card.primary { background: rgba(34,197,94,0.1); border-color: var(--accent); box-shadow: 0 0 24px rgba(34,197,94,0.15); }
.stat-value { font-family: var(--font-mono); font-size: 2rem; font-weight: 700; color: var(--text); line-height: 1; }
.stat-card.primary .stat-value { font-size: 2.4rem; background: linear-gradient(135deg,#22c55e,#06b6d4); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.stat-label { font-size: 0.8rem; font-weight: 600; color: var(--text-dim); }
.stat-desc { font-size: 0.65rem; color: var(--text-muted); text-align: center; }

.wpm-bar-section { display: flex; flex-direction: column; gap: 10px; }
.wpm-bar-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); }
.wpm-bar-track { position: relative; background: var(--surface); border: 1.5px solid var(--border); border-radius: 50px; height: 12px; }
.wpm-bar-fill { height: 100%; border-radius: 50px; background: linear-gradient(90deg,#34d399,#22c55e,#06b6d4); width: 0%; transition: width 1s cubic-bezier(0.25,0.46,0.45,0.94); box-shadow: 0 0 12px rgba(34,197,94,0.4); }
.wpm-bar-markers { display: flex; justify-content: space-between; margin-top: 6px; font-size: 0.65rem; color: var(--text-muted); }

.results-actions { display: flex; gap: 12px; }
.action-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 16px; border-radius: var(--radius); font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all var(--transition); border: 1.5px solid transparent; font-family: var(--font-ui); }
.action-btn.primary { background: linear-gradient(135deg,#22c55e,#16a34a); color: white; box-shadow: 0 4px 20px rgba(34,197,94,0.3); }
.action-btn.primary:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(34,197,94,0.45); }
.action-btn.secondary { background: var(--surface); border-color: var(--border); color: var(--text-dim); }
.action-btn.secondary:hover { background: var(--surface-hover); border-color: rgba(34,197,94,0.3); color: var(--text); transform: translateY(-2px); }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

@media (max-width: 700px) {
  .mode-grid { grid-template-columns: repeat(3,1fr); }
  .time-grid { grid-template-columns: repeat(3,1fr); }
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .target-display.mode-letters { font-size: 7rem; }
  .target-display.mode-cvc    { font-size: 4rem; }
  .target-display.mode-words  { font-size: 3.2rem; }
  .target-display.mode-sentences, .target-display.mode-punctuation { font-size: 1.8rem; }
  .logo-text { font-size: 2.2rem; }
}
