/* ============================================================
   app-ui.css — the signed-in app's visual layer
   - side navigation (grouped, coloured tiles)
   - "دوره‌های من" (hero, course cards, progress rings)
   - the review session (/Study): card stage, segmented progress,
     answer buttons, completion screen
   Everything is built from the design tokens in styles.css (--surface,
   --color-primary, --box-1..5 ...) so dark mode needs no extra rules.
   ============================================================ */

/* ---------- tones: one hue per destination / language ---------- */
[data-tone="indigo"]  { --tone: #6366f1; }
[data-tone="emerald"] { --tone: #10b981; }
[data-tone="sky"]     { --tone: #0ea5e9; }
[data-tone="amber"]   { --tone: #f59e0b; }
[data-tone="violet"]  { --tone: #8b5cf6; }
[data-tone="rose"]    { --tone: #f43f5e; }
[data-tone="teal"]    { --tone: #14b8a6; }
[data-tone="slate"]   { --tone: #64748b; }

/* ---------- side navigation ---------- */
.side-group-label {
  font-size: .68rem; font-weight: 800; letter-spacing: .04em; color: var(--text-faint);
  padding: 0 .55rem .4rem;
}
.side-group-rule { display: none; }

.side-link {
  position: relative; display: flex; align-items: center; gap: .7rem;
  padding: .32rem .45rem; border-radius: 1rem;
  font-size: .875rem; font-weight: 600; color: var(--text-muted);
  transition: background-color .18s ease, color .18s ease;
}
.side-link:hover { background: var(--surface-2); color: var(--text); }

.side-tile {
  width: 2.25rem; height: 2.25rem; flex-shrink: 0; border-radius: .8rem;
  display: grid; place-items: center;
  color: var(--tone);
  background: color-mix(in srgb, var(--tone) 13%, var(--surface));
  transition: transform .18s ease, background-color .18s ease, color .18s ease, box-shadow .18s ease;
}
.side-link:hover .side-tile { transform: scale(1.07) rotate(-3deg); }

.side-link.is-active {
  color: var(--text); font-weight: 800;
  background: color-mix(in srgb, var(--tone) 9%, var(--surface));
}
.side-link.is-active .side-tile {
  color: #fff;
  background: linear-gradient(135deg, var(--tone), color-mix(in srgb, var(--tone) 68%, #000));
  box-shadow: 0 8px 16px -8px var(--tone);
}
/* the accent on the edge that faces the page (the aside's border) */
.side-link.is-active::after {
  content: ""; position: absolute; inset-inline-end: -.8rem; top: 22%; bottom: 22%; width: 3px;
  border-radius: 3px 0 0 3px; background: var(--tone);
}
[dir="rtl"] .side-link.is-active::after { border-radius: 0 3px 3px 0; }

.side-search {
  display: flex; align-items: center; gap: .6rem; width: 100%;
  padding: .6rem .85rem; border-radius: 1rem; font-size: .8125rem;
  color: var(--text-muted); background: var(--surface-2);
  border: 1px solid transparent; transition: border-color .15s ease, color .15s ease;
}
.side-search:hover { color: var(--text); border-color: color-mix(in srgb, var(--color-primary) 35%, var(--border)); }

.side-cta {
  display: flex; align-items: center; gap: .7rem; padding: .65rem .8rem; border-radius: 1.1rem; color: #fff;
  background: linear-gradient(135deg, #7c6cf0, var(--color-primary-700));
  box-shadow: 0 12px 24px -12px rgba(91, 75, 219, .8);
  transition: transform .15s ease, box-shadow .2s ease;
}
.side-cta:hover { transform: translateY(-1px); box-shadow: 0 16px 28px -12px rgba(91, 75, 219, .9); }
.side-cta-icon {
  width: 2.25rem; height: 2.25rem; border-radius: .8rem; flex-shrink: 0;
  display: grid; place-items: center; background: rgba(255, 255, 255, .18);
}

/* collapsed icon rail */
.is-collapsed .side-group-label { display: none; }
.is-collapsed .side-group-rule { display: block; height: 1px; margin: .15rem .7rem .55rem; background: var(--border); }
.is-collapsed .side-link { justify-content: center; padding: .3rem; }
.is-collapsed .side-link.is-active::after { inset-inline-end: -.75rem; }
.is-collapsed .side-search, .is-collapsed .side-cta { justify-content: center; padding: .6rem; }

/* mobile bottom bar: the active tab sits on a soft pill */
.bn-icon { display: grid; place-items: center; width: 3rem; height: 1.75rem; border-radius: 999px; transition: background-color .18s ease; }
.bn-icon.is-on { background: var(--color-primary-soft); }

/* ---------- rings and bars ---------- */
/* registered so the ring can animate from empty to its value */
@property --p { syntax: "<number>"; inherits: false; initial-value: 0; }
.ring {
  transition: --p 1s cubic-bezier(.22, 1, .36, 1);
  --size: 4rem; --thick: .42rem; --p: 0; --fill: var(--color-success); --track: var(--surface-2); --ring-bg: var(--surface);
  position: relative; display: grid; place-items: center; flex-shrink: 0;
  width: var(--size); height: var(--size); border-radius: 50%;
  background: conic-gradient(var(--fill) calc(var(--p) * 1%), var(--track) 0);
}
.ring::before { content: ""; position: absolute; inset: var(--thick); border-radius: 50%; background: var(--ring-bg); }
.ring > * { position: relative; }

/* A course's Leitner distribution: new (grey) then boxes 1-5 */
.leit-bar { display: flex; gap: 2px; height: .5rem; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.leit-bar > span { display: block; min-width: 3px; transition: flex-grow .6s cubic-bezier(.22, 1, .36, 1); }
.leit-dot { display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; flex-shrink: 0; }

/* ---------- hero panel (dark gradient with glass stat tiles) ---------- */
.hero-panel {
  position: relative; overflow: hidden; border-radius: 1.75rem; color: #fff;
  background: linear-gradient(125deg, #7060ec 0%, #5040d4 52%, #392b9a 100%);
  box-shadow: 0 24px 48px -24px rgba(79, 63, 208, .75);
}
.hero-panel::before {
  content: ""; position: absolute; inset-inline-end: -4rem; top: -5rem; width: 18rem; height: 18rem; border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 158, 11, .55), transparent 68%);
}
.hero-panel::after {
  content: ""; position: absolute; inset-inline-start: -3rem; bottom: -6rem; width: 16rem; height: 16rem; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .18), transparent 65%);
}
.hero-panel > * { position: relative; z-index: 1; }
.hero-stat {
  display: flex; align-items: center; gap: .7rem; padding: .7rem .85rem; border-radius: 1.1rem;
  background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .16); backdrop-filter: blur(6px);
}
.hero-stat-icon { width: 2.4rem; height: 2.4rem; flex-shrink: 0; border-radius: .8rem; display: grid; place-items: center; background: rgba(255, 255, 255, .18); }
.btn-white {
  background: #fff; color: var(--color-primary-700);
  box-shadow: 0 10px 22px -10px rgba(0, 0, 0, .45);
}
.btn-white:hover { transform: translateY(-1px); box-shadow: 0 14px 26px -10px rgba(0, 0, 0, .5); }

/* ---------- course cards ---------- */
.mc-card { position: relative; display: flex; flex-direction: column; overflow: hidden; }
.mc-banner {
  position: relative; height: 5.5rem; overflow: hidden;
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 52%, #000));
}
.mc-banner::before { content: ""; position: absolute; inset: 0; opacity: .32; background: radial-gradient(circle at 85% 12%, #fff, transparent 42%); }
.mc-banner::after {
  content: ""; position: absolute; inset-inline-start: -1.5rem; bottom: -2.5rem; width: 7rem; height: 7rem;
  border-radius: 1.6rem; transform: rotate(14deg); background: rgba(255, 255, 255, .13);
}
.mc-flag {
  position: absolute; inset-inline-start: 1.1rem; top: 3.8rem; z-index: 2;
  width: 3.4rem; height: 3.4rem; padding: .3rem; border-radius: 1.1rem; background: var(--surface);
  box-shadow: 0 8px 18px -8px rgba(0, 0, 0, .4);
}
.mc-flag > * { width: 100%; height: 100%; border-radius: .75rem; overflow: hidden; object-fit: cover; display: block; }
.mc-pill {
  display: inline-flex; align-items: center; gap: .3rem; padding: .22rem .65rem; border-radius: 999px;
  font-size: .7rem; font-weight: 800; color: #fff; background: rgba(0, 0, 0, .28); backdrop-filter: blur(4px);
}
.mc-due { color: #3b2400; background: #fbbf24; animation: mcPulse 2.4s ease-in-out infinite; }
@keyframes mcPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, .55); } 50% { box-shadow: 0 0 0 .45rem rgba(251, 191, 36, 0); } }

.mc-stat { text-align: center; padding: .55rem .25rem; border-radius: .9rem; background: var(--surface-2); }
.mc-stat b { display: block; font-size: 1.05rem; font-weight: 900; line-height: 1.4; }
.mc-stat span { display: block; font-size: .68rem; color: var(--text-muted); }

.mc-menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + .35rem); z-index: 30; min-width: 11rem; padding: .35rem;
  border-radius: 1rem; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.mc-menu button, .mc-menu a {
  display: flex; align-items: center; gap: .55rem; width: 100%; padding: .55rem .7rem; border-radius: .7rem;
  font-size: .8125rem; font-weight: 600; text-align: start;
}
.mc-menu button:hover, .mc-menu a:hover { background: var(--surface-2); }

/* ---------- /Study: the review session ---------- */
.st-top { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.st-chip {
  display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .75rem; border-radius: 999px;
  font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--text-muted);
}
.st-chip.is-hot { background: var(--color-accent-soft); color: var(--color-accent); }
.st-chip.is-ok { background: var(--box-3-soft); color: var(--color-success); }
.st-chip.is-bad { background: var(--box-5-soft); color: var(--color-danger); }

.st-segs { display: flex; gap: .22rem; }
.st-seg { flex: 1; height: .4rem; border-radius: 999px; background: var(--surface-2); transition: background-color .25s ease, transform .25s ease; }
.st-seg.is-ok { background: var(--color-success); }
.st-seg.is-bad { background: var(--color-danger); }
.st-seg.is-now { background: var(--color-primary); transform: scaleY(1.6); }
.st-segs.is-dense .st-seg { height: .3rem; }

.st-stage { position: relative; }
.st-card { height: clamp(22rem, 54vh, 31rem); }
.st-card.is-compact { height: clamp(16rem, 42vh, 19rem); }
.st-card .flashcard-inner { border-radius: 1.75rem; box-shadow: var(--shadow-lg); }
.st-face {
  border-radius: 1.75rem; overflow: hidden; align-items: center; justify-content: center; text-align: center; padding: 2.25rem 1.5rem 1.5rem;
}
.st-front {
  background:
    radial-gradient(circle at 88% 8%, color-mix(in srgb, var(--color-primary) 11%, transparent), transparent 46%),
    radial-gradient(circle at 8% 96%, color-mix(in srgb, var(--color-accent) 9%, transparent), transparent 42%),
    var(--surface);
}
.st-back {
  background:
    radial-gradient(circle at 12% 6%, color-mix(in srgb, var(--color-success) 12%, transparent), transparent 44%),
    linear-gradient(165deg, var(--color-primary-soft), var(--surface) 78%);
}
/* The back face carries the meaning plus up to two examples with translations: start below the corner chips,
   centre when it fits, and scroll (never clip) when it does not. */
.st-back { padding-top: 3.2rem; overflow-y: auto; justify-content: center; justify-content: safe center; }
.st-back.has-examples .st-meaning { font-size: clamp(1.3rem, 3.4vw, 1.85rem); line-height: 1.6; }
.st-back.has-examples .st-examples { margin-top: .8rem; }
.st-examples [data-ex-text] { font-size: clamp(.95rem, 2.7vw, 1.1rem); line-height: 1.7; }
.st-examples .st-ex-tr { font-size: clamp(.82rem, 2.4vw, .95rem); line-height: 1.7; margin-top: .15rem; }
.st-examples > .st-example { padding: .55rem .9rem; }
.st-corner { position: absolute; top: .9rem; display: flex; align-items: center; gap: .4rem; }
.st-corner.is-start { inset-inline-start: .9rem; }
.st-corner.is-end { inset-inline-end: .9rem; }

.st-word { font-size: clamp(2rem, 6.4vw, 3.25rem); font-weight: 900; line-height: 1.3; overflow-wrap: anywhere; }
.st-meaning { font-size: clamp(1.6rem, 5vw, 2.4rem); font-weight: 900; line-height: 1.5; color: var(--text); }
.st-phon {
  display: inline-block; margin-top: .6rem; padding: .2rem .8rem; border-radius: 999px; direction: ltr;
  font-size: .95rem; color: var(--text-muted); background: var(--surface-2);
}
.st-hint { margin-top: 1.6rem; font-size: .75rem; color: var(--text-faint); display: inline-flex; align-items: center; gap: .4rem; }
.st-hint kbd, .st-ans kbd, .st-kbd {
  font-family: inherit; font-size: .68rem; font-weight: 800; padding: .05rem .45rem; border-radius: .4rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
}

.st-boxes { display: inline-flex; gap: .22rem; align-items: center; }
.st-boxes i { display: block; width: 1rem; height: .38rem; border-radius: 999px; background: var(--surface-2); }
.st-boxes i.on { background: var(--bx); }

.st-iconbtn {
  width: 2.5rem; height: 2.5rem; border-radius: .9rem; display: grid; place-items: center; flex-shrink: 0;
  color: var(--text-muted); background: var(--surface-2); transition: color .15s ease, background-color .15s ease, transform .15s ease;
}
.st-iconbtn:hover { color: var(--color-primary); background: var(--color-primary-soft); transform: translateY(-1px); }
.st-iconbtn.is-on { color: #fff; background: var(--color-primary); }

.st-examples { margin-top: 1.1rem; width: 100%; max-width: 34rem; display: grid; gap: .6rem; }
.st-example { margin-top: 1.1rem; max-width: 34rem; padding: .85rem 1.1rem; border-radius: 1.1rem; background: color-mix(in srgb, var(--surface) 80%, transparent); border: 1px solid var(--border); }
.st-examples > .st-example { margin-top: 0; padding: .65rem 1rem; border-inline-start: 3px solid var(--color-primary); }
.st-ex-tr.hidden, .st-examples.hidden { display: none; }
.st-example mark { background: var(--color-accent-soft); color: inherit; border-radius: .3rem; padding: 0 .2em; font-weight: 800; }

/* answer buttons */
.st-answers { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.st-ans {
  display: flex; align-items: center; justify-content: center; gap: .55rem; padding: 1rem .75rem;
  border-radius: 1.2rem; font-weight: 800; border: 2px solid transparent; cursor: pointer;
  transition: transform .15s ease, background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.st-ans:active { transform: scale(.98); }
.st-ans.is-wrong { color: var(--color-danger); background: color-mix(in srgb, var(--color-danger) 10%, var(--surface)); border-color: color-mix(in srgb, var(--color-danger) 28%, transparent); }
.st-ans.is-wrong:hover { color: #fff; background: var(--color-danger); box-shadow: 0 12px 22px -12px var(--color-danger); }
.st-ans.is-right { color: var(--color-success); background: color-mix(in srgb, var(--color-success) 11%, var(--surface)); border-color: color-mix(in srgb, var(--color-success) 30%, transparent); }
.st-ans.is-right:hover { color: #fff; background: var(--color-success); box-shadow: 0 12px 22px -12px var(--color-success); }
.st-ans:disabled { opacity: .6; cursor: default; }
.st-reveal { width: 100%; padding: 1rem; font-size: 1rem; }

/* sticky on phones so the buttons never scroll away from the card */
.st-actions { position: sticky; z-index: 20; bottom: calc(4.75rem + env(safe-area-inset-bottom)); padding-top: .25rem; }
@media (min-width: 1024px) { .st-actions { position: static; } }

/* what the answer did to the card's box */
/* a pill straddling the card's bottom edge */
.st-result-wrap { position: absolute; inset-inline: 0; bottom: -1.25rem; z-index: 5; display: flex; justify-content: center; padding-inline: .75rem; pointer-events: none; }
.st-result {
  display: flex; align-items: center; justify-content: center; gap: .6rem; max-width: 100%;
  padding: .65rem 1.1rem; border-radius: 1.1rem; font-size: .82rem; font-weight: 800; animation: stRise .35s cubic-bezier(.22, 1, .36, 1) both;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.st-stage { margin-bottom: .75rem; }
.st-result.is-ok { border-color: color-mix(in srgb, var(--color-success) 45%, transparent); }
.st-result.is-bad { border-color: color-mix(in srgb, var(--color-danger) 45%, transparent); }
.st-box-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 1.6rem; height: 1.6rem; padding: 0 .4rem; border-radius: .55rem; color: #fff; font-weight: 900; font-size: .78rem; }
@keyframes stRise { from { opacity: 0; transform: translateY(.75rem) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes stOut { to { opacity: 0; transform: translateX(-3rem) scale(.96); } }
@keyframes stIn { from { opacity: 0; transform: translateX(3rem) scale(.96); } to { opacity: 1; transform: none; } }
.st-out { animation: stOut .26s ease forwards; }
.st-in { animation: stIn .32s cubic-bezier(.22, 1, .36, 1) both; }

/* completion */
.st-done { position: relative; overflow: hidden; border-radius: 1.75rem; }
.st-done-head { position: relative; padding: 2.25rem 1.5rem 1.75rem; text-align: center; color: #fff; background: linear-gradient(135deg, #7060ec, #4a3bc8 60%, #392b9a); }
.st-done-head.is-great { background: linear-gradient(135deg, #10b981, #0d9488 60%, #0f766e); }
.st-done-head::after { content: ""; position: absolute; inset-inline-end: -3rem; top: -4rem; width: 14rem; height: 14rem; border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .22), transparent 66%); }
.st-done-head > * { position: relative; z-index: 1; }
.st-stat { text-align: center; padding: .9rem .5rem; border-radius: 1.1rem; background: var(--surface-2); }
.st-stat b { display: block; font-size: 1.35rem; font-weight: 900; line-height: 1.4; }
.st-stat span { display: block; font-size: .72rem; color: var(--text-muted); }
.st-missed { display: flex; align-items: center; gap: .75rem; padding: .65rem .85rem; border-radius: 1rem; background: var(--box-5-soft); }

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 2; }
.confetti i {
  position: absolute; top: -1rem; width: .5rem; height: .9rem; border-radius: .15rem; opacity: 0;
  animation: confettiFall var(--d, 2.8s) var(--delay, 0s) ease-in forwards;
}
@keyframes confettiFall {
  0% { opacity: 1; transform: translate3d(0, 0, 0) rotate(0); }
  100% { opacity: 0; transform: translate3d(var(--x, 0), 22rem, 0) rotate(var(--r, 540deg)); }
}

/* "no cards due" state */
.st-calm { position: relative; overflow: hidden; border-radius: 1.75rem; padding: 2rem 1.5rem; text-align: center; background: linear-gradient(160deg, var(--box-3-soft), var(--surface) 70%); border: 1px solid color-mix(in srgb, var(--color-success) 25%, var(--border)); }
.st-calm-icon { width: 4rem; height: 4rem; margin: 0 auto 1rem; border-radius: 1.4rem; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #34d399, #059669); box-shadow: 0 14px 26px -12px #059669; }

/* new-word picker tiles */
.nw-tile {
  display: flex; flex-direction: column; align-items: center; gap: .15rem; padding: .85rem .5rem; border-radius: 1.1rem;
  background: var(--surface-2); border: 2px solid transparent; font-weight: 900; transition: transform .15s ease, border-color .15s ease, background-color .15s ease;
}
.nw-tile:hover { transform: translateY(-2px); border-color: var(--color-primary); background: var(--color-primary-soft); }
.nw-tile b { font-size: 1.4rem; line-height: 1.3; }
.nw-tile span { font-size: .7rem; font-weight: 600; color: var(--text-muted); }

/* browse filters */
.bf-chip {
  display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .8rem; border-radius: 999px; font-size: .75rem; font-weight: 800;
  background: var(--surface-2); color: var(--text-muted); border: 1.5px solid transparent; transition: all .15s ease;
}
.bf-chip:hover { color: var(--text); }
.bf-chip.is-active { color: var(--bx, var(--color-primary)); background: color-mix(in srgb, var(--bx, var(--color-primary)) 13%, var(--surface)); border-color: color-mix(in srgb, var(--bx, var(--color-primary)) 55%, transparent); }

/* Tailwind's .hidden loads before this file, so a component rule that sets
   `display` (.btn, .st-chip ...) would otherwise win over it. */
.btn.hidden, .chip.hidden, .st-answers.hidden, .st-chip.hidden, .st-phon.hidden, .st-example.hidden,
.st-done.hidden, .st-actions.hidden, .st-corner.hidden, .st-boxes.hidden { display: none; }

@media (prefers-reduced-motion: reduce) {
  .mc-due, .confetti i, .st-result, .st-out, .st-in { animation: none !important; }
}
