:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #62708a;
  --line: #e2e6ef;
  --accent: #2f5bea;
  --accent-dark: #2447c4;
  --accent-soft: #e8eeff;
  --gold: #f5a524;
  --good: #16a34a;
  --bad: #dc2626;
  --board-bg: #d7dded;
  --cell-bg: #eaeef7;
  --board: min(92vw, 520px);
  --font-head: "Outfit", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
body.modal-open { overflow: hidden; }

h1, h2, h3 { font-family: var(--font-head); letter-spacing: -0.01em; line-height: 1.2; }

.wrap { max-width: 780px; margin: 0 auto; padding: 0 16px; }

/* ---------- header ---------- */
.site-header { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 60px; gap: 12px; }
.brand {
  font-family: var(--font-head); font-weight: 800; font-size: 1.35rem; letter-spacing: -0.02em;
  color: var(--text); text-decoration: none; display: inline-flex; align-items: baseline; gap: 7px; flex-wrap: wrap;
}
.brand-play { font-weight: 600; color: var(--muted); }
.brand-main { background: linear-gradient(90deg, #2f5bea, #7c3aed); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-unl {
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  background: var(--accent-soft); color: var(--accent); padding: 3px 8px; border-radius: 999px; align-self: center;
}
.nav a { margin-left: 18px; color: var(--muted); text-decoration: none; font-size: 0.93rem; font-weight: 500; }
.nav a:hover { color: var(--text); }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 28px 0 8px; }
.hero h1 { margin: 0 0 8px; font-size: clamp(1.55rem, 5vw, 2.25rem); font-weight: 800; }
.sub { margin: 0 auto; max-width: 560px; color: var(--muted); }

/* ---------- game ---------- */
.game { display: flex; flex-direction: column; align-items: center; padding: 14px 0 8px; }

.sizes { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; justify-content: center; }
.sizes .sep { width: 1px; background: var(--line); margin: 4px 4px; }
.pill {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 7px 16px; border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.pill:hover { border-color: #c3cbe0; }
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill[data-mode="hard"][aria-pressed="true"] { background: #b42318; border-color: #b42318; }

.stats { display: flex; gap: 26px; margin-bottom: 12px; }
.stats > div { text-align: center; min-width: 58px; }
.stats .label { display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.stats span:last-child { font-family: var(--font-head); font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.board {
  --gap: 6px;
  width: var(--board);
  height: var(--board);
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: var(--gap);
  padding: var(--gap);
  background: var(--board-bg);
  border-radius: 16px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.cell { background: var(--cell-bg); border-radius: 10px; position: relative; min-width: 0; min-height: 0; }
.cell.target { outline: 3px solid var(--accent); outline-offset: -3px; }
.cell.hint-from, .cell.hint-to { outline: 3px solid var(--gold); outline-offset: -3px; }

.tile {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px; color: #fff;
  font-family: var(--font-head); font-weight: 700;
  font-size: calc(var(--board) / var(--n) * 0.42);
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.14);
  cursor: grab;
}
.tile[data-len="3"] { font-size: calc(var(--board) / var(--n) * 0.34); }
.tile[data-len="4"], .tile[data-len="5"] { font-size: calc(var(--board) / var(--n) * 0.26); }
.tile.wild { background: #1f2937 !important; border: 3px dashed var(--gold); color: #ffd277; box-shadow: none; }
.tile.selected { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--accent); }
.tile.dragging { z-index: 10; cursor: grabbing; pointer-events: none; box-shadow: 0 10px 22px rgba(0, 0, 0, 0.32); }

.message { min-height: 1.7em; margin: 12px 0 4px; text-align: center; color: var(--muted); padding: 0 8px; }
.message.warn { color: #b45309; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 20px; border-radius: 12px; font: inherit; font-weight: 600; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { border-color: #c3cbe0; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }

/* ---------- result popup ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto;
  animation: fade-in 0.18s ease-out;
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative; width: min(100%, 420px);
  background: var(--card); border-radius: 22px; padding: 28px 24px 22px; text-align: center;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
  animation: pop-in 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.modal-close {
  position: absolute; top: 10px; right: 12px; width: 34px; height: 34px;
  border: 0; background: transparent; color: var(--muted); font-size: 1.6rem; line-height: 1; cursor: pointer; border-radius: 50%;
}
.modal-close:hover { background: var(--bg); }
.modal-emoji { font-size: 3rem; line-height: 1; margin-bottom: 6px; }
.modal-card h2 { margin: 0 0 4px; font-size: 1.9rem; font-weight: 800; }
.modal-card.win h2 { color: var(--good); }
.modal-card.fail h2 { color: var(--bad); }
.modal-sub { margin: 0 0 12px; color: var(--muted); }
.badge {
  display: inline-block; margin-bottom: 12px; padding: 5px 14px; border-radius: 999px;
  background: #fff4d6; color: #9a6200; font-weight: 700; font-size: 0.85rem; border: 1px solid #f7d98a;
}
.badge[hidden] { display: none; }
.mstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 14px; }
.mstat { background: var(--bg); border-radius: 12px; padding: 10px 4px; }
.mstat b { display: block; font-family: var(--font-head); font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.mstat span { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 600; }
.mstat.hl { background: var(--accent-soft); }
.modal-foot { margin: 0 0 14px; font-size: 0.85rem; color: var(--muted); }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 101; }
.confetti i {
  position: absolute; top: -14px; width: 9px; height: 15px; border-radius: 2px; opacity: 0.95;
  animation: confetti-fall linear forwards;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.88) translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes confetti-fall {
  to { transform: translate3d(var(--dx), 105vh, 0) rotate(var(--rot)); opacity: 0.9; }
}
@media (prefers-reduced-motion: reduce) {
  .modal, .modal-card { animation: none; }
  .confetti { display: none; }
}

/* ---------- ads (hidden until enabled) ---------- */
.ad-slot { margin: 16px auto; text-align: center; min-height: 90px; }
.ad-slot[hidden] { display: none; }

/* ---------- content ---------- */
.prose { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px 24px; margin: 20px 0; }
.prose h2 { margin-top: 0; font-size: 1.5rem; }
.prose h3 { margin: 18px 0 4px; font-size: 1.08rem; }
.prose p { margin-top: 0; }
.prose li { margin-bottom: 6px; }
.prose a { color: var(--accent); }
.page { padding: 24px 0 8px; }
.page h1 { font-size: clamp(1.6rem, 5vw, 2.1rem); margin: 0 0 6px; }
.updated { color: var(--muted); font-size: 0.9rem; margin-top: 0; }

.site-footer { border-top: 1px solid var(--line); margin-top: 32px; padding: 22px 0 40px; text-align: center; color: var(--muted); font-size: 0.9rem; }
.site-footer a { color: var(--muted); }
.disclaimer { max-width: 580px; margin: 10px auto 0; font-size: 0.8rem; }

@media (max-width: 520px) {
  .nav { display: none; }
  .stats { gap: 14px; }
  .brand { font-size: 1.15rem; }
  .mstats { grid-template-columns: repeat(2, 1fr); }
}
