@font-face { font-family: "Nunito"; src: url(../fonts/nunito.woff2) format("woff2"); font-weight: 400 900; font-display: block; }
@font-face { font-family: "Vazirmatn"; src: url(../fonts/vazirmatn.woff2) format("woff2"); font-weight: 100 900; font-display: block; }

:root {
  --bg: #0f1226;
  --bg2: #171b38;
  --card: #1f2550;
  --card2: #283066;
  --line: #343c7a;
  --text: #f3f4ff;
  --muted: #a3a9d9;
  --accent: #7c5cff;
  --accent2: #22d3ee;
  --good: #22c55e;
  --gold: #fbbf24;
  --warn: #fb923c;
  --bad: #f43f5e;
  --radius: 22px;
  --font: "Nunito", "Vazirmatn", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { overflow: hidden; user-select: none; -webkit-user-select: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.hidden { display: none !important; }
[dir="auto"], .fa { font-family: "Vazirmatn", var(--font); }

/* ---------- home ---------- */
#home { position: absolute; inset: 0; display: flex; flex-direction: column;
  background: radial-gradient(1200px 600px at 10% -10%, #2b1f6b 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 10%, #0e4a5c 0%, transparent 55%), var(--bg); }
.top { display: flex; align-items: center; gap: 16px; padding: 22px 28px 10px; }
.hello { font-size: 34px; font-weight: 900; letter-spacing: .3px; }
.hello small { display: block; font-size: 16px; font-weight: 700; color: var(--muted); letter-spacing: 0; }
.spacer { flex: 1; }
.starbank { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-radius: 999px;
  background: linear-gradient(135deg, #3a2a00, #5a3d00); border: 2px solid #8a6200; font-size: 24px; font-weight: 900;
  color: var(--gold); box-shadow: 0 0 24px #fbbf2433; }
.starbank .s { font-size: 28px; filter: drop-shadow(0 0 6px #fbbf24aa); }
.iconbtn { width: 52px; height: 52px; border-radius: 16px; background: var(--card); display: grid; place-items: center;
  font-size: 24px; border: 2px solid var(--line); }
.iconbtn:active { transform: scale(.94); }

.tabs { display: flex; gap: 12px; padding: 8px 28px 14px; }
.tab { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; padding: 14px 24px; border-radius: 18px;
  background: var(--bg2); border: 2px solid var(--line); font-size: 22px; font-weight: 800; color: var(--muted); }
.tab .n { min-width: 34px; height: 34px; padding: 0 10px; border-radius: 999px; display: grid; place-items: center;
  background: var(--card2); color: var(--text); font-size: 18px; }
.tab.on { color: var(--text); background: linear-gradient(135deg, var(--accent), #5b3df5); border-color: #a593ff;
  box-shadow: 0 8px 28px #7c5cff55; }
.tab.on .n { background: #ffffff33; }

.grid { flex: 1; overflow-y: auto; padding: 6px 28px 40px; display: grid; gap: 22px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); align-content: start; touch-action: pan-y; }
.card { position: relative; border-radius: var(--radius); background: var(--card); border: 2px solid var(--line);
  overflow: hidden; display: flex; flex-direction: column; text-align: left; transition: transform .15s; }
.card:active { transform: scale(.96); }
.card .thumb { aspect-ratio: 3 / 4; background: #fff center / cover no-repeat; }
.card .meta { padding: 10px 14px 14px; }
.card .t { font-size: 18px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { font-size: 14px; font-weight: 700; color: var(--muted); margin-top: 2px; }
.badge { position: absolute; top: 10px; right: 10px; padding: 6px 12px; border-radius: 999px; font-size: 15px;
  font-weight: 900; background: #000a; backdrop-filter: blur(6px); }
.badge.redo { background: var(--warn); color: #2a1300; }
.badge.wait { background: #1e3a8acc; color: #dbeafe; }
.badge.ok { background: linear-gradient(135deg, #f59e0b, #fde047); color: #3a2400; box-shadow: 0 0 16px #fbbf2499; }
.card.fresh { border-color: var(--accent2); box-shadow: 0 0 0 3px #22d3ee44, 0 10px 30px #22d3ee33; }
.empty { grid-column: 1 / -1; text-align: center; padding: 70px 20px; color: var(--muted); font-size: 22px; font-weight: 800; }
.empty .big { font-size: 80px; display: block; margin-bottom: 12px; }

/* ---------- worksheet ---------- */
#sheetview { position: absolute; inset: 0; background: #2a2f55; display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg2);
  border-bottom: 2px solid var(--line); z-index: 5; flex-wrap: nowrap; }
.bar .title { font-size: 20px; font-weight: 900; padding: 0 8px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 22vw; }
@media (max-width: 520px) {
  .bar { gap: 6px; padding: 6px 8px; }
  .bar .spacer { display: none; }
  .top { padding: 16px 14px 6px; gap: 10px; } .hello { font-size: 26px; }
  .tabs { padding: 6px 14px 10px; gap: 8px; } .tab { flex: 1 1 0; padding: 10px 12px; font-size: 16px; gap: 6px; justify-content: center; }
  .tab .n { min-width: 28px; height: 28px; padding: 0 7px; }
  .bar .donebtn { height: 46px; padding: 0 14px; font-size: 18px; }
  .bar .tool { height: 44px; min-width: 44px; }
  .bar .prog { font-size: 14px; padding: 4px 8px; }
  .bar .title { flex: 1 1 0; min-width: 0; max-width: none; font-size: 15px; line-height: 1.15; padding: 0 2px;
    white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
}
.tool { height: 50px; min-width: 50px; padding: 0 10px; border-radius: 15px; display: grid; place-items: center;
  background: var(--card); border: 2px solid transparent; font-size: 22px; font-weight: 900; }
.tool.on { border-color: #fff; background: var(--card2); box-shadow: 0 0 0 3px #7c5cff88; }
.tool:active { transform: scale(.93); }
.tool:disabled { opacity: .35; }
.dot { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #fff3; }
.sep { width: 2px; height: 34px; background: var(--line); margin: 0 4px; }
.donebtn { height: 54px; padding: 0 26px; border-radius: 17px; font-size: 22px; font-weight: 900; color: #052e14;
  background: linear-gradient(135deg, #4ade80, #22c55e); box-shadow: 0 6px 22px #22c55e66; white-space: nowrap; }
.donebtn:active { transform: scale(.95); }
.saved { font-size: 14px; font-weight: 800; color: var(--muted); min-width: 80px; text-align: right; }
.note { margin: 0; padding: 10px 18px; font-size: 18px; font-weight: 800; background: #7c2d12; color: #ffedd5;
  border-bottom: 2px solid #c2410c; }
.note.ok { background: #713f12; color: #fef3c7; border-color: #ca8a04; }

#stage { position: relative; flex: 1; overflow: hidden; touch-action: none; }
#sheet { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: 0 20px 60px #0008; background: #fff; }
#sheet img { display: block; pointer-events: none; -webkit-user-drag: none; }
#sheet canvas { position: absolute; left: 0; top: 0; pointer-events: none; }
#texts { position: absolute; inset: 0; }
.tbox { position: absolute; min-width: 40px; padding: 4px 10px; border-radius: 10px; outline: none;
  font-family: "Nunito", "Vazirmatn", sans-serif; font-weight: 700; line-height: 1.2; white-space: pre;
  user-select: text; -webkit-user-select: text; border: 3px dashed transparent; background: transparent; }
.editing .tbox { border-color: #7c5cff55; background: #ffffffaa; }
.tbox:focus { border-color: #7c5cff; background: #ffffffdd; }
.tdel { position: absolute; width: 46px; height: 46px; margin: -23px 0 0 -10px; border-radius: 50%; background: var(--bad);
  color: #fff; font-size: 22px; font-weight: 900; display: grid; place-items: center; z-index: 3; }

.zoomhint { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column;
  gap: 8px; z-index: 4; }
.zoomhint .tool { background: #171b38ee; border-color: var(--line); }
.toolbar { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center;
  gap: 6px; padding: 8px; border-radius: 24px; background: #171b38f2; border: 2px solid var(--line); z-index: 5;
  box-shadow: 0 14px 40px #000a; backdrop-filter: blur(10px); max-width: calc(100vw - 16px); overflow-x: auto; }
.toolbar .tool { flex: 0 0 auto; }
/* pop-up at the pen tip, opened by the pen's buttons */
.penmenu { position: fixed; display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 24px;
  background: #171b38f8; border: 2px solid #a593ff; z-index: 20; box-shadow: 0 14px 40px #000c, 0 0 0 4px #7c5cff44; }
.penmenu .tool { height: 60px; min-width: 60px; font-size: 26px; }
.penmenu .dot { width: 34px; height: 34px; }
@media (max-width: 860px) { .toolbar .tool { height: 46px; min-width: 46px; padding: 0 6px; font-size: 20px; }
  .toolbar { gap: 4px; padding: 6px; } .toolbar .sep { margin: 0 1px; } }

/* ---------- overlays ---------- */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.cheer { position: fixed; inset: 0; display: grid; place-items: center; z-index: 51; pointer-events: none; }
.cheer .word { font-size: 110px; font-weight: 900; color: #fff; text-shadow: 0 0 30px #7c5cff, 0 8px 0 #4c1d95;
  animation: pop 1.6s cubic-bezier(.2, 1.6, .4, 1) both; text-align: center; }
.cheer .word small { display: block; font-size: 40px; color: var(--gold); text-shadow: 0 0 20px #f59e0b; }
@keyframes pop { 0% { transform: scale(.2) rotate(-12deg); opacity: 0; } 25% { transform: scale(1.15) rotate(3deg); opacity: 1; }
  40% { transform: scale(1) rotate(0); } 80% { opacity: 1; } 100% { transform: scale(1.05) translateY(-30px); opacity: 0; } }

.modal { position: fixed; inset: 0; background: #05061299; backdrop-filter: blur(8px); display: grid; place-items: center; z-index: 40; }
.panel { width: min(560px, 92vw); background: var(--bg2); border: 2px solid var(--line); border-radius: 28px; padding: 26px;
  text-align: center; box-shadow: 0 30px 80px #000a; }
.panel h2 { margin: 0 0 8px; font-size: 28px; }
.panel p { color: var(--muted); font-weight: 700; margin: 6px 0 16px; word-break: break-all; }
.panel .qr { background: #fff; border-radius: 18px; padding: 14px; display: inline-block; }
.panel .row { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }
.big-btn { height: 56px; padding: 0 26px; border-radius: 18px; font-size: 20px; font-weight: 900; background: var(--card2); }
.big-btn.primary { background: linear-gradient(135deg, var(--accent), #5b3df5); }

/* ---------- pairing ---------- */
#pair { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; overflow-y: auto; }
#pair .panel { text-align: center; }
#pair .code { width: 100%; max-width: 340px; height: 84px; margin: 6px auto 0; display: block; text-align: center;
  font: 900 50px/1 var(--font); letter-spacing: 14px; color: var(--text); background: var(--card); border: 3px solid var(--line);
  border-radius: 20px; outline: none; }
#pair .code:focus { border-color: var(--accent); box-shadow: 0 0 0 4px #7c5cff55; }
#pairmsg { min-height: 1.4em; color: var(--warn) !important; }
#kidpick { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }

/* ---------- answer fields over the page ---------- */
#texts { pointer-events: none; }
#texts .tbox, #texts .tdel { pointer-events: auto; }
#fields { position: absolute; inset: 0; pointer-events: none; }
.fld { position: absolute; pointer-events: auto; margin: 0; padding: 0 2px; min-width: 24px; text-align: center;
  font-family: var(--font); font-weight: 800; line-height: 1; color: #1d4ed8; background: #eef2ff99;
  border: 2px solid #7c5cff88; border-radius: 6px; outline: none; user-select: text; -webkit-user-select: text;
  transition: box-shadow .15s, background .15s; }
.fld:focus { background: #fffffff2; border-color: #7c5cff; box-shadow: 0 0 0 4px #7c5cff66; }
.fld.locked { background: transparent; border-color: transparent; }
.fld.good { color: #15803d; background: #dcfce799; border-color: #22c55e; }
.fld.bad { color: #be123c; background: #ffe4e6cc; border-color: #f43f5e; border-width: 3px; animation: wob 1.6s ease-in-out 2; }
.fld.bad.changed, .fld.changed { color: #1d4ed8; }
.fld.good.locked::after { content: ""; }
button.fld { display: grid; place-items: center; }
button.fld:disabled { opacity: 1; cursor: default; }
@keyframes wob { 0%, 100% { transform: none; } 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }
.hint { position: absolute; pointer-events: auto; border-radius: 50%; background: #fde047; display: grid; place-items: center;
  box-shadow: 0 0 0 3px #fff, 0 4px 14px #0006; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }
.pop { position: fixed; z-index: 30; display: flex; gap: 8px; padding: 10px; border-radius: 22px; background: var(--bg2);
  border: 2px solid var(--line); box-shadow: 0 16px 40px #0009; }
#cmpop .tool { height: 70px; min-width: 70px; font-size: 38px; font-weight: 900; }
#hint { flex-direction: column; max-width: min(460px, 92vw); }
#hint .txt { font-size: 20px; font-weight: 700; line-height: 1.5; padding: 4px 6px; user-select: text; }
#hint .txt[lang="fa"] { font-family: "Vazirmatn", sans-serif; font-weight: 500; }
#hint .row { display: flex; gap: 8px; justify-content: flex-end; }
.prog { font-size: 16px; font-weight: 900; padding: 6px 12px; border-radius: 999px; background: var(--card); }
.donebtn.ready { animation: pulse 1.2s ease-in-out infinite; }
