/* ========================================
   Hangman Game – Styles
   Mobile-first • Clean • Modern • Light & dark
======================================== */

:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --surface: #26264a;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --text: #eeeef5;
  --muted: #9a9cb8;
  --correct: #4ecca3;
  --wrong: #e94560;
  --gold: #f9c74f;
  --gallows: #e8e8f0;
  --figure: #ffffff;
  --on-correct: #10251d;
  --backdrop: rgba(0, 0, 0, 0.7);
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* Light theme – opt-in via the header toggle (dark is the default) */
:root[data-theme="light"] {
  --bg: #f4f1ea;
  --card: #ffffff;
  --surface: #e8e4f3;
  --accent: #d63a55;
  --accent-hover: #b82d46;
  --text: #1f2233;
  --muted: #5d6275;
  --correct: #1f9e76;
  --wrong: #d63a55;
  --gold: #b7791f;
  --gallows: #6b6f80;
  --figure: #2b2e3f;
  --on-correct: #ffffff;
  --backdrop: rgba(20, 20, 40, 0.5);
  --shadow: 0 6px 24px rgba(40, 40, 80, 0.12);
  color-scheme: light;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
}

a {
  color: inherit;
}

button,
select {
  font: inherit;
  color: inherit;
}

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

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 300;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 700;
}

.skip-link:focus {
  top: 12px;
}

/* ---------- Site header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  width: 100%;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid color-mix(in srgb, var(--muted) 22%, transparent);
  padding-top: env(safe-area-inset-top);
}

.site-header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  min-width: 0;
}

.brand img {
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  font-size: 1.1rem;
  cursor: pointer;
}

.premium-btn {
  min-width: 44px;
  height: 44px;
  padding: 0 12px;
  border: none;
  border-radius: 22px;
  background: linear-gradient(135deg, #f9c74f, #f8961e);
  color: #3a2300;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.premium-btn.owned {
  background: var(--surface);
  color: var(--text);
}

/* Phones: compact header buttons, star-only Premium button */
@media (max-width: 420px) {
  .icon-btn,
  .premium-btn {
    width: 40px;
    min-width: 40px;
    height: 40px;
  }

  .brand-name {
    font-size: 1.2rem;
  }
}

/* Narrow phones: icon-only brand (the name stays for screen readers) */
@media (max-width: 380px) {
  .brand-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

@media (max-width: 420px) {
  .premium-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .premium-btn {
    padding: 0;
    justify-content: center;
  }
}

/* ---------- Game card ---------- */
.container {
  width: calc(100% - 24px);
  max-width: 480px;
  margin: 14px 12px 0;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.container:focus {
  outline: none;
}

/* ---------- Banner ad slot ---------- */
.ad-slot {
  width: calc(100% - 24px);
  max-width: 480px;
  min-height: 60px;
  margin: 14px 12px 0;
  border-radius: 10px;
  overflow: hidden;
}

.ad-slot.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px dashed color-mix(in srgb, var(--muted) 45%, transparent);
  color: var(--muted);
  font-size: 0.85rem;
}

.ad-label {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--gold);
  color: #3a2300;
}

/* ---------- Site footer ---------- */
.site-footer {
  width: 100%;
  max-width: 720px;
  margin-top: auto;
  padding: 24px 12px calc(20px + env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin-bottom: 6px;
}

.footer-links a,
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 10px 2px;
  font-size: inherit;
}

.footer-links a:hover,
.link-btn:hover {
  color: var(--text);
}

.footer-links > :not([hidden]) ~ :not([hidden])::before {
  content: "|";
  display: inline-block;
  margin-right: 18px;
  color: color-mix(in srgb, var(--muted) 50%, transparent);
  text-decoration: none;
}

.footer-meta {
  font-size: 0.78rem;
}

/* Mode tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border-radius: 12px;
  margin-bottom: 12px;
}

.tab {
  border: none;
  background: transparent;
  padding: 10px;
  min-height: 44px;
  border-radius: 9px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

.tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.badge {
  display: inline-block;
  margin-left: 4px;
  color: var(--correct);
  font-weight: 800;
}

/* Classic options */
.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.options select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--surface);
  cursor: pointer;
}

/* Stats strip (a button – opens full statistics) */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  text-align: center;
  margin-bottom: 8px;
  padding: 6px 0;
  border: none;
  border-radius: 10px;
  background: none;
  cursor: pointer;
}

.stats:hover {
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.stat-value {
  font-size: 1.05rem;
  font-weight: 700;
}

/* Hangman SVG */
.hangman-area {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}

#hangman-svg {
  width: 150px;
  height: 188px;
}

.gallows line {
  stroke: var(--gallows);
  stroke-width: 4;
  stroke-linecap: round;
}

/* Round info */
.round-info {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

/* Word Display */
/* One row always: boxes shrink with the word length (--n is set by script.js) */
.word-display {
  --n: 6;
  display: flex;
  justify-content: center;
  gap: clamp(3px, 1.2vw, 6px);
  margin-bottom: 10px;
  min-height: 48px;
  font-size: min(1.7rem, calc((min(100vw, 480px) - 72px) / var(--n) * 0.72));
  font-weight: 700;
}

.letter-box {
  flex: 0 1 32px;
  min-width: 0;
  height: 44px;
  border-bottom: 3px solid var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.letter-box.revealed {
  border-bottom-color: var(--correct);
  color: var(--correct);
}

.letter-box.missed {
  border-bottom-color: var(--wrong);
  color: var(--wrong);
}

.letter-box.pop {
  animation: pop 0.3s ease;
}

@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

/* Message */
.message {
  text-align: center;
  font-size: 1rem;
  min-height: 26px;
  margin-bottom: 12px;
  color: var(--muted);
}

.message.win {
  color: var(--correct);
  font-weight: 700;
}

.message.lose {
  color: var(--wrong);
  font-weight: 700;
}

/* Keyboard */
/* QWERTY rows; every key is 1/10 of the row so shorter rows sit centred */
.keyboard {
  --key-gap: 5px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 14px;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: var(--key-gap);
}

.key {
  flex: 0 0 calc((100% - 9 * var(--key-gap)) / 10);
  max-width: 46px;
  padding: 0;
  background: var(--surface);
  border: none;
  font-size: 1.05rem;
  font-weight: 700;
  min-height: 50px;
  border-radius: 9px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
  .key:hover:not(:disabled) {
    background: var(--accent);
    color: #fff;
    transform: translateY(-2px);
  }
}

.key:active:not(:disabled) {
  transform: scale(0.94);
}

.key:disabled {
  cursor: default;
  opacity: 0.45;
}

.key.correct {
  background: var(--correct);
  color: var(--on-correct);
  opacity: 1;
}

.key.wrong {
  background: var(--wrong);
  color: #fff;
  opacity: 0.55;
}

/* Footer controls */
.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wrong-info {
  flex: 1;
  font-size: 0.9rem;
  color: var(--muted);
}

.btn,
.btn-secondary {
  border: none;
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
  min-height: 44px;
  transition: transform 0.15s, background 0.15s, opacity 0.15s;
}

.btn {
  background: var(--accent);
  color: #fff;
  padding: 12px 28px;
  font-size: 1.05rem;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  padding: 10px 14px;
  font-size: 0.9rem;
}

.btn-secondary:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-secondary.unaffordable:not(:disabled) {
  opacity: 0.65;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fade 0.2s ease;
}

.modal.hidden {
  display: none;
}

@keyframes fade {
  from { opacity: 0; }
}

.modal-content {
  position: relative;
  background: var(--card);
  padding: 32px 24px 24px;
  border-radius: var(--radius);
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease;
}

@keyframes rise {
  from { transform: translateY(16px); opacity: 0; }
}

.modal-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  font-size: 1.1rem;
  color: var(--muted);
  cursor: pointer;
  border-radius: 50%;
}

.modal-content h2 {
  font-size: 1.8rem;
  margin-bottom: 8px;
}

.modal-content h2.win { color: var(--correct); }
.modal-content h2.lose { color: var(--wrong); }

.modal-word {
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.modal-word strong {
  letter-spacing: 2px;
}

.modal-detail {
  color: var(--muted);
  margin-bottom: 4px;
}

.modal-stats {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.modal-actions.stacked {
  flex-direction: column;
  align-items: stretch;
}

.modal-content {
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.modal-content:focus {
  outline: none;
}

/* Hint chooser */
.choice-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 12px 16px;
  min-height: 56px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.choice:hover:not(:disabled) {
  border-color: var(--accent);
}

.choice:disabled {
  opacity: 0.5;
  cursor: default;
}

.choice-title {
  font-weight: 700;
}

.choice-sub {
  font-size: 0.82rem;
  color: var(--muted);
}

/* Simulated ad */
.ad-content .ad-label {
  margin-bottom: 8px;
}

.ad-placeholder-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 180px;
  margin: 12px 0;
  border: 2px dashed color-mix(in srgb, var(--muted) 45%, transparent);
  border-radius: 12px;
  color: var(--muted);
}

.ad-countdown {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--text);
}

/* Premium */
.perk-list {
  list-style: none;
  text-align: left;
  display: grid;
  gap: 8px;
  margin: 12px 0 16px;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.stats-grid div {
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 8px;
}

.stats-grid dd {
  font-size: 1.4rem;
  font-weight: 800;
}

.stats-grid dt {
  font-size: 0.78rem;
  color: var(--muted);
}

/* How to play */
.help-content {
  text-align: left;
}

.help-content h2 {
  text-align: center;
}

.help-list {
  display: grid;
  gap: 8px;
  padding-left: 20px;
  margin: 12px 0 16px;
}

/* Cookie consent */
.consent {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 150;
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  border: 1px solid color-mix(in srgb, var(--muted) 25%, transparent);
  font-size: 0.9rem;
}

.consent-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

/* Confetti */
.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 200;
  display: none;
}

.confetti.active {
  display: block;
}

/* Small phones */
@media (max-width: 380px) {
  .container,
  .ad-slot {
    width: calc(100% - 16px);
    margin-left: 8px;
    margin-right: 8px;
  }

  .container {
    padding: 14px 10px;
  }

  .keyboard {
    --key-gap: 4px;
  }

  .key {
    font-size: 0.95rem;
  }

  .letter-box {
    height: 40px;
  }
}

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

/* ---------- Text pages (privacy) ---------- */
.prose {
  line-height: 1.65;
}

.prose h1 {
  font-size: 1.6rem;
  margin-bottom: 2px;
}

.prose h2 {
  font-size: 1.1rem;
  margin: 20px 0 6px;
}

.prose p,
.prose ul {
  margin-bottom: 10px;
}

.prose ul {
  padding-left: 20px;
}

.prose a {
  color: var(--accent);
}

.prose .muted {
  color: var(--muted);
  font-size: 0.85rem;
}

a.premium-btn {
  text-decoration: none;
}

/* ---------- Category picker ---------- */
.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

@media (min-width: 421px) {
  .category-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.category-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}

.category-tile:hover {
  border-color: color-mix(in srgb, var(--gold) 50%, transparent);
}

.category-tile[aria-pressed="true"] {
  border-color: var(--gold);
}

.category-icon {
  font-size: 1.5rem;
  line-height: 1.2;
}

.category-name {
  font-weight: 700;
}

.category-count {
  font-size: 0.75rem;
  color: var(--muted);
}

.difficulty-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 12px;
  padding: 4px;
  background: var(--surface);
  border-radius: 12px;
}

.diff-btn {
  border: none;
  background: transparent;
  min-height: 40px;
  border-radius: 9px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.diff-btn[aria-pressed="true"] {
  background: var(--card);
  color: var(--text);
}

.help-heading {
  font-size: 1rem;
  margin-top: 14px;
}

.help-heading + .help-list {
  margin-top: 6px;
}
