/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Dark theme (default) */
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --key-bg: #475569;
  --key-text: #f1f5f9;
  --tile-border: #475569;
  --modal-bg: #1e293b;
  --accent: #38bdf8;
  --message-bg: #f1f5f9;
  --message-text: #0f172a;
}

body.light {
  --bg: #f8fafc;
  --bg-secondary: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #cbd5e1;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --key-bg: #e2e8f0;
  --key-text: #0f172a;
  --tile-border: #94a3b8;
  --modal-bg: #ffffff;
  --accent: #0284c7;
  --message-bg: #0f172a;
  --message-text: #f8fafc;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  transition: background 0.25s, color 0.25s;
}

body {
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 500px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 8px;
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}

.header-left,
.header-right {
  display: flex;
  gap: 4px;
  width: 90px;
}

.header-right {
  justify-content: flex-end;
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--bg-secondary);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Board ===== */
.board-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 0;
  position: relative;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 350px;
  aspect-ratio: 5 / 6.2;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  border: 2px solid var(--tile-border);
  border-radius: 4px;
  text-transform: uppercase;
  background: transparent;
  color: var(--text);
  transition: transform 0.1s, background 0.3s, border-color 0.3s, color 0.3s;
  user-select: none;
}

.tile.filled {
  border-color: var(--text-muted);
  animation: pop 0.08s ease-in-out;
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: white;
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: #ffffff;
}

.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: white;
}

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

@keyframes pop {
  50% { transform: scale(1.1); }
}

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

/* ===== Message ===== */
.message {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--message-bg);
  color: var(--message-text);
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  z-index: 10;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.message.hidden {
  display: none;
}

/* ===== Keyboard ===== */
.keyboard {
  padding: 8px 0 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.key {
  background: var(--key-bg);
  color: var(--key-text);
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  height: 54px;
  min-width: 28px;
  flex: 1;
  max-width: 43px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.15s, transform 0.1s;
  user-select: none;
}

.key:active {
  transform: scale(0.95);
}

.key.wide {
  max-width: 65px;
  font-size: 0.75rem;
}

.key.correct {
  background: var(--correct);
  color: white;
}

.key.present {
  background: var(--present);
  color: #ffffff;
}

.key.absent {
  background: var(--absent);
  color: white;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--modal-bg);
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
  color: var(--text);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
}

.modal-content h2 {
  margin-bottom: 16px;
  font-size: 1.4rem;
}

.modal-content h3 {
  margin: 20px 0 10px;
  font-size: 1rem;
  color: var(--text-muted);
}

.modal-content p {
  margin-bottom: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.examples {
  margin: 16px 0;
}

.example {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.example .tile {
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.note {
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--accent);
}

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0;
  text-align: center;
}

.stat-num {
  font-size: 1.8rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.guess-dist {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.dist-label {
  width: 12px;
  font-weight: 600;
}

.dist-bar {
  height: 22px;
  background: var(--absent);
  border-radius: 3px;
  min-width: 18px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 6px;
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  transition: width 0.4s ease;
}

.dist-bar.win {
  background: var(--correct);
}

/* Meaning Section */
.meaning-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.meaning-section.hidden {
  display: none;
}

.meaning-box {
  background: var(--bg-secondary);
  border-radius: 10px;
  padding: 14px 16px;
  text-align: center;
}

.meaning-word {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  margin-bottom: 6px;
  color: var(--accent);
}

.meaning-text {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.share-section {
  margin-top: 20px;
  text-align: center;
}

.share-section.hidden {
  display: none;
}

#result-text {
  font-family: monospace;
  white-space: pre;
  background: var(--bg);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text);
}

.btn-primary {
  background: var(--correct);
  color: white;
  border: none;
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary:hover {
  opacity: 0.9;
}

/* ===== Responsive ===== */
@media (max-width: 400px) {
  .tile {
    font-size: 1.5rem;
  }
  .key {
    height: 50px;
    font-size: 0.8rem;
  }
  .logo {
    font-size: 1.3rem;
  }
  .header-left,
  .header-right {
    width: 80px;
  }
}

/* Next Game Timer */
.next-game {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.next-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.next-timer {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: 0.05em;
}

/* ==============================
   AD SLOTS - Mobile Friendly
   ============================== */

.ad-label {
  font-size: 10px;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  text-align: center;
}

.ad-placeholder {
  background: #e5e7eb;
  color: #9ca3af;
  border: 1px dashed #d1d5db;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 500;
  width: 100%;
  min-height: 50px;
}

/* Top Banner */
.ad-top {
  width: 100%;
  max-width: 728px;
  margin: 8px auto 4px;
  padding: 0 8px;
  text-align: center;
  min-height: 50px;
}

.ad-top .ad-placeholder {
  min-height: 50px;
  height: 50px;
}

/* Footer Banner */
.ad-footer {
  width: 100%;
  max-width: 728px;
  margin: 12px auto 4px;
  padding: 0 8px;
  text-align: center;
  min-height: 50px;
}

.ad-footer .ad-placeholder {
  min-height: 50px;
  height: 50px;
}

/* Side Ads - Desktop only */
.ad-side {
  display: none;
  position: fixed;
  top: 80px;
  width: 160px;
  z-index: 50;
  text-align: center;
}

.ad-left {
  left: 12px;
}

.ad-right {
  right: 12px;
}

.ad-side .ad-placeholder {
  min-height: 600px;
  height: 600px;
}

/* Result Modal Ad */
.ad-result {
  margin: 16px auto 8px;
  max-width: 300px;
  text-align: center;
}

.ad-result .ad-placeholder {
  min-height: 250px;
  height: 250px;
}

/* Desktop: Show side ads + bigger top/footer */
@media (min-width: 1100px) {
  .ad-side {
    display: block;
  }

  .ad-top .ad-placeholder,
  .ad-footer .ad-placeholder {
    min-height: 90px;
    height: 90px;
  }

  .app {
    max-width: 500px;
  }
}

/* Large Desktop: wider side ads */
@media (min-width: 1300px) {
  .ad-side {
    width: 300px;
  }

  .ad-left {
    left: 20px;
  }

  .ad-right {
    right: 20px;
  }
}

/* Mobile: keep ads compact */
@media (max-width: 600px) {
  .ad-top,
  .ad-footer {
    margin: 6px auto;
    padding: 0 6px;
  }

  .ad-top .ad-placeholder,
  .ad-footer .ad-placeholder {
    min-height: 50px;
    height: 50px;
    font-size: 12px;
  }

  .ad-result .ad-placeholder {
    min-height: 200px;
    height: 200px;
  }
}
