/* Streakle — styles. Mobile-first, responsive, light/dark themes. */

:root {
  --bg: #ffffff;
  --fg: #1a1a1b;
  --muted: #787c7e;
  --border: #d3d6da;
  --border-strong: #878a8c;
  --key-bg: #d3d6da;
  --key-fg: #1a1a1b;
  --tile-empty-border: #d3d6da;
  --tile-active-border: #878a8c;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --modal-bg: #ffffff;
  --backdrop: rgba(0, 0, 0, 0.5);
  --ad-bg: #f4f4f4;
  --accent: #6aaa64;
}

html[data-theme="dark"] {
  --bg: #121213;
  --fg: #ffffff;
  --muted: #818384;
  --border: #3a3a3c;
  --border-strong: #565758;
  --key-bg: #818384;
  --key-fg: #ffffff;
  --tile-empty-border: #3a3a3c;
  --tile-active-border: #565758;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --modal-bg: #1e1e1f;
  --backdrop: rgba(0, 0, 0, 0.7);
  --ad-bg: #1e1e1f;
  --accent: #538d4e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 800;
  font-size: clamp(22px, 6vw, 30px);
  letter-spacing: 0.12em;
  margin: 0;
  text-align: center;
  flex: 1;
}
.topbar-right { display: flex; gap: 4px; }
.icon-btn {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 20px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--ad-bg); }
#helpBtn { font-weight: 700; border: 2px solid var(--border-strong); font-size: 16px; }

/* ---------- Ad slots ---------- */
.ad-slot {
  background: var(--ad-bg);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 1px dashed var(--border);
  margin: 6px 12px;
  border-radius: 6px;
  min-height: 50px;
  flex-shrink: 0;
}
.ad-slot span { opacity: 0.6; }

/* ---------- Board ---------- */
main {
  flex: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 4px;
}
.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  padding: 6px;
  width: min(330px, 88vw);
  aspect-ratio: 5 / 6;
}
.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}
.tile {
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: clamp(20px, 7vw, 32px);
  text-transform: uppercase;
  border: 2px solid var(--tile-empty-border);
  color: var(--fg);
  user-select: none;
  aspect-ratio: 1;
}
.tile.filled { border-color: var(--tile-active-border); animation: pop 100ms ease; }
.tile.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.tile.present { background: var(--present); border-color: var(--present); color: #fff; }
.tile.absent  { background: var(--absent);  border-color: var(--absent);  color: #fff; }

.tile.reveal { animation: flip 500ms ease forwards; }
.row.shake { animation: shake 500ms; }
.row.win .tile { animation: bounce 600ms; }

@keyframes pop { from { transform: scale(0.9); } to { transform: scale(1); } }
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-6px); }
  40%,80% { transform: translateX(6px); }
}
@keyframes bounce {
  0%,100% { transform: translateY(0); }
  40% { transform: translateY(-18px); }
  60% { transform: translateY(-8px); }
}

/* ---------- Keyboard ---------- */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 6px max(8px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1;
  min-width: 0;
  height: 52px;
  border: none;
  border-radius: 4px;
  background: var(--key-bg);
  color: var(--key-fg);
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 120ms;
}
.key.wide { flex: 1.5; font-size: 11px; }
.key:active { opacity: 0.7; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent  { background: var(--absent);  color: #fff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms;
  z-index: 100;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--modal-bg);
  color: var(--fg);
  border-radius: 12px;
  padding: 24px;
  width: min(420px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
}
.modal h2 { margin: 0 0 12px; text-align: center; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 26px;
  color: var(--fg);
  cursor: pointer;
  line-height: 1;
}
.rules { padding-left: 18px; }
.muted { color: var(--muted); font-size: 14px; }
.examples .ex-row { display: flex; gap: 4px; margin: 12px 0 4px; }
.tile.sm { width: 36px; height: 36px; font-size: 18px; border-width: 2px; aspect-ratio: auto; }

/* ---------- Stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  text-align: center;
  margin-bottom: 16px;
}
.stat-num { font-size: 30px; font-weight: 700; display: block; }
.stat-label { font-size: 11px; line-height: 1.1; display: block; }
.dist { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 18px; }
.dist-row { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.dist-label { width: 12px; text-align: right; }
.dist-bar {
  background: var(--absent);
  color: #fff;
  text-align: right;
  padding: 2px 6px;
  min-width: 22px;
  font-weight: 700;
  border-radius: 2px;
}
.dist-bar.current { background: var(--correct); }

.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.countdown-wrap { display: flex; flex-direction: column; text-align: center; }
.countdown { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.share-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 14px 28px;
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.share-btn:active { opacity: 0.85; }

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 0 6px;
  flex-shrink: 0;
}
.footer a { color: var(--muted); }

@media (max-height: 680px) {
  .ad-slot { min-height: 40px; }
  .key { height: 46px; }
}
