/* CSS Reset and Base Styles */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  line-height: 1.5;
  /* Always reserve the scrollbar gutter, so pages that do and don't
     scroll are laid out at the same width */
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

/* Dark, unobtrusive scrollbars to match the rest of the UI */
* {
  scrollbar-width: thin;
  scrollbar-color: #3a3a3a transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: #3a3a3a;
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: #555555;
  background-clip: content-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 50%, #000000 100%);
  color: #ffffff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Accessibility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus styles */
*:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

*:focus:not(:focus-visible) {
  outline: none;
}

*:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Header */
.header {
  background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
  border-bottom: 2px solid #333333;
  padding: 1rem 0.5rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: all 0.15s ease;
}

.header--hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

.header__title {
  margin: 0 0 1rem 0;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.3);
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Controls */
.controls {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: #000000;
  border-radius: 0.75rem;
  border: 2px solid #333333;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  color: white;
  position: relative;
  overflow: hidden;
  transition: all 0.4s ease, opacity 0.4s ease, transform 0.4s ease;
  opacity: 1;
}

.controls__container {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  width: 100%;
  transition: opacity 0.15s ease;
}

/* Waiting for the saved settings. Hidden rather than removed, so the header
   keeps its size and nothing jumps when the controls appear. */
.controls__container--loading {
  visibility: hidden;
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .controls__container {
    transition: none;
  }
}

/* Controls are now always visible - no hidden state */

.controls__title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #ffffff;
  margin: 0;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  letter-spacing: 1px;
}

.controls__row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.controls__fieldset {
  border: 2px solid #333333;
  border-radius: 0.5rem;
  padding: 0.75rem;
  margin: 0;
  background: #111111;
  min-width: 180px;
  position: relative;
  transition: all 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  opacity: 1;
  transform: translateY(0);
}

/* Hidden fieldsets keep their slot so switching modes never shifts the UI */
.controls__fieldset--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Shared options box: fixed footprint so swapping contents moves nothing.
   It must stay a block - a flex fieldset turns its legend into a flex item. */
.controls__fieldset--options {
  width: 340px;
  min-width: 340px;
}

/* Extras sits next to the options box and keeps the same inner height */
.controls__fieldset--extras > .controls__group {
  min-height: 2.375rem;
  align-items: center;
  justify-content: center;
  margin-top: 0.25rem;
  flex-wrap: nowrap;
}

/* Every swappable block is the same height, so the box never resizes */
.controls__fieldset--options > .controls__group,
.controls__fieldset--options > .controls__hint {
  min-height: 2.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.25rem;
  flex-wrap: nowrap;
}

/* Must outrank the display:flex above, hence the same child selector */
.controls__fieldset--options > .controls__group--hidden,
.controls__group--hidden {
  display: none;
}

.controls__hint {
  margin: 0;
  font-size: 0.75rem;
  color: #cccccc;
  text-align: center;
  white-space: nowrap;
}

.controls__legend {
  font-weight: 700;
  color: #ffffff;
  padding: 0 0.5rem;
  font-size: 0.75rem;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  background: #000000;
  border-radius: 4px;
}

.controls__group {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.controls__label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s ease,
    opacity 0.3s ease;
  background: #1a1a1a;
  border: 2px solid #333333;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  user-select: none;
}

.controls__label::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    45deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transform: translateX(-100%);
  pointer-events: none;
}

.controls__label:hover {
  background: #222222;
  border-color: #555555;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), 0 0 20px rgba(255, 255, 255, 0.1);
}

.controls__label:hover::before {
  transform: translateX(100%);
  transition: transform 0.6s ease;
}

.controls__label:active {
  transform: translateY(0) scale(0.98);
  transition: all 0.1s ease;
}

.controls__radio,
.controls__checkbox {
  margin: 0;
  accent-color: #ffffff;
  width: 18px;
  height: 18px;
}

/* Highlight the selection without changing text metrics, which would
   shift every label next to it */
.controls__radio:checked + .controls__text,
.controls__checkbox:checked + .controls__text {
  color: #ffffff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.controls__label:has(.controls__radio:checked),
.controls__label:has(.controls__checkbox:checked) {
  background: #16233b;
  border-color: #3b82f6;
}

.controls__text {
  font-size: 0.75rem;
  color: #cccccc;
  font-weight: 500;
  transition: all 0.3s ease, color 0.3s ease, font-weight 0.3s ease;
  letter-spacing: 0.2px;
}

.controls__buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  margin-top: 0.5rem;
}

/* Buttons */
.button {
  padding: 0.5rem 1rem;
  border: 2px solid #333333;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  background: #1a1a1a;
  color: white;
  text-align: center;
  min-width: 80px;
  position: relative;
  overflow: hidden;
  user-select: none;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.button::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    45deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transform: translateX(-100%);
  pointer-events: none;
}

.button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}

.button:disabled::before {
  display: none;
}

.button--primary {
  background: #000000;
  border-color: #ffffff;
  color: #ffffff;
}

.button--primary:hover:not(:disabled) {
  background: #111111;
  border-color: #ffffff;
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), 0 0 30px rgba(255, 255, 255, 0.2);
}

.button--primary:hover::before {
  transform: translateX(100%);
  transition: transform 0.6s ease;
}

.button--primary:active:not(:disabled) {
  transform: translateY(-1px) scale(0.98);
  transition: all 0.1s ease;
}

.button--secondary {
  background: #1a1a1a;
  border-color: #555555;
  color: #cccccc;
}

.button--secondary:hover:not(:disabled) {
  background: #222222;
  border-color: #777777;
  color: #ffffff;
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), 0 0 20px rgba(255, 255, 255, 0.1);
}

.button--secondary:hover::before {
  transform: translateX(100%);
  transition: transform 0.6s ease;
}

.button--secondary:active:not(:disabled) {
  transform: translateY(-1px) scale(0.98);
  transition: all 0.1s ease;
}

/* Start Screen */
.start-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.start-screen__content {
  max-width: 600px;
  text-align: center;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 2rem;
  padding: 3rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.start-screen__title {
  font-size: 3rem;
  font-weight: 700;
  margin: 0 0 1rem 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.start-screen__subtitle {
  font-size: 1.25rem;
  margin: 0 0 3rem 0;
  opacity: 0.9;
}

.start-screen__settings {
  display: grid;
  gap: 2rem;
  margin-bottom: 3rem;
}

.setting-group h3 {
  font-size: 1.25rem;
  margin: 0 0 1rem 0;
  font-weight: 600;
}

.radio-group {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2rem;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.radio-option:hover {
  background: rgba(255, 255, 255, 0.2);
}

.radio-option input[type="radio"] {
  display: none;
}

.radio-option input[type="radio"]:checked + span {
  font-weight: 600;
}

.radio-option:has(input:checked) {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
}

.start-screen__button {
  background: #3b82f6;
  color: white;
  border: none;
  padding: 1rem 3rem;
  font-size: 1.25rem;
  font-weight: 600;
  border-radius: 2rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 10px 20px rgba(59, 130, 246, 0.3);
}

.start-screen__button:hover {
  background: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 15px 30px rgba(59, 130, 246, 0.4);
}

/* End Screen */
.end-screen {
  display: none;
  width: 100%;
  margin: 0 auto;
  background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
  border: 2px solid #3b82f6;
  border-radius: 0.75rem;
  color: white;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

/* Results left, high scores right - both start at the top */
.end-screen__container {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 1.25rem;
  align-items: start;
}

.end-screen--visible {
  display: block;
  animation: end-screen-in 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes end-screen-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.end-screen__content {
  padding: 1.5rem 2rem;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
}

.end-screen__header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.end-screen__title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.25rem 0;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.3);
  letter-spacing: 0.5px;
}

.end-screen__subtitle {
  font-size: 0.75rem;
  color: #cccccc;
  margin: 0;
  font-weight: 400;
}

.end-screen__results {
  margin-bottom: 0;
}

.end-screen__results-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 0;
}

.end-screen__result-card {
  background: linear-gradient(135deg, #111111 0%, #1a1a1a 100%);
  border: 1px solid #333333;
  border-radius: 0.5rem;
  padding: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.end-screen__result-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    45deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transform: translateX(-100%);
  pointer-events: none;
  animation: card-shine 3s ease-in-out infinite;
}

.end-screen__result-card:hover {
  border-color: #555555;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), 0 0 20px rgba(255, 255, 255, 0.1);
}

.end-screen__result-card:hover::before {
  transform: translateX(100%);
  transition: transform 0.6s ease;
}

.end-screen__result-card--primary {
  border-color: #3b82f6;
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
}

.end-screen__result-card--primary:hover {
  border-color: #60a5fa;
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4),
    0 0 30px rgba(59, 130, 246, 0.2);
}

.end-screen__result-icon {
  font-size: 1rem;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 0.25rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: icon-pulse 2s ease-in-out infinite;
}

.end-screen__result-content {
  flex: 1;
}

.end-screen__result-value {
  font-size: 1.125rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 0.125rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  animation: value-glow 2s ease-in-out infinite alternate;
}

.end-screen__result-label {
  font-size: 0.625rem;
  color: #cccccc;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.25px;
}

.end-screen__leaderboard {
  background: linear-gradient(135deg, #111111 0%, #1a1a1a 100%);
  border: 1px solid #333333;
  border-radius: 0.5rem;
  padding: 0.75rem;
  margin-bottom: 0;
}

.end-screen__leaderboard-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #ffffff;
  margin: 0 0 0.5rem 0;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.end-screen__leaderboard-content {
  max-height: 260px;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.end-screen__leaderboard-empty {
  text-align: center;
  color: #888888;
  font-style: italic;
  margin: 1rem 0;
}

.end-screen__leaderboard-table {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.end-screen__leaderboard-row {
  display: grid;
  grid-template-columns: 1.5rem 1fr auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
}

.end-screen__leaderboard-row:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.end-screen__leaderboard-rank {
  font-weight: 700;
  color: #3b82f6;
  font-size: 0.9375rem;
  text-align: center;
}

.end-screen__leaderboard-wpm {
  font-weight: 600;
  color: #10b981;
  font-size: 0.9375rem;
}

.end-screen__leaderboard-accuracy {
  color: #cccccc;
  font-size: 0.875rem;
}

.end-screen__leaderboard-date {
  color: #888888;
  font-size: 0.75rem;
}

.end-screen__actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.end-screen__stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2rem;
  margin-bottom: 3rem;
}

.stat-card {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 1rem;
  padding: 2rem;
  text-align: center;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.stat-value {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.stat-label {
  font-size: 1.125rem;
  opacity: 0.8;
  font-weight: 500;
}

.end-screen__rounds {
  margin-bottom: 3rem;
}

.end-screen__rounds h3 {
  font-size: 1.5rem;
  margin: 0 0 1.5rem 0;
  text-align: center;
}

.rounds-list {
  display: grid;
  gap: 1rem;
}

.round-entry {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 1rem;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 1rem;
  align-items: center;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.round-entry__info {
  display: flex;
  flex-direction: column;
}

.round-entry__round {
  font-weight: 600;
  font-size: 1.125rem;
}

.round-entry__time {
  opacity: 0.8;
  font-size: 0.875rem;
}

.round-entry__wpm {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: right;
}

.round-entry__accuracy {
  font-size: 1.125rem;
  text-align: right;
  opacity: 0.8;
}

.end-screen__chart {
  margin-bottom: 3rem;
}

.end-screen__chart h3 {
  font-size: 1.5rem;
  margin: 0 0 1.5rem 0;
  text-align: center;
}

.chart-container {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 1rem;
  padding: 2rem;
  border: 2px solid rgba(255, 255, 255, 0.2);
  margin: 0;
}

.end-screen__actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.25rem;
}

.end-screen__button {
  padding: 1rem 2rem;
  font-size: 1.125rem;
  font-weight: 600;
  border-radius: 2rem;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.end-screen__button--primary {
  background: #3b82f6;
  color: white;
  box-shadow: 0 10px 20px rgba(59, 130, 246, 0.3);
}

.end-screen__button--primary:hover {
  background: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 15px 30px rgba(59, 130, 246, 0.4);
}

.end-screen__button--secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border-color: rgba(255, 255, 255, 0.3);
}

.end-screen__button--secondary:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

/* Main Layout */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  width: 100%;
  position: relative;
  transition: all 0.15s ease;
}

.main--focused {
  grid-template-columns: 1fr;
  padding: 1rem;
}

.main--focused .bottom-bar {
  display: none;
}

/* Game Area */
.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  /* Swapping the panel for the end screen animates this height, so the
     stats bar below glides instead of jumping */
  transition: height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.game-area--animating {
  overflow: hidden;
}

/* Text Panel */
.text-panel {
  background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
  border: 3px solid #3b82f6;
  border-radius: 1.5rem;
  padding: 2rem;
  font-size: 1.5rem;
  line-height: 1.75;
  /* Exactly three rows of text, so the panel never jumps and the reader
     always has the same window to look at (rows + padding + border) */
  height: calc(3 * 1.75em + 4rem + 6px);
  min-height: calc(3 * 1.75em + 4rem + 6px);
  max-height: calc(3 * 1.75em + 4rem + 6px);
  overflow: hidden;
  overscroll-behavior: contain;
  cursor: text;
  position: relative;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  text-align: left;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  color: white;
  display: flex;
  /* Rows fill from the top; the content itself slides up as you type */
  align-items: flex-start;
  justify-content: flex-start;
}

.text-panel--focused {
  transform: scale(1.02);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
  border-color: #60a5fa;
}

.text-panel:focus {
  border-color: #3b82f6;
}

.text-panel__content {
  position: relative;
  transition: opacity 0.3s ease;
  width: 100%;
  /* The window onto the text: exactly three rows, anything else is clipped */
  height: calc(3 * 1.75em);
  overflow: hidden;
  /* Real spaces + wrapping, so a long sample never runs off the panel */
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
}

.text-panel__content--loading {
  opacity: 0.5;
}

/* The rows themselves, slid up a whole row at a time - never mid-line */
.text-panel__lines {
  transition: transform 0.25s ease;
}

/* Character spans */
.text__char {
  display: inline;
  position: relative;
  transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  color: #ffffff;
  white-space: pre-wrap;
}

.text__char--ok {
  color: #10b981;
  background: linear-gradient(
    135deg,
    rgba(16, 185, 129, 0.2) 0%,
    rgba(16, 185, 129, 0.1) 100%
  );
  border-radius: 2px;
  transition: all 0.05s ease;
  animation: char-success 0.2s ease-out;
}

.text__char--err {
  color: #ef4444;
  background: linear-gradient(
    135deg,
    rgba(239, 68, 68, 0.2) 0%,
    rgba(239, 68, 68, 0.1) 100%
  );
  border-radius: 2px;
  text-decoration: underline;
  text-decoration-color: #ef4444;
  text-decoration-thickness: 2px;
  transition: all 0.05s ease;
  animation: char-error 0.2s ease-out;
}

@keyframes char-success {
  0% {
    transform: scale(1);
    background: rgba(16, 185, 129, 0.4);
  }
  50% {
    transform: scale(1.05);
    background: rgba(16, 185, 129, 0.3);
  }
  100% {
    transform: scale(1);
    background: linear-gradient(
      135deg,
      rgba(16, 185, 129, 0.2) 0%,
      rgba(16, 185, 129, 0.1) 100%
    );
  }
}

@keyframes char-error {
  0% {
    transform: scale(1);
    background: rgba(239, 68, 68, 0.4);
  }
  50% {
    transform: scale(1.05);
    background: rgba(239, 68, 68, 0.3);
  }
  100% {
    transform: scale(1);
    background: linear-gradient(
      135deg,
      rgba(239, 68, 68, 0.2) 0%,
      rgba(239, 68, 68, 0.1) 100%
    );
  }
}

.text__char--caret {
  position: relative;
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.text__char--caret::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, #3b82f6 0%, #60a5fa 100%);
  border-radius: 1px;
  animation: caret-blink 1.2s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

@keyframes caret-blink {
  0%,
  45% {
    opacity: 1;
    transform: scaleY(1);
  }
  50%,
  95% {
    opacity: 0.3;
    transform: scaleY(0.8);
  }
  100% {
    opacity: 1;
    transform: scaleY(1);
  }
}

/* Hidden input for capturing keyboard input */
.hidden-input {
  position: absolute;
  left: -9999px;
  opacity: 0;
  pointer-events: none;
}

/* bottom-bar */
.bottom-bar {
  display: flex;
  flex-direction: column;
  gap: 1rem;

  margin-top: 4rem;
  background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
  border: 2px solid #333333;
  border-radius: 0.75rem;
  padding: 1rem;
  width: 100%;
  max-width: 800px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  color: white;
  position: relative;
  overflow: hidden;
  min-width: 250px;
  transition: all 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
  opacity: 1;
  transform: translateY(0);
}

/* Bottom bar is now always visible - no hidden state */

.bottom-bar--playing {
  border-color: #3b82f6;
}

/* Docked in the top-right corner of the stats panel. Deliberately quiet -
   it is an escape hatch, not something to invite clicks. */
.bottom-bar__stop-btn {
  z-index: 2;
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: #1a1a1a;
  border: 1px solid #3a3a3a;
  border-radius: 0.5rem;
  color: #9ca3af;
  padding: 0.25rem 0.6rem;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.bottom-bar__stop-btn:hover {
  background: #262626;
  border-color: #5a5a5a;
  color: #e5e7eb;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.bottom-bar__stop-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Metrics */
.metrics {
  background: linear-gradient(135deg, #111111 0%, #1a1a1a 100%);
  border: 2px solid #333333;
  border-radius: 0.5rem;
  padding: 0.5rem;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  position: relative;
  transition: all 0.3s ease;
  flex: 1;
  min-width: 150px;
}

.metrics__title {
  margin: 0 0 0.5rem 0;
  /* Keep the centred title clear of the stop button in the corner */
  padding: 0 5rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  text-align: center;
}

/* Fixed columns so changing numbers never resize the stats box */
.metrics__grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin: 20px 5px 5px 5px;
}

.metrics__item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0.375rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
  gap: 0.3rem;
}

.metrics__item:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.metrics__label {
  font-weight: 500;
  color: #cccccc;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.metrics__value {
  font-weight: 700;
  color: #ffffff;
  font-size: 1rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: color 0.2s ease, transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-block;
  /* Equal-width digits + a reserved slot keep the box from breathing */
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  min-width: 4ch;
  text-align: right;
  white-space: nowrap;
}

.metrics__value--changed {
  color: #60a5fa;
  transform: scale(1.05);
}

.metrics__progress {
  margin-bottom: 1rem;
  padding: 0.5rem 0;
}

.metrics__progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  margin-bottom: 0.5rem;
}

.metrics__progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6 0%, #60a5fa 100%);
  border-radius: 4px;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.metrics__progress-fill::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  animation: progress-shimmer 2s infinite;
}

@keyframes progress-shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@keyframes card-shine {
  0% {
    transform: translateX(-100%);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: translateX(100%);
    opacity: 0;
  }
}

@keyframes value-glow {
  0% {
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 0 10px rgba(255, 255, 255, 0.1);
  }
  100% {
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 0 20px rgba(255, 255, 255, 0.3);
  }
}

@keyframes icon-pulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.1);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.1);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.1);
  }
}

.metrics__progress-text {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #60a5fa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Leaderboard */
.leaderboard {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.leaderboard__title {
  margin: 0 0 1rem 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: #1e293b;
}

.leaderboard__content {
  max-height: 300px;
  overflow-y: auto;
}

.leaderboard__empty {
  text-align: center;
  color: #6b7280;
  font-style: italic;
  margin: 1rem 0;
}

.leaderboard__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.leaderboard__table th,
.leaderboard__table td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.leaderboard__table th {
  font-weight: 600;
  color: #374151;
  background: #f8fafc;
}

.leaderboard__table tr:hover {
  background: #f8fafc;
}

.leaderboard__rank {
  font-weight: 600;
  color: #3b82f6;
  width: 3rem;
}

.leaderboard__wpm {
  font-weight: 600;
  color: #059669;
  text-align: right;
}

.leaderboard__date {
  color: #6b7280;
  font-size: 0.75rem;
}

/* Footer */
.footer {
  background: white;
  border-top: 1px solid #e2e8f0;
  padding: 1rem;
  text-align: center;
  transition: all 0.15s ease;
}

.footer--hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

.footer__content {
  max-width: 1200px;
  margin: 0 auto;
}

.footer__text {
  margin: 0;
  color: #6b7280;
  font-size: 0.875rem;
}

/* Keyboard key styling */
kbd {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-family: monospace;
  color: #475569;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
}

.modal__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
}

.modal__content {
  position: relative;
  background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
  border: 2px solid #333333;
  border-radius: 1.5rem;
  padding: 2.5rem;
  max-width: 600px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  color: white;
}

.modal__content--finish {
  max-width: 800px;
  padding: 2rem;
}

.modal__title {
  margin: 0 0 1rem 0;
  font-size: 1.5rem;
  font-weight: 600;
  color: #ffffff;
}

.modal__text {
  margin: 0 0 1.5rem 0;
  color: #cccccc;
}

.modal__buttons {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
}

/* Finish Modal Specific Styles */
.finish-modal__header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.finish-modal__title {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  color: #ffffff;
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.3);
  letter-spacing: 1px;
}

.finish-modal__subtitle {
  font-size: 0.95rem;
  color: #cccccc;
  margin: 0;
  font-weight: 400;
}

.finish-modal__results {
  margin-bottom: 1.5rem;
}

.finish-modal__results-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.finish-modal__result-card {
  background: linear-gradient(135deg, #111111 0%, #1a1a1a 100%);
  border: 2px solid #333333;
  border-radius: 1rem;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.finish-modal__result-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    45deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transform: translateX(-100%);
  pointer-events: none;
  animation: card-shine 3s ease-in-out infinite;
}

.finish-modal__result-card:hover {
  border-color: #555555;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), 0 0 20px rgba(255, 255, 255, 0.1);
}

.finish-modal__result-card:hover::before {
  transform: translateX(100%);
  transition: transform 0.6s ease;
}

.finish-modal__result-card--primary {
  border-color: #3b82f6;
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
}

.finish-modal__result-card--primary:hover {
  border-color: #60a5fa;
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.4),
    0 0 30px rgba(59, 130, 246, 0.2);
}

.finish-modal__result-icon {
  font-size: 1.5rem;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  animation: icon-pulse 2s ease-in-out infinite;
}

.finish-modal__result-content {
  flex: 1;
}

.finish-modal__result-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 0.25rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  animation: value-glow 2s ease-in-out infinite alternate;
}

.finish-modal__result-label {
  font-size: 0.875rem;
  color: #cccccc;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.finish-modal__container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.finish-modal__leaderboard {
  background: linear-gradient(135deg, #111111 0%, #1a1a1a 100%);
  border: 2px solid #333333;
  border-radius: 1rem;
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.finish-modal__leaderboard-title {
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
  margin: 0 0 1rem 0;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.finish-modal__leaderboard-content {
  max-height: 200px;
  overflow-y: auto;
}

.finish-modal__leaderboard-empty {
  text-align: center;
  color: #888888;
  font-style: italic;
  margin: 1rem 0;
}

.finish-modal__leaderboard-table {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.finish-modal__leaderboard-row {
  display: grid;
  grid-template-columns: 2rem 1fr auto auto;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.2s ease;
}

.finish-modal__leaderboard-row:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.finish-modal__leaderboard-rank {
  font-weight: 700;
  color: #3b82f6;
  font-size: 1.125rem;
  text-align: center;
}

.finish-modal__leaderboard-wpm {
  font-weight: 600;
  color: #059669;
  font-size: 1rem;
}

.finish-modal__leaderboard-accuracy {
  color: #cccccc;
  font-size: 0.875rem;
}

.finish-modal__leaderboard-date {
  color: #888888;
  font-size: 0.75rem;
}

.finish-modal__actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.button--large {
  padding: 1.25rem 2.5rem;
  font-size: 1rem;
  min-width: 150px;
}

/* Floating Metrics */
.floating-metrics {
  position: fixed;
  top: 2rem;
  right: 2rem;
  background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
  border: 2px solid #333333;
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
  z-index: 100;
  opacity: 0;
  transform: translateY(-20px);
  transition: all 0.15s ease;
  pointer-events: none;
  min-width: 200px;
}

.floating-metrics--visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.floating-metrics__header {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.floating-metrics__pause-btn {
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
  border: 2px solid #3b82f6;
  border-radius: 0.5rem;
  padding: 0.5rem;
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}

.floating-metrics__pause-btn svg {
  width: 16px;
  height: 16px;
}

.floating-metrics__pause-btn:hover {
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%);
  border-color: #60a5fa;
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(59, 130, 246, 0.4);
}

.floating-metrics__pause-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.floating-metrics__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.floating-metrics__item {
  text-align: center;
  color: white;
}

.floating-metrics__label {
  display: block;
  font-size: 0.75rem;
  color: #cccccc;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.floating-metrics__value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: #ffffff;
}

/* Responsive Design */
@media (max-width: 768px) {
  /* Stack the option boxes instead of overflowing the row */
  .controls__fieldset,
  .controls__fieldset--options {
    width: 100%;
    min-width: 0;
  }

  .controls__fieldset--options > .controls__group,
  .controls__fieldset--extras > .controls__group {
    flex-wrap: wrap;
  }

  .header {
    padding: 1rem 0.75rem;
  }

  .header__title {
    font-size: 1.5rem;
  }

  .controls {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .controls__group {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .controls__buttons {
    justify-content: center;
  }

  .main {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 1.5rem;
  }

  .text-panel {
    padding: 2rem;
    font-size: 1.75rem;
    margin: 0 1rem;
  }

  .floating-metrics {
    top: 1rem;
    right: 1rem;
    padding: 1rem;
    min-width: 150px;
  }

  .floating-metrics__value {
    font-size: 1.25rem;
  }

  .bottom-bar {
    order: -1;
  }

  .metrics__grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .metrics__item {
    flex-direction: column;
    gap: 0.25rem;
    text-align: center;
  }

  .metrics__label {
    font-size: 0.75rem;
  }

  .metrics__value {
    font-size: 1rem;
  }

  .modal__content {
    padding: 1.5rem;
    margin: 1rem;
  }

  .modal__buttons {
    flex-direction: column;
  }

  .finish-modal__results-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .finish-modal__result-card {
    padding: 1rem;
  }

  .finish-modal__result-value {
    font-size: 1.5rem;
  }

  .finish-modal__result-icon {
    font-size: 1.5rem;
    width: 2.5rem;
    height: 2.5rem;
  }

  .finish-modal__leaderboard-row {
    grid-template-columns: 1.5rem 1fr auto;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
  }

  .finish-modal__leaderboard-date {
    display: none;
  }

  .finish-modal__actions {
    flex-direction: column;
  }

  .button--large {
    width: 100%;
  }

  .end-screen__results-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .end-screen__result-card {
    padding: 1rem;
  }

  .end-screen__result-value {
    font-size: 1.5rem;
  }

  .end-screen__result-icon {
    font-size: 1.5rem;
    width: 2.5rem;
    height: 2.5rem;
  }

  .end-screen__leaderboard-row {
    grid-template-columns: 1.5rem 1fr auto;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
  }

  .end-screen__leaderboard-date {
    display: none;
  }

  .end-screen__actions {
    flex-direction: column;
  }

  .bottom-bar {
    min-width: 0;
    padding: 0.75rem;
  }

  .metrics__progress-bar {
    height: 6px;
  }

  .metrics__item {
    padding: 0.375rem 0.5rem;
  }

  .metrics__value {
    font-size: 0.875rem;
  }

  .metrics__label {
    font-size: 0.625rem;
  }

  /* Start Screen Mobile */
  .start-screen__title {
    font-size: 2rem;
  }

  .start-screen__content {
    padding: 2rem;
    margin: 1rem;
  }

  .radio-group {
    flex-direction: column;
    align-items: center;
  }

  .radio-option {
    width: 100%;
    max-width: 200px;
  }

  /* End Screen Mobile */
  .end-screen__stats {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .end-screen__content {
    padding: 1rem;
  }

  .end-screen__container {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .round-entry {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    text-align: center;
  }

  .round-entry__wpm,
  .round-entry__accuracy {
    text-align: center;
  }

  .end-screen__actions {
    flex-direction: column;
  }

  .chart-container {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .controls__buttons {
    flex-direction: column;
    width: 100%;
  }

  .button {
    width: 100%;
  }

  .metrics__grid {
    grid-template-columns: 1fr;
  }

  .leaderboard__table {
    font-size: 0.75rem;
  }

  .leaderboard__table th,
  .leaderboard__table td {
    padding: 0.25rem;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .text__char--ok {
    background-color: #000;
    color: #fff;
    border: 1px solid #fff;
  }

  .text__char--err {
    background-color: #fff;
    color: #000;
    border: 2px solid #000;
  }

  .text__char--caret::after {
    background-color: #000;
    width: 3px;
  }
}

/* Print styles */
@media print {
  .controls,
  .bottom-bar,
  .footer,
  .modal {
    display: none;
  }

  .main {
    grid-template-columns: 1fr;
    padding: 0;
  }

  .text-panel {
    border: 1px solid #000;
    box-shadow: none;
  }
}

/* ==========================================================================
   Falling Words mode
   ========================================================================== */

.text-panel--falling {
  height: min(50vh, 400px);
  min-height: min(50vh, 400px);
  max-height: min(50vh, 400px);
  padding: 0;
  overflow: hidden;
  cursor: default;
  align-items: stretch;
}

.text-panel--falling .text-panel__content {
  height: 100%;
}

.falling {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 1.25rem;
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.falling--hit {
  box-shadow: inset 0 0 0 3px rgba(239, 68, 68, 0.8);
}

.falling__words {
  position: absolute;
  inset: 0;
  bottom: 56px;
}

.falling__word {
  position: absolute;
  top: 0;
  white-space: nowrap;
  font-size: 1.25rem;
  font-weight: 600;
  color: #e5e7eb;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.5rem;
  padding: 0.15rem 0.6rem;
  will-change: transform;
}

.falling__word--active {
  color: #ffffff;
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.18);
}

.falling__word-typed {
  color: #22c55e;
}

/* Centred prompt shown before the round starts */
.falling__start {
  position: absolute;
  inset: 0 0 56px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 2;
  transition:
    opacity 0.2s ease,
    visibility 0.2s ease;
}

.falling__start--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.falling__start-btn {
  min-width: 12rem;
}

.falling__start-hint,
.falling__start-rules {
  margin: 0;
  color: #cccccc;
  font-size: 0.875rem;
}

.falling__start-rules {
  color: #8b8b8b;
  font-size: 0.75rem;
}

.falling__start-hint kbd {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border: 1px solid #4b5563;
  border-bottom-width: 2px;
  border-radius: 0.3rem;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.8125rem;
}

@media (prefers-reduced-motion: reduce) {
  .falling__start {
    transition: none;
  }
}

.falling__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: rgba(0, 0, 0, 0.6);
  border-top: 2px solid #333333;
}

.falling__lives {
  font-size: 1rem;
  letter-spacing: 2px;
  flex-shrink: 0;
}

.falling__buffer {
  flex: 1;
  text-align: left;
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.15s ease;
}

.falling__buffer--miss {
  color: #ef4444;
}

.falling__buffer-hint {
  color: #6b7280;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: normal;
}

/* ==========================================================================
   Finish celebration
   ========================================================================== */

.confetti {
  position: fixed;
  inset: 0;
  z-index: 1200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.confetti--visible {
  opacity: 1;
}
