* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
}

body {
  background: #f6efe7;
  color: #5c4b3b;
  min-height: 100vh;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 18px 20px 24px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 15px;
  margin-bottom: 8px;
}

.top-bar__side {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stats-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}

.stats-label {
  font-size: 0.65rem;
  font-weight: 800;
  color: #8c6a46;
  letter-spacing: 0.5px;
}

.stats-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: #b7c44a;
}

.header-btn {
  background: #f2d7bf;
  border: 1px solid #dcb594;
  padding: 6px 12px;
  border-radius: 10px;
  color: #a0774f;
  font-weight: 800;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.header-btn:hover {
  background: #e9c4a4;
}

.header-btn:active {
  transform: scale(0.95);
}

.mistakes {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  letter-spacing: 1px;
  color: #8c6a46;
}

.mistakes__dots {
  display: flex;
  gap: 8px;
}

.mistakes__dots span {
  width: 18px;
  height: 18px;
  border: 2px solid #c7a177;
  border-radius: 50%;
  transition: background-color 0.3s ease;
}

.mistakes__dots span.mistake--active {
  background-color: #c84545;
  border-color: #c84545;
}

.sub-bar {
  display: flex;
  justify-content: space-between;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 1px;
  color: #b1906b;
  padding: 10px 6px 16px;
  border-bottom: 2px dashed #e2d1bd;
}

.app__main {
  padding: 26px 0 10px;
  position: relative;
}

.modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(246, 239, 231, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 5;
}

.modal--show {
  opacity: 1;
  pointer-events: all;
}

.modal__content {
  background: #fffaf4;
  border: 2px solid #e3c4a5;
  border-radius: 18px;
  padding: 24px 28px;
  text-align: center;
  max-width: 320px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
}

.modal__icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.modal__title {
  font-size: 1.2rem;
  color: #8d5e3c;
  margin-bottom: 8px;
}

.modal__phrase {
  font-size: 0.9rem;
  font-weight: 700;
  color: #5c4b3b;
  margin-bottom: 6px;
}

.modal__quote {
  font-size: 0.85rem;
  color: #9b7b5c;
  margin-bottom: 16px;
}

.modal__btn {
  border: none;
  background: #b7c44a;
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.modal__btn:hover {
  background: #a0b03a;
}

.phrase {
  display: grid;
  gap: 22px;
  text-align: center;
}

.phrase__row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 15px 0; /* Use row-gap for vertical spacing, horizontal handled by margin-inline */
  font-size: 1.5rem;
  letter-spacing: 2px;
  padding: 10px;
}

.word {
  display: flex;
  gap: 6px; /* Tight spacing between letters within a word */
  align-items: center;
  margin-inline: clamp(14px, 4vw, 32px); /* Horizontal spacing only */
}

.punctuation {
  font-size: 1.4rem;
  font-weight: 700;
  color: #9b7b5c;
  margin-left: 2px;
}

.letter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 40px;
}

.letter__input {
  width: 40px;
  height: 40px;
  border: 2px solid #b99b7b;
  border-radius: 8px;
  background: #ffffff;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #4b3b2b;
  outline: none;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.letter__input:disabled {
  background: #fdfaf7;
  color: #4b3b2b;
  border-color: #dcb594;
}

.letter__input--active {
  border: 3px solid #2980b9;
  background: rgba(41, 128, 185, 0.05);
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(41, 128, 185, 0.25);
}

.letter__input--active-error {
  border: 3px solid #c84545;
  background: rgba(200, 69, 69, 0.1);
  color: #c84545 !important;
  animation: shake 0.4s;
}

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

.letter__number {
  font-size: 0.75rem;
  color: #c4a77d;
  font-weight: 700;
}

.letter__number--highlight {
  color: #c5514d;
}

.instruction {
  margin-top: 20px;
  display: grid;
  justify-items: center;
  gap: 8px;
  transition: opacity 0.3s ease, height 0.3s ease;
  overflow: hidden;
}

.instruction--hidden {
  opacity: 0;
  height: 0;
  margin: 0;
  pointer-events: none;
}

.instruction__btn {
  background: #f1c7a7;
  border: none;
  padding: 18px 32px;
  border-radius: 18px;
  color: #8d5e3c;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: inset 0 -3px 0 rgba(255, 255, 255, 0.4);
}

.status {
  font-size: 0.9rem;
  color: #b79978;
}

.status--success {
  color: #1f7a3a;
  font-weight: 700;
}

.status--warn {
  color: #c84545;
  font-weight: 700;
}

.instruction__actions {
  display: flex;
  gap: 16px;
  align-items: center;
}

.reset {
  display: none; /* Removed from bottom as it moved to header */
}

.next-level {
  border: none;
  background: #b7c44a;
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 12px;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.next-level:hover {
  background: #a0b03a;
}

.keyboard {
  margin-top: 28px;
  background: #f4dec8;
  border-radius: 22px 22px 0 0;
  padding: 12px 10px 20px;
}

.keyboard__row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.key {
  min-width: 32px;
  padding: 10px 10px;
  text-align: center;
  border-radius: 10px;
  background: #f7e6d4;
  border: 1px solid #e3c4a5;
  font-weight: 700;
  color: #8d5e3c;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.key:active {
  background: #e8d5c0;
}

.key--wide {
  min-width: 50px;
}

.keyboard--disabled .key {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 700px) {
  .app__main {
    padding: 16px 0 6px;
  }

  .phrase__row {
    gap: 10px 0;
  }

  .letter__input {
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
    border-radius: 6px;
  }

  .letter {
    min-width: 32px;
  }

  .keyboard {
    border-radius: 18px 18px 0 0;
  }
}
