.tt-tool [hidden] {
  display: none !important;
}

.tt-tool {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 1000px;
  margin: 0 auto;
}

.tt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tt-toggle-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  border: 0.5px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
}

.tt-toggle-icon {
  padding-left: 10px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 16px;
}

.tt-toggle {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.2px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.tt-toggle:hover {
  color: #fff;
}

.tt-toggle.is-active {
  background: #6e00ff;
  color: #fff;
}

.tt-restart {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: 0.5px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
}

.tt-restart:hover {
  background: rgba(255, 255, 255, 0.14);
}

.tt-stage {
  position: relative;
  border-radius: 24px;
  border: 0.5px solid rgba(255, 255, 255, 0.12);
  background: rgba(8, 2, 18, 0.6);
  padding: 32px;
}

.tt-viewport {
  height: 144px;
  overflow: hidden;
}

.tt-track {
  display: flex;
  flex-wrap: wrap;
  gap: 0 14px;
  transition: transform 0.2s ease;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 26px;
  line-height: 48px;
  color: rgba(255, 255, 255, 0.38);
}

.tt-word {
  position: relative;
  white-space: nowrap;
}

.tt-word.is-wrong {
  text-decoration: underline;
  text-decoration-color: rgba(239, 68, 68, 0.8);
  text-underline-offset: 6px;
}

.tt-char {
  position: relative;
}

.tt-char.is-correct {
  color: #fff;
}

.tt-char.is-incorrect {
  color: #ef4444;
}

.tt-char.is-current::before {
  content: "";
  position: absolute;
  width: 2px;
  height: 30px;
  margin-top: 8px;
  margin-left: -2px;
  background: #6e00ff;
  animation: tt-caret 1s steps(1) infinite;
}

.tt-char.is-at-end::before {
  left: 100%;
  margin-left: 0;
}

/* Only the letter still waiting to be pressed carries the error colour. Once
   the caret sits on a letter that was already typed, recolouring it would
   contradict what the reader typed -- the caret bar alone stays red. */
.tt-char.is-current.is-error:not(.is-at-end) {
  color: #ef4444;
  animation: tt-error 1s steps(1) infinite;
}

.tt-char.is-current.is-error::before {
  background: #ef4444;
}

@keyframes tt-error {
  50% {
    opacity: 0.35;
  }
}

@keyframes tt-caret {
  50% {
    opacity: 0;
  }
}

.tt-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  background: transparent;
  cursor: text;
}

.tt-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 24px;
  background: rgba(8, 2, 18, 0.72);
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  pointer-events: none;
}

.tt-tool.is-focused .tt-overlay,
.tt-tool.is-finished .tt-overlay {
  display: none;
}

.tt-keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.tt-key-row {
  display: flex;
  gap: 8px;
}

.tt-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 0.5px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  text-transform: uppercase;
  transition: background 0.1s ease, color 0.1s ease, transform 0.1s ease;
}

.tt-key--space {
  width: 260px;
}

.tt-key.is-pressed {
  background: #6e00ff;
  border-color: #6e00ff;
  color: #fff;
  transform: translateY(2px);
}

.tt-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 20px;
  margin: 0;
  color: rgba(255, 255, 255, 0.5);
  font-size: 13px;
}

.tt-hint span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tt-hint kbd {
  padding: 2px 8px;
  border-radius: 6px;
  border: 0.5px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.8);
  font-family: inherit;
  font-size: 12px;
}

.tt-result {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 32px;
  border-radius: 24px;
  border: 0.5px solid rgba(110, 0, 255, 0.4);
  background: linear-gradient(180deg, rgba(110, 0, 255, 0.18) 0%, rgba(8, 2, 18, 0.6) 100%);
}

.tt-result-title {
  color: #fff;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.4px;
  margin: 0;
}

.tt-result-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
}

.tt-result-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tt-result-value {
  color: #fff;
  font-size: 28px;
  font-weight: 600;
  line-height: 36px;
}

.tt-result-label {
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
}

.tt-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

@media (max-width: 1200px) {
  .tt-result-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 992px) {
  .tt-keyboard {
    display: none;
  }
}

@media (max-width: 768px) {
  .tt-tool {
    gap: 16px;
  }

  .tt-toolbar {
    justify-content: center;
  }

  .tt-stage {
    padding: 20px;
  }

  .tt-viewport {
    height: 120px;
  }

  .tt-track {
    font-size: 20px;
    line-height: 40px;
    gap: 0 10px;
  }

  .tt-char.is-current::before {
    height: 24px;
    margin-top: 8px;
  }

  .tt-result {
    padding: 20px;
  }

  .tt-result-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .tt-toggle {
    padding: 8px 12px;
    font-size: 13px;
  }

  .tt-track {
    font-size: 18px;
  }
}
