/* ==========================================================================
   TileBox — design tokens
   Palette: warm parchment surface, ink navy text, a mustard-gold accent for
   progress/streaks, and a teal/coral pair borrowed from the tile-feedback
   game mechanic itself (so the "brand colors" are literally the game's
   correct/absent colors, not decoration).
   Type: Fraunces (display serif, a little characterful) for headlines,
   Inter for body/UI, IBM Plex Mono for letter tiles and score readouts —
   monospace here is functional, not a stylistic label tic, since letters
   need fixed width to sit in a grid.
   ========================================================================== */

:root {
  --ink: #22262f;
  --ink-soft: #565b68;
  --paper: #f2eee1;
  --surface: #fffdf7;
  --line: #ddd6c2;

  --gold: #d99e2b;
  --gold-dark: #a97613;
  --teal: #2f8f76;
  --teal-dark: #1f6a56;
  --coral: #d1543f;
  --muted-tile: #c9c2ac;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Menlo, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: var(--font-display);
  color: var(--ink);
  line-height: 1.1;
  margin: 0 0 0.4em;
  font-weight: 600;
}

h1 { font-size: clamp(1.9rem, 4vw, 2.8rem); }
h2 { font-size: clamp(1.4rem, 2.6vw, 1.8rem); }
h3 { font-size: 1.1rem; }

p { margin: 0 0 1em; color: var(--ink-soft); max-width: 62ch; }

button { font-family: inherit; }

a { color: var(--teal-dark); }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------------------------------- Header --------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(242, 238, 225, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--ink);
}

.brand-tiles { display: flex; gap: 2px; }
.brand-tiles span {
  font-family: var(--font-mono);
  font-weight: 700;
  background: var(--teal);
  color: var(--surface);
  width: 1.6rem;
  height: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 0.95rem;
}
.brand-tiles span:nth-child(2) { background: var(--gold); }
.brand-tiles span:nth-child(3) { background: var(--coral); }
.brand-tiles span:nth-child(4) { background: var(--ink); }

.site-nav { display: flex; gap: 0.25rem; flex: 1; }
.site-nav button {
  background: none;
  border: none;
  padding: 0.5rem 0.7rem;
  font-size: 0.92rem;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.site-nav button:hover { background: rgba(0,0,0,0.05); color: var(--ink); }
.site-nav button.active { color: var(--ink); font-weight: 600; background: rgba(217,158,43,0.18); }

.header-right { display: flex; align-items: center; gap: 0.6rem; }

.difficulty-picker { display: flex; align-items: center; gap: 0.35rem; font-size: 0.82rem; color: var(--ink-soft); }
.difficulty-picker select {
  font-family: var(--font-body);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.4rem;
  background: var(--surface);
  color: var(--ink);
}

.streak-pill, .account-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.streak-pill .flame { filter: grayscale(0); }

.nav-toggle { display: none; background: none; border: none; cursor: pointer; padding: 0.4rem; }
.nav-toggle span { display: block; width: 22px; height: 2px; background: var(--ink); margin: 4px 0; }

@media (max-width: 880px) {
  .site-nav { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--surface); flex-direction: column; padding: 0.5rem; border-bottom: 1px solid var(--line); }
  .site-nav.open { display: flex; }
  .site-nav button { text-align: left; }
  .nav-toggle { display: block; }
  .difficulty-picker span { display: none; }
}

/* ---------------------------------- Layout --------------------------------- */

.view { display: none; max-width: 1180px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
.view.active { display: block; }

/* ---------------------------------- Hero --------------------------------- */

.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 2.5rem;
  align-items: center;
  padding: 2rem 0 3rem;
}
.hero-copy p { font-size: 1.05rem; }
.hero-demo { display: flex; justify-content: center; }

.hero-tiles { display: flex; gap: 8px; }
.hero-tiles .htile {
  width: 3.4rem; height: 3.4rem;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 1.5rem;
  color: var(--surface);
  animation: flipIn 0.5s ease both;
}
@keyframes flipIn {
  from { transform: rotateX(90deg); opacity: 0; }
  to { transform: rotateX(0deg); opacity: 1; }
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: var(--radius-sm);
  padding: 0.65rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--ink); color: var(--surface); }
.btn-primary:hover { background: #000; }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-secondary:hover { border-color: var(--ink); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { color: var(--ink); border-color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.link-btn { background: none; border: none; color: var(--teal-dark); font-weight: 600; cursor: pointer; padding: 0; }

@media (max-width: 800px) {
  .hero { grid-template-columns: 1fr; }
  .hero-demo { order: -1; }
}

/* ---------------------------------- Mode grid --------------------------------- */

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 3rem;
}
.mode-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
}
.mode-card.featured {
  grid-column: span 3;
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1.5rem;
  align-items: center;
  background: var(--ink);
  border-color: var(--ink);
}
.mode-card.featured h2, .mode-card.featured p { color: var(--surface); }
.mode-kicker { font-size: 0.85rem; color: var(--gold); font-weight: 600; margin: 0 0 0.2rem; }
.mode-card-preview { display: flex; justify-content: center; gap: 5px; }
.mode-card-preview .ptile {
  width: 2.2rem; height: 2.2rem; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; color: var(--surface);
}

@media (max-width: 880px) {
  .mode-grid { grid-template-columns: 1fr; }
  .mode-card.featured { grid-column: span 1; grid-template-columns: 1fr; text-align: left; }
}

/* ---------------------------------- Progress panel --------------------------------- */

.progress-panel { margin-bottom: 3rem; }
.progress-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
.progress-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 1rem;
}
.progress-label { display: block; font-size: 0.8rem; color: var(--ink-soft); margin-bottom: 0.3rem; }
.progress-value { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700; }
.progress-sub { font-size: 0.78rem; color: var(--ink-soft); }
.xp-bar { background: var(--line); border-radius: 999px; height: 8px; margin: 0.4rem 0; overflow: hidden; }
.xp-bar-fill { background: var(--gold); height: 100%; width: 0%; transition: width 0.3s ease; }

@media (max-width: 800px) { .progress-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---------------------------------- Leaderboard --------------------------------- */

.section-heading-row { display: flex; justify-content: space-between; align-items: baseline; }
.leaderboard-list { list-style: none; margin: 1rem 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.leaderboard-list li {
  display: flex; align-items: center; gap: 0.8rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 0.6rem 1rem;
}
.leaderboard-list li.is-you { border-color: var(--gold); background: #fbf3de; }
.lb-rank { font-family: var(--font-mono); font-weight: 700; width: 1.6rem; color: var(--ink-soft); }
.lb-name { flex: 1; font-weight: 600; }
.lb-score { font-family: var(--font-mono); color: var(--teal-dark); font-weight: 700; }

/* ---------------------------------- Ads --------------------------------- */

.ad-slot {
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.8rem;
  margin: 2rem 0;
  background: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(0,0,0,0.02) 10px, rgba(0,0,0,0.02) 20px);
}

/* ---------------------------------- SEO copy blocks --------------------------------- */

.seo-copy { margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--line); }

/* ---------------------------------- Game shared --------------------------------- */

.game-header { margin-bottom: 1.2rem; }
.game-sub { font-size: 1rem; }
.game-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; font-size: 0.9rem; color: var(--ink-soft); flex-wrap: wrap; gap: 0.6rem;
}
.game-actions { display: flex; gap: 0.6rem; margin: 1rem 0; flex-wrap: wrap; }
.game-message { min-height: 1.4em; font-weight: 600; }

/* ---------------------------------- Daily Word --------------------------------- */

.daily-board { display: flex; flex-direction: column; gap: 6px; margin-bottom: 1.2rem; }
.daily-row { display: flex; gap: 6px; justify-content: center; }
.tile {
  width: 3rem; height: 3rem;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 1.35rem;
  background: var(--surface);
  text-transform: uppercase;
}
.tile.filled { border-color: var(--ink-soft); }
.tile.correct { background: var(--teal); border-color: var(--teal); color: var(--surface); }
.tile.present { background: var(--gold); border-color: var(--gold-dark); color: var(--surface); }
.tile.absent { background: var(--muted-tile); border-color: var(--muted-tile); color: var(--surface); }

.keyboard { display: flex; flex-direction: column; gap: 6px; align-items: center; margin-top: 1rem; }
.keyboard-row { display: flex; gap: 5px; }
.key {
  min-width: 2.1rem;
  height: 2.6rem;
  padding: 0 0.4rem;
  border: none;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 600;
  font-family: var(--font-mono);
  cursor: pointer;
  text-transform: uppercase;
  font-size: 0.85rem;
}
.key.wide { min-width: 3.6rem; font-family: var(--font-body); font-size: 0.75rem; }
.key.correct { background: var(--teal); color: var(--surface); border-color: var(--teal); }
.key.present { background: var(--gold); color: var(--surface); border-color: var(--gold-dark); }
.key.absent { background: var(--muted-tile); color: var(--surface); border-color: var(--muted-tile); }

/* ---------------------------------- Unscramble --------------------------------- */

.letter-slots, .letter-pool { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 1.2rem; }
.letter-slot {
  width: 3rem; height: 3rem; border-bottom: 3px solid var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 1.35rem; text-transform: uppercase;
}
.letter-tile {
  width: 3rem; height: 3rem; border-radius: var(--radius-sm);
  border: 2px solid var(--line); background: var(--surface);
  font-family: var(--font-mono); font-weight: 700; font-size: 1.35rem; text-transform: uppercase;
  cursor: pointer;
}
.letter-tile:hover { border-color: var(--ink); }
.letter-tile.used { visibility: hidden; }

.shake { animation: shake 0.35s ease; }
@keyframes shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-6px);} 75%{transform:translateX(6px);} }

/* ---------------------------------- Word Connect --------------------------------- */

.connect-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
.connect-board { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.connect-current {
  min-height: 2.4rem; font-family: var(--font-mono); font-weight: 700; font-size: 1.4rem;
  letter-spacing: 2px; text-transform: uppercase;
}
.connect-letters {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 260px;
}
.connect-letter {
  width: 3.2rem; height: 3.2rem; border-radius: 50%;
  background: var(--ink); color: var(--surface); border: none;
  font-family: var(--font-mono); font-weight: 700; font-size: 1.3rem; cursor: pointer;
  text-transform: uppercase;
}
.connect-letter.active { background: var(--gold); }
.connect-found-list { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 8px; }
.connect-blank {
  min-width: 3rem; padding: 0.4rem 0.6rem; text-align: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-weight: 700; background: var(--surface);
  text-transform: uppercase; color: var(--ink-soft); letter-spacing: 2px;
}
.connect-blank.found { color: var(--teal-dark); background: #eaf5f0; border-color: var(--teal); }

@media (max-width: 800px) { .connect-layout { grid-template-columns: 1fr; } }

/* ---------------------------------- Word Search --------------------------------- */

.search-layout { display: grid; grid-template-columns: 1fr 280px; gap: 2rem; align-items: start; }
.search-grid {
  display: grid;
  gap: 2px;
  background: var(--line);
  border: 1px solid var(--line);
  width: fit-content;
  user-select: none;
  touch-action: none;
}
.search-cell {
  width: 2.1rem; height: 2.1rem;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 1rem;
  cursor: pointer; text-transform: uppercase;
}
.search-cell.selecting { background: #fbf3de; }
.search-cell.found { background: var(--teal); color: var(--surface); }
.search-cell.hinted { background: var(--gold); color: var(--surface); }

.search-wordlist { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.search-wordlist li { font-family: var(--font-mono); font-weight: 600; }
.search-wordlist li.found { text-decoration: line-through; color: var(--ink-soft); }

@media (max-width: 880px) {
  .search-layout { grid-template-columns: 1fr; }
  .search-grid { margin: 0 auto; }
}

/* ---------------------------------- Stats --------------------------------- */

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stats-grid .progress-stat { background: var(--surface); }

.achievements-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.achievement {
  border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: 1rem; background: var(--surface);
}
.achievement.locked { opacity: 0.45; }
.achievement h3 { margin-bottom: 0.2rem; font-size: 1rem; }
.achievement p { margin: 0; font-size: 0.85rem; }

/* ---------------------------------- Toast --------------------------------- */

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%) translateY(120%);
  background: var(--ink); color: var(--surface); padding: 0.7rem 1.2rem;
  border-radius: var(--radius-md); font-size: 0.9rem; z-index: 100;
  transition: transform 0.25s ease; max-width: 90vw; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.share-fallback {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.share-fallback[hidden] { display: none; }
.share-fallback-box { background: var(--surface); padding: 1.5rem; border-radius: var(--radius-md); width: min(90vw, 420px); }
.share-fallback-box textarea { width: 100%; height: 100px; margin-bottom: 1rem; font-family: var(--font-mono); }

/* ---------------------------------- Footer --------------------------------- */

.site-footer { max-width: 1180px; margin: 0 auto; padding: 1rem 1.25rem 3rem; color: var(--ink-soft); font-size: 0.85rem; }
