:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e8eef4;
  --muted: #8b9cb3;
  --accent: #3d9cf5;
  --success: #3ecf8e;
  --error: #f07178;
  --ring: #ffd166;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #1e3a5f 0%, var(--bg) 55%);
  color: var(--text);
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.header {
  text-align: center;
  margin-bottom: 1rem;
}

.header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

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

.toolbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 0.45rem 0.75rem;
  padding: 0.8rem 0.85rem;
  min-height: 3.25rem;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.btn-generate {
  background: linear-gradient(180deg, #7c3aed, #5b21b6);
}

.upload-extras {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin: -0.35rem 0 1rem;
  padding: 0 0.5rem;
}

.upload-extras .upload-file-name {
  font-size: 0.8rem;
  color: var(--muted);
  word-break: break-all;
  text-align: center;
  max-width: 100%;
  min-height: 1.2em;
}

.upload-preview-wrap {
  width: 100%;
  max-width: 320px;
}

.upload-preview-img {
  display: block;
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #000;
}

.upload-status {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  max-width: 28rem;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  flex-shrink: 0;
}

.stat-label {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 1.05rem;
}

.stat-value.success {
  color: var(--success);
}

.stat-value.error {
  color: var(--error);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.88rem;
  color: var(--text);
  white-space: nowrap;
}

.toggle input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}

.btn {
  background: linear-gradient(180deg, #2a6fb8, #1e5490);
  color: #fff;
  border: none;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:active {
  transform: translateY(1px);
}

.btn-start {
  background: linear-gradient(180deg, #2d8f6e, #1e6b52);
}

.select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  font-size: 0.88rem;
  min-width: 0;
  max-width: 11.25rem;
  flex-shrink: 1;
}

#levelPickWrap {
  flex-shrink: 1;
  min-width: 0;
}

#levelPickWrap .stat-label {
  white-space: nowrap;
}

@media (max-width: 520px) {
  .toolbar {
    justify-content: flex-start;
  }
}

.stage-wrap {
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  background: #000;
}

.stage {
  position: relative;
  width: 100%;
  min-height: min(70vh, 620px);
  max-height: min(70vh, 620px);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Author rules must not override [hidden], or a "broken image" icon stays visible beside the canvas */
.stage img[hidden],
.stage canvas[hidden] {
  display: none !important;
}

.stage img:not([hidden]),
.stage canvas:not([hidden]) {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(70vh, 620px);
  object-fit: contain;
  object-position: center;
  flex-shrink: 0;
}

.hit-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hit-layer.interactive {
  pointer-events: auto;
  cursor: crosshair;
}

.feedback {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: clamp(2rem, 6vw, 3.5rem);
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.6));
  animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  pointer-events: none;
}

.feedback.good {
  color: var(--success);
}

.feedback.bad {
  color: var(--error);
}

.answer-ring {
  position: absolute;
  border: 4px solid var(--ring);
  border-radius: 50%;
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.5),
    inset 0 0 0 2px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: ringIn 0.35s ease-out forwards;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes ringIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

