:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #1f2a37;
  background: #f5f7fb;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  background-attachment: fixed;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

main {
  max-width: 1024px;
  margin: 0 auto;
  padding: 0.5rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.page-header {
  display: none;
}

footer {
  text-align: center;
  padding: 1rem 1.5rem;
  color: white;
}

.card {
  background: #fff;
  border-radius: 20px;
  padding: 1.25rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: linear-gradient(90deg, #667eea, #764ba2, #f093fb, #f5576c);
  background-size: 200% 100%;
  animation: gradientShift 3s ease infinite;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.scoreboard {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-weight: 700;
  color: #1f2a37;
}

.scoreboard span {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-size: 0.875rem;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  transition: transform 0.2s ease;
}

.scoreboard span:first-child {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  box-shadow: 0 4px 15px rgba(79, 172, 254, 0.4);
}

.scoreboard span:last-child {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  box-shadow: 0 4px 15px rgba(67, 233, 123, 0.4);
}

.scoreboard span:hover {
  transform: translateY(-2px);
}

.result-meta {
  margin: 0.5rem 0;
  color: #475569;
  font-weight: 600;
  font-size: 1.05rem;
}

.attempt-hint {
  margin: 0.5rem 0 0.25rem;
  color: #6b7280;
  font-size: 0.85rem;
  font-weight: 500;
}

.keyboard {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.keyboard-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(60px, 1fr));
  gap: 0.5rem;
}

.keyboard button {
  background: linear-gradient(135deg, #fff 0%, #f8f9ff 100%);
  border: 2px solid #e0e7ff;
  border-radius: 14px;
  font-size: 1.125rem;
  padding: 0.75rem 0;
  min-height: 50px;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15), inset 0 -2px 0 rgba(102, 126, 234, 0.1);
  transition: all 0.2s ease;
  font-weight: 700;
  touch-action: manipulation;
  color: #667eea;
}

.keyboard button:active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border-color: #667eea;
  transform: translateY(3px) scale(0.98);
  box-shadow: 0 2px 6px rgba(102, 126, 234, 0.3);
}

@media (hover: hover) and (pointer: fine) {
  .keyboard button:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-color: #667eea;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
  }
}

.keyboard button[data-action] {
  font-size: 0.9rem;
  font-weight: 700;
}

#practice.card {
  width: min(900px, 100%);
  align-self: center;
}

.target-form label {
  font-weight: 600;
}

.form-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

input[type="number"],
input[type="text"] {
  flex: 1;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 2px solid #e0e7ff;
  font-size: 1.05rem;
  transition: all 0.2s ease;
  min-height: 44px;
  background: #fff;
  font-weight: 600;
  color: #1f2a37;
}

input[type="number"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
  background: linear-gradient(135deg, #fff 0%, #f8f9ff 100%);
}

.answer-field {
  flex: 1;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  border: 2px solid #e0e7ff;
  font-size: 1.05rem;
  transition: all 0.2s ease;
  min-height: 44px;
  background: #fff;
  font-weight: 600;
  color: #1f2a37;
}

.answer-field:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.2);
  background: linear-gradient(135deg, #fff 0%, #f8f9ff 100%);
}

.answer-field.correct {
  border-color: #43e97b;
  box-shadow: 0 0 0 4px rgba(67, 233, 123, 0.3);
  background: linear-gradient(135deg, #fff 0%, #f0fdf4 100%);
}

.answer-field.incorrect {
  border-color: #f5576c;
  box-shadow: 0 0 0 4px rgba(245, 87, 108, 0.3);
  background: linear-gradient(135deg, #fff 0%, #fef2f2 100%);
}

button {
  border: none;
  border-radius: 999px;
  padding: 0.65rem 1.25rem;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

button[type="submit"] {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
  border: 3px solid transparent;
}

button[type="submit"]:active {
  transform: scale(0.96) translateY(2px);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

@media (hover: hover) and (pointer: fine) {
  button[type="submit"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(102, 126, 234, 0.5);
  }
}

button.secondary {
  background: linear-gradient(135deg, #f8f9ff 0%, #e0e7ff 100%);
  color: #667eea;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.15);
  border: 3px solid #e0e7ff;
}

button.secondary:active {
  transform: scale(0.96);
}

button.next-primary:not(:disabled) {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  color: #fff;
  box-shadow: 0 8px 25px rgba(67, 233, 123, 0.4);
}

button.pill {
  background: linear-gradient(135deg, #fff 0%, #f8f9ff 100%);
  color: #667eea;
  border: 3px solid #e0e7ff;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
  transition: all 0.2s ease;
  font-weight: 700;
}

button.pill:active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border-color: #667eea;
  transform: scale(0.95);
}

@media (hover: hover) and (pointer: fine) {
  button:hover {
    transform: translateY(-3px);
  }

  button.pill:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-color: #667eea;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.35);
  }
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.quick-buttons {
  margin-top: 0.75rem;
  --quick-btn-width: clamp(45px, 5vw, 58px);
  --quick-gap: 0.4rem;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(10, var(--quick-btn-width));
  justify-content: flex-start;
  gap: var(--quick-gap);
}

.quick-buttons .button-row + .button-row {
  margin-top: 0.5rem;
}

.quick-buttons .pill {
  width: var(--quick-btn-width);
  text-align: center;
  justify-self: start;
  font-size: 0.95rem;
  padding: 0.6rem 0;
}

.pill.placeholder {
  visibility: hidden;
  pointer-events: none;
  display: inline-block;
}

.practice-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  flex-wrap: wrap;
}

.practice-header h2 {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.35rem;
}

.link-button {
  background: transparent;
  color: #667eea;
  padding: 0.5rem 1rem;
  box-shadow: none;
  border-radius: 12px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.link-button:hover {
  background: linear-gradient(135deg, #f8f9ff 0%, #e0e7ff 100%);
}

.prompt {
  font-size: 1.75rem;
  font-weight: 800;
  margin: 0.75rem 0 0.5rem;
  color: #1f2a37;
  text-align: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 2px 10px rgba(102, 126, 234, 0.1);
}

.answer-form {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

#answer-input {
  flex: 1;
}

.feedback {
  min-height: 2.5rem;
  margin-top: 0.5rem;
  font-weight: 700;
  padding: 0.5rem 0.85rem;
  border-radius: 12px;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  font-size: 0.9rem;
}

.feedback.success {
  color: #065f46;
  background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
  border-color: #43e97b;
  box-shadow: 0 4px 15px rgba(67, 233, 123, 0.2);
}

.feedback.error {
  color: #9f1239;
  background: linear-gradient(135deg, #fef2f2 0%, #fecdd3 100%);
  border-color: #f5576c;
  box-shadow: 0 4px 15px rgba(245, 87, 108, 0.2);
}

footer {
  color: rgba(255, 255, 255, 0.9);
  font-size: 1rem;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.1);
}

.sr-only {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  width: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
}

.hint {
  font-size: 0.85rem;
  color: #4b5563;
  margin: 0.5rem 0 0.35rem;
  font-weight: 500;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.choice-grid button {
  border: 2px solid #e0e7ff;
  background: linear-gradient(135deg, #fff 0%, #f8f9ff 100%);
  color: #667eea;
  border-radius: 12px;
  padding: 0.65rem 0;
  font-size: 1.05rem;
  font-weight: 700;
  min-height: 48px;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.choice-grid button:active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border-color: #667eea;
  transform: scale(0.95);
}

@media (hover: hover) and (pointer: fine) {
  .choice-grid button:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-color: #667eea;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.35);
  }
}

.choice-grid button.correct {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  color: #fff;
  border-color: #43e97b;
  box-shadow: 0 0 0 4px rgba(67, 233, 123, 0.3);
}

.choice-grid button.incorrect {
  background: linear-gradient(135deg, #f5576c 0%, #f093fb 100%);
  color: #fff;
  border-color: #f5576c;
  box-shadow: 0 0 0 4px rgba(245, 87, 108, 0.3);
  animation: shake 400ms ease;
}

.animate-pop {
  animation: pop 300ms ease;
}

input[type="number"].correct {
  border-color: #43e97b;
  box-shadow: 0 0 0 4px rgba(67, 233, 123, 0.3);
}

input[type="number"].incorrect {
  border-color: #f5576c;
  box-shadow: 0 0 0 4px rgba(245, 87, 108, 0.3);
  animation: shake 300ms ease;
}

@keyframes pop {
  0% {
    transform: scale(0.94);
  }
  50% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

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

#confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 999;
}

.confetti-piece {
  position: absolute;
  width: 12px;
  height: 16px;
  border-radius: 3px;
  opacity: 0;
  transform: translate3d(0, -60px, 0) rotate(0deg);
  animation: confetti-fall var(--confetti-duration, 1.8s) cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
  animation-delay: var(--confetti-delay, 0s);
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translate3d(0, -60px, 0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate3d(
        var(--confetti-drift, 0px),
        110vh,
        0
      )
      rotate(var(--confetti-rotation, 720deg));
  }
}

#result-screen h2 {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.75rem;
  margin-bottom: 0.75rem;
}

#result-screen p {
  font-size: 1rem;
  color: #1f2a37;
  font-weight: 600;
  margin: 0.5rem 0;
}

@media (max-width: 540px) {
  .scoreboard {
    flex-direction: column;
  }

  .form-row,
  .answer-form {
    flex-direction: column;
  }

  button,
  input[type="number"],
  input[type="text"] {
    width: 100%;
  }

  .button-row {
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  }

  .button-row.row-first .placeholder {
    display: none;
  }

  .quick-buttons .pill {
    width: 100%;
  }

  .choice-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .prompt {
    font-size: 2rem;
  }

  .page-header h1 {
    font-size: 2rem;
  }

  .card {
    padding: 1.75rem;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  .card {
    padding: 3rem;
  }

  .keyboard-row {
    grid-template-columns: repeat(3, minmax(110px, 150px));
    justify-content: center;
  }

  .choice-grid {
    grid-template-columns: repeat(6, minmax(85px, 1fr));
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
  }

  .quick-buttons {
    --quick-btn-width: clamp(65px, 6vw, 80px);
  }
}

@media (min-width: 1024px) {
  .keyboard-row {
    grid-template-columns: repeat(3, 150px);
    justify-content: center;
  }

  .choice-grid {
    grid-template-columns: repeat(6, 100px);
    justify-content: center;
  }
}
