/* ==========================================================================
   styles.css — Connections GCSE revision game
   Mobile-first, no external dependencies.
   ========================================================================== */

:root {
  /* Difficulty colours (WCAG AA against the dark text used on them) */
  --c-d1: #f9df6d; /* yellow  — easiest */
  --c-d2: #a0c35a; /* green   */
  --c-d3: #b0c4ef; /* blue    */
  --c-d4: #ba81c5; /* purple  — hardest */

  --tile-bg: #efefe6;
  --tile-bg-active: #5a594e;
  --tile-text: #121212;
  --tile-text-active: #ffffff;

  --page-bg: #ffffff;
  --ink: #121212;
  --muted: #5a594e;
  --border: #d2d2c8;

  --radius: 8px;
  --gap: 8px;
  --tile-h: clamp(56px, 17vw, 80px);
}

* { box-sizing: border-box; }

/* The [hidden] attribute must win over explicit display rules below. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  background: var(--page-bg);
  color: var(--ink);
  line-height: 1.4;
  /* Scales with browser zoom; rem-based sizing throughout */
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 12px 48px;
}

/* ---- Header ---- */
.app__header { text-align: center; border-bottom: 2px solid var(--ink); padding-bottom: 8px; }
.app__title {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.app__subtitle { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }

/* ---- Pickers ---- */
.pickers {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 16px 0;
}
.picker { display: flex; flex-direction: column; gap: 4px; flex: 1 1 160px; }
.picker__label { font-size: 0.78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.picker__select {
  font-size: 1rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}
.picker__select:focus-visible { outline: 3px solid #1e6fff; outline-offset: 1px; }

/* ---- Instruction & messages ---- */
.instruction { text-align: center; margin: 4px 0; font-size: 1rem; }
.message {
  min-height: 1.6em;
  text-align: center;
  font-weight: 700;
  margin: 4px 0 12px;
}
.message__pill {
  display: inline-block;
  background: var(--ink);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.95rem;
  animation: pop 0.18s ease-out;
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---- Solved groups ---- */
.solved { display: flex; flex-direction: column; gap: var(--gap); margin-bottom: var(--gap); }
.solved__row {
  border-radius: var(--radius);
  padding: 10px 12px;
  text-align: center;
  color: #121212;
  animation: rise 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.solved__row[data-difficulty="1"] { background: var(--c-d1); }
.solved__row[data-difficulty="2"] { background: var(--c-d2); }
.solved__row[data-difficulty="3"] { background: var(--c-d3); }
.solved__row[data-difficulty="4"] { background: var(--c-d4); }

.solved__meta { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; display: flex; align-items: center; justify-content: center; gap: 6px; }
/* A distinct symbol per difficulty so colour is never the only cue */
.solved__symbol { font-family: monospace; font-weight: 700; }
.solved__category { font-size: 1.02rem; font-weight: 800; margin-top: 2px; }
.solved__members { font-size: 0.95rem; margin-top: 2px; }

@keyframes rise {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ---- Board ---- */
.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}
.tile {
  position: relative;
  min-height: var(--tile-h);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px;
  border: none;
  border-radius: var(--radius);
  background: var(--tile-bg);
  color: var(--tile-text);
  font-weight: 700;
  font-size: clamp(0.62rem, 3.4vw, 1.05rem);
  line-height: 1.05;
  text-transform: uppercase;
  cursor: pointer;
  overflow: hidden;
  word-break: break-word;
  hyphens: auto;
  transition: transform 0.08s ease, background 0.12s ease, color 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.tile:hover { transform: translateY(-1px); }
.tile:active { transform: scale(0.97); }
.tile:focus-visible { outline: 3px solid #1e6fff; outline-offset: 2px; }

.tile[aria-pressed="true"] {
  background: var(--tile-bg-active);
  color: var(--tile-text-active);
  transform: scale(0.96);
}

/* Long single words: allow the engine to add a class that shrinks text more */
.tile--long { font-size: clamp(0.5rem, 2.8vw, 0.85rem); }

.tile--shake { animation: shake 0.4s ease; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

.tile--correct { animation: bounce 0.4s ease; }
@keyframes bounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ---- Mistakes ---- */
.mistakes {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 16px 0;
  font-size: 0.95rem;
  color: var(--muted);
}
.mistakes__dots { display: flex; gap: 8px; }
.dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.2s ease, transform 0.2s ease;
}
.dot--spent { background: var(--border); transform: scale(0.8); }

/* ---- Controls ---- */
.controls { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn {
  font-size: 1rem;
  font-weight: 700;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}
.btn:hover:not(:disabled) { background: #f0f0f0; }
.btn:focus-visible { outline: 3px solid #1e6fff; outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn--primary { background: var(--ink); color: #fff; }
.btn--primary:hover:not(:disabled) { background: #333; }

/* ---- Endgame ---- */
.endgame {
  margin-top: 24px;
  padding: 18px 14px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  text-align: center;
}
.endgame__heading { margin: 0 0 12px; font-size: 1.4rem; }
.endgame__grid { display: flex; flex-direction: column; gap: 4px; align-items: center; margin-bottom: 16px; }
.endgame__row { display: flex; gap: 4px; }
.sq {
  width: 28px; height: 28px;
  border-radius: 5px;
}
.sq[data-difficulty="1"] { background: var(--c-d1); }
.sq[data-difficulty="2"] { background: var(--c-d2); }
.sq[data-difficulty="3"] { background: var(--c-d3); }
.sq[data-difficulty="4"] { background: var(--c-d4); }
.endgame__buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---- Utility ---- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* Slightly larger tiles on bigger screens */
@media (min-width: 480px) {
  :root { --gap: 10px; }
}
