*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  background: #fff;
  color: #1a1a1a;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Nav ── */
.nav {
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 48px;
  position: relative;
}
.nav-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.nav-icons { display: flex; gap: 16px; margin-left: auto; align-items: center; }
.nav-icon {
  background: none; border: none; cursor: pointer;
  color: #1a1a1a; padding: 4px; display: flex; align-items: center;
}
.nav-icon svg { width: 22px; height: 22px; }

/* ── Main ── */
.main {
  display: flex; flex-direction: column; align-items: center;
  padding: 20px 12px 40px; flex: 1; gap: 14px;
  width: 100%; overflow-x: hidden;
}
.instructions { font-size: 14px; color: #555; text-align: center; line-height: 1.5; }

/* ── Round label ── */
#round-label {
  font-size: 12px; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: #999; margin-bottom: -6px;
}

/* ── Solved bars ── */
.solved-rows {
  width: 100%; max-width: 560px;
  display: flex; flex-direction: column; gap: 6px;
}
.solved-row {
  border-radius: 8px; padding: 8px 14px;
  display: flex; flex-direction: column; gap: 2px;
  animation: popIn 0.35s ease;
}
.solved-row-top { display: flex; justify-content: space-between; align-items: baseline; }
.solved-row-label  { font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; }
.solved-row-round  { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.55; }
.solved-row-words  { font-size: 13px; font-weight: 700; letter-spacing: 0.02em; line-height: 1.3; }
.solved-row-elim   { font-size: 10px; opacity: 0.5; font-style: italic; margin-top: 1px; }

/* ── Colors ── */
.color-yellow { background: #f9df6d; color: #4a3600; }
.color-orange { background: #f4a234; color: #4a2000; }
.color-red    { background: #e05252; color: #fff; }
.color-purple { background: #6b3fa0; color: #fff; }

/* ── Grid ── */
.grid {
  width: 100%;
  max-width: 560px;
  display: grid;
  gap: 8px;
  /* prevent horizontal overflow on mobile */
  box-sizing: border-box;
  padding: 0 2px;
}
.tile {
  background: #efede3;
  border-radius: 8px;
  height: 90px;
  min-width: 0;           /* allow shrinking below content size */
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: clamp(10px, 2.2vw, 14px);  /* fluid — won't overflow on mobile */
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  border: none;
  color: #1a1a1a;
  padding: 6px 4px;
  line-height: 1.2;
  word-break: break-word;
  transition: background 0.1s, opacity 0.4s, transform 0.15s;
}
/* Smaller tiles when only 4 remain (2×2 final round) */
.grid.round-final .tile {
  height: 64px;
  font-size: clamp(10px, 2vw, 13px);
}
.tile:hover    { background: #dddbc9; }
.tile.selected { background: #5a594e; color: #fff; }
.tile.shake    { animation: shake 0.5s ease; }
.tile.bounce   { animation: bounce 0.6s ease; }
.tile.fade-out { opacity: 0; transform: scale(0.85); pointer-events: none; }
.tile.flip-out { animation: flipOut 0.22s ease forwards; }
.tile.flip-in  { animation: flipIn  0.28s ease forwards; }

/* ── Mistakes ── */
.mistakes-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.mistake-dots { display: flex; gap: 6px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: #5a594e; transition: opacity 0.3s; }
.dot.gone { opacity: 0; }

/* ── Game controls ── */
#game-controls { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.controls { display: flex; gap: 10px; align-items: center; }
.btn {
  background: #fff; border: 1.5px solid #1a1a1a; border-radius: 999px;
  padding: 11px 20px; font-size: 14px; font-family: inherit; font-weight: 600;
  cursor: pointer; color: #1a1a1a; transition: background 0.15s; letter-spacing: 0.02em;
}
.btn:hover    { background: #f5f5f0; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Toast ── */
.toast {
  position: fixed; top: 64px; left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: #1a1a1a; color: #fff; padding: 10px 20px;
  border-radius: 8px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; z-index: 300; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Overlay (shared by help + end screen) ── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.overlay.show { opacity: 1; pointer-events: all; }

.modal {
  background: #fff; border-radius: 16px;
  padding: 32px 28px 28px;
  width: 92%; max-width: 440px;
  max-height: 88vh; overflow-y: auto;
  position: relative;
  transform: translateY(16px);
  transition: transform 0.25s;
}
.overlay.show .modal { transform: translateY(0); }

.modal-close-x {
  position: absolute; top: 14px; right: 16px;
  background: none; border: none; font-size: 22px;
  cursor: pointer; color: #888; line-height: 1;
}
.modal-close-x:hover { color: #1a1a1a; }

.modal-title {
  font-size: 22px; font-weight: 700;
  text-align: center; margin-bottom: 14px;
}

.modal-body {
  font-size: 14px; color: #444; line-height: 1.6;
  text-align: center; margin-bottom: 8px;
}

/* ── How-to-play rounds ── */
.how-rounds { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.how-round  { display: flex; align-items: flex-start; gap: 12px; text-align: left; font-size: 14px; line-height: 1.5; }
.how-dot    { width: 18px; height: 18px; border-radius: 4px; flex-shrink: 0; margin-top: 2px; }

.how-divider { width: 100%; height: 1px; background: #e8e8e8; margin: 16px 0; }

/* ── Stats row (in end modal) ── */
.stats-row {
  display: flex; justify-content: center;
  border-top: 1px solid #e0e0e0; border-bottom: 1px solid #e0e0e0;
  padding: 14px 0; margin-bottom: 16px;
}
.stat-block { flex: 1; text-align: center; padding: 0 6px; border-right: 1px solid #e0e0e0; }
.stat-block:last-child { border-right: none; }
.stat-num   { font-size: 26px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: 10px; color: #666; line-height: 1.3; }

/* ── Guess history squares ── */
#guess-history {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; margin-bottom: 24px; width: 100%;
}
.gh-row { display: flex; gap: 5px; justify-content: center; }
.gh-sq  { width: 34px; height: 26px; border-radius: 4px; }
.gh-wrong { background: #1a1a1a; border: none; }

/* ── Shared modal action button ── */
.btn-modal-action {
  display: block; width: 100%;
  background: #1a1a1a; color: #fff; border: none;
  border-radius: 999px; padding: 15px;
  font-size: 15px; font-weight: 700; font-family: inherit;
  cursor: pointer; letter-spacing: 0.02em;
  transition: background 0.15s; margin-top: 4px;
}
.btn-modal-action:hover { background: #333; }

/* ── Animations ── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); } 30% { transform: translateX(6px); }
  45% { transform: translateX(-5px); } 60% { transform: translateX(5px); }
  75% { transform: translateX(-3px); } 90% { transform: translateX(3px); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  20% { transform: translateY(-12px); } 40% { transform: translateY(0); }
  60% { transform: translateY(-6px); }  80% { transform: translateY(0); }
}
@keyframes popIn {
  0%   { transform: scale(0.94); opacity: 0; }
  100% { transform: scale(1);    opacity: 1; }
}
@keyframes flipOut {
  0%   { transform: rotateY(0deg)   scale(1);    opacity: 1; }
  100% { transform: rotateY(90deg)  scale(0.85); opacity: 0; }
}
@keyframes flipIn {
  0%   { transform: rotateY(-90deg) scale(0.85); opacity: 0; }
  100% { transform: rotateY(0deg)   scale(1);    opacity: 1; }
}