/* ---------- fonts ---------- */
@font-face { font-family:"Vazirmatn"; src:url("./fonts/Vazirmatn-Regular.woff2") format("woff2"); font-weight:400; font-display:swap; }
@font-face { font-family:"Vazirmatn"; src:url("./fonts/Vazirmatn-Bold.woff2") format("woff2"); font-weight:700; font-display:swap; }
@font-face { font-family:"Vazirmatn"; src:url("./fonts/Vazirmatn-ExtraBold.woff2") format("woff2"); font-weight:800; font-display:swap; }

/* ---------- forest / earthy theme ---------- */
:root {
  --bg1: #1a231e;
  --bg2: #232f27;
  --card: #27332c;
  --card-2: #1f2a23;   /* recessed */
  --line: rgba(255,255,255,.07);
  --line-2: rgba(255,255,255,.12);
  --ink: #e9f0e4;
  --ink-soft: #9fb4a4;
  --accent: #8ec63f; --accent-l: #b6e57a; --acc: 142,198,63;
  --hint: #ffd24a; --hint-rgb: 255,210,74;
  --font: "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
  --n: 5;
  --shadow: 0 10px 26px rgba(0,0,0,.38);
}
:root[data-diff="5"]  { --accent:#8ec63f; --accent-l:#bce77e; --acc:142,198,63; }  /* خزه */
:root[data-diff="6"]  { --accent:#57b98a; --accent-l:#8fe0b6; --acc:87,185,138; }  /* سبزآبی */
:root[data-diff="7"]  { --accent:#d9a43c; --accent-l:#f0cf6b; --acc:217,164,60; }  /* کهربایی */
:root[data-diff="8"]  { --accent:#e0872f; --accent-l:#f4b163; --acc:224,135,47; }  /* نارنجی */
:root[data-diff="9"]  { --accent:#d66a3a; --accent-l:#ec9868; --acc:214,106,58; }  /* نارنجیِ سوخته */
:root[data-diff="10"] { --accent:#cf5148; --accent-l:#e58072; --acc:207,81,72; }   /* آجری/سرخ */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(142,198,63,.10), transparent 60%),
    radial-gradient(700px 500px at 0% 105%, rgba(217,154,60,.08), transparent 55%),
    linear-gradient(160deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  min-height: 100dvh; display: flex; justify-content: center;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.app { width: 100%; max-width: 462px; display: flex; flex-direction: column; gap: 15px; padding: 20px 4px 28px; }
.app[hidden] { display: none; }

/* ---------- home menu ---------- */
.home { width: 100%; max-width: 462px; display: flex; align-items: center; justify-content: center; padding: 24px 8px 32px; }
.home[hidden] { display: none; }
.home-inner { width: 100%; display: flex; flex-direction: column; align-items: center; }
.home-logo {
  width: 78%; max-width: 300px; height: auto; margin-top: 10px;
}
.home-hi { margin: 16px 0 0; font-size: 15px; color: var(--ink-soft); font-weight: 600; }
.menu { width: 100%; display: flex; flex-direction: column; gap: 12px; margin-top: 26px; }
.menu-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 16px; cursor: pointer; font-family: inherit; text-align: start;
  box-shadow: var(--shadow); transition: transform .08s ease, filter .15s ease;
}
.menu-item:active { transform: translateY(1px) scale(.995); }
@media (hover:hover){ .menu-item:hover { filter: brightness(1.06); } }
.mi-ic {
  width: 50px; height: 50px; flex: 0 0 auto; display: grid; place-items: center; font-size: 24px;
  border-radius: 14px; background: rgba(255,255,255,.05); border: 1px solid var(--line);
}
.mi-tx { flex: 1; display: flex; flex-direction: row; align-items: center; gap: 8px; min-width: 0; }
.mi-tx b { font-size: 18px; font-weight: 800; color: var(--ink); }
.mi-badge { font-size: 11px; font-weight: 800; color: #e0872f; background: rgba(224,135,47,.18); padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.mi-ar { color: var(--ink-soft); font-size: 26px; }
.menu-item:disabled { opacity: .55; cursor: default; }
.menu-item:disabled:hover { filter: none; }
/* accent per menu item */
#mDaily .mi-ic { background: rgba(142,198,63,.20); }
#mLevels .mi-ic { background: rgba(217,164,60,.20); }
#mComp .mi-ic { background: rgba(214,106,58,.20); }
#mPractice .mi-ic { background: rgba(87,185,138,.20); }
#mLogin .mi-ic { background: rgba(207,81,72,.20); }

/* ---------- header ---------- */
.hero { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 13px; }
.logo {
  width: 48px; height: 48px; border-radius: 14px; object-fit: cover;
  border: 1px solid var(--line-2);
}
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.2px; color: var(--ink); }
.subtitle { margin: 3px 0 0; font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.hero-actions { display: flex; align-items: center; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 44px; padding: 0 14px; border-radius: 13px;
  background: var(--card); border: 1px solid var(--line); color: var(--hint);
  font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip-coin { cursor: pointer; font-family: inherit; color: #e7c14b; }
.chip-coin:active { transform: translateY(1px); }
.coin-balance { display: flex; gap: 12px; margin: 4px 0 16px; }
.coin-bal-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px 8px;
}
.coin-bal-item .cb-ic { font-size: 22px; }
.coin-bal-item b { font-size: 22px; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }
.coin-bal-item span { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line); font-size: 18px; cursor: pointer; color: var(--ink);
  transition: background .15s ease, transform .1s ease;
}
.icon-btn:active { transform: translateY(1px); }
@media (hover:hover){ .icon-btn:hover { background: #2d3b32; } }

/* ---------- difficulty ---------- */
.segment {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 6px;
  background: var(--card-2); border: 1px solid var(--line); border-radius: 16px;
}
.tab {
  border: 0; background: transparent; color: var(--ink-soft);
  font-family: inherit; font-size: 14px; font-weight: 800; padding: 11px 6px; cursor: pointer;
  border-radius: 11px; transition: all .18s ease; letter-spacing: .3px;
}
.tab:active { transform: translateY(1px); }
.tab.active {
  color: #12210a; background: linear-gradient(160deg, var(--accent-l), var(--accent));
  box-shadow: 0 6px 14px rgba(var(--acc),.35);
}

/* ---------- stats ---------- */
.statcard {
  display: flex; align-items: stretch; background: var(--card);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.stat { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 14px 6px; }
.stat-value { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.divider { width: 1px; background: var(--line); }

/* ---------- time bar ---------- */
.timebar { height: 12px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); overflow: hidden; }
.timebar-fill {
  height: 100%; width: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-l), var(--accent));
  transition: width .35s linear, background .35s ease;
}
.timebar-fill.warn { background: linear-gradient(90deg,#f0c96b,#d99a3c); }
.timebar-fill.over  { background: linear-gradient(90deg,#e58c68,#cf6242); width:100% !important; }
.goal { margin: -5px 4px 0; text-align: center; font-size: 12px; color: var(--ink-soft); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- board ---------- */
.board-wrap { position: relative; margin-top: 3px; }
.mode-chip {
  position: absolute; top: -12px; inset-inline-start: 14px; z-index: 3;
  font-size: 11.5px; font-weight: 800; color: #12210a; padding: 6px 13px; border-radius: 999px;
  background: linear-gradient(160deg, var(--accent-l), var(--accent));
  box-shadow: 0 6px 14px rgba(var(--acc),.4);
}
.board {
  width: 100%; background: var(--card); border: 1px solid var(--line-2); border-radius: 22px;
  padding: clamp(12px, 3.4vw, 16px); box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.05);
}
.board.solved { animation: leafPop .6s ease; }
@keyframes leafPop { 0%,100%{transform:scale(1);} 45%{transform:scale(1.012);} }

.nono { display: grid; grid-template-columns: max-content repeat(var(--n), minmax(0,1fr)); gap: clamp(4px,1.4vw,7px); }
.corner {}
.cclue {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  gap: 1px; padding-bottom: 5px; line-height: 1.2;
  font-size: clamp(9px,2.3vw,13px); font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums;
}
.rclue {
  display: flex; align-items: center; justify-content: flex-end; gap: clamp(4px,1.4vw,7px);
  padding-inline-end: 8px; white-space: nowrap;
  font-size: clamp(9px,2.3vw,13px); font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums;
}
.pcell {
  aspect-ratio: 1; border-radius: 26%; cursor: pointer; position: relative;
  background: var(--card-2); border: 1px solid var(--line);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.28);
  transition: transform .1s ease, background .12s ease;
}
.pcell.fill {
  background: linear-gradient(155deg, var(--accent-l), var(--accent));
  border-color: rgba(255,255,255,.25);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4), inset 0 -4px 7px rgba(0,0,0,.15);
}
.pcell.x::after {
  content: "✕"; position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--ink-soft); font-size: clamp(11px,3vw,16px); font-weight: 800;
}
.pcell:active { transform: scale(.9); }
/* hint: کادرِ ثابتِ زرد + رنگِ داخل چشمک‌زن، بدون تغییرِ اندازه */
.pcell.hint { border-color: var(--hint); box-shadow: inset 0 0 0 2px var(--hint); }
.pcell.hint::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: var(--hint); animation: hintInner .85s ease-in-out infinite;
}
@keyframes hintInner { 0%,100%{opacity:.16;} 50%{opacity:.58;} }

/* ---------- win overlay ---------- */
.win-overlay[hidden]{ display:none; }
.win-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(10,16,12,.6); backdrop-filter: blur(3px); border-radius: 22px; padding: 16px;
}
.win-card {
  width: 90%; background: var(--card); border: 1px solid var(--line-2); border-radius: 22px;
  padding: 26px 22px 20px; text-align: center; box-shadow: 0 26px 50px rgba(0,0,0,.5);
  animation: pop .32s cubic-bezier(.2,1.2,.4,1);
}
@keyframes pop { 0%{transform:scale(.82);opacity:0;} 100%{transform:scale(1);opacity:1;} }
.win-stars { font-size: 44px; letter-spacing: 8px; color: var(--hint); }
.win-card h2 { margin: 8px 0 4px; font-size: 25px; font-weight: 800; }
.win-card #winSummary { margin: 0 0 14px; color: var(--ink-soft); font-size: 13.5px; line-height: 2; white-space: pre-line; }
.win-rank { margin: 0 0 14px; font-size: 14px; font-weight: 800; color: var(--accent-l); }
.win-rank[hidden] { display: none; }
.win-actions { display: flex; gap: 10px; margin-bottom: 10px; }
.win-hint { margin: 10px 0 0; font-size: 12px; color: var(--ink-soft); font-weight: 600; }

/* ---------- buttons ---------- */
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.btn {
  flex: 1; border: 1px solid var(--line-2); border-radius: 15px; cursor: pointer;
  background: var(--card); color: var(--ink);
  font-family: inherit; font-size: 14.5px; font-weight: 800; padding: 14px 12px;
  transition: transform .08s ease, background .12s ease;
}
.btn:active { transform: translateY(1px); }
@media (hover:hover){ .btn:hover { filter: brightness(1.08); } }
.btn-primary { color: #12210a; background: linear-gradient(160deg, var(--accent-l), var(--accent)); border-color: transparent; box-shadow: 0 8px 18px rgba(var(--acc),.35); }
.btn-ghost { width: 100%; background: transparent; color: var(--ink-soft); }
.btn-mode.mark { color: #12210a; background: linear-gradient(160deg,#cfe0b0,#a9c47f); }
.btn-hint { color: var(--hint); border-color: rgba(var(--hint-rgb),.5); }
.btn-hint:disabled { opacity: .45; cursor: default; }

.btn-levels {
  width: 100%; flex: 0 0 auto; color: #12210a;
  background: linear-gradient(160deg, #bce77e, #8ec63f); border-color: transparent;
  box-shadow: 0 8px 18px rgba(142,198,63,.30);
}

/* levels screen */
.levels-screen { width: 100%; max-width: 462px; padding: 20px 8px 32px; }
.levels-screen[hidden] { display: none; }
.levels-inner { width: 100%; display: flex; flex-direction: column; }
.levels-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 20px; }
.levels-head h2 { margin: 0; font-size: 21px; font-weight: 800; }
.levels-total { font-size: 14px; font-weight: 800; color: var(--hint); background: rgba(217,164,60,.15); border: 1px solid rgba(217,164,60,.3); padding: 6px 13px; border-radius: 999px; white-space: nowrap; }
.levels-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px;
  padding: 2px;
}
.level-tile {
  aspect-ratio: 1; border: 1px solid var(--line); border-radius: 14px; background: var(--card-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  cursor: pointer; color: var(--ink); font-family: inherit; padding: 0;
  transition: transform .1s ease, background .12s ease;
}
.level-tile:active { transform: scale(.94); }
.level-tile .lv-num { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.level-tile .lv-sz { font-size: 10px; color: var(--ink-soft); font-weight: 700; }
.level-tile .lv-stars { font-size: 11px; letter-spacing: 1px; color: var(--hint); height: 13px; }
.level-tile.done { background: linear-gradient(160deg, rgba(var(--acc),.28), rgba(var(--acc),.12)); border-color: rgba(var(--acc),.5); }
.level-tile.current { border-color: var(--hint); box-shadow: inset 0 0 0 2px var(--hint); }
.level-tile.locked { opacity: .5; cursor: not-allowed; }
.level-tile.locked .lv-num { filter: grayscale(1); }

.hint { text-align: center; color: var(--ink-soft); font-size: 12.5px; margin: 2px 8px 0; line-height: 1.9; }
.footer { text-align: center; color: var(--ink-soft); font-size: 11.5px; opacity: .85; }

/* ---------- toast / confetti ---------- */
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: #12190f; color: var(--ink); padding: 12px 20px; border-radius: 999px;
  font-size: 13px; font-weight: 700; z-index: 70; border: 1px solid var(--line-2);
}
.confetti { position: fixed; z-index: 60; border-radius: 2px; pointer-events: none; will-change: transform, opacity; }

/* ---------- leaderboard modal ---------- */
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  background: rgba(10,16,12,.62); backdrop-filter: blur(3px); padding: 18px;
}
.modal-card {
  width: 100%; max-width: 442px; max-height: 86dvh; display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line-2); border-radius: 20px; padding: 22px; box-shadow: 0 26px 50px rgba(0,0,0,.55);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
.modal-sub { margin: 6px 0 14px; color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.name-row { display: flex; gap: 9px; margin-bottom: 14px; }
.name-input {
  flex: 1; font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
.name-input:focus { border-color: var(--accent); }
.name-row .btn { flex: 0 0 auto; padding: 12px 17px; }
.lb-list { overflow-y: auto; display: flex; flex-direction: column; gap: 7px; }
.lb-empty { text-align: center; color: var(--ink-soft); font-size: 13px; padding: 22px 0; line-height: 1.8; }
.lb-row {
  display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px;
  padding: 12px 13px; border-radius: 13px; background: var(--card-2); border: 1px solid var(--line);
}
.lb-row.you { background: linear-gradient(160deg, var(--accent-l), var(--accent)); color:#12210a; border-color: transparent; }
.lb-row.you .lb-score, .lb-row.you .lb-score b, .lb-row.you .lb-rank { color:#12210a; }
.lb-rank { font-weight: 800; font-variant-numeric: tabular-nums; text-align: center; }
.lb-rank.top { color: var(--accent-l); }
.lb-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-size: 12.5px; color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lb-score b { color: var(--ink); font-weight: 800; }
.lb-you { margin: 12px 0 0; text-align: center; font-size: 13px; color: var(--ink); font-weight: 800; }
.lb-you[hidden] { display: none; }

@media (max-width: 360px){ .stat-value { font-size: 21px; } .brand h1 { font-size: 20px; } }
@media (prefers-reduced-motion: reduce){ * { animation: none !important; transition: none !important; } }
