:root {
  --bg: #ffffff;
  --fg: #1a1a1f;
  --muted: #5c5c66;
  --accent: #2b6cff;
  --good: #14a44d;
  --bad: #e5484d;
  --card: rgb(239, 239, 230);
  --border: #e2e2ea;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

.app { max-width: 760px; margin: 0 auto; padding: 16px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 64px; padding: 16px 0; }
.title { font-weight: 700; letter-spacing: 0.4px; display: flex; align-items: baseline; gap: 16px; }
.game-title { font-weight: 900; font-size: 26px; letter-spacing: 0.6px; display: inline-flex; flex-direction: column; line-height: 1.05; }
.game-title .subtitle { font-weight: 700; font-size: 16px; color: var(--muted); margin-top: 2px; }
.date-label { color: var(--muted); font-weight: 600; font-size: 16px; }
.status { display: flex; gap: 12px; align-items: center; color: var(--muted); }
.dots { font-variant-numeric: tabular-nums; letter-spacing: 2px; }
.mistakes-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 30px 0 30px;
  font-size: 14px;
}
.mistakes-label { color: var(--muted); font-weight: 700; font-size: 18px; transition: opacity 200ms ease; }
.mistakes-label.hidden { opacity: 0; }
.mistakes-panel .dots { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 0; line-height: 0; }
.mistakes-dot { width: 16px; height: 16px; display: inline-block; position: relative; }
.mistakes-dot-fill { position: absolute; inset: 0; background: #000000; border-radius: 50%; transform: scale(1); opacity: 1; transition: transform 520ms ease, opacity 520ms ease; will-change: transform, opacity; }
@keyframes dotPop { 0% { transform: scale(0.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.mistakes-dot.appear .mistakes-dot-fill { animation: dotPop 220ms ease-out; }
.mistakes-dot.consumed .mistakes-dot-fill { transform: scale(0); opacity: 0; }

.message { min-height: 24px; margin: 8px 0 12px; color: var(--muted); }
.message:empty { margin: 0; min-height: 0; }
@keyframes winPop { 0% { opacity: 0; transform: scale(0.94); } 100% { opacity: 1; transform: scale(1); } }
.message.win { color: #000000; font-weight: 900; font-size: 28px; letter-spacing: 0.5px; text-align: center; margin: 12px 0 16px; animation: winPop 400ms ease-out; }
.message.lose { color: #000000; font-weight: 900; font-size: 28px; letter-spacing: 0.5px; text-align: center; margin: 12px 0 16px; animation: winPop 400ms ease-out; }
@keyframes msgOneOff {
  0% { opacity: 0; transform: translateY(-8px); }
  12% { opacity: 1; transform: translateY(0); }
  85% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(0); }
}
.message.oneoff { color: #000000; font-weight: 700; text-align: center; animation: msgOneOff 2400ms ease-out forwards; will-change: opacity, transform; }
.instructions { color: var(--muted); font-weight: 600; letter-spacing: 0.2px; margin: 8px 0 16px; text-align: center; font-size: 18px; }

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--grid-gap, 12px);
  position: relative;
}
.solved { display: flex; flex-direction: column; gap: var(--grid-gap, 12px); margin-bottom: 8px; }
.solved-row {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 6px;
  background: color-mix(in oklab, var(--good) 25%, #ffffff);
  color: #000000;
  overflow: hidden;
  text-transform: uppercase;
  text-align: center;
  min-height: var(--tile-h, 0);
  padding: 12px 10px;
}

/* Per-group solved colors */
.solved-row.solved-tier-0 { background: #f7e8a3; } /* soft yellow */
.solved-row.solved-tier-1 { background: #cfead1; } /* soft green */
.solved-row.solved-tier-2 { background: #d5e3fa; } /* soft blue */
.solved-row.solved-tier-3 { background: #ead8f8; } /* soft purple */
.solved-title {
  padding: 6px 10px 2px 10px;
  font-weight: 900;
  letter-spacing: 0.4px;
  text-align: center;
  font-size: 18px;
}

.difficulty-info {
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  margin-left: 8px;
  opacity: 0.8;
}
.solved-words {
  padding: 0 10px 6px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-weight: 600;
  justify-content: center;
  text-align: center;
  font-size: 16px;
  line-height: 1.2;
}
.pill { padding: 0; border: 0; background: transparent; border-radius: 0; }

.info-button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 18px;
  height: 18px;
  min-width: 18px;
  min-height: 18px;
  max-width: 18px;
  max-height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.4);
  background: rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.6);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  opacity: 0.7;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

.info-button:hover {
  background: rgba(0, 0, 0, 0.2);
  color: rgba(0, 0, 0, 0.8);
  opacity: 1;
  transform: scale(1.05);
}

.info-button:active {
  transform: scale(0.95);
}

.info-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: popupFadeIn 0.2s ease-out;
}

.info-popup-content {
  background: white;
  border-radius: 12px;
  padding: 20px;
  max-width: 400px;
  width: 90%;
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  animation: popupSlideIn 0.3s ease-out;
}

.info-popup-close {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 24px;
  font-weight: bold;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

.info-popup-close:hover {
  color: var(--fg);
}

.info-popup-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--fg);
}

.info-popup-difficulty {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--accent);
}

.info-popup-explanation {
  font-size: 14px;
  line-height: 1.4;
  color: var(--fg);
  margin: 0;
}

@keyframes popupFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popupSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes groupReveal {
  0% { opacity: 0; transform: translateY(-6px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.solved-row.reveal { animation: groupReveal 650ms ease-out; }

.cell.fade-out { opacity: 0; transform: scale(0.96); transition: opacity 350ms ease, transform 350ms ease; }
.cell.clone { position: absolute; z-index: 5; pointer-events: none; }
.cell {
  border: none;
  background: var(--card);
  color: var(--fg);
  padding: 28px 14px; /* taller */
  border-radius: 6px; /* tighter corners */
  font-size: 20px;
  font-weight: 600;
  text-transform: uppercase;
  text-align: center;
  word-break: break-word;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.35s ease, color 0.35s ease, box-shadow 0.35s ease;
}
.cell:hover { transform: translateY(-1px); }
.cell.selected { background: #2b2b2b; color: #ffffff; box-shadow: 0 0 0 2px rgba(0,0,0,0.25) inset; }
.cell:disabled { opacity: 0.85; cursor: default; }
.cell.solved { background: color-mix(in oklab, var(--good) 12%, var(--card)); border-color: color-mix(in oklab, var(--good) 32%, var(--border)); }

@keyframes celebratePulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(20,164,77,0.0); }
  30% { transform: scale(1.06); box-shadow: 0 0 0 6px rgba(20,164,77,0.12); }
  60% { transform: scale(1.02); box-shadow: 0 0 0 3px rgba(20,164,77,0.08); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(20,164,77,0.0); }
}
.cell.bounce { animation: submitBounce 520ms ease-out; }
@keyframes submitBounce {
  0% { transform: translateY(0); }
  35% { transform: translateY(-8px); }
  70% { transform: translateY(0); }
  85% { transform: translateY(-3px); }
  100% { transform: translateY(0); }
}
.cell.shake { animation: headShake 650ms ease-in-out; }
@keyframes headShake {
  0% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
  90% { transform: translateX(2px); }
  100% { transform: translateX(0); }
}
.cell.celebrate {
  border-color: var(--good);
  background: color-mix(in oklab, var(--good) 18%, var(--card));
  animation: celebratePulse 550ms ease-out;
}

.controls { display: flex; align-items: center; justify-content: center; margin: 18px 0; }
button {
  background: #ffffff;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: default; }

.primary {
  background: #ffffff;
  color: #000000;
  border: 2px solid #000000;
  padding: 14px 26px;
  border-radius: 28px;
  font-size: 18px;
}

.score { color: var(--muted); margin-top: 8px; }

footer { margin-top: 18px; color: var(--muted); font-size: 12px; }

.splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  font-weight: 900;
  font-size: 22px;
  color: var(--muted);
  text-align: center;
}

.splash-subnote {
  margin-top: 8px;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
}

.debug-panel { border: 1px dashed var(--border); padding: 10px; border-radius: 6px; margin-top: 8px; }

.admin-link {
  display: inline-block;
  padding: 10px 14px;
  margin: 0 4px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.admin-link:hover {
  background: var(--bg-accent);
  border-color: var(--text-secondary);
}
.debug-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.debug-actions { display: flex; gap: 8px; }
.debug-note { margin-top: 6px; color: var(--muted); font-size: 12px; }

/* Responsive tweaks */
@media (max-width: 480px) {
  .app { padding: 12px; }
  .topbar { flex-wrap: wrap; row-gap: 6px; padding: 12px 0; }
  .game-title { font-size: 22px; }
  .date-label { font-size: 14px; }
  .grid { gap: 8px; }
  .cell { padding: 24px 8px; font-size: 12px; border-radius: 4px; }
  .primary { padding: 12px 20px; font-size: 16px; border-radius: 24px; }
  .solved-title { font-size: 16px; }
  .solved-words { font-size: 14px; }
}

@media (max-width: 360px) {
  .cell { font-size: 12px; padding: 16px 6px; }
}

/* Mobile responsiveness for info popup */
@media (max-width: 480px) {
  .info-popup-content {
    margin: 20px;
    padding: 16px;
    max-width: none;
    width: calc(100% - 40px);
  }

  .info-button {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    max-width: 18px;
    max-height: 18px;
    font-size: 10px;
    top: 6px;
    right: 6px;
  }

  .info-popup-title {
    font-size: 16px;
  }

  .info-popup-difficulty {
    font-size: 14px;
  }

  .info-popup-explanation {
    font-size: 13px;
  }
}

