:root {
  color-scheme: light dark;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  --surface: rgba(255, 255, 255, 0.9);
  --background: linear-gradient(160deg, #f9fafb 0%, #e2e8f0 40%, #f9fafb 100%);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --accent: #2563eb;
  --accent-muted: #93c5fd;
  --success: #16a34a;
  --warning: #dc2626;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  background: var(--background);
  color: var(--text-primary);
  user-select: none;
}

.page {
  width: min(1080px, 100%);
  padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 4vw, 2rem) 3rem;
  display: grid;
  gap: 2rem;
}

.page__header {
  text-align: center;
  display: grid;
  gap: 0.75rem;
}

.page__header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
}

.page__header p {
  margin: 0;
  color: var(--text-secondary);
}

.controls {
  display: grid;
  gap: 1rem;
  background: var(--surface);
  padding: 1.5rem;
  border-radius: 24px;
  box-shadow: 0 18px 35px rgba(15, 23, 42, 0.12);
}

.controls label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.input-group input {
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.95);
  transition: border-color 120ms ease, box-shadow 120ms ease;
  -moz-appearance: textfield;
}

.input-group input::-webkit-outer-spin-button,
.input-group input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.controls__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
}

.timer {
  font-size: 1.1rem;
  font-weight: 600;
}

#new-game {
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.35);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

#new-game:hover {
  transform: translateY(-1px);
}

#new-game:active {
  transform: translateY(0);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.25);
}

.board {
  background: var(--surface);
  border-radius: 28px;
  padding: clamp(1.5rem, 4vw, 2.5rem);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.1);
  display: grid;
  gap: 1.5rem;
}

.board__row {
  display: grid;
  gap: 1rem;
}

.board__row--top {
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  min-height: 120px;
}

.board__row--bottom {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.fraction-card {
  background: #fff;
  border-radius: 18px;
  border: 2px solid transparent;
  padding: 1.1rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 600;
  cursor: grab;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  user-select: none;
  touch-action: none;
}

.fraction-card:active {
  cursor: grabbing;
}

.fraction-card.is-dragging {
  opacity: 0.9;
  transform: scale(1.06);
  box-shadow: 0 18px 30px rgba(37, 99, 235, 0.3);
  border-color: var(--accent-muted);
}

.fraction-card.is-touch-dragging {
  cursor: grabbing;
  pointer-events: none;
  transition: none;
}

.fraction-card--placeholder {
  visibility: hidden;
}

.fraction-card.is-matched {
  cursor: default;
  border-color: var(--success);
  box-shadow: 0 16px 28px rgba(22, 163, 74, 0.25);
}

.fraction {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.fraction__numerator {
  border-bottom: 2px solid currentColor;
  padding: 0 0.25em 0.2em;
  margin-bottom: 0.2em;
}

.fraction__denominator {
  padding: 0 0.25em;
}

.match-card {
  position: relative;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 1.2rem 1.4rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.85rem;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.35);
  transition: box-shadow 150ms ease, border-color 150ms ease;
}

.match-card.is-active {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.match-card.is-correct {
  box-shadow: inset 0 0 0 2px rgba(22, 163, 74, 0.8);
}

.match-card__decimal {
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 600;
  color: var(--text-primary);
}

.match-card__dropzone {
  min-height: 60px;
  border-radius: 14px;
  border: 2px dashed rgba(148, 163, 184, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  font-size: 0.95rem;
  color: var(--text-secondary);
  transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
}

.match-card__dropzone.is-hovered {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(37, 99, 235, 0.08);
}

.match-card__dropzone.filled {
  border-style: solid;
  border-color: rgba(22, 163, 74, 0.35);
  background: rgba(22, 163, 74, 0.08);
  color: var(--success);
}

.match-card__dropzone .placeholder {
  opacity: 0.65;
}

.fraction-card.incorrect {
  animation: shake 400ms ease;
}

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

.status-message {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-height: 1.4rem;
}

.status-message.is-complete {
  color: var(--success);
}

.status-message.is-warning {
  color: var(--warning);
}

@media (max-width: 720px) {
  .controls {
    gap: 0.75rem;
  }

  .controls__meta {
    flex-direction: column;
    align-items: stretch;
  }

  #new-game {
    width: 100%;
    text-align: center;
  }

  .board__row--top {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  }

  .board__row--bottom {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 960px) {
  .board__row--top {
    grid-template-columns: repeat(8, minmax(110px, 1fr));
  }

  .board__row--bottom {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: auto;
  }
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease;
  z-index: 20;
}

#confetti-canvas.is-active {
  opacity: 1;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 25;
  padding: 1.5rem;
}

.modal.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.modal__content {
  background: #fff;
  border-radius: 24px;
  padding: clamp(2rem, 4vw, 2.75rem);
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 26px 55px rgba(15, 23, 42, 0.25);
  display: grid;
  gap: 1.5rem;
}

.modal__content h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.2rem);
}

.modal__content p {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-secondary);
}

#modal-new-game {
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  padding: 0.85rem 1.8rem;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 16px 30px rgba(37, 99, 235, 0.35);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

#modal-new-game:hover {
  transform: translateY(-1px);
}

#modal-new-game:active {
  transform: translateY(0);
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.25);
}
