:root {
  color-scheme: dark;
  --timed-bg: #0b1120;
  --timed-card: #151e33;
  --timed-border: rgba(148, 163, 184, 0.3);
  --timed-accent: #22c55e;
  --timed-ink: #f8fafc;
  --timed-muted: #cbd5f5;
  --timed-danger: #f97316;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Noto Sans', system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at 20% 20%, rgba(34, 197, 94, 0.12), transparent 30%),
    radial-gradient(circle at 80% 10%, rgba(59, 130, 246, 0.12), transparent 32%),
    var(--timed-bg);
  color: var(--timed-ink);
}

body.has-splash {
  overflow: hidden;
}

#splash-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

#splash-mask {
  position: fixed;
  pointer-events: none;
  z-index: 1;
  background: transparent;
  border: none;
  border-radius: 24px;
}

.splash-icon {
  position: absolute;
  z-index: 0;
  opacity: 0;
  will-change: transform, opacity;
  animation: splashFade 24s ease-in-out infinite;
  animation-play-state: paused;
  visibility: hidden;
  border-radius: 14px;
  object-fit: cover;
}

.splash-icon.is-ready {
  animation-play-state: running;
  visibility: visible;
}

@keyframes splashFade {
  0% {
    opacity: 0;
  }
  15% {
    opacity: 0.85;
  }
  70% {
    opacity: 0.9;
  }
  85% {
    opacity: 0.35;
  }
  100% {
    opacity: 0;
  }
}

.timed-splash {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: clamp(24px, 5vw, 48px);
  background: linear-gradient(135deg, rgba(10, 15, 28, 0.78), rgba(6, 10, 20, 0.88));
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.timed-splash.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.timed-splash-panel {
  width: min(560px, 100%);
  padding: clamp(24px, 4vw, 36px);
  border-radius: 24px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: color-mix(in srgb, var(--timed-card) 80%, #0b1222 20%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
  display: grid;
  gap: 16px;
}

.timed-splash-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.75rem;
  color: var(--timed-muted);
}

.timed-splash-panel h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 40px);
  color: var(--timed-accent);
}

.timed-splash-lede {
  margin: 0;
  color: var(--timed-muted);
  line-height: 1.6;
}

.timed-splash-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
  text-align: left;
  color: var(--timed-ink);
}

.timed-splash-list li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  font-size: 0.95rem;
  line-height: 1.5;
}

.timed-splash-list li::before {
  content: '•';
  color: var(--timed-accent);
  font-size: 1.2rem;
  line-height: 1;
  margin-top: 2px;
}

main {
  max-width: 1300px;
  margin: 0 auto;
  padding: 20px clamp(16px, 4vw, 32px) 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: relative;
  z-index: 2;
}

.timed-hero {
  background: color-mix(in srgb, var(--timed-card) 75%, #0b1222 25%);
  border: 1px solid var(--timed-border);
  border-radius: 18px;
  padding: clamp(14px, 2.4vw, 22px);
  display: grid;
  gap: 8px;
}

.timed-hero h1 {
  margin: 0;
  font-size: clamp(24px, 3.4vw, 34px);
  color: var(--timed-accent);
}

.timed-hero p {
  margin: 0;
  color: var(--timed-muted);
  line-height: 1.5;
  font-size: 0.95rem;
}

.timed-cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--timed-accent);
  background: var(--timed-accent);
  color: #0b1120;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
}

.timed-layout {
  display: grid;
  gap: 20px;
}

.timed-scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.timed-score-card {
  padding: 14px 16px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--timed-card) 80%, #0b1222 20%);
  border: 1px solid var(--timed-border);
  display: grid;
  gap: 6px;
}

.timed-score-card span {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--timed-muted);
}

.timed-score-card strong {
  font-size: 1.6rem;
  color: var(--timed-ink);
}

.timed-game-shell {
  background: var(--timed-card);
  border: 1px solid var(--timed-border);
  border-radius: 18px;
  padding: clamp(12px, 2.5vw, 22px);
  display: grid;
  gap: 14px;
  position: relative;
  overflow: hidden;
}

.timed-game-area {
  position: relative;
  height: clamp(460px, 60vh, 680px);
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.9), rgba(12, 17, 30, 0.95)),
    radial-gradient(circle at 10% 20%, rgba(34, 197, 94, 0.18), transparent 40%);
  overflow: hidden;
}

.timed-spawn-indicator {
  position: absolute;
  top: 12px;
  left: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: var(--timed-muted);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  z-index: 4;
}

.timed-spawn-indicator strong {
  color: var(--timed-ink);
  font-weight: 700;
}

.timed-spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(148, 163, 184, 0.4);
  border-top-color: var(--timed-accent);
  animation: timed-spin 1s linear infinite;
}

@keyframes timed-spin {
  to {
    transform: rotate(360deg);
  }
}

.timed-game-area::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: #ef4444;
  z-index: 1;
}

.timed-game-zones {
  position: absolute;
  inset: 16px;
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(0, 2.4fr) minmax(160px, 0.8fr);
  gap: 14px;
  pointer-events: none;
  z-index: 2;
  align-items: stretch;
}

.timed-zone-column {
  display: grid;
  gap: 12px;
  align-content: stretch;
  height: 100%;
  grid-auto-rows: 1fr;
}

.timed-zone-column[data-zone-column='right'] {
  grid-column: 3;
}

.drop-zone {
  padding: 14px 12px;
  border-radius: 14px;
  border: 1px dashed rgba(34, 197, 94, 0.5);
  background: rgba(15, 23, 42, 0.6);
  color: var(--timed-ink);
  font-weight: 600;
  text-align: center;
  min-height: 0;
  height: 100%;
  display: grid;
  place-items: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  pointer-events: auto;
}

.drop-zone.is-target {
  border-color: var(--timed-accent);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.drop-zone.is-correct {
  border-color: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.3);
}

.drop-zone.is-wrong {
  border-color: var(--timed-danger);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.3);
}

.falling-piece {
  position: absolute;
  width: clamp(160px, 18vw, 200px);
  aspect-ratio: 4 / 3;
  border-radius: 14px;
  border: 2px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.8);
  overflow: hidden;
  cursor: grab;
  user-select: none;
  touch-action: none;
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.45);
  z-index: 3;
  transform: translate3d(var(--piece-x, 0px), var(--piece-y, 0px), 0);
  will-change: transform;
}

.falling-piece.is-warning {
  border-color: #f87171;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.35), 0 12px 22px rgba(0, 0, 0, 0.45);
  animation: timed-fall-warning 0.6s ease-in-out infinite;
}

.falling-piece.is-warning.is-dragging {
  animation-play-state: paused;
}

.falling-piece:focus-visible {
  outline: 2px solid var(--timed-accent);
  outline-offset: 2px;
}

.falling-piece.is-dragging {
  cursor: grabbing;
  box-shadow: 0 16px 28px rgba(34, 197, 94, 0.25);
}

.falling-piece img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  user-select: none;
}

@keyframes timed-fall-warning {
  0%,
  100% {
    transform: translate3d(var(--piece-x, 0px), var(--piece-y, 0px), 0) scale(1);
  }
  50% {
    transform: translate3d(var(--piece-x, 0px), var(--piece-y, 0px), 0) scale(1.04);
  }
}

.timed-status {
  font-size: 0.95rem;
  color: var(--timed-muted);
}

.timed-game-over {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 24, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.timed-game-over.active {
  display: flex;
}

.timed-game-over-card {
  background: var(--timed-card);
  border: 1px solid var(--timed-border);
  border-radius: 16px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  display: grid;
  gap: 14px;
}

@media (prefers-reduced-motion: reduce) {
  #splash-background,
  #splash-mask {
    display: none;
  }
}

@media (max-width: 768px) {
  #splash-mask {
    display: none;
  }
}

.timed-game-over-card h2 {
  margin: 0;
  color: var(--timed-accent);
}

.timed-game-over-stats {
  display: grid;
  gap: 8px;
  text-align: left;
}

.timed-game-over-row {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
}

.timed-game-over-row span {
  color: var(--timed-muted);
}

.timed-game-over-row strong {
  color: var(--timed-ink);
}

.timed-game-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.timed-secondary-btn {
  background: transparent;
  color: var(--timed-ink);
  border: 1px solid var(--timed-border);
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 720px) {
  .timed-game-area {
    height: 400px;
  }

  .falling-piece {
    width: 140px;
  }

  .timed-game-zones {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    inset: 12px;
  }

  .timed-zone-column[data-zone-column='right'] {
    grid-column: auto;
  }
}
