:root {
  --bg-deep: #f7f9fc;
  --bg-mid: #eef3f9;
  --bg-top: #ffffff;
  --bg-bottom: #e8eef7;
  --panel: rgba(255, 255, 255, 0.82);
  --surface-top: rgba(255, 255, 255, 0.94);
  --surface-bottom: rgba(246, 249, 253, 0.94);
  --surface-highlight: #ffffff;
  --sea-ring: rgba(70, 130, 200, 0.09);
  --sea-wash: rgba(120, 170, 220, 0.14);
  --kbd-bg: rgba(16, 24, 40, 0.05);
  --line: rgba(16, 24, 40, 0.12);
  --line-strong: rgba(16, 24, 40, 0.2);
  --gold: #b7791f;
  --gold-dim: #8a5a12;
  --ink: #101828;
  --muted: #5b6b82;
  --good: #15803d;
  --bad: #dc2626;
  --shadow: 0 18px 44px rgba(16, 24, 40, 0.12);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg-deep: #080e19;
  --bg-mid: #0e1728;
  --bg-top: #16233a;
  --bg-bottom: #060b13;
  --panel: rgba(18, 29, 47, 0.84);
  --surface-top: rgba(20, 31, 50, 0.95);
  --surface-bottom: rgba(11, 19, 32, 0.95);
  --surface-highlight: rgba(255, 255, 255, 0.06);
  --sea-ring: rgba(98, 169, 255, 0.1);
  --sea-wash: rgba(60, 120, 200, 0.18);
  --kbd-bg: rgba(226, 232, 240, 0.08);
  --line: rgba(226, 232, 240, 0.12);
  --line-strong: rgba(226, 232, 240, 0.24);
  --gold: #e3b65a;
  --gold-dim: #c99738;
  --ink: #edf3fb;
  --muted: #96a6bd;
  --good: #4ade80;
  --bad: #fb7185;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.38);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100svh;
  padding: clamp(14px, 3vw, 40px);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1100px 560px at 50% -12%, var(--bg-top) 0%, var(--bg-mid) 46%, var(--bg-bottom) 100%);
  overflow-x: hidden;
}

.sea {
  position: fixed;
  inset: auto 0 0 0;
  height: 46vh;
  pointer-events: none;
  opacity: 0.55;
  background:
    repeating-radial-gradient(circle at 50% 120%, transparent 0 38px, var(--sea-ring) 39px 40px),
    linear-gradient(180deg, transparent, var(--sea-wash));
  mask-image: linear-gradient(180deg, transparent, #000 45%);
}

:root[data-theme="dark"] .sea {
  opacity: 0.38;
}

.app {
  position: relative;
  width: min(100%, 980px);
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 3vw, 30px);
}

.hud {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}

.stats {
  display: flex;
  gap: 8px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}

.theme-toggle:hover {
  border-color: var(--gold-dim);
  transform: translateY(-1px);
}

.theme-toggle:focus-visible {
  border-color: var(--gold);
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.theme-toggle-icon {
  width: 1em;
  color: var(--gold);
  font-size: 16px;
  line-height: 1;
  text-align: center;
}

.stat {
  min-width: 110px;
  padding: 8px 12px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(8px);
}

.stat-label {
  display: block;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  display: block;
  margin-top: 2px;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.mode-value {
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.4;
}

.board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(16px, 3vw, 26px);
  padding: clamp(16px, 3vw, 30px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, var(--surface-top), var(--surface-bottom));
  box-shadow: var(--shadow), inset 0 1px 0 var(--surface-highlight);
  backdrop-filter: blur(10px);
}

.eyebrow {
  margin: 0 0 10px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--gold);
}

.choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(9px, 2.2vw, 22px);
  width: min(100%, 780px);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: clamp(170px, 34vw, 340px);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  aspect-ratio: 5 / 7;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: clamp(10px, 1.6vw, 16px);
  background: linear-gradient(180deg, #111c2e, #0a1220);
  color: inherit;
  font: inherit;
  text-align: left;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

button.card {
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

button.card:hover:not(:disabled),
button.card:focus-visible {
  transform: translateY(-6px) scale(1.015);
  border-color: var(--gold-dim);
  box-shadow: 0 20px 42px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(245, 196, 81, 0.25);
  outline: none;
}

button.card:disabled {
  cursor: default;
}

.art {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 30% 8%, rgba(255, 255, 255, 0.18), transparent 55%),
    linear-gradient(155deg, var(--c1, #2b3d5c), var(--c2, #0b1424));
}

.glyph {
  font-size: clamp(34px, 6.4vw, 66px);
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.45));
  transform: translateY(-2%);
}

.art img {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card.has-image .art img {
  display: block;
}

.card.has-image .glyph {
  display: none;
}

.shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.2) 48%, transparent 60%);
  transform: translateX(-120%);
  transition: transform 0.6s ease;
  pointer-events: none;
}

button.card:hover .shine {
  transform: translateX(120%);
}

.card .meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: clamp(7px, 1.2vw, 12px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(4, 8, 15, 0.78);
}

.card .name {
  overflow: hidden;
  font-size: clamp(10px, 1.55vw, 14px);
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.card .tags {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: clamp(8px, 1.15vw, 11px);
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.card .power {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(245, 196, 81, 0.14);
  color: var(--gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.card.image-card {
  display: block;
  padding: 0;
  background: #0a1220;
}

.card.image-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card.image-error {
  background: repeating-linear-gradient(135deg, #111c2e 0 12px, #0a1220 12px 24px);
}

.choices .card {
  animation: deal 0.4s cubic-bezier(0.2, 0.7, 0.3, 1.1) backwards;
}

.choices .card:nth-child(2) {
  animation-delay: 0.05s;
}

.choices .card:nth-child(3) {
  animation-delay: 0.1s;
}

.card.correct {
  border-color: var(--good);
  box-shadow: 0 0 0 2px rgba(61, 220, 132, 0.4), 0 0 40px rgba(61, 220, 132, 0.28);
  animation: pop 0.45s ease;
}

.card.wrong {
  border-color: var(--bad);
  box-shadow: 0 0 0 2px rgba(255, 93, 108, 0.4), 0 0 34px rgba(255, 93, 108, 0.22);
  animation: shake 0.42s ease;
}

.card.dim {
  opacity: 0.42;
  filter: saturate(0.55);
}

.feedback {
  margin: 0;
  min-height: 22px;
  font-size: clamp(13px, 1.8vw, 16px);
  font-weight: 600;
  text-align: center;
}

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

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

.incorrect-log {
  margin: 0;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  text-align: center;
  overflow-wrap: anywhere;
}

.btn {
  padding: 10px 20px;
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(245, 196, 81, 0.22), rgba(245, 196, 81, 0.08));
  color: var(--gold);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:hover,
.btn:focus-visible {
  background: linear-gradient(180deg, rgba(245, 196, 81, 0.32), rgba(245, 196, 81, 0.14));
  box-shadow: 0 8px 20px rgba(245, 196, 81, 0.18);
  outline: none;
  transform: translateY(-1px);
}

.btn-primary {
  margin-top: 8px;
  padding: 12px 28px;
}

.results {
  padding: clamp(26px, 5vw, 54px) clamp(18px, 4vw, 40px);
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, var(--surface-top), var(--surface-bottom));
  box-shadow: var(--shadow), inset 0 1px 0 var(--surface-highlight);
  animation: deal 0.4s ease;
}

.results-rank {
  margin: 0;
  font-size: clamp(34px, 7vw, 62px);
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #dfb25a, var(--gold) 55%, #7a4d0e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

:root[data-theme="dark"] .results-rank {
  background: linear-gradient(180deg, #f6d98a, var(--gold) 55%, #a8751e);
  -webkit-background-clip: text;
  background-clip: text;
}

.results-score {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.results-score strong {
  color: var(--ink);
  font-size: 26px;
}

.results-detail {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.comparison {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(12px, 3vw, 26px);
  margin: 0 0 18px;
  flex-wrap: wrap;
}

.compare-card {
  margin: 0;
  width: min(42vw, 200px);
}

.compare-card img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.16);
}

.compare-wrong img {
  outline: 3px solid rgba(220, 38, 38, 0.55);
  outline-offset: 2px;
}

.compare-right img {
  outline: 3px solid rgba(21, 128, 61, 0.5);
  outline-offset: 2px;
}

.compare-card figcaption {
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint {
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--kbd-bg);
  font: inherit;
  font-size: 10px;
  text-align: center;
  color: var(--ink);
}

.hidden {
  display: none !important;
}

@keyframes deal {
  from {
    opacity: 0;
    transform: translateY(18px) rotate(-1deg);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.045); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

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

@media (max-width: 560px) {
  .stats {
    width: 100%;
    justify-content: center;
  }

  .stat {
    flex: 1;
    min-width: 0;
  }

  .board {
    padding: 14px 10px 18px;
  }

  .hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
