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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --text: #e0e0e0;
  --text-dim: #8888aa;
  --border: #2a2a4a;
  --green: #538d4e;
  --yellow: #b59f3b;
  --grey-fb: #3a3a3c;
  --cell-size: 62px;
  --cell-gap: 6px;
  --radius: 8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 8px 40px;
}

/* ── Header ── */
header {
  text-align: center;
  margin-bottom: 20px;
}

header h1 {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 4px;
  text-transform: uppercase;
  background: linear-gradient(135deg, #e94560, #0f3460, #e94560);
  background-size: 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 4s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

header p.subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 4px;
  letter-spacing: 1px;
}

/* ── Guess counter ── */
#guess-counter {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  letter-spacing: 1px;
}

/* ── Board ── */
#board-wrapper {
  overflow-x: auto;
  width: 100%;
  max-width: 520px;
  -webkit-overflow-scrolling: touch;
}

#board {
  display: grid;
  grid-template-columns: repeat(6, var(--cell-size));
  gap: var(--cell-gap);
  justify-content: center;
  min-width: calc(6 * var(--cell-size) + 5 * var(--cell-gap));
  padding-bottom: 4px;
}

/* Column headers row */
.col-headers {
  display: contents;
}

.col-header {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ── Cells ── */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  position: relative;
  font-size: 0.55rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  user-select: none;
  overflow: hidden;
}

.cell:hover:not(.na):not(.locked) {
  border-color: #6666aa;
  transform: scale(1.04);
}

.cell.na {
  cursor: default;
  border-color: transparent;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 4px,
    rgba(255,255,255,0.03) 4px,
    rgba(255,255,255,0.03) 8px
  );
  opacity: 0.35;
}

.cell.locked {
  cursor: default;
}

.cell.filled {
  border-color: #555577;
}

.result-icon {
  font-size: 1.3rem;
  font-weight: 900;
  color: white;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9), 0 0 6px rgba(0,0,0,0.7);
  pointer-events: none;
}

.cell[data-color="white"] .result-icon,
.cell[data-color="yellow"] .result-icon {
  color: #111;
  text-shadow: 0 1px 3px rgba(255,255,255,0.5);
}

.cell .color-label {
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 2px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  pointer-events: none;
}

/* Feedback states — background comes from inline gradient in JS */
.cell.fb-green  { border-color: var(--green);   color: white; }
.cell.fb-yellow { border-color: var(--yellow);  color: white; }
.cell.fb-grey   { border-color: var(--grey-fb); color: #aaa; }

/* Green carry-forward cells */
.cell.green-carry {
  cursor: default;
  border-color: var(--green);
  opacity: 0.85;
}

/* Cell flip animation */
@keyframes flip-in {
  0%   { transform: rotateX(0deg); }
  50%  { transform: rotateX(-90deg); }
  100% { transform: rotateX(0deg); }
}

.cell.flip {
  animation: flip-in 0.4s ease forwards;
}

/* Current row highlight */
.cell.current-row {
  border-color: var(--surface2);
}

.cell.current-row:not(.filled):not(.na) {
  background: rgba(15, 52, 96, 0.3);
}

/* ── Colour picker popup ── */
#color-picker {
  position: fixed;
  z-index: 100;
  background: #12122a;
  border: 2px solid var(--surface2);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.15s, visibility 0.15s;
  width: 180px;
}

#color-picker.open {
  visibility: visible;
  opacity: 1;
}

.swatch {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  cursor: pointer;
  border: 3px solid transparent;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 3px;
  font-size: 0.5rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  transition: transform 0.1s, border-color 0.1s;
}

.swatch.swatch-hidden {
  display: none;
}

.swatch:hover {
  transform: scale(1.12);
  border-color: rgba(255,255,255,0.6);
}

.swatch.selected {
  border-color: white;
  transform: scale(1.08);
}

/* ── Submit button ── */
#submit-row {
  margin-top: 16px;
  display: flex;
  justify-content: center;
}

#submit-btn {
  background: var(--surface2);
  color: var(--text);
  border: 2px solid #1a5c9a;
  border-radius: 10px;
  padding: 10px 32px;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

#submit-btn:hover:not(:disabled) {
  background: #1a5c9a;
  transform: translateY(-1px);
}

#submit-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ── Banner ── */
#banner {
  display: none;
  margin-top: 20px;
  padding: 20px 24px;
  border-radius: 14px;
  max-width: 500px;
  width: 100%;
  text-align: center;
  animation: pop-in 0.3s ease;
}

@keyframes pop-in {
  from { transform: scale(0.9); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

#banner.win {
  background: #1a3a1a;
  border: 2px solid var(--green);
}

#banner.lose {
  background: #3a1a1a;
  border: 2px solid #8b1a1a;
}

#banner h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

#banner .flag-emoji {
  font-size: 4rem;
  line-height: 1;
  margin: 8px 0 4px;
}

#banner .country-names {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffd700;
  margin-bottom: 12px;
}

#banner .flag-fact {
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.6;
  font-style: italic;
}

#play-again-btn {
  margin-top: 16px;
  background: transparent;
  color: var(--text);
  border: 2px solid #555577;
  border-radius: 8px;
  padding: 8px 24px;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

#play-again-btn:hover {
  background: var(--surface);
  border-color: #8888aa;
}

/* ── Colour swatch CSS custom properties ── */
.swatch[data-color="white"]  { background: #f0f0f0; color: #333; }
.swatch[data-color="black"]  { background: #1c1c1c; color: #aaa; }
.swatch[data-color="red"]    { background: #c0392b; color: #fcc; }
.swatch[data-color="blue"]   { background: #2471a3; color: #cce; }
.swatch[data-color="green"]  { background: #1e8449; color: #cec; }
.swatch[data-color="yellow"] { background: #d4ac0d; color: #333; }
.swatch[data-color="orange"] { background: #d35400; color: #fdd; }
.swatch[data-color="brown"]  { background: #784212; color: #dbb; }
.swatch[data-color="grey"]   { background: #707070; color: #eee; }

/* Cell filled colour backgrounds */
.cell[data-color="white"]  { background: #f0f0f0; color: #333; }
.cell[data-color="black"]  { background: #1c1c1c; color: #aaa; }
.cell[data-color="red"]    { background: #c0392b; color: #fcc; }
.cell[data-color="blue"]   { background: #2471a3; color: #cce; }
.cell[data-color="green"]  { background: #1e8449; color: #cec; }
.cell[data-color="yellow"] { background: #d4ac0d; color: #333; }
.cell[data-color="orange"] { background: #d35400; color: #fdd; }
.cell[data-color="brown"]  { background: #784212; color: #dbb; }
.cell[data-color="grey"]   { background: #707070; color: #eee; }

/* ── Legend ── */
#legend {
  margin-top: 20px;
  display: flex;
  gap: 16px;
  font-size: 0.75rem;
  color: var(--text-dim);
  flex-wrap: wrap;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-symbol {
  font-weight: 900;
  font-size: 1rem;
  color: var(--text);
}

/* ── Responsive ── */
@media (max-width: 430px) {
  :root {
    --cell-size: 50px;
    --cell-gap: 4px;
  }

  header h1 {
    font-size: 1.8rem;
  }

  #board-wrapper {
    max-width: 100%;
  }

  .swatch {
    width: 40px;
    height: 40px;
  }

  #color-picker {
    width: 158px;
  }
}
