/* Shared tokens and components. Values come from DESIGN.md. */
/* Fredoka has no Persian letters, so the browser falls back to Vazirmatn for them. */
:root { --ink: #232849; --muted: #6b6f8a; --line: #d9dbe6; --tile: #f4f5f9; --error: #b3261e; --bg: #fff;
  --accent: #f5b83d; --accent-soft: #fce9b8; --accent-ink: #8a5a00; /* gold, on Progress only: today, the streak, milestones */
  /* The four skills (Colorful theme): soft for backgrounds, -dot for their dots */
  --sk-read: #e2eeff; --sk-listen: #eee8ff; --sk-speak: #ffeadc; --sk-write: #dff4e7;
  --sk-read-dot: #7fb6ff; --sk-listen-dot: #b29dff; --sk-speak-dot: #ffa877; --sk-write-dot: #7fd0a0;
  --blend-dir: 135deg; /* skill colours blend from the start corner */
  --font: Fredoka, Vazirmatn, system-ui, sans-serif;
  --font-read: Charter, 'Iowan Old Style', Georgia, 'Noto Serif', serif; /* long reading in Books: the system's book serif, nothing to download */
  --ease: cubic-bezier(.2, 0, 0, 1); --dur: .2s; --dur-page: .3s; /* motion: fast out, gentle stop, no bounce */ }
[dir="rtl"] { --blend-dir: 225deg; --wash-dir: 200deg; }
/* Colorful theme (Profile, remembered on the device): the page is a faint wash of the four skills, from the start
   corner down; tiles turn frosted white so they sit on it instead of greying it, and muted text darkens to keep
   4.5:1 on the colours. */
[data-theme="colorful"] { --muted: #555a75; --tile: rgb(255 255 255 / .7);
  --wash: linear-gradient(var(--wash-dir, 160deg), color-mix(in srgb, var(--sk-read) 55%, var(--bg)),
    color-mix(in srgb, var(--sk-listen) 55%, var(--bg)) 38%, color-mix(in srgb, var(--sk-speak) 55%, var(--bg)) 70%,
    color-mix(in srgb, var(--sk-write) 55%, var(--bg))); }
* { margin: 0; box-sizing: border-box; }
html, body { background: var(--bg); color: var(--ink); }
html[data-theme="colorful"] { background: var(--wash) fixed; }
[data-theme="colorful"] body { background: none; }
body { font-family: var(--font); }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 4px; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: max(52px, 2.6em); padding: 0 1.6em; border-radius: 999px; border: 2px solid var(--ink); font: 600 1.1rem/1 var(--font); text-decoration: none; cursor: pointer; transition: transform .15s; }
.btn:hover { transform: translateY(-2px); }
.primary { background: var(--ink); color: var(--bg); }
.secondary { background: none; color: var(--ink); }

/* FA/EN language switch, on every page */
.lang { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 3px; border: 2px solid var(--line); border-radius: 999px; background: var(--bg); cursor: pointer; }
.lang:hover { border-color: var(--ink); }
.lang span { display: grid; place-items: center; min-width: 40px; height: 34px; padding: 0 .6rem; border-radius: 999px; color: var(--muted); font: 600 .95rem/1 var(--font); transition: background .2s, color .2s; }
.lang span.on { background: var(--ink); color: var(--bg); }
/* Signed-in pages: top bar with the brand */
body > header { display: flex; align-items: center; gap: 1rem; padding: 12px 5vw; border-bottom: 2px solid var(--line); }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; font-size: 1.25rem; text-decoration: none; }
.brand img { width: 44px; }
body > header .lang { margin-inline-start: auto; }
.crumb { color: var(--muted); }
/* The back button at the start of every feature page's header (activity.js sends it to the screen before). */
.hback { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border: 2px solid var(--line); border-radius: 50%; color: var(--ink); }
.hback:hover { border-color: var(--ink); }
.hback svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[dir="rtl"] .hback svg { transform: scaleX(-1); }
@media (max-width: 767px) {
  body > header { padding: 12px 16px; }
  /* Phones: back, then the feature's name; the brand gives up its place. */
  .hback ~ .brand { display: none; }
  .hback ~ .crumb { font-size: 0; }
  .hback ~ .crumb span { font-size: 1.15rem; font-weight: 600; color: var(--ink); }
}
.corner { position: fixed; top: 16px; inset-inline-end: 16px; z-index: 2; }

/* Auth pages: one centered column */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth main { width: min(100%, 420px); }
.auth .face { display: block; width: 112px; margin-bottom: 1.5rem; }
.auth h1 { font-weight: 600; font-size: clamp(2rem, 6vw, 2.75rem); line-height: 1.1; }
.auth form { display: grid; gap: 1.25rem; margin-top: 2rem; }
.field { display: grid; gap: .5rem; }
.field label { font-weight: 600; }
.field input { min-height: 52px; padding: 0 1rem; border: 2px solid var(--line); border-radius: 14px; font: 400 1.1rem var(--font); color: var(--ink); }
.field input:focus { border-color: var(--ink); outline: none; }
/* Emails and passwords are always typed left-to-right */
[dir="rtl"] input[type="email"], [dir="rtl"] input[type="password"] { direction: ltr; text-align: end; }
.auth form .btn { width: 100%; }
.hint, .switch { color: var(--muted); }
.error { color: var(--error); font-weight: 600; }
.error:empty { display: none; }
.btn:disabled { opacity: .6; cursor: wait; }
.switch { margin-top: 1.5rem; text-align: center; }
.switch a { font-weight: 600; color: var(--ink); }
.auth-intro { color: var(--muted); margin-top: 1rem; line-height: 1.6; overflow-wrap: anywhere; }
.phone-auth form { display: grid; gap: 1.25rem; margin-top: 1.5rem; }
.phone-auth .field { min-width: 0; }
.phone-auth input { width: 100%; min-width: 0; }
.phone-auth input[dir="ltr"] { direction: ltr; text-align: start; }
.otp-input { letter-spacing: .25em; }
.auth-options { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; justify-content: space-between; }
.auth-action { min-height: 44px; padding: .5rem 0; border: 0; background: none; color: var(--ink); font: 400 1rem var(--font); text-decoration: underline; cursor: pointer; }
.auth-action:disabled { color: var(--muted); cursor: default; text-decoration: none; }
.auth .legacy-toggle { display: block; margin: 1rem auto 0; }

/* Sheets: centered dialogs on wide screens, bottom sheets on phones (lists-sheet.js, My words) */
.sheet { width: min(calc(100% - 32px), 440px); margin: auto; padding: 1.5rem; border: 0; border-radius: 22px; background: var(--bg); color: var(--ink); font-family: var(--font); }
.sheet::backdrop { background: rgb(35 40 73 / .35); }
.sheet h2 { font-size: 1.35rem; font-weight: 600; }
.sheet-sub { color: var(--muted); margin-top: .2rem; overflow-wrap: anywhere; }
.sheet input[type="text"] { width: 100%; min-height: 52px; margin-top: 1rem; padding: 0 1rem; border: 2px solid var(--line); border-radius: 14px; font: 400 1.05rem var(--font); color: var(--ink); }
.sheet input[type="text"]:focus { outline: none; border-color: var(--ink); }
.sheet-opts { display: grid; gap: .4rem; margin-top: .75rem; max-height: 300px; overflow: auto; }
.sheet-opts:empty { display: none; }
.opt { display: flex; align-items: center; gap: .75rem; min-height: 52px; padding: 0 1rem; border-radius: 14px; background: var(--tile); font-weight: 600; cursor: pointer; }
.opt input { width: 22px; height: 22px; margin: 0; accent-color: var(--ink); flex: none; }
.opt small { margin-inline-start: auto; color: var(--muted); font-weight: 400; }
.opt.create { width: 100%; border: 2px dashed var(--line); background: none; color: var(--ink); font: 600 1rem var(--font); text-align: start; }
.opt.create:hover { border-color: var(--ink); }
.sheet .error { margin-top: .75rem; }
.sheet .btn { width: 100%; margin-top: 1rem; }
@media (max-width: 767px) {
  .sheet { width: 100%; max-width: none; margin: auto auto 0; border-radius: 22px 22px 0 0; padding-bottom: 2rem; }
}

/* Motion. Sheets grow in on wide screens (from their trigger when a page sets transform-origin) and slide up on phones,
   and play it backwards on close. overlay/display keep a closing sheet on screen until it has finished. */
.sheet, .sheet::backdrop { transition: opacity var(--dur) var(--ease), scale var(--dur) var(--ease), translate var(--dur) var(--ease), overlay var(--dur) allow-discrete, display var(--dur) allow-discrete; }
.sheet, .sheet::backdrop { opacity: 0; }
.sheet { scale: .96; }
.sheet[open], .sheet[open]::backdrop { opacity: 1; scale: 1; }
@starting-style { .sheet[open], .sheet[open]::backdrop { opacity: 0; } .sheet[open] { scale: .96; } }
@media (max-width: 767px) {
  .sheet, .sheet[open] { opacity: 1; scale: 1; }
  .sheet { translate: 0 100%; }
  .sheet[open] { translate: 0; }
  @starting-style { .sheet[open] { opacity: 1; scale: 1; translate: 0 100%; } }
}
/* Menus and bars pop from their button (pages set transform-origin); notes rise from the bottom. Both only on the way in. */
@keyframes pop { from { opacity: 0; scale: .9; } }
@keyframes rise { from { opacity: 0; translate: 0 1rem; } }
.menu { animation: pop var(--dur) var(--ease); }
/* Between pages: a crossfade, and an Explore box grows into the page it opens, which shrinks back into it on the way back.
   app.html names the box; a feature page (one with a back button) names itself. Explore holds still underneath.
   Browsers without cross-document View Transitions keep the plain cut. */
@media (prefers-reduced-motion: no-preference) { @view-transition { navigation: auto; } }
html:has(.hback) { view-transition-name: feature; }
::view-transition-group(*) { animation-duration: var(--dur-page); animation-timing-function: var(--ease); }
::view-transition-old(root):only-child, ::view-transition-new(root):only-child { animation: none; }
::view-transition-old(feature), ::view-transition-new(feature) { height: 100%; object-fit: cover; object-position: top; } /* fill the growing shape, not stretch */
/* One white surface changes shape; what it held fades out in the first third (no blown-up ghost), what it becomes fades in. */
::view-transition-image-pair(feature) { background: var(--bg); }
::view-transition-old(feature) { animation-duration: calc(var(--dur-page) / 3); }

/* Highlighted phrases in sentence cards (and course text) */
mark { padding: 0 .15em; border-radius: 4px; background: #fde68a; color: inherit; }

/* New sentence card (card-sheet.js) */
.cardsheet { max-height: 92dvh; overflow: auto; }
@media (min-width: 768px) { .cardsheet { width: min(calc(100% - 32px), 560px); } }
.cs-label { display: block; margin-top: 1rem; font-weight: 600; }
.cs-label span { color: var(--muted); font-weight: 400; }
.cardsheet textarea { width: 100%; min-height: 96px; margin-top: .4rem; padding: .8rem 1rem; border: 2px solid var(--line); border-radius: 14px; font: 400 1.1rem/1.5 Vazirmatn, system-ui, sans-serif; color: var(--ink); resize: vertical; }
.cardsheet textarea:focus { outline: none; border-color: var(--ink); }
.cardsheet input[type="text"] { margin-top: .4rem; }
.tokens { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: 1rem; }
.tok { min-height: 44px; padding: 0 .65rem; border: 2px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font: 400 1.1rem Vazirmatn, system-ui, sans-serif; cursor: pointer; }
.tok:hover { border-color: var(--ink); }
.tok[aria-pressed="true"] { border-color: #e9c84a; background: #fde68a; }
.picked { min-height: 1.6em; margin-top: .75rem; color: var(--muted); line-height: 1.8; }
.cs-wait { margin-top: .75rem; color: var(--muted); }
.cs-pair { display: flex; gap: .5rem; margin-top: 1.25rem; }
.cs-pair .btn { flex: 1; margin: 0; }
.loading::after { content: '…'; display: inline-block; width: 1.2em; overflow: hidden; vertical-align: bottom; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { from { width: 0; } to { width: 1.2em; } }
@media (prefers-reduced-motion: reduce) { .loading::after { animation: none; } }

/* A short note at the bottom of the screen, e.g. "Saved · Add to a list" */
.toast { position: fixed; z-index: 5; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; align-items: center; gap: 1rem; max-width: calc(100% - 32px); padding: .5rem .5rem .5rem 1.25rem; padding-inline: 1.25rem .5rem; border-radius: 999px; background: var(--ink); color: var(--bg); animation: rise var(--dur) var(--ease); }
.toast span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast button { flex: none; min-height: 44px; padding: 0 1rem; border: 0; border-radius: 999px; background: var(--bg); color: var(--ink); font: 600 1rem var(--font); cursor: pointer; }

/* Shelf: one card per book or course (Courses, Books), a navy cover then what it is and how far the learner has got */
.shelf { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin-top: 1.75rem; padding: 0; list-style: none; }
.shelf a { display: grid; grid-template-columns: 132px 1fr; gap: 1.25rem; height: 100%; padding: 1rem; border: 2px solid var(--line); border-radius: 22px; text-decoration: none; }
.shelf a:hover { border-color: var(--ink); }
.shelf .cover { display: flex; flex-direction: column; justify-content: space-between; min-height: 176px; padding: .9rem .8rem; border-radius: 6px 14px 14px 6px; background: var(--ink); color: var(--bg); box-shadow: inset 8px 0 0 rgb(255 255 255 / .12); }
[dir="rtl"] .shelf .cover { border-radius: 14px 6px 6px 14px; box-shadow: inset -8px 0 0 rgb(255 255 255 / .12); } /* the spine follows reading direction */
.shelf .cover b { font-size: 1.15rem; font-weight: 600; line-height: 1.15; overflow-wrap: anywhere; }
.shelf .cover small { opacity: .75; font-size: .85rem; }
.shelf .info { display: flex; flex-direction: column; gap: .4rem; min-width: 0; }
.shelf .kind { align-self: flex-start; padding: .15rem .6rem; border-radius: 999px; background: var(--tile); color: var(--muted); font-size: .85rem; font-weight: 600; }
.shelf .info h2 { font-size: 1.4rem; font-weight: 600; }
.shelf .info p { color: var(--muted); line-height: 1.4; }
.shelf .meter { display: flex; align-items: center; gap: .75rem; margin-top: auto; padding-top: .5rem; }
.shelf .bar { flex: 1; height: 8px; border-radius: 999px; background: var(--tile); overflow: hidden; }
.shelf .bar i { display: block; height: 100%; border-radius: inherit; background: var(--ink); }
.shelf .meter span { color: var(--muted); font-size: .95rem; white-space: nowrap; }
.shelf .info .btn { align-self: flex-start; min-height: 48px; margin-top: .5rem; font-size: 1rem; }
@media (max-width: 899px) { .shelf { grid-template-columns: 1fr; } }
@media (max-width: 767px) {
  .shelf a { grid-template-columns: 96px 1fr; gap: 1rem; }
  .shelf .cover { min-height: 132px; padding: .7rem .6rem; }
  .shelf .cover b { font-size: 1rem; }
}

/* Persian: letter-spacing breaks joined letters, and the script needs taller lines */
:lang(fa) h1, :lang(fa) h2 { letter-spacing: 0; line-height: 1.4; }
:lang(fa) body { line-height: 1.7; }

@media (prefers-reduced-motion: reduce) { .btn, .lang span, .sheet, .sheet::backdrop { transition: none; } .menu, .toast { animation: none; } }
