* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #171e28;
  --panel: #0d1117;
  --text: #eee;
  --subtle: #a0a7b4;
  --button: linear-gradient(180deg, #4460a1, #202e4e);
  --button-hover: linear-gradient(180deg, #446ba1, #1a2a4e);
  --correct: #4caf50;
  --wrong: #f44336;
  --href: #fff;
  --glyph: #fff;
  --glyph-height: 80px;
  --glyph-gap: 24px;
  --CTA: linear-gradient(180deg, #ffd900, #ff8800);
  --CTA-hover: linear-gradient(180deg, #fffb00, #ff9c00);
  --CTA-text: #000;
}

.light-theme {
  --bg: #f7f7f7;
  --panel: #ffffff;
  --text: #222;
  --subtle: #4c5663;
  --button: #bec7eb;
  --button-hover: #aeb8e0;
  --href: #0066ff;
  --glyph: #294767;
  --CTA: linear-gradient(180deg, #0099ff, #005d9b);
  --CTA-hover: linear-gradient(180deg, #00a2ff, #006bb3);
  --CTA-text: #fff;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 32px 16px;
}

.hidden {
  display: none !important;
}

.app {
  text-align: center;
  width: min(520px, 100%);
  color: var(--text);
}

h1 {
  font-size: 1.4rem;
  margin-bottom: 24px;
}

.card {
  background: var(--panel);
  padding: 32px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#welcome-screen {
  margin-bottom: 32px;
}

#welcome-screen p {
  margin-bottom: 20px;
}

#game.card {
  margin: 24px 0;
  transition: box-shadow 0.2s;
}

#results {
  margin: 24px 0;
}

.game-flash {
  animation: flash-red 400ms ease;
}

@keyframes flash-red {
  0% {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }

  40% {
    box-shadow: 0 10px 30px rgba(244, 67, 54, 0.8);
  }

  100% {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

.glyph-board {
  display: inline-flex;
  gap: 64px;
  margin: 16px 0 24px;
}

.glyph-column {
  display: grid;
  grid-template-rows: repeat(2, var(--glyph-height));
  row-gap: var(--glyph-gap);
  justify-items: center;
  border: 1px solid;
  padding: 10px;
  min-width: 90px;
}

.glyph {
  width: 60px;
  height: var(--glyph-height);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  color: var(--glyph);
  transition: transform 0.15s ease-out;
  font-weight: bold;
}

.challenge-ui {
  margin-bottom: 20px;
  text-align: left;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar {
  position: relative;
  height: 100%;
  width: 100%;
  background: var(--CTA);
  transition: width 0.1s linear;
  overflow: hidden;
}

.progress-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #ff2424, #a10000);
  opacity: 0;
  transition: opacity 8s linear;
}

.progress-bar.danger::after {
  opacity: 1;
}

.challenge-meta {
  font-size: 0.9rem;
  color: var(--subtle);
  text-align: right;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.buttons {
  display: flex;
  gap: 12px;
}

button {
  min-width: 56px;
  padding: 10px 0;
  border-radius: 6px;
  border: none;
  background: var(--button);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.08s ease-out, background 0.15s;
}

button:hover {
  background: var(--button-hover);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

.feedback {
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
}

#feedback-icon {
  font-size: 1.2rem;
}

.feedback.correct #feedback-icon {
  color: var(--correct);
}

.feedback.wrong #feedback-icon {
  color: var(--wrong);
}

.hint {
  color: var(--subtle);
  margin-top: 16px;
}

.hint-text {
  line-height: 1.4;
}

.hint.challenge-mode .hint-text {
  display: none;
}

.hint-actions {
  margin-top: 30px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.cta-button {
  background: var(--CTA);
  color: var(--CTA-text);
  border: none;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.2s;
}

.cta-button:hover {
  transform: translateY(-1px);
  background: var(--CTA-hover);
}

.cta-button:active {
  transform: translateY(1px);
}

.cta-group {
  display: flex;
  gap: 20px;
  margin-top: 50px;
  justify-content: center;
  flex-wrap: wrap;
}

.back-link {
  color: var(--href);
  font-size: 0.9rem;
}

#coffee {
  font-style: italic;
  margin-top: 30px;
}

#coffee a {
  color: var(--href);
}

#coffee a:visited {
  color: var(--href);
}

#return-to-practice {
  display: inline-block;
}

#results h2 {
  margin-bottom: 12px;
}

.results-grid {
  margin: 16px 0;
  text-align: left;
  font-size: 1.25rem;
}

.results-grid div {
  margin: 10px 0px;
}

.leaderboard {
  text-align: left;
  margin: 30px 0;
}

.leaderboard ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.leaderboard li {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.9rem;
}

.high-score {
  margin: 12px 0;
  font-size: 1.1rem;
  color: var(--CTA);
}

.high-score:not(.hidden) {
  animation: pop 0.6s ease-in-out infinite alternate;
}

@keyframes pop {
  from {
    transform: scale(1);
  }

  to {
    transform: scale(1.08);
  }
}

.top-toggles {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-end;
}

.toggle-switch {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.toggle-text {
  margin-right: 10px;
  font-size: 0.9rem;
}

.toggle-disabled {
  color: #999;
}

.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  width: 48px;
  height: 26px;
  background: var(--subtle);
  border-radius: 16px;
  position: relative;
  transition: background 0.2s ease;
}

.toggle-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.2s ease, background 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.toggle-switch input:checked+.toggle-track {
  background: var(--button);
}

.toggle-switch input:checked+.toggle-track .toggle-thumb {
  transform: translateX(22px);
  background: var(--panel);
}

#about {
  position: absolute;
  bottom: 20px;
}

#about a {
  color: var(--href);
  text-decoration: none;
}

#about a:hover {
  text-decoration: underline;
}

@media (max-width: 540px) {
  body {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
  }

  .app {
    padding-top: 60px;
  }

  #game,
  #welcome-screen,
  #results {
    padding: 24px;
  }

  .glyph-board {
    gap: 32px;
  }

  .buttons {
    width: 100%;
    justify-content: center;
  }

  button {
    flex: 1;
  }

  .top-toggles {
    position: static;
    margin-left: auto;
    gap: 12px;
  }

  #about {
    position: unset;
    margin-top: 24px;
    width: 100%;
    text-align: center;
  }

  .cta-group {
    flex-direction: column;
  }
}

@media (max-width: 320px) {
  .glyph-board {
    flex-direction: column;
  }
}