/* =========================================
   WHAT THE FURDLE — Styles
   Dark, irreverent, punk-meets-modern
   ========================================= */

:root {
  --bg: #0d0d0d;
  --bg-card: #161616;
  --bg-key: #2a2a2a;
  --bg-key-hover: #3a3a3a;
  --text: #f0ece2;
  --text-dim: #777;
  --accent: #ff3c5f;
  --accent-glow: rgba(255, 60, 95, 0.3);
  --green: #3ddc84;
  --green-bg: #1b7a42;
  --yellow: #ffd93d;
  --yellow-bg: #8a7a1a;
  --gray: #3a3a3a;
  --gray-text: #666;
  --border: #333;
  --tile-size: 58px;
  --tile-gap: 6px;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --radius: 8px;
  --radius-lg: 16px;
}

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

html {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-display);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* Scanline overlay */
body::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.03) 2px,
    rgba(0,0,0,0.03) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* ---- HEADER ---- */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left, .header-right { width: 48px; display: flex; }
.header-right { justify-content: flex-end; }

.header-center h1 {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 1.3rem;
  letter-spacing: 3px;
  text-align: center;
  white-space: nowrap;
}

.header-center .accent {
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
}

.icon-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.icon-btn:hover {
  background: var(--bg-key);
  border-color: var(--accent);
}

/* ---- GAME AREA ---- */
#game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  overflow-x: hidden;
}

#puzzle-number {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  padding: 8px 0 4px;
  letter-spacing: 2px;
  flex-shrink: 0;
}

/* ---- BOARD ---- */
#board-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 4px 0;
}

#board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile-size));
  grid-template-columns: repeat(5, var(--tile-size));
  gap: var(--tile-gap);
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  border: 2px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.6rem;
  text-transform: uppercase;
  transition: transform 0.1s;
  color: var(--text);
  background: transparent;
}

.tile.active {
  border-color: var(--text-dim);
}

.tile.filled {
  border-color: var(--text);
  animation: pop 0.1s ease;
}

.tile.correct {
  background: var(--green-bg);
  border-color: var(--green);
  color: #fff;
}
.tile.present {
  background: var(--yellow-bg);
  border-color: var(--yellow);
  color: #fff;
}
.tile.absent {
  background: var(--gray);
  border-color: var(--gray);
  color: var(--gray-text);
}

.tile.flip {
  animation: flip 0.5s ease forwards;
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes flip {
  0% { transform: rotateX(0deg); }
  45% { transform: rotateX(90deg); }
  55% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.row-shake .tile {
  animation: shake 0.4s ease;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-20px); }
  70% { transform: translateY(-8px); }
}

.tile.win-bounce {
  animation: bounce 0.6s ease;
}

/* ---- KEYBOARD ---- */
#keyboard {
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.keyboard-row {
  display: flex;
  gap: 5px;
}

.key {
  height: 52px;
  min-width: 30px;
  padding: 0 8px;
  border: none;
  border-radius: 6px;
  background: var(--bg-key);
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.key:hover { background: var(--bg-key-hover); }

.key.wide {
  min-width: 55px;
  font-size: 0.7rem;
  letter-spacing: 1px;
}

.key.correct {
  background: var(--green-bg);
  color: #fff;
}
.key.present {
  background: var(--yellow-bg);
  color: #fff;
}
.key.absent {
  background: #1a1a1a;
  color: #444;
}

/* ---- RESULT CARD ---- */
#result-card {
  width: 100%;
  max-width: 500px;
  padding: 0 16px 120px;
  animation: slideUp 0.5s ease;
}

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

.result-inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
}

.result-emoji {
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: 8px;
}

.result-word {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 6px;
  color: var(--accent);
  text-shadow: 0 0 30px var(--accent-glow);
}

.result-lang {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  margin: 4px 0 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.result-def {
  font-size: 1rem;
  text-align: center;
  margin-bottom: 6px;
  line-height: 1.5;
}

.result-synonyms {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 16px;
}

.result-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.result-sentence {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text);
  text-align: center;
  font-style: italic;
  padding: 12px 8px;
  border-left: 3px solid var(--accent);
  background: rgba(255, 60, 95, 0.05);
  border-radius: 0 var(--radius) var(--radius) 0;
  margin-bottom: 16px;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
}

.btn-primary {
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}
.btn-primary:hover {
  background: #e0324f;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-secondary {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover {
  border-color: var(--accent);
  background: rgba(255, 60, 95, 0.08);
}

.share-toast {
  text-align: center;
  font-size: 0.8rem;
  color: var(--green);
  margin-top: 8px;
  transition: opacity 0.3s;
}

/* ---- LEADERBOARD SUBMIT ---- */
.lb-submit-section {
  margin-top: 16px;
}

.lb-submit-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 10px;
}

.lb-submit-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.lb-submit-form input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.lb-submit-form input:focus {
  border-color: var(--accent);
}

/* ---- USER SENTENCES ---- */
.user-sentences-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.user-sentences-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 12px;
  text-align: center;
}

.sentence-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.sentence-form input,
.sentence-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}

.sentence-form input:focus,
.sentence-form textarea:focus {
  border-color: var(--accent);
}

.sentence-form textarea {
  resize: none;
  height: 70px;
}

.user-sentences-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-sentence-item {
  padding: 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  animation: fadeIn 0.3s ease;
}

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

.user-sentence-item .us-name {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--accent);
  margin-bottom: 4px;
}

.user-sentence-item .us-text {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
  font-style: italic;
}

.user-sentence-item .us-time {
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px; right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); }

#modal-content h2 {
  font-size: 1.2rem;
  font-weight: 900;
  margin-bottom: 16px;
  letter-spacing: 2px;
}

#modal-content p {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-dim);
  margin-bottom: 12px;
}

#modal-content .example-row {
  display: flex;
  gap: 4px;
  margin: 12px 0;
  justify-content: center;
}

#modal-content .example-tile {
  width: 36px; height: 36px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
}

/* ---- LEADERBOARD MODAL ---- */
.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.lb-rank {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-dim);
  width: 24px;
  text-align: center;
}
.lb-row:nth-child(1) .lb-rank { color: #ffd700; }
.lb-row:nth-child(2) .lb-rank { color: #c0c0c0; }
.lb-row:nth-child(3) .lb-rank { color: #cd7f32; }

.lb-name {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 600;
}

.lb-score {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--green);
}

.lb-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 20px;
}

/* ---- TOAST ---- */
#toast-container {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.85rem;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 1.5s forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* ---- UTILITIES ---- */
.hidden { display: none !important; }

/* ---- ARCHIVE BANNER ---- */
.archive-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  background: rgba(255, 60, 95, 0.1);
  border-bottom: 1px solid var(--accent);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  letter-spacing: 1px;
  flex-shrink: 0;
}

.btn-back-today {
  padding: 4px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: transparent;
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-back-today:hover {
  background: var(--accent);
  color: #fff;
}

/* ---- ARCHIVE MODAL LIST ---- */
.archive-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 50vh;
  overflow-y: auto;
  padding-right: 4px;
}

.archive-list::-webkit-scrollbar { width: 4px; }
.archive-list::-webkit-scrollbar-track { background: transparent; }
.archive-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.archive-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  text-align: left;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 0.85rem;
}

.archive-row:hover {
  border-color: var(--accent);
  background: rgba(255, 60, 95, 0.05);
}

.archive-row.archive-completed {
  opacity: 0.7;
}
.archive-row.archive-completed:hover {
  opacity: 1;
}

.archive-num {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text);
  width: 40px;
}

.archive-ago {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.archive-score {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.archive-arrow {
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* ---- RESPONSIVE ---- */
@media (max-height: 700px) {
  :root {
    --tile-size: 50px;
    --tile-gap: 5px;
  }
  .key { height: 46px; }
  #puzzle-number { padding: 4px 0 2px; }
}

@media (max-height: 600px) {
  :root {
    --tile-size: 44px;
    --tile-gap: 4px;
  }
  .tile { font-size: 1.3rem; }
  .key { height: 42px; font-size: 0.75rem; }
}

@media (max-width: 360px) {
  :root {
    --tile-size: 48px;
  }
  .key { min-width: 26px; padding: 0 5px; font-size: 0.75rem; }
  .key.wide { min-width: 44px; font-size: 0.6rem; }
}

/* Scrollbar styling for result area */
#game::-webkit-scrollbar { width: 4px; }
#game::-webkit-scrollbar-track { background: transparent; }
#game::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
