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

/* --- THEME SYSTEM STYLING --- */
:root {
  /* Default Theme: Serika Dark */
  --bg-color: #323437;
  --sub-bg-color: #2c2e31;
  --main-color: #e2b714;
  --text-color: #646669;
  --active-color: #d1d0c5;
  --error-color: #ca4754;
  --error-bg-color: rgba(202, 71, 84, 0.15);
  --key-bg-color: #2c2e31;
  --key-shadow: 0 3px 0px #1e1f21;
  --border-radius: 8px;
  --panel-blur: none;
  --body-gradient: none;
}

body.theme-carbon {
  --bg-color: #292a2d;
  --sub-bg-color: #1b1c1e;
  --main-color: #f6c177;
  --text-color: #6e6f7a;
  --active-color: #e0def4;
  --error-color: #eb6f92;
  --error-bg-color: rgba(235, 111, 146, 0.15);
  --key-bg-color: #212225;
  --key-shadow: 0 3px 0px #141517;
}

body.theme-nord {
  --bg-color: #2e3440;
  --sub-bg-color: #242933;
  --main-color: #88c0d0;
  --text-color: #4c566a;
  --active-color: #d8dee9;
  --error-color: #bf616a;
  --error-bg-color: rgba(191, 97, 106, 0.15);
  --key-bg-color: #242933;
  --key-shadow: 0 3px 0px #1b1f27;
}

body.theme-matrix {
  --bg-color: #090a09;
  --sub-bg-color: #0c0f0d;
  --main-color: #00ff41;
  --text-color: #005f11;
  --active-color: #00ff41;
  --error-color: #ff3333;
  --error-bg-color: rgba(255, 51, 51, 0.15);
  --key-bg-color: #0d120e;
  --key-shadow: 0 3px 0px #040605;
}

body.theme-cyberpunk {
  --bg-color: #1a0f2b;
  --sub-bg-color: #130a21;
  --main-color: #fcee0a;
  --text-color: #8c82ab;
  --active-color: #00f0ff;
  --error-color: #ff0055;
  --error-bg-color: rgba(255, 0, 85, 0.15);
  --key-bg-color: #1e1333;
  --key-shadow: 0 3px 0px #0c0617;
}

body.theme-retro {
  --bg-color: #f5f2eb;
  --sub-bg-color: #eae5da;
  --main-color: #8f7f6f;
  --text-color: #a89f91;
  --active-color: #524b41;
  --error-color: #b85042;
  --error-bg-color: rgba(184, 80, 66, 0.15);
  --key-bg-color: #eae5da;
  --key-shadow: 0 3px 0px #cfc8b8;
}

body.theme-aurora {
  --bg-color: transparent;
  --sub-bg-color: rgba(255, 255, 255, 0.06);
  --main-color: #c084fc;
  --text-color: rgba(255, 255, 255, 0.4);
  --active-color: #ffffff;
  --error-color: #f43f5e;
  --error-bg-color: rgba(244, 63, 94, 0.2);
  --key-bg-color: rgba(255, 255, 255, 0.08);
  --key-shadow: 0 3px 0px rgba(0, 0, 0, 0.15);
  --panel-blur: blur(16px);
  --body-gradient: radial-gradient(at 0% 0%, #1e1b4b 0px, transparent 50%),
                    radial-gradient(at 100% 0%, #311042 0px, transparent 50%),
                    radial-gradient(at 50% 100%, #030712 0px, #0f0728 100%);
}

/* --- GENERAL RESET & LAYOUT --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

body {
  background-color: var(--bg-color);
  background-image: var(--body-gradient);
  background-attachment: fixed;
  color: var(--text-color);
  font-family: 'Outfit', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 2rem;
  overflow-x: hidden;
}

/* Background animated circles for Aurora theme */
.bg-aurora-circles {
  display: none;
}
body.theme-aurora .bg-aurora-circles {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -10;
  overflow: hidden;
  pointer-events: none;
}
body.theme-aurora .circle {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.25;
  animation: floatCircle 20s infinite alternate ease-in-out;
}
body.theme-aurora .circle-1 {
  width: 500px;
  height: 500px;
  background: #a855f7;
  top: -100px;
  left: 10%;
}
body.theme-aurora .circle-2 {
  width: 600px;
  height: 600px;
  background: #3b82f6;
  bottom: -100px;
  right: 10%;
  animation-duration: 25s;
  animation-delay: -5s;
}

@keyframes floatCircle {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(80px) scale(1.15); }
}

.container {
  max-width: 1050px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  margin: auto;
  z-index: 1;
}

/* Glassmorphism panel styling */
.glass-panel {
  background-color: var(--sub-bg-color);
  backdrop-filter: var(--panel-blur);
  -webkit-backdrop-filter: var(--panel-blur);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
  padding: 1.5rem;
}

/* --- HEADER & CONTROLS --- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.logo-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  order: 1;
}

.logo-icon {
  font-size: 1.8rem;
  color: var(--main-color);
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

.logo {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--active-color);
  text-decoration: none;
}
.logo span {
  color: var(--main-color);
}

.config-bar {
  display: flex;
  gap: 0.75rem;
  background-color: var(--sub-bg-color);
  padding: 0.4rem;
  border-radius: var(--border-radius);
  flex-wrap: wrap;
  order: 3;
  width: 100%;
  justify-content: center;
  margin-top: 0.5rem;
}

.config-group {
  display: flex;
  align-items: center;
  border-right: 2px solid var(--bg-color);
  padding-right: 0.75rem;
}
.config-group:last-child {
  border-right: none;
  padding-right: 0;
}

.config-button {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.2s ease;
}

.config-button:hover {
  color: var(--active-color);
}

.config-button.active {
  color: var(--main-color);
  background-color: rgba(255, 255, 255, 0.03);
}

.top-right-group {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  order: 2;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  opacity: 0.7;
}

.icon-btn:hover {
  color: var(--active-color);
  opacity: 1;
}

/* Theme / Sound Dropdowns */
.setting-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--sub-bg-color);
  padding: 0.4rem 0.75rem;
  border-radius: var(--border-radius);
  font-size: 0.85rem;
}

.setting-selector select {
  background: transparent;
  border: none;
  color: var(--text-color);
  font-weight: 600;
  outline: none;
  cursor: pointer;
}
.setting-selector select option {
  background-color: var(--bg-color);
  color: var(--active-color);
}

/* --- TYPING AREA --- */
.typing-container {
  position: relative;
  min-height: 160px;
  margin: 2rem 0;
  outline: none;
}

.hidden-input {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0.01;
  width: 0;
  height: 0;
  border: none;
  outline: none;
  background: transparent;
  pointer-events: auto;
  z-index: 1;
}

.out-of-focus-warning {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  border-radius: var(--border-radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--active-color);
}

.typing-container.out-of-focus .out-of-focus-warning {
  opacity: 1;
  pointer-events: auto;
  cursor: pointer;
}

/* Real-time stats header above typing words */
.live-stats-bar {
  display: flex;
  gap: 2rem;
  margin-bottom: 1rem;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--main-color);
  min-height: 2.2rem;
  align-items: center;
}

.live-timer {
  font-variant-numeric: tabular-nums;
}

.live-wpm {
  font-size: 1.1rem;
  color: var(--text-color);
  font-variant-numeric: tabular-nums;
}

/* Words layout container */
.words-viewport {
  position: relative;
  height: 120px; /* 3 lines of 40px */
  overflow: hidden;
  font-size: 1.75rem;
  line-height: 40px;
}

.words-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0px 18px; /* row-gap column-gap */
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  transition: top 0.25s ease;
  scroll-behavior: smooth;
  user-select: none;
}

/* Word elements */
.word {
  position: relative;
  display: inline-block;
  color: var(--text-color);
  font-family: 'Mukta', 'Outfit', sans-serif;
  font-weight: 500;
  white-space: nowrap;
  letter-spacing: 0.5px;
  border-bottom: 2px solid transparent;
  padding: 0 1px;
}

.word.english {
  font-family: 'Outfit', sans-serif;
  font-size: 1.5rem;
}

.word.current {
  /* optional subtle underline for active word */
}

.word.error {
  border-bottom-color: var(--error-color);
}

/* Character elements */
.char {
  color: var(--text-color);
  position: relative;
  display: inline-block;
}

.char.correct {
  color: var(--active-color);
}

.char.incorrect {
  color: var(--error-color);
}

.char.extra {
  color: var(--error-color);
  opacity: 0.6;
}

/* SMOOTH BLINKING CARET */
.caret {
  position: absolute;
  width: 2px;
  height: 28px;
  background-color: var(--main-color);
  border-radius: 2px;
  top: 6px;
  left: 0;
  pointer-events: none;
  z-index: 5;
  transition: left 0.12s cubic-bezier(0.2, 0.8, 0.2, 1), top 0.12s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 0 8px var(--main-color);
  animation: blink 1s infinite;
}

.caret.no-animation {
  animation: none;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* Input layout helper text at the bottom */
.keyboard-layout-hint {
  width: 100%;
  margin: 0.5rem 0;
  font-size: 0.78rem;
  color: var(--text-color);
}

.hint-simple {
  display: block;
  text-align: center;
  padding: 0.5rem 1rem;
  background: var(--sub-bg-color);
  border-radius: var(--border-radius);
  opacity: 0.8;
}

.hint-simple kbd,
.keyboard-layout-hint kbd {
  background-color: var(--key-bg-color);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 2px 0 rgba(0,0,0,0.25);
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: monospace;
  color: var(--main-color);
}


/* --- RESTART SHORTCUT TOOLTIP --- */
.restart-bar {
  display: flex;
  justify-content: center;
  margin: 1rem 0;
}

.restart-button {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 0.75rem 1.5rem;
  border-radius: var(--border-radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.restart-button:hover {
  color: var(--active-color);
  background-color: var(--sub-bg-color);
}

.restart-icon {
  font-size: 1.4rem;
  transition: transform 0.3s ease;
}

.restart-button:hover .restart-icon {
  transform: rotate(-180deg);
}

.restart-tooltip {
  font-size: 0.75rem;
  color: var(--text-color);
  opacity: 0.6;
}

/* --- INTERACTIVE VIRTUAL KEYBOARD --- */
.keyboard-container {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1.2rem;
  background-color: var(--sub-bg-color);
  border-radius: 12px;
  width: 100%;
  max-width: 950px;
  margin: 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.keyboard-row {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  width: 100%;
}

.keyboard-key {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: var(--key-bg-color);
  border-radius: 6px;
  height: 48px;
  flex: 1 1 0%;
  color: var(--text-color);
  box-shadow: var(--key-shadow);
  cursor: default;
  position: relative;
  transition: all 0.08s ease;
  user-select: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.keyboard-key .key-primary {
  font-size: 0.95rem;
  color: var(--active-color);
  pointer-events: none;
}

.keyboard-key .key-secondary {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 0.7rem;
  opacity: 0.5;
  font-weight: 400;
  pointer-events: none;
}

/* Key size variations */
.key-backspace { flex-grow: 1.6; }
.key-tab { flex-grow: 1.3; }
.key-backslash { flex-grow: 1.3; }
.key-caps { flex-grow: 1.8; }
.key-enter { flex-grow: 1.8; }
.key-shift-left { flex-grow: 2.3; }
.key-shift-right { flex-grow: 2.3; }
.key-space { flex-grow: 8; }

/* Keyboard key states */
.keyboard-key.key-active {
  background-color: var(--main-color) !important;
  color: var(--bg-color) !important;
  transform: translateY(2px);
  box-shadow: none !important;
}

.keyboard-key.key-active .key-primary,
.keyboard-key.key-active .key-secondary {
  color: var(--bg-color) !important;
}

.keyboard-key.key-held {
  background-color: rgba(255, 255, 255, 0.08);
  border: 1.5px solid var(--main-color);
}

.keyboard-key.key-target {
  background-color: rgba(226, 183, 20, 0.12);
  border: 1.5px solid var(--main-color);
  box-shadow: 0 0 6px rgba(226, 183, 20, 0.2);
}

/* --- STATS PANEL --- */
.stats-panel {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 2rem;
  width: 100%;
}

.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  justify-content: center;
}

.stat-box {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-color);
  font-weight: 500;
  text-transform: uppercase;
}

.stat-val {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--main-color);
}

.stat-val-sub {
  font-size: 1.1rem;
  color: var(--active-color);
  font-weight: 500;
}

.stats-chart-wrapper {
  position: relative;
  min-height: 250px;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Hide elements when they shouldn't be seen */
.hidden {
  display: none !important;
}

/* --- FOOTER --- */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  width: 100%;
  max-width: 1050px;
  color: var(--text-color);
  border-top: 1px solid rgba(255, 255, 255, 0.03);
  padding-top: 1.5rem;
  margin-top: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

footer a {
  color: var(--text-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

footer a:hover {
  color: var(--active-color);
}

.footer-left {
  display: flex;
  gap: 1.5rem;
}

.key-badge {
  background-color: var(--sub-bg-color);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-family: monospace;
}

/* --- SHAKE ANIMATION FOR ERRORS --- */
.shake {
  animation: shakeEffect 0.2s ease-in-out;
}

@keyframes shakeEffect {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

/* --- RESPONSIVE DESIGN --- */
@media (max-width: 900px) {
  .stats-panel {
    grid-template-columns: 1fr;
  }
  
  .stats-grid {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-around;
  }
}

@media (max-width: 768px) {
  body {
    padding: 1rem;
  }
  
  header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .config-bar {
    justify-content: center;
  }

  .header-right {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
  }
  
  .keyboard-container {
    display: none; /* Hide visual keyboard on smaller mobile touchscreens */
  }

  .hands-guide-container {
    overflow-x: auto;
  }

  .hand-labels {
    display: none; /* Hide labels on small screens, keep SVG */
  }
}

/* --- HANDS GUIDES SYSTEM --- */
.hands-guide-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0.5rem 0 1rem 0;
  width: 100%;
}

.hands-label-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: center;
}

.hand-labels {
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 0.7rem;
  color: var(--text-color);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.6;
  height: 130px;
  justify-content: space-between;
  padding: 8px 0 10px 0;
}

.hand-labels-left {
  align-items: flex-end;
  text-align: right;
}

.hand-labels-right {
  align-items: flex-start;
  text-align: left;
}

.finger-label {
  transition: color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.finger-label.active {
  opacity: 1;
  color: var(--main-color);
  font-weight: 600;
}

.hands-svg {
  color: var(--text-color);
  opacity: 0.9;
  transition: opacity 0.2s ease;
  overflow: visible;
}

.hands-svg .finger {
  fill: var(--key-bg-color);
  stroke: var(--text-color);
  stroke-width: 1.5;
  transition: fill 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), stroke 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.15s ease;
}

.hands-svg .hand-palm {
  fill: var(--sub-bg-color);
  stroke: var(--text-color);
  stroke-width: 1.5;
  opacity: 0.7;
}

.hands-svg .finger.active {
  fill: var(--main-color);
  stroke: var(--main-color);
  filter: drop-shadow(0 0 8px var(--main-color));
}

/* --- CUSTOM TIME MODAL --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(2px);
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.custom-time-modal {
  background-color: var(--sub-bg-color);
  border-radius: 12px;
  padding: 2rem;
  width: 460px;
  max-width: 90vw;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  transform: translateY(20px);
  transition: transform 0.2s ease;
  font-family: 'Outfit', monospace, sans-serif;
  border: 1px solid rgba(255,255,255,0.05);
}
.modal-overlay.active .custom-time-modal {
  transform: translateY(0);
}
.modal-title {
  color: var(--text-color);
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  font-weight: 500;
  font-family: monospace, sans-serif;
}
.modal-status {
  color: var(--active-color);
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-family: monospace, sans-serif;
}
.modal-input {
  background: transparent;
  border: 2px solid var(--text-color);
  border-radius: 8px;
  width: 100%;
  padding: 0.75rem 1rem;
  color: var(--main-color);
  font-size: 1.25rem;
  outline: none;
  margin-bottom: 1.5rem;
  transition: border-color 0.2s;
  font-family: monospace, sans-serif;
}
.modal-input:focus {
  border-color: var(--active-color);
}
.modal-desc {
  color: var(--active-color);
  opacity: 0.8;
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
  font-family: monospace, sans-serif;
}
.modal-desc kbd {
  background: rgba(255,255,255,0.1);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: monospace;
}
.modal-btn {
  background: rgba(255,255,255,0.05);
  border: none;
  color: var(--active-color);
  border-radius: 8px;
  padding: 0.75rem;
  width: 100%;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.2s, color 0.2s;
  font-family: monospace, sans-serif;
}
.modal-btn:hover {
  background: var(--bg-color);
  color: var(--main-color);
}
