:root {
  --primary: #2563eb;
  --correct: #16a34a;
  --wrong: #dc2626;
  --selected: #7c3aed;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --group: #0f766e;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 1rem 1rem 3rem;
}

header {
  text-align: center;
  padding: 1.25rem 0 0.75rem;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
}

header p {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.2rem;
  line-height: 1.45;
}

.categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.75rem 0 0.7rem;
}

.cat-btn {
  padding: 0.4rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  transition: all 0.15s;
}

.cat-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.cat-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.categories-secondary .cat-btn.active {
  background: var(--group);
  border-color: var(--group);
}

.toolbar {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.tool-btn {
  padding: 0.4rem 1rem;
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  background: var(--card);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  transition: all 0.15s;
}

.tool-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tool-btn.answer-btn {
  border-color: #d97706;
  color: #d97706;
}

.tool-btn.answer-btn:hover {
  background: #fffbeb;
}

.status {
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.status b {
  color: var(--text);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  max-width: 960px;
  margin: 0 auto;
}

.col-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.3rem;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.tile {
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 0.6rem;
  background: var(--card);
  cursor: pointer;
  font-size: 0.82rem;
  line-height: 1.48;
  transition: border-color 0.12s, background 0.12s, opacity 0.12s;
  user-select: none;
  min-height: 2.9rem;
  text-align: left;
}

.tile:hover:not(.matched):not(.flashing) {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.tile.selected {
  border-color: var(--selected);
  background: #f5f3ff;
}

.tile.matched {
  border-color: var(--correct);
  background: #f0fdf4;
  color: var(--correct);
  cursor: default;
  opacity: 0.75;
}

.tile.flashing {
  border-color: var(--wrong);
  background: #fef2f2;
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.result {
  display: none;
  text-align: center;
  max-width: 420px;
  margin: 1.5rem auto 0;
  padding: 1.75rem 1.5rem;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 1.25rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.07);
}

.result.show {
  display: block;
}

.result .big {
  font-size: 3.5rem;
  font-weight: 900;
  line-height: 1;
}

.result .big.perfect {
  color: var(--correct);
}

.result .big.good {
  color: #d97706;
}

.result .big.bad {
  color: var(--wrong);
}

.result p {
  color: var(--muted);
  margin: 0.6rem 0 1.25rem;
  font-size: 0.9rem;
  line-height: 1.55;
}

.result button {
  padding: 0.65rem 1.5rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 0.6rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  transition: background 0.15s;
}

.result button:hover {
  background: #1d4ed8;
}

#answerView {
  max-width: 960px;
  margin: 0 auto;
}

.answer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.answer-table th {
  background: var(--primary);
  color: #fff;
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}

.answer-table th:first-child {
  border-radius: 0.5rem 0 0 0;
}

.answer-table th:last-child {
  border-radius: 0 0.5rem 0 0;
}

.answer-table td {
  padding: 0.58rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.48;
  background: var(--card);
}

.answer-table tr:nth-child(even) td {
  background: #f8fafc;
}

.answer-table tr:last-child td {
  border-bottom: none;
}

.hidden {
  display: none !important;
}

@media (max-width: 700px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .tile {
    font-size: 0.79rem;
  }

  .toolbar {
    flex-wrap: wrap;
  }
}
