:root {
  --bg-1: #07111f;
  --bg-2: #12314c;
  --bg-3: #1b6b67;
  --panel: rgba(5, 14, 29, 0.78);
  --panel-strong: rgba(6, 18, 36, 0.9);
  --panel-soft: rgba(255, 255, 255, 0.08);
  --text: #f5fbff;
  --muted: #abc1d6;
  --accent: #63f5d0;
  --accent-2: #ffd166;
  --accent-3: #7cc8ff;
  --ok: #4ade80;
  --bad: #fb7185;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

body.light {
  --bg-1: #fdf4de;
  --bg-2: #dff5ff;
  --bg-3: #e7ffe8;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-strong: rgba(255, 255, 255, 0.94);
  --panel-soft: rgba(9, 30, 66, 0.06);
  --text: #0f1d33;
  --muted: #4b607c;
  --accent: #0fb99f;
  --accent-2: #ffb84d;
  --accent-3: #3aa7ff;
  --shadow: 0 20px 45px rgba(27, 54, 89, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(124, 200, 255, 0.18), transparent 35%),
    radial-gradient(circle at top right, rgba(99, 245, 208, 0.2), transparent 32%),
    linear-gradient(140deg, var(--bg-1), var(--bg-2), var(--bg-3));
  background-size: 100% 100%, 100% 100%, 200% 200%;
  animation: bgShift 16s ease infinite;
}

@keyframes bgShift {
  0% { background-position: 0% 0%, 100% 0%, 0% 50%; }
  50% { background-position: 10% 10%, 90% 20%, 100% 50%; }
  100% { background-position: 0% 0%, 100% 0%, 0% 50%; }
}

.screen {
  max-width: 1160px;
  margin: 0 auto;
  padding: 1.4rem;
}

.center {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.panel {
  width: min(100%, 1040px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 28px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.hero-panel,
.result-panel {
  padding: 2rem;
}

.game-panel {
  padding: 1rem;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}

.game-main,
.game-sidebar,
.hero-copy,
.hero-side {
  min-width: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.8rem;
  font-size: clamp(1.9rem, 4vw, 3.2rem);
  line-height: 0.95;
}

h2 {
  margin-bottom: 0.35rem;
  font-size: 1.05rem;
}

h3 {
  margin-bottom: 0.35rem;
}

.brand-title {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.brand-logo {
  width: 1.15em;
  height: 1.15em;
  object-fit: contain;
  flex: 0 0 auto;
}

.chip,
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.eyebrow {
  padding: 0.26rem 0.55rem;
  font-size: 0.68rem;
}

body.light .chip,
body.light .eyebrow {
  border-color: rgba(15, 29, 51, 0.16);
  background: rgba(15, 29, 51, 0.04);
}

.subtitle {
  margin-bottom: 1.2rem;
  max-width: 680px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.9rem;
}

.hero-actions,
.action-row {
  display: flex;
  gap: 0.7rem;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.btn {
  border: 0;
  border-radius: 16px;
  padding: 0.78rem 1.05rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible,
.tile:focus-visible,
.difficulty-card:focus-within {
  outline: 3px solid rgba(124, 200, 255, 0.75);
  outline-offset: 3px;
}

.btn-primary {
  color: #03231d;
  background: linear-gradient(90deg, var(--accent), #b4ffe8);
  box-shadow: 0 10px 24px rgba(99, 245, 208, 0.28);
}

.btn-secondary {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

body.light .btn-secondary {
  border-color: rgba(15, 29, 51, 0.14);
}

.btn-report {
  color: #2b1800;
  background: linear-gradient(90deg, var(--accent-2), #ff8a4c);
  box-shadow: 0 10px 26px rgba(255, 138, 76, 0.28);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-soft {
  margin-top: 0.9rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 0.9rem;
}

body.light .panel-soft {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.5));
  border-color: rgba(15, 29, 51, 0.08);
}

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

.stat-card {
  border-radius: 18px;
  padding: 0.8rem 0.9rem;
  background: var(--panel-soft);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.stat-card span {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin-top: 0.2rem;
  font-size: 1.35rem;
}

.danger strong {
  color: #ffd166;
}

.meter-header {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  font-size: 0.88rem;
}

.meter-track,
.progress-track,
.loading-track,
.chart-bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
}

.progress-track {
  margin-top: 0.8rem;
  height: 10px;
}

.meter-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff7f9f, var(--accent-3));
  transition: width 0.35s ease;
}

.progress-fill,
.loading-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.35s ease;
}

.instruction p {
  margin-bottom: 0.15rem;
  font-size: clamp(1rem, 2.3vw, 1.45rem);
  font-weight: 700;
}

.instruction small,
.helper-copy,
.empty-copy {
  color: var(--muted);
}

.grid {
  margin-top: 0.9rem;
  display: grid;
  gap: 0.7rem;
}

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

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

.grid.dense-grid {
  gap: 0.5rem;
}

.tile {
  position: relative;
  border: 2px solid transparent;
  border-radius: 18px;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.16), transparent 50%),
    rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  aspect-ratio: 1 / 1;
}

.tile:hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.22);
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 245, 208, 0.18), 0 0 20px rgba(99, 245, 208, 0.34);
}

.tile.correct-hit {
  border-color: var(--ok);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.18), 0 0 22px rgba(74, 222, 128, 0.28);
}

.tile.wrong-hit {
  border-color: var(--bad);
  animation: redShake 0.35s ease;
}

@keyframes redShake {
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 8, 19, 0.72);
  z-index: 50;
}

.particle-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 70;
}

.hidden {
  display: none;
}

.overlay-card {
  width: min(92%, 460px);
  border-radius: 22px;
  padding: 1.2rem;
  background: var(--panel-strong);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.15);
  text-align: center;
}

.result-message {
  margin: 1rem auto;
  max-width: 700px;
  font-size: 1.05rem;
  line-height: 1.55;
}

.round-feedback {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

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

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.btn-mini {
  padding: 0.42rem 0.7rem;
  border-radius: 12px;
  font-size: 0.75rem;
}

.history-summary {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.report-chip {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  padding: 0.45rem 0.55rem;
  background: linear-gradient(135deg, rgba(124, 200, 255, 0.14), rgba(255, 209, 102, 0.15));
}

.report-chip span {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.report-chip strong {
  font-size: 0.98rem;
}

.report-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.history-list {
  margin: 0.9rem 0 0;
  padding-left: 1rem;
  color: var(--muted);
}

.history-item {
  margin-bottom: 0.55rem;
  padding: 0.55rem 0.7rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.compact-list {
  padding-left: 0;
  list-style: none;
}

.helper-copy {
  margin-top: 0.7rem;
  font-size: 0.85rem;
}

kbd {
  font: inherit;
  padding: 0.1rem 0.35rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.history-chart {
  display: grid;
  gap: 0.7rem;
  margin-top: 1rem;
}

.chart-row {
  display: grid;
  gap: 0.4rem;
}

.chart-label {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
}

.chart-fill {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 2.2rem;
  height: 100%;
  padding-right: 0.4rem;
  color: #042028;
  font-size: 0.72rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent-3), var(--accent));
}

.chart-fill.fail {
  background: linear-gradient(90deg, #ff9b7a, #fb7185);
}

.recap-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.recap-card {
  display: grid;
  gap: 0.25rem;
  padding: 0.75rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.recap-card.pass {
  border-color: rgba(74, 222, 128, 0.28);
}

.recap-card.fail {
  border-color: rgba(251, 113, 133, 0.28);
}

@media (min-width: 900px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) 290px;
    align-items: start;
  }
}

@media (max-width: 760px) {
  .screen {
    padding: 1rem;
  }

  .hero-panel,
  .result-panel {
    padding: 1.2rem;
  }

  .topbar {
    flex-direction: column;
  }

  .toolbar,
  .hero-actions,
  .action-row {
    justify-content: flex-start;
  }

  .stats-grid,
  .history-summary {
    grid-template-columns: 1fr;
  }

  .round-feedback {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
