@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

/* ChatGPT / Claude shape: slim header, one reading column, rounded composer, the user's words in a bubble and the
   reply as plain text. Three kinds of box only: card, field, bubble. One teal accent, red only for errors and delete.
   Light by default, dark when the device asks for it. No motion of any kind. */

:root {
  color-scheme: light;
  --bg: #f6f6f3;        /* page */
  --surface: #fdfdfb;   /* cards, composer, outlined buttons */
  --hover: #ecede8;
  --line: #dcdfd8;      /* hairlines and card borders */
  --edge: #868e89;      /* borders of fields and outlined controls (3:1) */
  --text: #1a2220;
  --muted: #566360;
  --accent: #0f766e;
  --accent-hi: #0b5f59; /* hover, links, text on tint */
  --on-accent: #ffffff;
  --tint: #dcece8;      /* current page, notices, best plan */
  --bubble: #e4ebe7;
  --err: #b3261e;
  --err-bg: #fbeeec;
  --err-line: #e2b1ac;
  --danger: #b3261e;
  --on-danger: #ffffff;
  --s1: .25rem;
  --s2: .5rem;
  --s3: .75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2.5rem;
  --r-s: 12px;          /* fields, buttons, rows */
  --r-l: 18px;          /* cards, bubbles */
  --fs-s: .875rem;
  --fs-m: 1.0625rem;
  --fs-l: 1.25rem;
  --fs-xl: 1.75rem;
  --measure: 46rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #181c1c;
    --surface: #212626;
    --hover: #2b3131;
    --line: #313838;
    --edge: #6f7b78;
    --text: #e6ebe9;
    --muted: #9ba7a4;
    --accent: #5eb9ab;
    --accent-hi: #8fd3c8;
    --on-accent: #0d1d1b;
    --tint: #243b38;
    --bubble: #2d3836;
    --err: #f1a5a0;
    --err-bg: #2e2020;
    --err-line: #6b3b38;
    --danger: #e8847f;
    --on-danger: #2a0f0e;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; scrollbar-width: thin; scrollbar-color: var(--edge) transparent; }
html { -webkit-text-size-adjust: 100%; }
body { display: flex; flex-direction: column; height: 100dvh; margin: 0; overflow: hidden; background: var(--bg); color: var(--text); font: 400 var(--fs-m)/1.8 "Vazirmatn", system-ui, sans-serif; }
main { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
[hidden] { display: none !important; }

h1 { margin: 0 0 var(--s5); font-size: var(--fs-l); line-height: 1.5; }
h2 { margin: var(--s5) 0 var(--s2); font-size: var(--fs-m); line-height: 1.6; }
p { margin: 0 0 var(--s4); }
ul { margin: 0; padding: 0; list-style: none; }
a { color: var(--accent-hi); text-underline-offset: .25em; }
svg { flex: none; width: 1.375rem; height: 1.375rem; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent-hi); outline-offset: 2px; }
.hint { font-size: var(--fs-s); color: var(--muted); }

/* ---------------------------------------------------------------- shell: header with brand and the four destinations */

#bar { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); min-height: 3.5rem; padding: env(safe-area-inset-top) max(var(--s4), calc((100% - var(--measure)) / 2)) 0; border-bottom: 1px solid var(--line); }
#brand { color: var(--text); font-size: var(--fs-l); font-weight: 700; text-decoration: none; }
#nav { display: flex; gap: var(--s1); }
#nav a { display: flex; align-items: center; gap: var(--s2); min-height: 2.5rem; padding: 0 var(--s4); border-radius: var(--r-s); color: var(--muted); font-size: var(--fs-s); font-weight: 600; text-decoration: none; }
#nav a[aria-current="page"] { background: var(--tint); color: var(--accent-hi); }
#nav a:focus-visible { outline-offset: -2px; }
@media (hover: hover) { #nav a:hover:not([aria-current]) { background: var(--hover); color: var(--text); } }

/* phones: the same four links become a tab bar under the page, and the header keeps only the brand */
@media (max-width: 719.98px) {
  #bar { display: contents; }
  #brand { display: flex; align-items: center; justify-content: center; min-height: 3rem; padding-top: env(safe-area-inset-top); border-bottom: 1px solid var(--line); font-size: var(--fs-m); }
  #nav { order: 2; gap: 0; padding: var(--s1) var(--s1) calc(var(--s1) + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
  #nav a { flex: 1; flex-direction: column; justify-content: center; gap: 2px; min-height: 3.75rem; padding: 0; }
  #nav svg { box-sizing: content-box; width: 1.5rem; height: 1.5rem; padding: var(--s1) var(--s5); border-radius: 999px; }
  #nav a[aria-current="page"] { background: none; color: var(--text); font-weight: 700; }
  #nav a[aria-current="page"] svg { background: var(--tint); color: var(--accent-hi); }
}
/* keyboard open or landscape: give the room to the conversation */
@media (max-width: 719.98px) and (max-height: 520px) {
  #brand { display: none; }
  #nav a { min-height: 2.75rem; }
  #nav span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

.page { max-width: var(--measure); margin: 0 auto; padding: var(--s5) var(--s4) var(--s6); }

/* ---------------------------------------------------------------- cards */

.card { margin: 0; padding: var(--s4); border: 1px solid var(--line); border-radius: var(--r-l); background: var(--surface); }
.card > :last-child { margin-bottom: 0; }
.stack { display: grid; gap: var(--s4); }
.stack > * { margin: 0; }
.aside { padding: var(--s3) var(--s4); border-radius: var(--r-s); background: var(--tint); font-size: var(--fs-s); }

/* ---------------------------------------------------------------- fields and buttons */

label { display: grid; gap: var(--s1); font-size: var(--fs-s); font-weight: 600; line-height: 1.7; }
input[type=text], input[type=email], input[type=password] { width: 100%; min-height: 3rem; margin: 0; padding: var(--s2) var(--s4); border: 1px solid var(--edge); border-radius: var(--r-s); background: var(--bg); color: var(--text); font: inherit; font-size: var(--fs-m); line-height: 1.6; }
input[dir=ltr] { text-align: right; }
::placeholder { color: var(--muted); opacity: 1; }
input[type=text]:focus-visible, input[type=email]:focus-visible, input[type=password]:focus-visible { outline-offset: 0; border-color: var(--accent-hi); }

button { padding: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 3rem; padding: 0 var(--s5); border: 1px solid var(--edge); border-radius: var(--r-s); background: var(--surface); font-weight: 600; }
.btn.block { display: flex; width: 100%; }
.btn.primary, .plan.best .btn { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.btn.danger { border-color: var(--err); background: none; color: var(--err); }
.btn.danger:not(:disabled) { border-color: var(--danger); background: var(--danger); color: var(--on-danger); }
.btn:disabled, #send:disabled { opacity: .5; cursor: not-allowed; }
@media (hover: hover) {
  .btn:hover:not(:disabled) { background: var(--hover); }
  .btn.primary:hover:not(:disabled), .plan.best .btn:hover { border-color: var(--accent-hi); background: var(--accent-hi); }
  .btn.danger:hover:not(:disabled) { filter: brightness(1.08); }
  #mic:hover { background: var(--hover); }
}
.btn:active:not(:disabled), #send:active:not(:disabled), #mic:active { filter: brightness(.9); }
.link { min-height: 2.75rem; color: var(--accent-hi); font-weight: 600; text-decoration: underline; text-underline-offset: .25em; }
@media (hover: hover) { .link:hover { color: var(--text); } }
#nav a:active, .tab:active, .sos a:active { background: var(--hover); }

.check { display: flex; align-items: center; gap: var(--s3); min-height: 3rem; font-size: var(--fs-m); font-weight: 400; }
.check .hint { display: block; }
input[type=checkbox] { flex: none; width: 1.5rem; height: 1.5rem; margin: 0; accent-color: var(--accent); }
.switch > span { flex: 1; }
.switch input { appearance: none; position: relative; order: 2; width: 3rem; height: 1.75rem; border-radius: 999px; background: var(--edge); cursor: pointer; }
.switch input::before { content: ""; position: absolute; inset-block: .25rem; inset-inline-start: .25rem; width: 1.25rem; border-radius: 50%; background: var(--surface); }
.switch input:checked { background: var(--accent); }
.switch input:checked::before { inset-inline-start: 1.5rem; }

.error { position: sticky; bottom: var(--s4); margin: var(--s4) 0 0; padding: var(--s3) var(--s4); border: 1px solid var(--err-line); border-radius: var(--r-s); background: var(--err-bg); color: var(--err); font-size: var(--fs-s); }
.error:empty { display: none; }
#auth-busy { position: sticky; bottom: var(--s4); margin: var(--s4) 0 0; padding: var(--s3) var(--s4); border-radius: var(--r-s); background: var(--tint); color: var(--text); }

/* ---------------------------------------------------------------- sign in, recovery code */

.auth { max-width: 27rem; padding-top: clamp(var(--s5), 8vh, 4.5rem); }
.auth h1 { margin-bottom: var(--s3); font-size: var(--fs-xl); text-align: center; }
.lead { margin-bottom: var(--s5); text-align: center; }
.auth .card { padding: var(--s5); }
@media (max-width: 400px) { .auth .card { padding: var(--s4); } }
.tabs { display: flex; gap: var(--s1); margin-bottom: var(--s5); padding: var(--s1); border: 1px solid var(--line); border-radius: 16px; background: var(--bg); }
.tabs:not(:has(.on)) { display: none; }
.tab { flex: 1; min-height: 2.75rem; border-radius: var(--r-s); color: var(--muted); font-weight: 600; }
.tab.on { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--edge); }
@media (hover: hover) { .tab:not(.on):hover { color: var(--text); background: var(--hover); } }
.code { padding: var(--s4); border: 1px solid var(--edge); border-radius: var(--r-s); background: var(--bg); font: 700 clamp(1.25rem, 6.4vw, 1.75rem)/1.5 ui-monospace, Consolas, monospace; letter-spacing: .04em; text-align: center; user-select: all; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- conversation */

.chat { display: flex; flex-direction: column; height: 100%; }
#log { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--s5); padding: var(--s5) max(var(--s4), calc((100% - var(--measure)) / 2)) var(--s4); overflow-y: auto; overscroll-behavior: contain; }
#log:empty { display: none; }

.msg { flex: none; margin: 0; line-height: 1.95; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; max-width: 85%; padding: var(--s2) var(--s4); border-radius: var(--r-l); background: var(--bubble); line-height: 1.8; }
.msg.typing { color: var(--muted); }
.msg.note { align-self: center; max-width: 100%; font-size: var(--fs-s); line-height: 1.8; text-align: center; color: var(--muted); }
.msg.note.err { color: var(--err); }

#empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--s5) var(--s4) var(--s6); text-align: center; }
#hello { margin: 0; font-size: var(--fs-xl); line-height: 1.5; overflow-wrap: anywhere; }
#empty { margin: var(--s2) 0 0; color: var(--muted); }

#composer { display: flex; align-items: flex-end; gap: var(--s1); width: calc(100% - 2 * var(--s4)); max-width: var(--measure); margin: 0 auto var(--s4); padding: .375rem; border: 1px solid var(--edge); border-radius: 26px; background: var(--surface); }
#composer:has(#input:focus-visible) { border-color: var(--accent-hi); outline: 2px solid var(--accent-hi); }
#input { flex: 1; min-width: 0; min-height: 2.75rem; max-height: 40vh; margin: 0; padding: .5625rem var(--s3); border: 0; background: none; color: var(--text); font: inherit; line-height: 1.6; resize: none; outline: none; }
#mic, #send { flex: none; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 50%; }
#mic { color: var(--muted); }
#mic.rec { background: var(--accent); color: var(--on-accent); }
#mic .ico-stop, #mic.rec .ico-mic { display: none; }
#mic.rec .ico-stop { display: block; }
#send { background: var(--accent); color: var(--on-accent); }
#composer:has(#input:placeholder-shown) #send { background: var(--hover); color: var(--muted); }
#voice-note { width: calc(100% - 2 * var(--s4)); max-width: var(--measure); margin: calc(-1 * var(--s2)) auto var(--s4); font-size: var(--fs-s); color: var(--muted); text-align: center; }

/* ---------------------------------------------------------------- profile */

#profile-name { margin: 0; overflow-wrap: anywhere; }
#profile-email { margin: 0 0 var(--s4); overflow-wrap: anywhere; }
#profile-sub { display: inline-flex; align-items: center; gap: var(--s2); min-height: 2.5rem; padding: 0 var(--s4); border-radius: var(--r-s); background: var(--tint); font-size: var(--fs-s); font-weight: 600; text-decoration: none; }
#profile-sub::after { content: "\2039"; font-size: 1.4em; line-height: 1; }
.row { display: flex; align-items: flex-end; gap: var(--s3); margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--line); }
.row label { flex: 1; min-width: 0; }

#memory { padding: 0; }
#memory > .hint { margin: 0; padding: var(--s4); }
.mem { padding: var(--s4); }
.mem + .mem { border-top: 1px solid var(--line); }
.mem h3 { margin: 0 0 var(--s1); font-size: var(--fs-s); font-weight: 600; color: var(--muted); }
.mem p, .mem li { margin: 0; }
.mem li { display: flex; gap: var(--s3); }
.mem li::before { content: ""; flex: none; width: .375rem; height: .375rem; margin-top: 1.05em; border-radius: 50%; background: var(--accent); }
.meta { font-size: var(--fs-s); color: var(--muted); }
.meta span + span::before { content: "\00b7"; margin-inline: var(--s2); }
.pattern { display: flex; justify-content: space-between; gap: var(--s4); }
.pattern span:last-child { flex: none; font-size: var(--fs-s); color: var(--muted); }

/* ---------------------------------------------------------------- subscription */

#plan-status { margin: 0 0 var(--s4); padding: var(--s3) var(--s4); border: 1px solid var(--line); border-radius: var(--r-s); background: var(--surface); }
#plan-status[data-active="true"] { border-color: var(--accent); background: var(--tint); }
#plan-list { display: grid; gap: var(--s3); margin-bottom: var(--s4); }
.plan { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "name btn" "price btn" "sub btn"; align-items: center; column-gap: var(--s4); padding: var(--s4); border: 1px solid var(--line); border-radius: var(--r-l); background: var(--surface); }
.plan.best { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.plan-name { grid-area: name; font-weight: 700; }
.plan-price { grid-area: price; font-size: var(--fs-l); font-weight: 700; line-height: 1.7; }
.plan-sub { grid-area: sub; display: flex; flex-direction: column; align-items: flex-start; gap: var(--s1); font-size: var(--fs-s); color: var(--muted); }
.plan-save { padding: 0 var(--s3); border-radius: 999px; background: var(--tint); color: var(--accent-hi); font-weight: 600; }
.plan.best .plan-save { background: var(--accent); color: var(--on-accent); }
.plan .btn { grid-area: btn; min-width: 6.5rem; }
@media (min-width: 720px) {
  #plan-list { grid-template-columns: repeat(3, 1fr); }
  .plan { grid-template-columns: 1fr; grid-template-areas: "name" "price" "sub" "btn"; grid-template-rows: auto auto 1fr auto; align-items: start; }
  .plan .btn { margin-top: var(--s4); }
}

/* ---------------------------------------------------------------- settings */

.sos { display: grid; gap: var(--s2); }
.sos a { display: flex; align-items: center; gap: var(--s3); min-height: 3.5rem; padding: 0 var(--s3); border: 1px solid var(--edge); border-radius: var(--r-s); background: var(--bg); color: var(--text); text-decoration: none; }
.sos b { min-width: 3rem; font-size: var(--fs-l); color: var(--accent-hi); }
.sos span { flex: 1; }
.sos svg { color: var(--accent-hi); }
@media (hover: hover) { .sos a:hover { background: var(--hover); } }
#tg-url { overflow-wrap: anywhere; }
#logout { margin-top: var(--s5); }
.zone { margin-top: var(--s5); border-color: var(--err-line); background: var(--err-bg); }
.zone h2 { margin: 0; color: var(--err); }

/* ---------------------------------------------------------------- toast */

.toast { display: none; position: fixed; inset-inline: var(--s4); bottom: calc(var(--s5) + env(safe-area-inset-bottom)); width: fit-content; max-width: 28rem; margin-inline: auto; padding: var(--s3) var(--s4); border-radius: var(--r-s); background: var(--text); color: var(--bg); font-size: var(--fs-s); font-weight: 600; box-shadow: 0 4px 16px rgb(0 0 0 / .25); pointer-events: none; z-index: 10; }
.toast.show { display: block; }
.toast.err { background: var(--err); }
@media (max-width: 719.98px) { .toast { bottom: calc(5.5rem + env(safe-area-inset-bottom)); } }
