:root {

  --ink: #17191c;
  --paper: #ffffff;
  --mist: #f2f2f3;
  --fog: #fafafb;
  --slate: #777b86;
  --ash: #979799;
  --smoke: #a3a6af;
  --peach: #fbe1d1;
  --sienna: #5d2a1a;
  --miss: #c0392b;
  --miss-bg: #fbe6e2;
  --good: #2f8a4e;
  --good-bg: #dcefe1;
  --hairline: #ececec;
  --hairline-soft: #e6e6e7;

  --font-serif: "Amiri", "Noto Naskh Arabic", "Vazirmatn", ui-serif, Georgia, serif;
  --font-ui: "Vazirmatn", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --r-card: 24px;
  --r-elevated: 20px;
  --r-input: 16px;
  --r-small: 16px;
  --r-pill: 9999px;

  --shadow-artifact: rgba(4,23,43,.05) 0 0 0 1px, rgba(0,0,0,.10) 0 20px 25px -5px, rgba(0,0,0,.10) 0 8px 10px -6px;
  --shadow-overlay: oklab(0 0 0 / .05) 0 0 0 1px, rgba(0,0,0,.10) 0 8px 40px 0;
  --shadow-hover: oklab(0 0 0 / .05) 0 0 0 1px, rgba(0,0,0,.08) 0 4px 24px 0;

  --maxw: 960px;
}

[data-theme="dark"] {
  --ink: #e8eaed;
  --paper: #1e2025;
  --mist: #101216;
  --fog: #191b1f;
  --slate: #a4a8b2;
  --ash: #83868f;
  --smoke: #70737b;
  --peach: #3a2a1d;
  --sienna: #f0c9a9;
  --miss: #f28b82;
  --miss-bg: #3a1f1c;
  --good: #86d8a0;
  --good-bg: #1d3327;
  --hairline: #32353c;
  --hairline-soft: #3e414a;

  --shadow-artifact: rgba(0,0,0,.45) 0 1px 2px, rgba(0,0,0,.35) 0 10px 18px -8px;
  --shadow-overlay: rgba(0,0,0,.55) 0 10px 40px 0;
  --shadow-hover: rgba(0,0,0,.5) 0 8px 24px 0;
}
[data-theme="dark"] html,
[data-theme="dark"] body { background: #141519; }
[data-theme="dark"] .modal { background: rgba(0,0,0,.6); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100%;
}
body {
  min-height: 100vh;
  display: flex; flex-direction: column;
  overflow-x: hidden;
}

.pattern-bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    linear-gradient(180deg, var(--fog) 0%, var(--paper) 42%);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 24px clamp(20px, 5vw, 40px);
  max-width: var(--maxw); width: 100%; margin: 0 auto;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  background: none; border: none; padding: 0; margin: 0;
  cursor: pointer; font-family: var(--font-ui);
  transition: opacity .16s;
}
.brand:hover { opacity: .7; }
.brand-mark {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 500; font-size: 18px;
}
.brand-name { font-weight: 500; font-size: 20px; letter-spacing: -.2px; color: var(--ink); }

.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--slate);
  border-radius: var(--r-pill);
  cursor: pointer;
  font-family: var(--font-ui); font-size: 15px; font-weight: 450;
  transition: color .18s, background .18s, border-color .18s;
}
.icon-btn:hover { color: var(--ink); background: var(--fog); border-color: var(--hairline-soft); }

.theme-btn { padding: 0 12px; }
.theme-ico-sun { display: none; }
[data-theme="dark"] .theme-ico-moon { display: none; }
[data-theme="dark"] .theme-ico-sun { display: inline; }

.stage {
  flex: 1; width: 100%;
  max-width: var(--maxw); margin: 0 auto;
  padding: 8px clamp(20px, 5vw, 40px) 80px;
  display: flex; flex-direction: column;
}
.screen { flex: 1; display: flex; flex-direction: column; }
.screen[hidden] { display: none; }

.btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.btn {
  border: 1px solid transparent; cursor: pointer;
  padding: 0 24px; height: 52px;
  border-radius: var(--r-pill);
  font-family: var(--font-ui); font-weight: 450; font-size: 16px;
  transition: transform .16s, background .16s, color .16s, border-color .16s;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-lg { height: 56px; font-size: 17px; padding: 0 32px; }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-primary:hover { transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--ink); }
.btn-ghost:hover { background: var(--ink); color: var(--paper); }

.intro-card {
  margin: auto 0;
  width: 100%; max-width: 620px;
  align-self: center;
  padding: 40px 8px;
  text-align: center;
  animation: rise .5s ease both;
  background: transparent; border: none; box-shadow: none;
}
.intro-emblem {
  width: 72px; height: 72px;
  margin: 0 auto 28px;
  display: grid; place-items: center;
  border-radius: var(--r-elevated);
  font-size: 30px; font-weight: 500; color: var(--paper);
  background: var(--ink);
}
.intro-title {
  font-family: var(--font-serif); font-weight: 400;
  font-size: clamp(52px, 12vw, 90px); line-height: 1.3;
  letter-spacing: -2.25px;
  margin: 0 0 20px; color: var(--ink);
}
.intro-sub {
  color: var(--slate); line-height: 1.6; margin: 0 auto 32px;
  font-size: 18px; font-weight: 430; max-width: 440px;
}
.intro-puzzle { display: flex; gap: 20px; justify-content: center; margin-bottom: 32px; }

.pill {
  padding: 0; background: none;
  color: var(--ash); font-weight: 450; font-size: 14px;
}
.pill-ghost { color: var(--smoke); }

.how-to {
  text-align: start;
  margin: 40px auto 0; max-width: 440px;
  padding: 28px 28px 22px;
  list-style: none;
  background: var(--mist);
  border-radius: var(--r-card);
  color: var(--slate);
  font-size: 16px; line-height: 1.5;
}
.how-to li { position: relative; padding-inline-start: 22px; margin-bottom: 10px; }
.how-to li:last-child { margin-bottom: 0; }
.how-to li::before {
  content: "—"; position: absolute; inset-inline-start: 0; color: var(--ash);
}

.game-head {
  display: flex; flex-direction: column; align-items: center;
  gap: 20px; margin: 16px 0 40px;
}
.progress-wrap { width: 100%; max-width: 440px; }
.progress {
  height: 6px; border-radius: var(--r-pill);
  background: var(--mist); overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0; border-radius: var(--r-pill);
  background: var(--ink);
  transition: width .35s ease;
}
.counter { display: block; margin-top: 12px; color: var(--slate); font-size: 15px; font-weight: 450; text-align: center; }

.timer { position: relative; width: 72px; height: 72px; flex: none; }
.timer svg { transform: rotate(-90deg); }
.timer-track { fill: none; stroke: var(--mist); stroke-width: 3.5; }
.timer-arc {
  fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round;
  stroke-dasharray: 119.38; stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke .3s;
}
.timer.low .timer-arc { stroke: var(--sienna); }
.timer-text {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 480; font-size: 22px; color: var(--ink);
}

.hint-line { min-height: 32px; margin-bottom: 20px; text-align: center; }
.hint-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: none; border: none; cursor: pointer;
  color: var(--ink); font-family: var(--font-ui);
  font-weight: 450; font-size: 16px; padding: 4px 0;
}
.hint-toggle:hover { text-decoration: underline; text-underline-offset: 4px; }
.hint-text {
  margin: 16px auto 0; max-width: 460px;
  color: var(--sienna); font-size: 18px; font-weight: 430; line-height: 1.5;
  background: var(--peach);
  padding: 20px 28px; border-radius: var(--r-card);
  animation: rise .25s ease both;
}

.slots {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 10px; margin-bottom: 40px; min-height: 64px;
}
.slot {
  width: 58px; height: 66px;
  display: grid; place-items: center;
  border-radius: var(--r-input);
  border: 1px solid var(--hairline);
  background: var(--mist);
  font-size: 30px; font-weight: 480; color: var(--ink);
  transition: background .16s, border-color .16s, box-shadow .16s;
}
.slot.filled {
  background: var(--paper);
  border-color: var(--hairline);
  box-shadow: var(--shadow-artifact);
  cursor: pointer;
  animation: pop .18s ease;
}
.slot.revealed {
  background: var(--mist);
  border-color: var(--hairline-soft);
  box-shadow: none; cursor: default;
}
.slots.correct .slot {
  background: var(--good-bg); border-color: var(--good-bg);
  color: var(--good); box-shadow: none;
  animation: bounce .4s ease;
}
.slots.wrong { animation: shake .4s ease; }
.slots.wrong .slot.filled { background: var(--miss-bg); border-color: var(--miss); color: var(--miss); }

.bank {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; margin-bottom: 40px; min-height: 68px;
}
.bank-row {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 12px;
}
.tile {
  width: 62px; height: 68px;
  display: grid; place-items: center;
  border-radius: var(--r-input);
  border: 1px solid var(--hairline);
  background: var(--paper);
  color: var(--ink);
  font-size: 32px; font-weight: 480;
  cursor: pointer;
  box-shadow: var(--shadow-artifact);
  transition: transform .13s, box-shadow .13s, opacity .15s;
  user-select: none;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.tile:active { transform: translateY(0) scale(.97); }
.tile.used { opacity: 0; pointer-events: none; transform: scale(.6); }

.tools { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.tool {
  display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: var(--r-pill);
  border: 1px solid var(--hairline); background: transparent;
  color: var(--slate); cursor: pointer;
  font-family: var(--font-ui); font-weight: 450; font-size: 15px;
  transition: color .16s, background .16s, border-color .16s;
}
.tool:hover { color: var(--ink); background: var(--fog); border-color: var(--hairline-soft); }
.tool:disabled { opacity: .4; cursor: not-allowed; }
.tool:disabled:hover { background: transparent; color: var(--slate); }

.flash { text-align: center; margin-top: 28px; font-weight: 480; font-size: 18px; min-height: 26px; }
.flash.good { color: var(--ink); }
.flash.bad { color: var(--slate); }

.result-card {
  margin: auto 0; width: 100%; max-width: 560px; align-self: center;
  padding: 48px 8px; text-align: center;
  background: transparent; border: none; box-shadow: none;
  animation: rise .5s ease both;
}
.result-emoji { font-size: 44px; }
.result-title {
  font-family: var(--font-serif); font-weight: 400;
  font-size: clamp(34px, 7vw, 44px); line-height: 1.3; letter-spacing: -.66px;
  margin: 16px 0 8px; color: var(--ink);
}
.score-big { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: 8px 0 36px; }
#scoreNum {
  font-size: clamp(72px, 16vw, 90px); font-weight: 450; line-height: 1;
  letter-spacing: -2.25px; color: var(--ink);
}
.score-of { color: var(--slate); font-size: 20px; font-weight: 450; }

.result-stats { display: flex; gap: 12px; margin-bottom: 32px; }
.rstat { flex: 1; padding: 24px 8px; border-radius: var(--r-card); background: var(--mist); }
.rstat-num { display: block; font-size: 28px; font-weight: 500; color: var(--ink); }
.rstat-lbl { display: block; margin-top: 6px; font-size: 14px; color: var(--ash); }

.result-list {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin-bottom: 36px; max-height: 200px; overflow-y: auto;
}
.rword {
  padding: 8px 14px; border-radius: var(--r-pill); font-weight: 450; font-size: 17px;
  border: 1px solid var(--hairline);
}
.rword.ok { background: var(--paper); color: var(--ink); border-color: var(--hairline-soft); }
.rword.miss { background: var(--miss-bg); color: var(--miss); border-color: transparent; text-decoration: line-through; }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.result-actions .btn { flex: 0 1 auto; }
.comeback { color: var(--slate); font-size: 15px; margin: 24px 0 0; }

.modal {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(23,25,28,.28); backdrop-filter: blur(3px);
  padding: 20px; animation: fade .2s ease both;
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative; width: 100%; max-width: 400px; padding: 40px 32px; text-align: center;
  background: var(--paper); border-radius: var(--r-card); box-shadow: var(--shadow-overlay);
}
.modal-card h3 {
  font-family: var(--font-serif); font-weight: 400; font-size: 30px;
  letter-spacing: -.66px; margin: 0 0 28px;
}
.modal-close {
  position: absolute; inset-inline-end: 18px; inset-block-start: 14px;
  background: none; border: none; font-size: 26px; line-height: 1;
  color: var(--smoke); cursor: pointer;
}
.modal-close:hover { color: var(--ink); }
.modal-note { color: var(--ash); font-size: 14px; margin: 24px 0 0; }

.archive-card { max-width: 460px; text-align: start; }
.archive-card h3 { text-align: center; margin-bottom: 8px; }
.archive-intro { text-align: center; margin: 0 0 24px; }
.archive-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: min(60vh, 460px); overflow-y: auto;
  margin: 0 -8px; padding: 0 8px;
}
.archive-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 14px 18px;
  border: 1px solid var(--hairline); border-radius: var(--r-input);
  background: var(--paper); cursor: pointer;
  font-family: var(--font-ui); text-align: start;
  transition: background .16s, border-color .16s, transform .12s;
}
.archive-item:hover { background: var(--fog); border-color: var(--hairline-soft); }
.archive-item:active { transform: scale(.99); }
.archive-item.is-today { border-color: var(--ink); }
.archive-meta { display: flex; flex-direction: column; gap: 3px; }
.archive-no { font-weight: 500; font-size: 16px; color: var(--ink); }
.archive-date { font-size: 13px; color: var(--ash); }
.archive-badge {
  flex: none; font-size: 13px; font-weight: 450; color: var(--smoke);
  padding: 5px 12px; border-radius: var(--r-pill); background: var(--mist);
}
.archive-badge.done { color: var(--sienna); background: var(--peach); }

.toast {
  position: fixed; inset-block-end: 28px; inset-inline: 0;
  margin: auto; width: max-content; max-width: 90%;
  background: var(--ink); color: var(--paper);
  padding: 14px 22px; border-radius: var(--r-pill);
  font-weight: 450; font-size: 15px; z-index: 50;
  animation: rise .25s ease both;
}
.toast[hidden] { display: none; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(.7); } 100% { transform: scale(1); } }
@keyframes bounce { 0%,100% { transform: translateY(0); } 40% { transform: translateY(-10px); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }

@media (max-width: 420px) {
  .tile { width: 54px; height: 62px; font-size: 28px; }
  .slot { width: 50px; height: 60px; font-size: 27px; }
  .tool span { display: none; }
  .tool { padding: 0 14px; }
  .icon-btn span { display: none; }
  .icon-btn { padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .05ms !important; }
}
