/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --border:   #2a2d3a;
  --text:     #e4e4e7;
  --muted:    #71717a;
  --accent:   #6366f1;
  --accent-h: #818cf8;
  --green:    #22c55e;
  --red:      #ef4444;
  --yellow:   #eab308;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  /* Add padding bottom to ensure content isn't hidden behind the floating keyboard */
  padding-bottom: 240px; 
}

.container {
  max-width: 1050px;
  margin: 0 auto;
  padding: 1rem;
}

/* ── Flash messages ──────────────────────────────────────────── */
.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.flash.error   { background: #3b1219; color: #fca5a5; border: 1px solid #7f1d1d; }
.flash.success { background: #052e16; color: #86efac; border: 1px solid #14532d; }

/* ── Auth card ───────────────────────────────────────────────── */
.auth-card {
  max-width: 380px;
  margin: 6rem auto;
  background: var(--surface);
  padding: 2.5rem 2rem;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.auth-card h1 {
  font-size: 1.6rem;
  text-align: center;
  margin-bottom: 0.25rem;
}
.auth-card h2 {
  font-size: 1rem;
  color: var(--muted);
  text-align: center;
  margin-bottom: 1.5rem;
  font-weight: 400;
}
.auth-card label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.auth-card input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.auth-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.auth-card button {
  width: 100%;
  padding: 0.7rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}
.auth-card button:hover { background: var(--accent-h); }
.switch { text-align: center; margin-top: 1rem; font-size: 0.85rem; color: var(--muted); }
.switch a { color: var(--accent-h); text-decoration: none; }

/* ── Header ──────────────────────────────────────────────────── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
header h1 { font-size: 1.4rem; }
.header-right { display: flex; align-items: center; gap: 0.5rem; }
.user-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  border: 1px solid var(--border);
  transition: background 0.15s;
}
.btn:hover { background: var(--border); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-outline { background: transparent; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }

/* ── Game bar ────────────────────────────────────────────────── */
.game-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.timer {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-h);
}
.game-actions { display: flex; gap: 0.5rem; }

/* ── Puzzle area ─────────────────────────────────────────────── */
.puzzle-area {
  min-height: 200px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0;
  align-items: flex-end;
  margin-bottom: 1rem;
}
.placeholder-msg { color: var(--muted); font-size: 1.1rem; margin: auto; }

/* A "word" keeps letters together */
.word {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  margin-right: 1.8rem;
  margin-bottom: 0.6rem;
}

/* Each cell = encoded letter on top, guess on bottom */
.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 2.8rem;
  cursor: pointer;
  /* Prevent default context menu (long press) */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.cell.sibling .guess-box {
  border-color: var(--accent);
  background: #6366f120;
}
.cell.selected .guess-box {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}
.encoded-letter {
  font-size: 1.6rem;
  color: var(--text);
  height: 1.8rem;
  line-height: 1.8rem;
  font-family: monospace;
  font-weight: 700;
  text-transform: uppercase;
}
.guess-box {
  width: 2.6rem;
  height: 2.8rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: #ffffff;
  text-transform: uppercase;
  background: var(--surface);
  transition: border-color 0.15s, background 0.15s;
}
.cell.correct .guess-box {
  border-color: var(--green);
  color: var(--green);
  background: #052e1680;
}
.cell.hint .guess-box {
  border-color: var(--yellow);
  color: var(--yellow);
  background: #42350a80;
}

/* Punctuation / spaces */
.punct {
  display: inline-flex;
  align-items: flex-end;
}
.punct span {
  height: 2.8rem;
  display: flex;
  align-items: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: #ffffff;
  padding: 0 2px;
}

/* Author line */
.author-line {
  text-align: right;
  font-style: italic;
  color: var(--muted);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}
.hidden { display: none !important; }

/* ── Virtual keyboard ────────────────────────────────────────── */
.keyboard {
  /* Floating keyboard styling */
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1rem 0 2rem; /* extra padding at bottom for safe area on phones */
  z-index: 50;
  
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
}
.kb-row {
  display: flex;
  gap: 0.3rem;
  justify-content: center;
  width: 100%;
}
.keyboard button {
  width: 2.6rem;
  height: 2.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg); /* slight contrast against surface */
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, opacity 0.2s;
  /* Disable touch selection/highlighting on mobile */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.keyboard button:active { background: var(--accent); color: white; }
.keyboard button:hover { background: var(--border); }
.keyboard button.used {
  opacity: 0.25;
  /* pointer-events: none; REMOVED to allow long press */
}
.key-wide { width: 4.5rem; font-size: 1.2rem; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: #000000aa;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  max-width: 480px;
  width: 90%;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
}
.win-content { text-align: center; }
.win-content h2 { color: var(--green); font-size: 1.8rem; margin-bottom: 0.5rem; }
.win-content blockquote {
  font-style: italic;
  margin: 1rem 0;
  padding: 0.75rem;
  border-left: 3px solid var(--accent);
  text-align: left;
  color: var(--text);
}
.win-content .author { color: var(--muted); margin-bottom: 1.5rem; }

/* Stats */
#stats-body table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
#stats-body th, #stats-body td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
#stats-body th { color: var(--muted); font-weight: 600; }
.stat-number { font-size: 2rem; font-weight: 700; color: var(--accent-h); }
.stat-label  { font-size: 0.8rem; color: var(--muted); }
.stat-row { display: flex; gap: 2rem; margin-bottom: 1rem; }
#stats-body tr.no-hints { background: #052e1640; color: var(--green); }

/* ── Victory banner ─────────────────────────────────────────── */
.victory-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  text-align: center;
  padding: 1rem;
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  background: var(--green);
  animation: banner-flash 3s ease-out forwards;
}
@keyframes banner-flash {
  0%   { opacity: 0; transform: translateY(-100%); }
  10%  { opacity: 1; transform: translateY(0); }
  70%  { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-100%); }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  .container { padding: 0.5rem; }
  .puzzle-area { margin-bottom: 0; /* content scrolls behind keyboard */ }
  .cell { width: 1.8rem; }
  .guess-box { width: 1.6rem; height: 1.8rem; font-size: 1rem; }
  .encoded-letter { font-size: 0.7rem; height: 1.2rem; line-height: 1.2rem; }
  
  /* Make keyboard keys slightly smaller on very narrow screens */
  .keyboard button { width: 1.8rem; height: 2.4rem; font-size: 0.9rem; padding: 0; }
  .key-wide { width: 3rem; }
  .kb-row { gap: 0.2rem; }
  
  .word { margin-right: 0.8rem; margin-bottom: 0.4rem; }
  
  /* Win modal adjustments */
  .modal-content { padding: 1.5rem 1rem; }
}
