@font-face {
  font-family: "Chat Naskh";
  src: url("/learn/fonts/tutor-naskh-arabic.woff2") format("woff2");
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
}

:root {
  --bg: #eef4f1;
  --surface: #ffffff;
  --surface-2: #f6faf8;
  --ink: #0f2b26;
  --ink-soft: #3c5a54;
  --ink-dim: #6d8a84;
  --line: #dbe7e2;
  --line-strong: #c6d8d1;
  --green: #14564b;
  --green-deep: #0d3d35;
  --green-soft: #e6f0ec;
  --accent: #1a7a69;
  --danger: #ab4034;
  --danger-soft: #fbeeeb;
  --ok: #1c7a4f;
  --ok-soft: #e7f5ec;
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 300px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  overscroll-behavior-y: none;
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:disabled { cursor: default; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- shell / header ---------- */

.ca-shell {
  display: flex;
  flex-direction: column;
  width: min(100%, 520px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  box-shadow: 0 0 40px rgba(15, 43, 38, 0.07);
}

.ca-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  padding-top: calc(6px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.ca-header-start {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ca-home {
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink-soft);
  text-decoration: none;
}

.ca-home:hover,
.ca-home:focus-visible {
  border-color: var(--accent);
  color: var(--green);
  background: var(--green-soft);
}

.ca-home svg { width: 16px; height: 16px; }

.ca-brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ca-brand strong {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--green-deep);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ca-brand span {
  color: var(--ink-dim);
  font-size: 10px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ca-ui-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 0 0 auto;
  min-width: 96px;
  height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.ca-ui-switch button {
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
}

.ca-ui-switch button.active {
  background: var(--green-soft);
  color: var(--green-deep);
  box-shadow: inset 0 -2px var(--green);
}

/* ---------- main layout (single screen, no scroll) ---------- */

.ca-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.ca-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.ca-field-message {
  flex: 1 1 0;
  min-height: 0;
}

.ca-row-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 7px;
  flex: 0 0 auto;
}

.ca-row-inline {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}

.ca-label {
  display: block;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.3;
}

.ca-label-inline {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 12px;
}

.ca-row-inline .ca-select { flex: 1 1 auto; width: auto; }

.ca-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.ca-counter {
  color: var(--ink-dim);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.ca-counter[data-state="near"] { color: #8a6a1f; }
.ca-counter[data-state="max"] { color: var(--danger); }

/* ---------- inputs ---------- */

.ca-input,
.ca-select {
  display: block;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-appearance: none;
  appearance: none;
}

.ca-input {
  padding: 7px 9px;
  resize: none;
  overflow-wrap: anywhere;
  overflow-y: auto;
}

.ca-input-message {
  flex: 1 1 0;
  min-height: 54px;
  line-height: 1.6;
}

.ca-input-intent {
  flex: 0 0 auto;
  height: 38px;
  min-height: 38px;
}

.ca-input-custom {
  flex: 0 0 auto;
  height: 34px;
  min-height: 34px;
  padding-block: 0;
}

.ca-input-context {
  flex: 0 0 auto;
  height: 76px;
  min-height: 76px;
  line-height: 1.55;
}

.ca-input::placeholder { color: #93aaa4; }

.ca-input:focus,
.ca-select:focus {
  border-color: var(--accent);
  background: var(--surface);
  outline: none;
  box-shadow: 0 0 0 2px rgba(26, 122, 105, 0.14);
}

.ca-select {
  height: 34px;
  padding: 0 26px 0 9px;
  font-weight: 600;
  font-size: 15px;
  text-overflow: ellipsis;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231a7a69' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 13px 13px;
}

/* ---------- quick intent chips ---------- */

.ca-chips {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 1px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.ca-chips::-webkit-scrollbar { display: none; }

.ca-chip {
  flex: 0 0 auto;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.ca-chip:hover { border-color: var(--accent); color: var(--green); }

.ca-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--green-soft);
  color: var(--green-deep);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* ---------- actions ---------- */

.ca-actions {
  display: flex;
  gap: 7px;
  flex: 0 0 auto;
}

.ca-primary {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--green);
  border-radius: 10px;
  background: var(--green);
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 6px 14px rgba(20, 86, 75, 0.18);
}

.ca-primary:hover:not(:disabled) { background: var(--green-deep); border-color: var(--green-deep); }

.ca-primary:disabled {
  box-shadow: none;
  opacity: 0.66;
}

.ca-primary[data-state="working"] {
  border-color: var(--green-deep);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.16) 25%, transparent 25%) 0 0 / 12px 100%,
    var(--green-deep);
  opacity: 1;
}

.ca-secondary {
  flex: 0 0 auto;
  min-width: 58px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
}

.ca-secondary:hover {
  border-color: var(--accent);
  color: var(--green);
  background: var(--surface-2);
}

#cancelButton {
  border-color: #e2c4bd;
  background: var(--danger-soft);
  color: var(--danger);
}

#cancelButton:hover {
  border-color: var(--danger);
  background: #f9e3de;
  color: var(--danger);
}

.ca-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 18px;
  flex: 0 0 auto;
}

.ca-status {
  flex: 1 1 auto;
  margin: 0;
  min-height: 14px;
  color: var(--ink-dim);
  font-size: 11px;
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
}

.ca-status[data-kind="working"] { color: var(--accent); }
.ca-status[data-kind="error"] { color: var(--danger); }
.ca-status[data-kind="ok"] { color: var(--ok); }

.ca-view {
  flex: 0 0 auto;
  height: 24px;
  padding: 0 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-deep);
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.ca-view:hover { background: #d8e9e2; }

/* ---------- privacy / context blocks ---------- */

.ca-privacy,
.ca-context {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.ca-privacy summary,
.ca-context summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  color: var(--ink-dim);
  font-size: 11.5px;
  font-weight: 650;
  cursor: pointer;
  list-style: none;
}

.ca-privacy summary::-webkit-details-marker,
.ca-context summary::-webkit-details-marker,
.ca-analysis summary::-webkit-details-marker { display: none; }

.ca-privacy summary::before,
.ca-context summary::before,
.ca-analysis summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid currentColor;
  border-top: 3.5px solid transparent;
  border-bottom: 3.5px solid transparent;
  transition: transform 0.16s ease;
  transform: rotate(90deg);
  flex: 0 0 auto;
}

.ca-privacy[open] summary::before,
.ca-context[open] summary::before,
.ca-analysis[open] summary::before { transform: rotate(270deg); }

.ca-context[open] summary,
.ca-privacy[open] summary { color: var(--green); }

.ca-context-body {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0 10px 9px;
}

.ca-context-hint {
  margin: 0;
  color: var(--ink-dim);
  font-size: 11px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.ca-privacy ul {
  margin: 0;
  padding: 0 12px 8px 26px;
  color: var(--ink-dim);
  font-size: 11px;
  line-height: 1.6;
}

.ca-privacy li + li { margin-top: 3px; }

/* ---------- bottom sheet dialog ---------- */

.ca-dialog {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 50;
  width: min(100%, 520px);
  max-width: 520px;
  max-height: 85vh;
  max-height: 85dvh;
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 16px 16px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 -14px 42px rgba(13, 61, 53, 0.24);
  overflow: hidden;
}

.ca-dialog:not([open]) { display: none; }

.ca-dialog::backdrop { background: rgba(9, 34, 29, 0.42); }

.ca-sheet {
  display: flex;
  flex-direction: column;
  max-height: 85vh;
  max-height: 85dvh;
}

.ca-sheet-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px 8px;
  border-bottom: 1px solid var(--line);
}

.ca-sheet-title {
  flex: 1 1 auto;
  margin: 0;
  color: var(--green-deep);
  font-size: 15px;
  font-weight: 700;
}

.ca-sheet-close {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-soft);
}

.ca-sheet-close:hover { border-color: var(--accent); color: var(--green); }

.ca-sheet-close svg { width: 15px; height: 15px; }

.ca-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ---------- analysis ---------- */

.ca-analysis {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--surface-2);
}

.ca-analysis summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  color: var(--green);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.ca-analysis-text {
  margin: 0;
  padding: 0 11px 9px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ca-analysis-lang {
  margin: 0;
  padding: 0 11px 9px;
  color: var(--ink-dim);
  font-size: 11px;
}

/* ---------- replies ---------- */

.ca-reply-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ca-reply {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.ca-reply-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ca-tone {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-deep);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.ca-tone-index {
  color: var(--accent);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.ca-reply-text {
  margin: 0;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ca-copy {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  color: var(--green);
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.ca-copy:hover { background: var(--green-soft); }

.ca-copy[data-copied="true"] {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--ok);
}

.ca-copy svg { width: 13px; height: 13px; }

.ca-sheet-note {
  flex: 0 0 auto;
  margin: 2px 0 0;
  color: var(--ink-dim);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

/* ---------- toast ---------- */

.ca-toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 80;
  max-width: min(88vw, 420px);
  padding: 8px 14px;
  border: 1px solid var(--green);
  border-radius: 999px;
  background: var(--green-deep);
  color: #f2fbf8;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
  transform: translate(-50%, 8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: 0 8px 22px rgba(13, 61, 53, 0.28);
}

.ca-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Kazakh (Arabic script) typography ---------- */

.ca-shell[data-ui-language="kk"] {
  font-family: "Chat Naskh", "Noto Naskh Arabic", "Noto Sans Arabic", "Geeza Pro", "Al Bayan", "Microsoft Uighur", "Times New Roman", serif;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  text-rendering: optimizeLegibility;
}

.ca-reply-text[data-script="arabic"],
.ca-analysis-text[data-script="arabic"] {
  font-family: "Chat Naskh", "Noto Naskh Arabic", "Noto Sans Arabic", "Geeza Pro", "Al Bayan", "Microsoft Uighur", "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.95;
  text-align: start;
}

.ca-shell[data-ui-language="kk"] .ca-label,
.ca-shell[data-ui-language="kk"] .ca-label-inline {
  font-size: 12.5px;
  line-height: 1.6;
}

.ca-shell[data-ui-language="kk"] .ca-brand strong { font-size: 15px; }
.ca-shell[data-ui-language="kk"] .ca-chip { font-size: 13px; }
.ca-shell[data-ui-language="kk"] .ca-select { font-size: 15px; }
.ca-shell[data-ui-language="kk"] .ca-primary { font-size: 16px; }
.ca-shell[data-ui-language="kk"] .ca-secondary { font-size: 15px; }
.ca-shell[data-ui-language="kk"] .ca-counter { font-size: 11px; }
.ca-shell[data-ui-language="kk"] .ca-status { font-size: 12px; }
.ca-shell[data-ui-language="kk"] .ca-privacy summary { font-size: 12.5px; }
.ca-shell[data-ui-language="kk"] .ca-context summary { font-size: 12.5px; }
.ca-shell[data-ui-language="kk"] .ca-context-hint { font-size: 12px; line-height: 1.7; }
.ca-shell[data-ui-language="kk"] .ca-input-custom { font-size: 15px; }
.ca-shell[data-ui-language="kk"] .ca-input-context { font-size: 15px; line-height: 1.85; }
.ca-shell[data-ui-language="kk"] .ca-privacy ul { font-size: 12px; }
.ca-shell[data-ui-language="kk"] .ca-sheet-title { font-size: 16px; }
.ca-shell[data-ui-language="kk"] .ca-copy { font-size: 13px; }
.ca-shell[data-ui-language="kk"] .ca-home { direction: ltr; }

/* ---------- responsive ---------- */

@media (max-height: 620px) {
  .ca-main { gap: 5px; padding: 6px 8px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .ca-brand span { display: none; }
  .ca-primary,
  .ca-secondary { min-height: 38px; }
  .ca-input-intent { height: 34px; min-height: 34px; }
  .ca-input-custom { height: 32px; min-height: 32px; }
  .ca-input-context { height: 56px; min-height: 56px; }
  .ca-context-hint { font-size: 10.5px; }
  .ca-chip { height: 24px; font-size: 11.5px; }
  .ca-select { height: 32px; }
}

@media (max-height: 520px) {
  .ca-main { gap: 4px; }
  .ca-input-message { min-height: 46px; }
  .ca-privacy summary,
  .ca-context summary { padding: 3px 10px; }
  .ca-foot { min-height: 14px; }
}

@media (max-width: 340px) {
  .ca-main { padding-inline: 7px; }
  .ca-brand strong { font-size: 13px; }
  .ca-ui-switch { min-width: 86px; }
  .ca-ui-switch button { font-size: 10px; padding: 0 4px; }
  .ca-label-inline { font-size: 11px; }
}

@media (min-height: 780px) {
  .ca-main { gap: 9px; padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .ca-input-message { min-height: 130px; }
  .ca-input-intent { height: 46px; min-height: 46px; }
  .ca-primary,
  .ca-secondary { min-height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
