/* ============================================================================
 * styles.css — Floodle
 * Mobile-first, dark theme, touch-friendly. Pure CSS (no frameworks).
 * ========================================================================== */

:root {
  --bg: #0f1320;
  --bg-2: #171c2e;
  --panel: #1d2438;
  --panel-2: #252e48;
  --text: #eef1f8;
  --muted: #9aa3bd;
  --accent: #3f8efc;
  --danger: #ef4d4d;
  --good: #36c46a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --gap: 2px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2440 0%, var(--bg) 55%);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  /* 100dvh = dynamic viewport height: fixes iOS Safari's address-bar jump/
     overflow that plain 100vh causes (100vh ignores the toolbar). */
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Respect notches / home indicator on devices with display cut-outs. */
  padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right))
           calc(28px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
}

/* ---- Header ------------------------------------------------------------- */
header.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-right: auto;
}
.brand h1 {
  font-size: 1.55rem;
  margin: 0;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, #ef4d4d, #f59331, #f2cf3b, #36c46a, #3f8efc, #a45cf0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 800;
}
.brand .day {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
}

.streak-chip {
  background: rgba(245, 147, 49, 0.18);
  color: #ffce9e;
  border: 1px solid rgba(245, 147, 49, 0.45);
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

.icon-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  font-size: 1.05rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.05s;
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn:active { transform: scale(0.94); }

/* ---- Banner ------------------------------------------------------------- */
.challenge-banner {
  background: linear-gradient(90deg, rgba(63,142,252,0.18), rgba(164,92,240,0.18));
  border: 1px solid rgba(63, 142, 252, 0.4);
  color: #cfe6ff;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}
/* Solved-daily lock banner (green) — shown with a countdown to the next puzzle. */
.challenge-banner.solved {
  background: linear-gradient(90deg, rgba(54,196,106,0.20), rgba(63,142,252,0.16));
  border-color: rgba(54, 196, 106, 0.5);
  color: #b9f0cf;
}
.challenge-banner.solved strong { color: #eafff2; }

/* ---- HUD ---------------------------------------------------------------- */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 10px 14px;
}
.hud .moves-wrap { font-size: 1.1rem; font-weight: 800; }
.hud .moves-wrap.over-par #par { color: var(--danger); }
.hud .moves-wrap .slash { color: var(--muted); margin: 0 2px; }
.hud .mode-pill {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
}
.hud .timer-wrap {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}
.hud .timer-wrap #timer { color: var(--accent); }

/* ---- Board -------------------------------------------------------------- */
.board-wrap {
  display: flex;
  justify-content: center;
}
.board {
  display: grid;
  grid-template-columns: repeat(var(--size, 14), 1fr);
  gap: var(--gap);
  /* Fit-to-height: cap the (square) board by the space left after the header,
     HUD, colour row, actions, ad and footer, so on short/landscape screens the
     UI never overflows and needs scrolling. Falls back to 100vh pre-dvh. */
  width: min(100%, calc(100vh - 24rem));
  width: min(100%, calc(100dvh - 24rem));
  aspect-ratio: 1 / 1;
  background: #0b0f1a;
  padding: var(--gap);
  border-radius: 12px;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}
.cell {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  transition: background-color 0.32s ease;
  /* Centres the optional colour-blind symbol; harmless when the cell is blank. */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.5rem, 2.3vw, 0.95rem);
  font-weight: 900;
  line-height: 1;
  color: rgba(0, 0, 0, 0.6);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.22);
  user-select: none;
}

/* ---- Color buttons ------------------------------------------------------ */
.colors {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.color-btn {
  height: 54px;
  border: 3px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.06s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22);
  /* Centres the optional colour-blind symbol on the swatch. */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 900;
  color: rgba(0, 0, 0, 0.62);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}
.color-btn:hover { transform: translateY(-2px); }
.color-btn:active { transform: translateY(0) scale(0.96); }
.color-btn.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25), inset 0 -4px 0 rgba(0, 0, 0, 0.22);
}
/* Rewarded "Hint" highlights the recommended colour with a pulsing white ring. */
.color-btn.hint {
  border-color: #ffffff;
  box-shadow: 0 0 0 3px #ffffff, 0 0 18px 3px rgba(255, 255, 255, 0.7);
  animation: hintpulse 0.55s ease-in-out infinite alternate;
}
@keyframes hintpulse {
  from { transform: translateY(0) scale(1); }
  to   { transform: translateY(-3px) scale(1.07); }
}
/* Solved daily -> colour buttons are locked (greyed, non-interactive). */
.color-btn:disabled,
.color-btn.locked {
  cursor: not-allowed;
  opacity: 0.4;
  filter: grayscale(0.4);
  transform: none;
}
.color-btn:disabled:hover,
.color-btn.locked:hover { transform: none; }

/* ---- Actions ------------------------------------------------------------ */
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.btn {
  flex: 1 1 auto;
  min-width: 90px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: 12px 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--panel-2); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn .sub { color: var(--muted); font-weight: 600; font-size: 0.8rem; margin-left: 4px; }
.btn.primary { background: var(--good); color: #04241b; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.share { background: var(--accent); color: #042033; }

/* ---- Ad slot ------------------------------------------------------------ */
.ad-slot {
  display: flex;
  justify-content: center;
  min-height: 0;
}
.ad-fallback {
  width: 300px;
  max-width: 100%;
  height: 100px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: repeating-linear-gradient(45deg, #141a2b, #141a2b 10px, #171e31 10px, #171e31 20px);
  color: var(--muted);
}
.ad-fallback .ad-tag {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: rgba(255,255,255,0.1);
  padding: 1px 6px;
  border-radius: 4px;
}
.ad-fallback .ad-note { font-size: 0.72rem; }
.ad-fallback.skyscraper { width: 160px; height: 600px; }

/* ---- Desktop-only side rail (160x600) ----------------------------------- */
/* Hidden by default (mobile/tablet); only appears when there's real margin
   beside the centred 520px app. Zero mobile impact by construction. */
.side-rail { display: none; }
@media (min-width: 1180px) {
  .side-rail {
    display: block;
    position: fixed;
    top: 50%;
    right: 24px;
    transform: translateY(-50%);
    width: 160px;
    z-index: 5;
  }
}

footer.foot {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
}
footer.foot a { color: var(--accent); text-decoration: none; }

/* ---- Toast -------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: #ffffff;
  color: #10131c;
  padding: 11px 18px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Modals ------------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 16, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
  backdrop-filter: blur(3px);
}
.modal.show { display: flex; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--bg-2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  width: 100%;
  max-width: 420px;
  padding: 22px;
  box-shadow: var(--shadow);
  max-height: 86vh;
  overflow-y: auto;
  animation: pop 0.2s ease;
}
@keyframes pop { from { transform: translateY(14px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-card h2 { margin: 0 0 4px; font-size: 1.3rem; }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.modal-card p { color: var(--text); line-height: 1.5; }
.modal-card .muted { color: var(--muted); font-size: 0.9rem; }

/* Win modal */
.win-emoji {
  font-size: 1.4rem;
  letter-spacing: 1px;
  word-break: break-all;
  background: var(--panel);
  border-radius: 10px;
  padding: 12px;
  margin: 12px 0;
  text-align: center;
  line-height: 1.6;
}
.win-streak {
  text-align: center;
  color: #ffce9e;
  font-weight: 800;
  margin: 0 0 12px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* Settings toggles */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.toggle-row strong { display: block; font-size: 0.98rem; }
.toggle-sub { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.toggle {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid rgba(255, 255, 255, 0.12);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.toggle:checked { background: var(--good); }
.toggle:checked::after { transform: translateX(20px); }

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 14px 0;
}
.stat-cell { text-align: center; }
.stat-value { font-size: 1.6rem; font-weight: 800; }
.stat-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.hist-title { font-size: 1rem; margin: 16px 0 8px; }
.histogram { display: flex; flex-direction: column; gap: 5px; }
.hist-row { display: flex; align-items: center; gap: 8px; }
.hist-label { width: 34px; text-align: right; font-size: 0.8rem; color: var(--muted); font-weight: 700; }
.hist-bar { flex: 1; background: var(--panel); border-radius: 6px; overflow: hidden; height: 22px; }
.hist-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--good));
  color: #04241b;
  font-size: 0.72rem;
  font-weight: 800;
  text-align: right;
  padding-right: 6px;
  line-height: 22px;
  min-width: 0;
  transition: width 0.4s ease;
}
.hist-empty { color: var(--muted); font-size: 0.86rem; text-align: center; }

/* How-to list */
.help-list { padding-left: 18px; line-height: 1.6; }
.help-list li { margin-bottom: 6px; }
.swatch-row { display: flex; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 6px; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.2); }

/* Support modal */
.premium-perks { padding-left: 18px; line-height: 1.7; }
.tip-box {
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 12px;
  margin-top: 12px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tip-head { margin: 0; font-weight: 800; }
.tip-addr {
  display: block;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--accent);
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-all;
}

/* ---- Rewarded ad overlay ------------------------------------------------ */
.rewarded-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 70;
  color: #fff;
  gap: 10px;
}
.rewarded-overlay.show { display: flex; }
.rewarded-overlay .label { color: var(--muted); letter-spacing: 2px; text-transform: uppercase; font-size: 0.8rem; }
.rewarded-overlay .count {
  font-size: 5rem;
  font-weight: 900;
  background: linear-gradient(90deg, var(--accent), var(--good));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.rewarded-overlay .sub { color: var(--muted); font-size: 0.85rem; }

/* ---- Confetti ----------------------------------------------------------- */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 65;
}
.confetti {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: 0.9; }
}

/* ---- Content / info pages (guide, faq, about, privacy, terms) ----------- */
body.doc { display: block; min-height: 100vh; min-height: 100dvh; }
.doc-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  max-width: 820px; margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 18px 0;
}
.doc-brand {
  font-size: 1.5rem; font-weight: 800; letter-spacing: 0.5px; text-decoration: none;
  background: linear-gradient(90deg, #ef4d4d, #f59331, #f2cf3b, #36c46a, #3f8efc, #a45cf0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-right: auto;
}
.doc-nav { display: flex; flex-wrap: wrap; gap: 14px; }
.doc-nav a { color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600; }
.doc-nav a:hover { color: var(--text); }
.doc-main { max-width: 820px; margin: 0 auto; padding: 8px 18px 40px; line-height: 1.7; }
.doc-main h1 { font-size: 2rem; margin: 18px 0 6px; }
.doc-main h2 { font-size: 1.25rem; margin: 28px 0 8px; }
.doc-main h3 { font-size: 1.02rem; margin: 18px 0 6px; }
.doc-main p, .doc-main li { color: #d7dcec; }
.doc-main a { color: var(--accent); }
.doc-main ul, .doc-main ol { padding-left: 22px; }
.doc-main li { margin-bottom: 6px; }
.doc-lead { font-size: 1.1rem; color: var(--text) !important; }
.doc-updated { color: var(--muted); font-size: 0.85rem; }
.doc-cta {
  display: inline-block; margin: 12px 0;
  background: var(--good); color: #04241b; font-weight: 800; text-decoration: none;
  padding: 12px 22px; border-radius: 12px;
}
.doc-footer {
  max-width: 820px; margin: 0 auto;
  padding: 24px 18px calc(40px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255,255,255,0.08); color: var(--muted); font-size: 0.85rem;
}
.doc-footer a { color: var(--muted); }
.doc-footer a:hover { color: var(--text); }
.faq-q { font-weight: 800; color: var(--text) !important; margin-top: 20px; }

/* Page links row under the game footer */
.foot-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; margin-top: 6px; }
.foot-links a { color: var(--muted); text-decoration: none; }
.foot-links a:hover { color: var(--text); }

/* ---- Responsive niceties ------------------------------------------------ */
@media (max-width: 380px) {
  .color-btn { height: 46px; }
  .brand h1 { font-size: 1.35rem; }
}
@media (min-width: 560px) {
  .cell { border-radius: 4px; }
}
