:root {
  --ink: #1d2447;
  --ink-soft: #5d6690;
  --card: #ffffff;
  --brand: #2e7dff;
  --brand-dark: #1957c9;
  --good: #1fb26b;
  --good-bg: #dbf7e8;
  --bad: #ee5a5a;
  --bad-bg: #ffe3e3;
  --warn: #ff9f1c;
  --gold: #ffb400;
  --line: #dde4fb;
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 600px at 70% -10%, #3a4fb8 0%, #1a2150 55%, #10152f 100%) fixed;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 880px; margin: 0 auto; padding: 12px 12px 36px; min-height: 100vh; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3, p { margin: 0; }

/* ---------- دکمه‌ها ---------- */
.btn {
  border: 0; border-radius: 14px; padding: 12px 22px; font-weight: 800; font-size: 1.05rem;
  background: var(--brand); color: #fff; box-shadow: 0 5px 0 var(--brand-dark);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--brand-dark); }
.btn.big { width: 100%; padding: 15px; font-size: 1.2rem; }
.btn.good { background: var(--good); box-shadow: 0 5px 0 #14804d; }
.btn.good:active { box-shadow: 0 1px 0 #14804d; }
.btn.fire { background: linear-gradient(180deg, #ff7a3d, #ee3d3d); box-shadow: 0 5px 0 #a82a2a; }
.btn.fire:active { box-shadow: 0 1px 0 #a82a2a; }
.btn.ghost { background: #fff; color: var(--brand-dark); box-shadow: 0 5px 0 var(--line); border: 2px solid var(--line); }
.btn.ghost:active { box-shadow: 0 1px 0 var(--line); }
.btn.small { padding: 8px 14px; font-size: .9rem; border-radius: 12px; box-shadow: 0 3px 0 var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 10px 30px rgba(0, 0, 20, .35); }
.muted { color: var(--ink-soft); }

/* ---------- شروع ---------- */
.welcome { text-align: center; padding-top: 20px; color: #fff; max-width: 520px; margin: 0 auto; }
.welcome h1 { font-size: 2.1rem; font-weight: 800; }
.welcome .sub { color: #c5cdf5; margin: 4px 0 18px; }
.welcome .card { color: var(--ink); text-align: right; display: grid; gap: 16px; }
.lbl { font-weight: 800; display: block; margin-bottom: 8px; }
.text-input { width: 100%; font: inherit; font-size: 1.15rem; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: #f7f9ff; color: var(--ink); }
.text-input:focus { outline: 3px solid #b5ceff; border-color: var(--brand); }
.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.choice { border: 3px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 6px; text-align: center; font-weight: 600; }
.choice[aria-pressed="true"] { border-color: var(--brand); background: #eaf2ff; box-shadow: 0 0 0 3px #bcd5ff; }
.code-input { text-align: center; letter-spacing: .2em; font-weight: 800; }
.code-input::placeholder { letter-spacing: .1em; font-weight: 400; }
.msg { border-radius: 12px; padding: 8px 12px; font-weight: 600; }
.msg.bad { background: var(--bad-bg); color: #9b2b2b; }
.msg.good { background: var(--good-bg); color: #0f6b44; }
.welcome a { color: #fff; font-weight: 800; }

/* ---------- پروفایل‌ها ---------- */
.profile-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.profile-pick { display: grid; grid-template-columns: 52px 1fr; gap: 12px; align-items: center; text-align: right; background: #fff; border: 3px solid var(--line); border-radius: 20px; padding: 10px 14px; box-shadow: 0 6px 0 var(--line); }
.profile-row.active .profile-pick { border-color: var(--brand); box-shadow: 0 6px 0 var(--brand-dark); }
.profile-pick .av { width: 48px; height: 48px; border-radius: 50%; background: #eaf2ff; color: var(--brand-dark); display: grid; place-items: center; font-weight: 800; font-size: 1.4rem; }
.profile-pick .t { font-weight: 800; font-size: 1.1rem; }
.profile-pick .s { color: var(--ink-soft); font-size: .9rem; }

/* ---------- همگام‌سازی و فصل‌ها ---------- */
.sync-line { text-align: center; color: #c5cdf5; font-size: .85rem; margin-top: 8px; }
.chapters { background: #fff; border-radius: 18px; padding: 10px 16px; margin-top: 14px; }
.chapters summary { cursor: pointer; font-weight: 800; }
.chapters > div { margin-top: 10px; }
.chk { display: flex; gap: 10px; align-items: center; padding: 8px 4px; font-weight: 600; cursor: pointer; }
.chk input { width: 22px; height: 22px; accent-color: var(--good); }

/* ---------- انتخاب مأموریت ---------- */
.missions h1 { color: #fff; font-size: 1.6rem; margin: 6px 0 2px; }
.missions .sub { color: #c5cdf5; margin-bottom: 14px; }
.mission-list { display: grid; gap: 12px; }
.mission {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; text-align: right; width: 100%;
  background: #fff; border: 3px solid var(--line); border-radius: 20px; padding: 12px 16px; box-shadow: 0 6px 0 var(--line);
}
.mission .ic { width: 56px; height: 56px; border-radius: 16px; background: #eaf2ff; display: grid; place-items: center; font-size: 1.9rem; }
.mission .t { font-weight: 800; font-size: 1.1rem; }
.mission .s { color: var(--ink-soft); font-size: .9rem; }
.mission.open { border-color: var(--brand); box-shadow: 0 6px 0 var(--brand-dark); }
.mission.done { border-color: var(--good); box-shadow: 0 6px 0 #14804d; }
.mission.locked { opacity: .55; filter: grayscale(.6); cursor: not-allowed; }
.stars { letter-spacing: 2px; color: var(--gold); font-size: 1.3rem; white-space: nowrap; }
.stars .off { color: #d3d9ef; }
.footer-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }

/* ---------- نبرد ---------- */
.hud { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; color: #fff; }
.hud .pill { background: rgba(255, 255, 255, .14); border-radius: 99px; padding: 2px 12px; font-weight: 600; font-size: .92rem; white-space: nowrap; }
.hud .title { font-weight: 800; margin-inline-end: auto; }
.shield { display: flex; align-items: center; gap: 6px; }
.shield .bar { width: 120px; height: 12px; background: rgba(255, 255, 255, .2); border-radius: 99px; overflow: hidden; }
.shield .bar i { display: block; height: 100%; background: linear-gradient(90deg, #4be3a0, #1fb26b); transition: width .4s; }
.shield .bar i.low { background: linear-gradient(90deg, #ffb347, #ee5a5a); }
.pip { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, .25); margin-inline-start: 3px; }
.pip.on { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.pill.armed { background: var(--warn); color: #3a2300; animation: glow 1s ease-in-out infinite; }
.stage { position: relative; border-radius: 18px; overflow: hidden; box-shadow: 0 10px 30px rgba(0, 0, 20, .45); border: 3px solid rgba(255, 255, 255, .25); }
#cv { display: block; width: 100%; height: auto; background: #8ad0ff; touch-action: none; }
#banner {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); background: rgba(20, 25, 60, .85); color: #fff;
  padding: 6px 20px; border-radius: 99px; font-weight: 800; pointer-events: none; opacity: 0; transition: opacity .25s; white-space: nowrap;
}
#banner.show { opacity: 1; }

#panel { margin-top: 10px; }
.qmeta { color: var(--ink-soft); font-size: .88rem; margin-bottom: 4px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.qtag { background: #eaf2ff; color: var(--brand-dark); border-radius: 99px; padding: 0 10px; font-weight: 600; }
.qtag.again { background: var(--bad-bg); color: #b73636; }
.qtext { font-size: 1.35rem; font-weight: 800; margin: 4px 0 12px; }
.options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.opt {
  display: grid; grid-template-columns: 32px 1fr; gap: 8px; align-items: center; text-align: right;
  background: #fff; border: 3px solid var(--line); border-radius: 14px; padding: 10px 12px; font-size: 1.1rem; font-weight: 600;
  box-shadow: 0 4px 0 var(--line); transition: transform .08s;
}
.opt .k { width: 28px; height: 28px; border-radius: 8px; background: #eaf2ff; display: grid; place-items: center; font-size: .8rem; color: var(--brand-dark); }
.opt:hover:not(:disabled) { border-color: #8db4ff; }
.opt:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.opt.right { background: var(--good-bg); border-color: var(--good); box-shadow: 0 4px 0 #14804d; }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad); box-shadow: 0 4px 0 #c24141; animation: shake .4s; }
.opt:disabled { cursor: default; }
.feedback { margin-top: 12px; border-radius: 14px; padding: 12px 14px; animation: rise .3s; display: grid; gap: 8px; }
.feedback.good { background: var(--good-bg); color: #0f6b44; }
.feedback.bad { background: var(--bad-bg); color: #9b2b2b; }
.feedback .head { font-weight: 800; font-size: 1.1rem; }
.feedback .why { color: var(--ink); }
.feedback .effect { font-weight: 600; }

.aim { display: grid; gap: 12px; }
.aim .status { border-radius: 12px; padding: 8px 12px; font-weight: 600; }
.aim .status.good { background: var(--good-bg); color: #0f6b44; }
.aim .status.bad { background: var(--bad-bg); color: #9b2b2b; }
.aim .status.plain { background: #eaf2ff; color: var(--brand-dark); }
.sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.slider label { display: flex; justify-content: space-between; font-weight: 800; margin-bottom: 4px; }
.slider input[type=range] { width: 100%; height: 34px; accent-color: var(--brand); }
.hint { text-align: center; font-weight: 600; color: var(--ink-soft); padding: 10px 0; }

/* ---------- عبارت‌های ریاضی ---------- */
.code { display: inline-block; direction: ltr; unicode-bidi: isolate; white-space: pre; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em; }
.math { display: inline-block; direction: ltr; unicode-bidi: isolate; white-space: nowrap; font-weight: 600; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 .12em; line-height: 1.15; font-size: .92em; }
.frac > span:first-child { border-bottom: 2px solid currentColor; padding: 0 .25em; }
.frac > span:last-child { padding: 0 .25em; }
.math sup { font-size: .65em; }
.qtext .math { font-size: 1.15em; }

/* ---------- نتیجه ---------- */
.result { text-align: center; padding: 8px 0; }
.result .big-em { font-size: 4rem; line-height: 1.2; }
.result h2 { font-size: 1.7rem; margin: 4px 0; }
.result .stars { font-size: 2.4rem; margin: 4px 0 8px; }
.result .note { color: var(--ink-soft); margin-bottom: 14px; }
.actions { display: grid; gap: 10px; max-width: 420px; margin: 0 auto; }

/* ---------- گزارش ---------- */
.report { max-width: 640px; margin: 0 auto; }
.report h2 { margin-bottom: 12px; }
.report section { margin-bottom: 16px; }
.report h3 { margin-bottom: 6px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: #eef3ff; border-radius: 14px; padding: 10px; text-align: center; }
.kpi b { display: block; font-size: 1.5rem; }
.stat-row { display: grid; grid-template-columns: 150px 1fr 56px; gap: 10px; align-items: center; margin: 8px 0; }
.stat-row .bar { height: 12px; background: #e3eaff; border-radius: 99px; overflow: hidden; }
.stat-row .bar i { display: block; height: 100%; background: linear-gradient(90deg, #4be3a0, #1fb26b); }
.stat-row .p { text-align: left; font-weight: 800; }
.weak { padding: 10px 12px; border: 2px solid var(--line); border-radius: 14px; margin: 8px 0; }
.weak .n { color: var(--bad); font-weight: 600; font-size: .9rem; }

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
#confetti span { position: absolute; top: -40px; font-size: 1.6rem; animation: fall linear forwards; }

@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
@keyframes glow { 50% { box-shadow: 0 0 14px var(--warn); } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-width: 640px) {
  .options, .sliders { grid-template-columns: 1fr; }
  .qtext { font-size: 1.15rem; }
  .mission { grid-template-columns: 52px 1fr; }
  .mission .stars { grid-column: 1 / -1; }
}

.qtag.review { background: #fff1d6; color: #9a5b00; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.pills .pill { background: rgba(255,255,255,.14); color: #fff; border-radius: 99px; padding: 2px 12px; font-weight: 600; font-size: .92rem; }

/* ---------- صفحهٔ عریض (لپ‌تاپ/دسکتاپ): نبرد بدون اسکرول؛ پنل سؤال کنار صحنه ---------- */
@media (min-width: 820px) and (min-aspect-ratio: 5/4) {
  .in-battle #app { max-width: 1400px; padding-bottom: 12px; }
  .battle { display: grid; grid-template-columns: 420px minmax(0, 1fr); grid-template-areas: "hud hud" "panel stage"; gap: 12px; align-items: start; }
  .battle .hud { grid-area: hud; margin-bottom: 0; }
  .battle .stage { grid-area: stage; }
  .battle #panel { grid-area: panel; margin-top: 0; max-height: calc(100vh - 100px); overflow-y: auto; }
  .battle #cv { max-height: calc(100vh - 100px); object-fit: contain; }
  .battle .sliders { grid-template-columns: 1fr; }
  .battle .options { gap: 8px; }
  .battle .opt { grid-template-columns: 26px 1fr; gap: 6px; }
  .battle .feedback { margin-top: 10px; padding: 10px 12px; gap: 6px; }
  .battle .feedback .btn { position: sticky; bottom: 0; }
  .battle .qtext { font-size: 1.2rem; margin-bottom: 10px; }
  .battle .opt { padding: 8px 12px; font-size: 1.05rem; }
}

.hud .quit { box-shadow: 0 3px 0 var(--line); }
