/* ========================================
   TYPO — CRT Typing Tutor Styles
   ======================================== */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  min-width: 980px;
  background: #060e1a;
  color: #f0ede8;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- CRT Scanlines --- */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10000;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0, 0, 0, 0.08) 3px,
    rgba(0, 0, 0, 0.08) 4px
  );
}

/* --- CRT vignette + glow --- */
.crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.35) 100%);
}

/* --- Main App Container (80% width) --- */
#app {
  width: 96%;
  min-width: 920px;
  max-width: 1680px;
  height: 96vh;
  position: relative;
  overflow: hidden;
}

/* --- Screen Base --- */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  transition: opacity 0.35s ease;
  padding: 20px;
}

.screen.active {
  display: flex;
  opacity: 1;
}

/* --- Boot Screen --- */
#screen-boot .title-logo {
  font-size: clamp(3rem, 8vw, 6rem);
  letter-spacing: 0.3em;
  text-shadow: 0 0 30px rgba(240, 237, 232, 0.5), 0 0 60px rgba(59, 130, 246, 0.3);
  animation: boot-fadein 1s ease forwards;
}

#screen-boot .subtitle {
  margin-top: 16px;
  font-size: clamp(0.8rem, 2vw, 1.1rem);
  color: #7a8ba8;
  letter-spacing: 0.15em;
  animation: boot-fadein 1s ease 0.5s forwards;
  opacity: 0;
}

.boot-loader {
  margin-top: 40px;
  width: 200px;
  height: 3px;
  background: rgba(59, 130, 246, 0.15);
  border-radius: 2px;
  overflow: hidden;
  opacity: 1;
  animation: boot-loader-fadeout 0.45s ease 2s forwards;
}

.boot-loader::after {
  content: '';
  display: block;
  width: 0%;
  height: 100%;
  background: #3b82f6;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.6);
  animation: boot-progress 2s ease forwards;
}

.boot-ready {
  margin-top: 34px;
  min-width: 180px;
  opacity: 0;
  animation: boot-fadein 1s ease 1.8s forwards;
}

@keyframes boot-fadein {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes boot-progress {
  to { width: 100%; }
}

@keyframes boot-loader-fadeout {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

/* --- General Screen Titles --- */
.screen h1, .screen h2 {
  font-size: clamp(1.4rem, 3.5vw, 2.4rem);
  letter-spacing: 0.08em;
  text-shadow: 0 0 15px rgba(240, 237, 232, 0.3);
  text-align: center;
}

.screen > p {
  margin-top: 12px;
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  color: #8a9bb5;
  text-align: center;
}

/* --- Inputs --- */
input[type="text"],
input[type="number"] {
  width: min(360px, 70%);
  margin-top: 24px;
  padding: 14px 20px;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  color: #f0ede8;
  background: rgba(10, 22, 40, 0.8);
  border: 2px solid #1e3a5f;
  border-radius: 8px;
  outline: none;
  text-align: center;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus,
input[type="number"]:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.3);
}

input[type="number"]::-webkit-inner-spin-button { opacity: 0.3; }

/* --- Back Button --- */
.btn-back {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 70;
  width: 54px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #3b82f6;
  color: #f0ede8;
  border: 0;
  border-radius: 8px;
  padding: 0;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.3);
  transition: all 0.2s ease;
}

.btn-back:hover {
  color: #f0ede8;
  background: #5a9cf7;
  box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
  transform: translateY(-1px);
}

.btn-corner {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 50;
  background: transparent;
  color: #7a8ba8;
  border: 1px solid #1e3a5f;
  border-radius: 8px;
  padding: 8px 16px;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: clamp(0.8rem, 1.5vw, 1rem);
  letter-spacing: 0.05em;
  cursor: pointer;
}

.btn-corner:hover {
  color: #f0ede8;
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.08);
}

/* --- Buttons --- */
.btn-primary, .btn-secondary {
  margin-top: 32px;
  padding: 14px 36px;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  letter-spacing: 0.1em;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: #3b82f6;
  color: #f0ede8;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  background: #5a9cf7;
  box-shadow: 0 0 25px rgba(59, 130, 246, 0.5);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(1px);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.btn-secondary {
  background: transparent;
  color: #7a8ba8;
  border: 1px solid #1e3a5f;
}

.btn-secondary:hover {
  color: #f0ede8;
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.08);
}

.icon-only {
  min-width: 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 1.1rem;
}

/* --- Profile Grid --- */
.profile-grid {
  display: flex;
  gap: 16px;
  margin-top: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.profile-card {
  position: relative;
  width: 160px;
  height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 22, 40, 0.7);
  border: 2px solid #1e3a5f;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.profile-card:hover {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.08);
  transform: translateY(-2px);
}

.profile-card .profile-name {
  font-size: 1rem;
  letter-spacing: 0.05em;
}

.profile-card .profile-lessons-count {
  font-size: 0.75rem;
  color: #7a8ba8;
  margin-top: 4px;
}

.profile-card.empty {
  border-style: dashed;
  color: #4a5a78;
}

.profile-card.editing {
  border-color: rgba(251, 191, 36, 0.65);
}

.profile-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fca5a5;
  background: rgba(10, 22, 40, 0.9);
  border: 1px solid rgba(239, 68, 68, 0.65);
  border-radius: 50%;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.profile-delete:hover {
  color: #fff;
  background: rgba(239, 68, 68, 0.3);
}

.btn-secondary:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

/* --- Menu Screen --- */
.menu-title {
  font-size: clamp(1.2rem, 3vw, 2rem);
  color: #e8f0ff;
}

.menu-lesson-area {
  width: min(760px, 88%);
  display: grid;
  grid-template-columns: minmax(360px, 1fr) auto;
  align-items: start;
  gap: 18px;
  margin-top: 20px;
}

.lesson-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-height: 45vh;
  overflow-y: auto;
  padding-right: 8px;
}

.btn-practice {
  margin-top: 0;
  min-width: 150px;
  height: 54px;
  padding: 0 22px;
}

.btn-practice.hidden {
  display: none;
}

.lesson-grid::-webkit-scrollbar { width: 4px; }
.lesson-grid::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 2px; }
.lesson-grid::-webkit-scrollbar-thumb { background: #1e3a5f; border-radius: 2px; }

.lesson-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  background: rgba(10, 22, 40, 0.5);
  border: 1px solid #1e3a5f;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.lesson-item:hover {
  background: rgba(59, 130, 246, 0.1);
  border-color: #3b82f6;
}

.lesson-item.current {
  padding: 18px 20px;
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.13);
  box-shadow: 0 0 18px rgba(59, 130, 246, 0.16);
}

.lesson-item.current .lesson-number {
  color: #9ebcff;
  font-size: 0.78rem;
}

.lesson-item.locked {
  opacity: 0.35;
  cursor: default;
}

.lesson-item.completed {
  opacity: 0.62;
  border-color: rgba(30, 58, 95, 0.75);
  background: rgba(10, 22, 40, 0.28);
  padding: 9px 14px;
}

.lesson-item .lesson-key {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59, 130, 246, 0.15);
  border-radius: 6px;
  font-size: 1.2rem;
  font-weight: bold;
}

.lesson-item.current .lesson-key {
  width: 50px;
  height: 50px;
  color: #f0ede8;
  border: 1px solid rgba(59, 130, 246, 0.55);
}

.lesson-item.completed .lesson-key {
  width: 30px;
  height: 30px;
  background: rgba(122, 139, 168, 0.09);
  color: #8a9bb5;
  font-size: 0.9rem;
}

.lesson-item.locked .lesson-key {
  background: rgba(100, 100, 100, 0.15);
}

.lesson-item .lesson-info {
  flex: 1;
}

.lesson-item .lesson-name {
  font-size: 0.9rem;
  letter-spacing: 0.05em;
}

.lesson-item .lesson-number {
  font-size: 0.68rem;
  color: #5f7190;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.lesson-item .lesson-status {
  font-size: 0.7rem;
  color: #7a8ba8;
  margin-top: 2px;
}

.menu-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

/* --- Intro Screen --- */
#screen-intro {
  justify-content: flex-start;
  padding: 44px 12px 8px;
  overflow: hidden;
}

#screen-intro h1,
.intro-subtitle,
.key-reveal {
  display: none;
}

.big-key {
  font-size: clamp(3.6rem, 8vw, 5.9rem);
  letter-spacing: 0;
  text-shadow: 0 0 20px rgba(59, 130, 246, 0.6);
  animation: bigkey-pulse 2s ease-in-out infinite;
}

.big-key.wide-key {
  font-size: clamp(1.8rem, 4vw, 2.7rem);
}

@keyframes bigkey-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}

.finger-name {
  margin-top: 0;
  font-size: clamp(0.92rem, 1.45vw, 1.18rem);
  color: #c8d4e8;
  letter-spacing: 0.04em;
}

.intro-keyboard-heading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 44px;
  padding: 6px 14px;
  margin-top: 2px;
  border: 1px solid rgba(59, 130, 246, 0.24);
  border-radius: 8px;
  background: rgba(10, 22, 40, 0.38);
}

.intro-start-gate {
  margin-top: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 38px;
  color: #d8e4f6;
  letter-spacing: 0.04em;
}

.intro-gate-label {
  font-size: clamp(0.84rem, 1.25vw, 1rem);
  color: #92a3bd;
}

.intro-gate-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(59, 130, 246, 0.65);
  border-radius: 8px;
  background: rgba(59, 130, 246, 0.18);
  color: #ffffff;
  font-size: 1.25rem;
  box-shadow: 0 0 18px rgba(59, 130, 246, 0.25);
}

.keyboard-teach {
  width: 100%;
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.keyboard-teach .kb-key {
  width: clamp(44px, 4.4vw, 56px);
  height: clamp(44px, 4.4vw, 56px);
  font-size: clamp(0.66rem, 0.9vw, 0.82rem);
  border-radius: 6px;
}

.keyboard-teach .kb-key.space-bar { width: clamp(318px, 28vw, 370px); }
.keyboard-teach .kb-key.shift-key { width: clamp(82px, 8.2vw, 110px); }

.keyboard-teach .on-screen-keyboard {
  width: max-content;
  align-items: flex-start;
}

.keyboard-teach .hand-guide {
  margin-top: 18px;
  gap: clamp(34px, 5vw, 70px);
}

.keyboard-teach .hand-outline {
  width: clamp(230px, 23vw, 330px);
}

.keyboard-teach .on-screen-keyboard {
  gap: 4px;
}

.keyboard-teach .kb-row {
  gap: 4px;
}

.keyboard-teach .kb-row-0 { margin-left: clamp(24px, 3.4vw, 42px); }
.keyboard-teach .kb-row-1 { margin-left: clamp(48px, 5.5vw, 82px); }
.keyboard-teach .kb-row-2 { margin-left: clamp(46px, 5.2vw, 72px); }
.keyboard-teach .kb-row-3 { margin-left: 0; }
.keyboard-teach .kb-row-4 { margin-left: clamp(226px, 18vw, 278px); }

/* --- Stage Transition Screen --- */
#screen-stage h1 {
  font-size: clamp(2rem, 5vw, 4rem);
}

#stage-subtitle {
  color: #8a9bb5;
  letter-spacing: 0.08em;
}

.stage-stats {
  display: flex;
  gap: 14px;
  margin-top: 24px;
  justify-content: center;
  flex-wrap: wrap;
}

.stage-stat {
  min-width: 116px;
  padding: 12px 14px;
  border: 1px solid rgba(59, 130, 246, 0.55);
  border-radius: 8px;
  background: rgba(10, 22, 40, 0.68);
  text-align: center;
}

.stage-stat-value {
  display: block;
  color: #f0ede8;
  font-size: clamp(1.4rem, 3vw, 2rem);
  line-height: 1;
}

.stage-stat-label {
  display: block;
  margin-top: 8px;
  color: #7a8ba8;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* --- Typing Screen --- */
.typing-top-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 0 140px;
  margin-bottom: 16px;
  min-height: 48px;
}

.current-key-hint {
  font-size: clamp(0.8rem, 1.5vw, 1rem);
  color: #7a8ba8;
}

.progress-bar-container {
  flex: 1;
  max-width: 300px;
  height: 6px;
  background: rgba(30, 58, 95, 0.5);
  border-radius: 3px;
  overflow: hidden;
  margin: 0 16px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #5a9cf7);
  border-radius: 3px;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.4);
}

.progress-percent {
  font-size: clamp(0.8rem, 1.5vw, 1rem);
  color: #7a8ba8;
}

/* --- Exercise Area --- */
.exercise-container {
  width: 100%;
  flex: 0 0 auto;
  height: clamp(230px, 37vh, 285px);
  max-height: min(50vh, 285px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
  margin-top: 8px;
}

.exercise-text {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: clamp(1.72rem, 2.55vw, 2.5rem);
  line-height: 1.95;
  letter-spacing: 0.08em;
  text-align: center;
  width: 100%;
  height: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px;
  overflow: hidden;
  white-space: nowrap;
  word-break: normal;
}

.exercise-text.four-lines {
  font-size: clamp(1.45rem, 2.28vw, 2.12rem);
  line-height: 1.72;
}

.exercise-line {
  display: block;
  height: 33.333%;
  width: 100%;
  text-align: center;
  white-space: nowrap;
}

/* --- Dancing Alien Reward --- */
.alien-party {
  position: absolute;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  overflow: hidden;
}

.stage-alien-party {
  position: relative;
  width: min(760px, 78vw);
  height: 150px;
  margin-top: 18px;
  pointer-events: none;
}

.stage-space-prompt {
  margin-top: 18px;
  color: #f0ede8;
  font-size: clamp(1rem, 2.1vw, 1.28rem);
  letter-spacing: 0.11em;
  text-shadow: 0 0 16px rgba(59, 130, 246, 0.42);
}

.stage-space-prompt.hidden {
  display: none;
}

.cheat-toast {
  position: fixed;
  left: 50%;
  top: 28px;
  z-index: 120;
  transform: translate(-50%, -8px);
  min-width: 180px;
  padding: 12px 18px;
  border: 1px solid rgba(251, 191, 36, 0.7);
  border-radius: 8px;
  background: rgba(10, 22, 40, 0.92);
  color: #fbbf24;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 0 22px rgba(251, 191, 36, 0.24);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.cheat-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.alien-dancer {
  position: absolute;
  left: var(--alien-x, 78%);
  top: var(--alien-y, 78%);
  width: 86px;
  height: 118px;
  z-index: 35;
  pointer-events: none;
  opacity: 0.94;
  --alien-speed: 1.45s;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 0 10px rgba(240, 237, 232, 0.28));
  transition: filter 0.2s ease, transform 0.12s ease;
}

.alien-dancer.hidden {
  display: none;
}

.alien-dancer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 4px,
    rgba(6, 14, 26, 0.42) 4px,
    rgba(6, 14, 26, 0.42) 6px
  );
  pointer-events: none;
  mix-blend-mode: multiply;
}

.alien-sprite {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  background-size: 1290px 118px;
  background-position: 0 0;
  image-rendering: pixelated;
  transform-origin: 50% 84%;
}

.alien-dancer.dancing {
  animation: alien-arrive 0.55s ease both;
}

.alien-dancer.dancing.dance-bob {
  animation:
    alien-arrive 0.55s ease both,
    alien-bob calc(var(--alien-speed) * 3.2) ease-in-out 0.55s infinite;
}

.alien-dancer.dancing.dance-slide {
  animation:
    alien-arrive 0.55s ease both,
    alien-side-step calc(var(--alien-speed) * 3.6) ease-in-out 0.55s infinite;
}

.alien-dancer.paused {
  opacity: 0.45;
  filter: drop-shadow(0 0 6px rgba(240, 237, 232, 0.18));
}

.alien-dancer.fading {
  animation: alien-fade-out 0.45s ease forwards;
}

.alien-dancer.idle-fading {
  animation: alien-idle-fade-out 3.2s ease forwards;
}

.alien-dancer.dancing .alien-sprite {
  animation: alien-sprite-dance var(--alien-speed) steps(15, end) infinite;
}

.alien-dancer.key-pressed {
  transform: translate(-50%, -50%) rotate(var(--alien-hit-tilt, 5deg)) scale(1.07);
  filter: drop-shadow(0 0 18px rgba(251, 191, 36, 0.46));
}

.alien-dancer.key-pressed .alien-sprite {
  filter: brightness(1.24) saturate(1.35) hue-rotate(8deg);
}

.stage-alien-party .alien-dancer {
  z-index: 1;
}

.stage-alien-party .alien-dancer::after {
  display: none;
}

.stage-alien-party .stage-party-alien {
  opacity: 0.94;
  animation: alien-stage-arrive 0.65s ease both;
}

.result-alien-party {
  height: 126px;
  margin-top: 12px;
}

.alien-dancer.paused .alien-sprite {
  animation: none;
  background-position: 0 0;
}

.alien-dancer.idle-fading .alien-sprite {
  animation: none;
  background-position: 0 0;
}

.alien-dancer.swinging .alien-sprite {
  animation:
    alien-sprite-dance var(--alien-speed) steps(15, end) infinite,
    alien-swing calc(var(--alien-speed) * 2.5) ease-in-out infinite alternate;
}

.alien-dancer.dance-warp .alien-sprite {
  animation:
    alien-sprite-dance var(--alien-speed) steps(15, end) infinite,
    alien-soft-warp calc(var(--alien-speed) * 2.2) ease-in-out infinite alternate;
}

.alien-dancer.swinging.dance-warp .alien-sprite {
  animation:
    alien-sprite-dance var(--alien-speed) steps(15, end) infinite,
    alien-swing calc(var(--alien-speed) * 2.5) ease-in-out infinite alternate,
    alien-soft-warp calc(var(--alien-speed) * 2.2) ease-in-out infinite alternate;
}

.alien-dancer.tempo-break .alien-sprite {
  filter: brightness(1.22) saturate(1.35);
}

@keyframes alien-arrive {
  from {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 12px)) scale(0.9);
  }
  to {
    opacity: 0.94;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes alien-fade-out {
  from {
    opacity: 0.94;
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 8px)) scale(0.92);
  }
}

@keyframes alien-idle-fade-out {
  from {
    opacity: 0.84;
    transform: translate(-50%, -50%) scale(0.98);
  }
  to {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 10px)) scale(0.88);
  }
}

@keyframes alien-stage-arrive {
  from {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 10px)) scale(0.86);
  }
  to {
    opacity: 0.94;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes alien-sprite-dance {
  to { background-position: -1290px 0; }
}

@keyframes alien-swing {
  from { transform: rotate(-4deg) translateY(0); }
  to   { transform: rotate(4deg) translateY(-3px); }
}

@keyframes alien-bob {
  0%, 100% { transform: translate(-50%, -50%) translateY(0) scale(1); }
  38%      { transform: translate(-50%, -50%) translateY(-8px) scale(1.04); }
  58%      { transform: translate(-50%, -50%) translateY(2px) scale(0.98); }
}

@keyframes alien-side-step {
  0%, 100% { transform: translate(-50%, -50%) translateX(0) rotate(0deg); }
  34%      { transform: translate(-50%, -50%) translateX(-8px) rotate(-3deg); }
  68%      { transform: translate(-50%, -50%) translateX(8px) rotate(3deg); }
}

@keyframes alien-soft-warp {
  0%   { filter: brightness(1) saturate(1); transform: scale(1); }
  45%  { filter: brightness(1.18) saturate(1.25) hue-rotate(5deg); transform: scale(1.035, 0.98); }
  100% { filter: brightness(1.04) saturate(1.1); transform: scale(0.98, 1.03); }
}

.char {
  display: inline-block;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.1s ease;
  position: relative;
}

.char.pending    { color: #4a5a78; }
.char.current     { 
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  animation: char-blink 1s ease-in-out infinite;
}
.char.correct     { color: #4ade80; }
.char.incorrect   { 
  color: #fb923c;
  background: rgba(251, 146, 60, 0.18);
  animation: char-shake 0.3s ease;
}

.char.error-pulse {
  outline: 2px solid rgba(251, 146, 60, 0.62);
  outline-offset: 2px;
}

.char.had-error {
  color: #fb923c;
  background: rgba(251, 146, 60, 0.14);
  box-shadow: inset 0 -3px 0 rgba(251, 146, 60, 0.62);
}

.char.correct.had-error {
  color: #fb923c;
  text-shadow: 0 0 8px rgba(251, 146, 60, 0.42);
}

@keyframes char-blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

@keyframes char-shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-3px); }
  75%      { transform: translateX(3px); }
}

/* Space character visible marker */
.char[data-space="true"] {
  background: rgba(74, 90, 120, 0.18);
  border-radius: 4px;
}

.char[data-space="true"].had-error {
  background: rgba(251, 146, 60, 0.42);
  box-shadow: inset 0 0 0 2px rgba(251, 146, 60, 0.95), 0 0 14px rgba(251, 146, 60, 0.24);
}
.char[data-space="true"]::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 2px;
  right: 2px;
  height: 2px;
  background: rgba(122, 139, 168, 0.6);
}

.char.current[data-space="true"] {
  background: rgba(251, 191, 36, 0.18);
}
.char.current[data-space="true"]::after {
  background: rgba(251, 191, 36, 0.8);
}

.char[data-space="true"].had-error::after {
  background: rgba(251, 146, 60, 1);
}

.char.correct[data-space="true"] {
  background: rgba(74, 222, 128, 0.12);
}
.char.correct[data-space="true"]::after {
  background: rgba(74, 222, 128, 0.6);
}

.char.current[data-space="true"].had-error,
.char.correct[data-space="true"].had-error,
.char.incorrect[data-space="true"].had-error {
  background: rgba(251, 146, 60, 0.42);
  box-shadow: inset 0 0 0 2px rgba(251, 146, 60, 0.95), 0 0 14px rgba(251, 146, 60, 0.24);
}

.char.current[data-space="true"].had-error::after,
.char.correct[data-space="true"].had-error::after,
.char.incorrect[data-space="true"].had-error::after {
  background: rgba(251, 146, 60, 1);
}

/* --- Keyboard Hints --- */
.keyboard-area {
  width: 100%;
  padding: 10px 0 0;
}

.on-screen-keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 0 auto;
  width: fit-content;
}

.kb-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.kb-key {
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #101b2d;
  border: 1px solid rgba(122, 139, 168, 0.34);
  border-radius: 6px;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 1rem;
  color: #a7b4ca;
  transition: all 0.15s ease;
  user-select: none;
}

.kb-key.active {
  background: #16243a;
  border-color: #8a9bb5;
  transform: scale(0.95);
}

.kb-key.target-key {
  background: rgba(240, 237, 232, 0.08);
  border-color: #f0ede8;
  color: #fbbf24;
  box-shadow: 0 0 12px rgba(240, 237, 232, 0.22);
  animation: target-pulse 1.5s ease-in-out infinite;
}

@keyframes target-pulse {
  0%, 100% { box-shadow: 0 0 12px rgba(240, 237, 232, 0.18); }
  50%      { box-shadow: 0 0 24px rgba(240, 237, 232, 0.36); }
}

.kb-key.space-bar {
  width: 318px;
  font-size: 0.7rem;
  color: #a7b4ca;
}

.kb-key.shift-key {
  width: 92px;
  font-size: 0.68rem;
}

.kb-key.combo-key {
  font-size: 0.82rem;
  letter-spacing: 0;
}

.kb-key.help-flash {
  color: #fbbf24;
  border-color: #fbbf24;
  outline: 2px solid rgba(251, 191, 36, 0.45);
  outline-offset: 2px;
  animation: help-key-flash 0.7s ease-in-out 3;
}

@keyframes help-key-flash {
  0%, 100% { background: #101b2d; }
  50%      { background: rgba(251, 191, 36, 0.16); }
}

/* --- Temporary Hand Guide --- */
.hand-guide {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(22px, 4vw, 58px);
  margin-top: 18px;
}

.hand-outline {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  padding: 10px 12px 8px;
  border: 1px solid rgba(240, 237, 232, 0.28);
  border-top: 0;
  border-radius: 0 0 28px 28px;
}

.finger-part {
  display: block;
  width: 13px;
  height: 42px;
  border: 1px solid rgba(240, 237, 232, 0.34);
  border-radius: 12px 12px 8px 8px;
  background: rgba(16, 27, 45, 0.52);
}

.hand-outline {
  position: relative;
  border: 0;
  padding: 0;
  width: clamp(160px, 17vw, 235px);
}

.hand-image {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0 5px rgba(240, 237, 232, 0.22));
}

.hand-outline.right .hand-image,
.hand-outline.right .hand-glow-layer {
  transform: scaleX(-1);
}

.hand-glow-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.hand-glow {
  position: absolute;
  display: none;
  background: rgba(251, 191, 36, 0.55);
  border: 2px solid rgba(251, 191, 36, 0.88);
  border-radius: 999px;
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.76);
}

.hand-glow.active {
  display: block;
  animation: finger-fade 1.4s ease-in-out infinite;
}

.hand-glow.pinky  { left: 9%;  top: 31%; width: 5%;   height: 25%; transform: rotate(-13deg); }
.hand-glow.ring   { left: 25%; top: 15%; width: 5.5%; height: 29%; transform: rotate(-7deg); }
.hand-glow.middle { left: 44%; top: 8%;  width: 5.2%; height: 33%; transform: rotate(0deg); }
.hand-glow.index  { left: 61%; top: 18%; width: 5.8%; height: 28%; transform: rotate(11deg); }
.hand-glow.thumb  { left: 58%; top: 47%; width: 34%;  height: 14%;  transform: rotate(-37deg); }

@keyframes finger-fade {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 1; }
}

.typing-help {
  position: absolute;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  z-index: 60;
  width: min(420px, 92%);
  padding: 12px 16px;
  background: rgba(6, 14, 26, 0.92);
  border: 1px solid rgba(251, 191, 36, 0.42);
  border-radius: 8px;
  pointer-events: none;
  text-align: center;
}

.typing-help.hidden {
  display: none;
}

.typing-help.flash-on {
  animation: help-panel-flash 2.2s ease forwards;
}

.typing-help-label {
  color: #f0ede8;
  font-size: clamp(0.85rem, 1.7vw, 1rem);
  letter-spacing: 0.06em;
}

.typing-help-key-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.typing-help-key-row .kb-key {
  width: 76px;
  height: 62px;
  font-size: 1.15rem;
}

.typing-help-key-row .kb-key.space-bar {
  width: 190px;
}

.typing-help-key-row .kb-key.shift-key {
  width: 110px;
}

.typing-help .hand-guide {
  margin-top: 8px;
}

.typing-help .hand-svg {
  width: 260px;
  height: auto;
}

@keyframes help-panel-flash {
  0%   { opacity: 0; transform: translate(-50%, 8px); }
  16%  { opacity: 1; transform: translate(-50%, 0); }
  78%  { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 8px); }
}

/* --- Finger Guide Overlay --- */
.finger-guide-overlay {
  position: absolute;
  bottom: 80px;
  right: 20px;
  background: rgba(10, 22, 40, 0.95);
  border: 1px solid #1e3a5f;
  border-radius: 12px;
  padding: 16px;
  font-size: 0.8rem;
  color: #7a8ba8;
  display: none;
}

.finger-guide-overlay.visible {
  display: block;
}

.finger-guide-overlay .hand-svg {
  width: 200px;
  height: 140px;
}

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 14, 26, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
}

.modal.hidden { display: none; }

.modal-content {
  background: #0a1628;
  border: 2px solid #1e3a5f;
  border-radius: 14px;
  padding: 32px;
  width: min(620px, 85%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal-content h2 {
  margin-bottom: 24px;
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 0;
  cursor: pointer;
  font-size: 1rem;
  color: #c8d4e8;
}

.setting-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: #3b82f6;
}

.account-settings {
  width: 100%;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid rgba(30, 58, 95, 0.8);
}

.account-settings h3 {
  font-size: 0.95rem;
  color: #f0ede8;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.settings-profile-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-profile-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid rgba(30, 58, 95, 0.75);
  border-radius: 8px;
}

.settings-profile-info,
.settings-profile-empty {
  color: #c8d4e8;
  font-size: 0.9rem;
}

.btn-small {
  padding: 7px 12px;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 0.75rem;
  color: #8a9bb5;
  background: transparent;
  border: 1px solid #1e3a5f;
  border-radius: 6px;
  cursor: pointer;
}

.btn-small:hover {
  color: #f0ede8;
  border-color: #3b82f6;
}

.btn-small.danger:hover {
  color: #fca5a5;
  border-color: #ef4444;
}

/* --- Results Screen --- */
#screen-results {
  justify-content: center;
}

#screen-results h1 {
  font-size: clamp(2.2rem, 5vw, 4.2rem);
  color: #e8f0ff;
}

.results-stats {
  display: flex;
  gap: 24px;
  margin-top: 28px;
  flex-wrap: wrap;
  justify-content: center;
}

.stat-card {
  width: 150px;
  height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 22, 40, 0.7);
  border: 2px solid #1e3a5f;
  border-radius: 12px;
}

.stat-value {
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  letter-spacing: 0.05em;
  text-shadow: 0 0 15px rgba(74, 222, 128, 0.4);
}

.stat-label {
  font-size: 0.75rem;
  color: #7a8ba8;
  margin-top: 6px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.results-details {
  margin-top: 20px;
  font-size: 0.9rem;
  color: #7a8ba8;
  text-align: center;
  max-width: 400px;
}

.results-actions {
  display: flex;
  gap: 12px;
  margin-top: 32px;
  flex-wrap: wrap;
  justify-content: center;
}

.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -24px;
  left: var(--confetti-x, 50%);
  width: 9px;
  height: 16px;
  background: var(--confetti-color, #fbbf24);
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall var(--confetti-speed, 2.8s) ease-in forwards;
  animation-delay: var(--confetti-delay, 0s);
}

@keyframes confetti-fall {
  0% {
    opacity: 0;
    transform: translate3d(0, -20px, 0) rotate(0deg);
  }
  12% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--confetti-drift, 0px), 108vh, 0) rotate(680deg);
  }
}

/* --- Shake Animation (for stall mode) --- */
.shake {
  animation: screen-shake 0.3s ease;
}

@keyframes screen-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-3px); }
  80%      { transform: translateX(3px); }
}
