:root {
  --bg: #0e1320;
  --bg-soft: #172038;
  --panel: rgba(23, 32, 56, 0.88);
  --panel-border: rgba(125, 144, 187, 0.35);
  --text: #ecf2ff;
  --muted: #afbdd8;
  --accent: #75e6c1;
  --good: #6ef59e;
  --bad: #ff8080;
  --timer: #70cbff;
  --shadow: 0 18px 38px rgba(2, 5, 12, 0.45);
}

body[data-theme="light"] {
  --bg: #eef3ff;
  --bg-soft: #dce6ff;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-border: rgba(83, 109, 163, 0.34);
  --text: #1c2743;
  --muted: #566589;
  --accent: #2faa86;
  --good: #1f9d4a;
  --bad: #cc2f2f;
  --timer: #2f84d8;
  --shadow: 0 18px 38px rgba(66, 91, 137, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(
      1000px circle at 10% -10%,
      rgba(107, 118, 255, 0.18),
      transparent 55%
    ),
    radial-gradient(
      900px circle at 90% 115%,
      rgba(93, 240, 194, 0.14),
      transparent 50%
    ),
    linear-gradient(170deg, var(--bg), var(--bg-soft));
  display: grid;
  place-items: center;
  padding: 14px;
}

.app {
  width: min(940px, 100%);
  background: var(--panel);
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  padding: 16px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: clamp(1.4rem, 3.8vw, 2rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

.home-link {
  text-decoration: none;
  color: #0f2d23;
  background: #bff5df;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 800;
}

.settings {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.settings label,
.settings button {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-weight: 700;
  padding: 9px 10px;
}

.settings label {
  display: grid;
  gap: 7px;
  font-size: 0.87rem;
}

.settings select {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: rgba(6, 10, 24, 0.25);
  color: var(--text);
  padding: 8px;
}

body[data-theme="light"] .settings select {
  background: rgba(255, 255, 255, 0.88);
}

.toggle-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.toggle-item input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.stats {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.stat-card {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  text-align: center;
  background: rgba(255, 255, 255, 0.05);
  padding: 9px;
}

.stat-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.15rem;
}

.prompt-panel {
  margin-top: 14px;
  text-align: center;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.03);
  padding: 14px;
  min-height: 190px;
}

.combo-text {
  min-height: 24px;
  font-weight: 800;
  color: var(--accent);
}

.combo-text.pop {
  animation: pop 0.34s ease;
}

.color-word {
  margin: 6px 0 12px;
  font-size: clamp(2.2rem, 8vw, 4rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.color-word.black-visible {
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.85);
}

body[data-theme="light"] .color-word.black-visible {
  text-shadow: 0 0 10px rgba(18, 33, 69, 0.35);
}

.question-timer {
  width: min(500px, 100%);
  margin: 0 auto;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.question-timer-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--timer), #3dd0a1);
  transition: width 0.09s linear;
}

.answer-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.answer-btn {
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 11px;
  min-height: 58px;
  color: #f8fcff;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition:
    transform 0.14s ease,
    filter 0.2s ease,
    box-shadow 0.2s ease;
}

.answer-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.08);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.24);
}

.answer-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.answer-btn .key-badge {
  opacity: 0.8;
  margin-right: 6px;
}

body.color-blind .answer-btn {
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.16) 0 8px,
    rgba(255, 255, 255, 0.06) 8px 16px
  );
}

.actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.actions button,
.settings button,
.modal button {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    filter 0.2s ease;
}

.actions button:hover:not(:disabled),
.settings button:hover,
.modal button:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary-btn {
  background: linear-gradient(180deg, #b2f1df, #68c9ad);
  color: #10221d;
}

.message {
  margin: 12px 0 2px;
  min-height: 24px;
  text-align: center;
  font-weight: 800;
  color: #ffe39e;
}

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

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

.stats-panels {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.panel {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.best-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.best-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  padding: 7px 8px;
  background: rgba(255, 255, 255, 0.06);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(1, 6, 14, 0.72);
  display: grid;
  place-items: center;
  z-index: 40;
}

.overlay.hidden {
  display: none;
}

.countdown-text {
  margin: 0;
  font-size: clamp(3rem, 14vw, 6rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #f6fffd;
  text-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 20, 0.72);
  display: grid;
  place-items: center;
  padding: 12px;
  z-index: 50;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  width: min(460px, 100%);
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: rgba(17, 24, 43, 0.95);
  color: #edf5ff;
  padding: 16px;
}

body[data-theme="light"] .modal {
  background: rgba(255, 255, 255, 0.97);
  color: #182541;
}

.modal h2 {
  margin-top: 0;
}

.modal ul {
  padding-left: 20px;
  line-height: 1.5;
}

.prompt-panel.correct-flash {
  animation: correctFlash 0.24s ease;
}

.prompt-panel.wrong-flash {
  animation: wrongFlash 0.24s ease;
}

@keyframes correctFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(110, 245, 158, 0.5);
  }
  100% {
    box-shadow: 0 0 0 14px rgba(110, 245, 158, 0);
  }
}

@keyframes wrongFlash {
  0% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(5px);
  }
  75% {
    transform: translateX(-4px);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes pop {
  0% {
    transform: scale(0.84);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 860px) {
  .settings {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .top-bar {
    flex-direction: column;
    align-items: flex-start;
  }

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

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

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

  .stats-panels {
    grid-template-columns: 1fr;
  }
}
