/* ══════════════════════════════════════════════════════════════════════════
   Lanly Web — «Стикерная тетрадь»
   Те же принципы, что у главной страницы: фирменный зелёный из логотипа,
   тёплая бумага, карточки-наклейки с контуром и жёсткой тенью.
   Имена переменных (--green-600 и т.д.) сохранены: на них опираются
   стили, которые app.js, school.js и coach.js вставляют в разметку.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
  --green-600: #2da52d;
  --green-700: #1d7a1f;
  --green-100: #e3f5d8;
  --text-900: #11240f;
  --text-600: #56664f;
  --muted: #56664f;
  --bg: #fbf6ea;
  --card: #ffffff;
  --line: rgba(17, 36, 15, .16);
  --danger: #e0472f;
  --sun: #ffd43b;
  --sky: #bfe4ff;
  --coral: #ff6a4d;
  --ink: #11240f;
  --shadow: 3px 3px 0 var(--ink);
  --shadow-lg: 5px 5px 0 var(--ink);
  --stroke: 2px solid var(--ink);
  --radius: 20px;
  --display: "Druk Wide Cyr", "Druk Wide", "Unbounded", "Arial Black", sans-serif;
  --ease: cubic-bezier(.2, .9, .25, 1.15);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }

body {
  margin: 0;
  font-family: "Onest", "Segoe UI", system-ui, sans-serif;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(17, 36, 15, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17, 36, 15, .045) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--text-900);
  height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--sun); color: var(--ink); }

.app-shell {
  max-width: 680px; width: 100%; height: 100dvh; margin: 0 auto;
  position: relative; overflow: hidden;
}

.screen {
  display: none; height: 100%;
  padding: 22px 22px 120px;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: rgba(17, 36, 15, .25) transparent;
}
.screen.active { display: block; animation: screenIn .38s var(--ease) both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.center-screen { display: flex; flex-direction: column; justify-content: center; }
.screen.center-screen { display: none; }
.screen.active.center-screen { display: flex; }

h1, h2, h3, p { margin: 0; }

/* ── Логотип ──────────────────────────────────────────────────────────── */
.wordmark {
  display: block; aspect-ratio: 1400 / 370; background: currentColor;
  -webkit-mask: url("/brand/lanly-wordmark.png") center / contain no-repeat;
  mask: url("/brand/lanly-wordmark.png") center / contain no-repeat;
}

.logo {
  width: 120px; height: 120px; margin: 0 auto 16px; cursor: pointer;
  transition: transform .15s var(--ease); transform-origin: center;
}
.logo:active { transform: scale(.92); }

/* Обложка экрана входа: зелёная наклейка с логотипом и Пепланом */
.auth-brand {
  position: relative; background: var(--green-600); color: #fff;
  border: var(--stroke); border-radius: 28px; box-shadow: var(--shadow-lg);
  padding: 26px 22px 20px; margin-bottom: 22px; overflow: hidden;
  transform: rotate(-1.2deg);
}
.auth-brand::before {
  content: ""; position: absolute; width: 220px; height: 190px; right: -70px; top: -80px;
  background: rgba(255, 255, 255, .1); border-radius: 48% 52% 38% 62% / 55% 38% 62% 45%;
}
.auth-brand .wordmark { width: 190px; color: #fff; filter: drop-shadow(3px 3px 0 var(--ink)); }
.auth-brand p { margin-top: 10px; font-weight: 600; max-width: 24ch; line-height: 1.35; }
.auth-brand .logo {
  position: absolute; right: 10px; bottom: -6px; width: 104px; height: 104px; margin: 0;
  filter: drop-shadow(3px 4px 0 rgba(17, 36, 15, .35));
}

/* ── Заголовки ────────────────────────────────────────────────────────── */
.title {
  font-family: var(--display); font-size: 28px; font-weight: 800;
  text-align: center; margin-bottom: 18px; letter-spacing: -.04em; line-height: 1.1;
}
.subtitle { font-size: 14.5px; color: var(--text-600); text-align: center; margin-bottom: 20px; line-height: 1.5; }
.subtitle.left { text-align: left; }

.header { margin-bottom: 18px; }
.header h2 { font-family: var(--display); font-size: 28px; font-weight: 800; letter-spacing: -.045em; line-height: 1.05; }
.header p { font-size: 14px; color: var(--text-600); margin-top: 6px; }

.section-caption {
  display: inline-block; font-family: var(--display); font-size: 11px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--ink);
  background: var(--green-100); border: 2px solid var(--ink); border-radius: 999px;
  padding: 4px 11px; margin: 20px 0 10px;
}

.label { font-size: 13px; font-weight: 600; color: var(--text-600); margin-bottom: 6px; }

/* ── Поля ─────────────────────────────────────────────────────────────── */
.field, .textarea {
  width: 100%; border: var(--stroke); border-radius: 16px; padding: 14px 16px;
  font-size: 15.5px; margin-bottom: 12px; background: #fff; color: var(--text-900);
  font-family: inherit; transition: box-shadow .15s, transform .15s;
}
.field::placeholder, .textarea::placeholder { color: #8a977f; }
.field:focus, .textarea:focus { outline: none; box-shadow: 0 0 0 4px var(--sun); }
.field:disabled, .textarea:disabled { background: #f4f1e8; }
select.field { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: calc(100% - 22px) 55%, calc(100% - 16px) 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 40px; }
.textarea { resize: vertical; min-height: 84px; line-height: 1.5; }

/* ── Кнопки-наклейки ──────────────────────────────────────────────────── */
.btn {
  width: 100%; border: var(--stroke); border-radius: 16px; padding: 14px 16px;
  font-family: var(--display); font-size: 14.5px; font-weight: 700; letter-spacing: -.01em;
  cursor: pointer; box-shadow: var(--shadow);
  transition: transform .12s var(--ease), box-shadow .12s var(--ease), filter .15s;
}
.btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-primary { background: var(--green-600); color: #fff; }
.btn-outline { background: #fff; color: var(--text-900); }
.btn-danger { background: var(--coral); color: #fff; }

.muted-link { text-align: center; margin-top: 14px; font-size: 14px; color: var(--text-600); }
.muted-link a, a.muted-link { color: var(--green-700); text-decoration: none; font-weight: 700; cursor: pointer; }
a.muted-link:hover, .muted-link a:hover { text-decoration: underline; text-underline-offset: 3px; }
.header a.muted-link { display: inline-flex; align-items: center; gap: 6px; margin: 0 0 6px; }
.header a.muted-link::before { content: "←"; }

#auth-screen .btn + .subtitle { margin: 16px 0 0; font-size: 13px; }
.error { color: var(--danger); text-align: center; min-height: 20px; font-size: 14px; font-weight: 600; margin-bottom: 10px; }

.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.mt6 { margin-top: 6px; }
.mt10 { margin-top: 10px; }
.half { width: 49%; }

/* ── Карточки ─────────────────────────────────────────────────────────── */
.tile {
  background: var(--card); border: var(--stroke); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.tile h3 { font-family: var(--display); font-size: 16px; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; margin-bottom: 5px; }
.tile p { font-size: 13.5px; color: var(--text-600); line-height: 1.5; }
.tile.clickable, .tile[style*="cursor:pointer"], .tile[style*="cursor: pointer"] {
  cursor: pointer; transition: transform .15s var(--ease), box-shadow .15s var(--ease);
}
.tile.clickable:hover, .tile[style*="cursor:pointer"]:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-lg); }
.tile.clickable:active, .tile[style*="cursor:pointer"]:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
details.tile summary { list-style: none; }
details.tile summary::-webkit-details-marker { display: none; }
details.tile summary::after { content: " ▾"; color: var(--text-600); }

/* Инструменты на главном экране — сетка цветных наклеек */
.tools { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tools .tile { margin: 0; display: flex; flex-direction: column; min-height: 132px; }
.tools .tile .ico {
  width: 42px; height: 42px; border: var(--stroke); border-radius: 13px; background: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 20px; margin-bottom: 10px;
}
.tools .t-book { background: var(--green-600); color: #fff; grid-column: span 2; min-height: 0; }
.tools .t-book p { color: rgba(255, 255, 255, .9); }
.tools .t-book .ico { background: var(--sun); }
.tools .t-words { background: var(--sun); }
.tools .t-words p, .tools .t-listen p { color: #3a4735; }
.tools .t-listen { background: var(--sky); }
@media (max-width: 420px) { .tools .tile { min-height: 0; } }

/* ── Чипы ─────────────────────────────────────────────────────────────── */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  border: var(--stroke); background: #fff; padding: 8px 13px; border-radius: 999px;
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; color: var(--ink);
  transition: transform .12s var(--ease);
}
.chip:active { transform: scale(.96); }
.chip.active { background: var(--green-600); color: #fff; box-shadow: 2px 2px 0 var(--ink); }

/* ── Нижняя панель — плавающий «док» ──────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  width: calc(100% - 24px); max-width: 640px;
  display: none; padding: 6px;
  background: rgba(251, 246, 234, .94); backdrop-filter: blur(12px);
  border: var(--stroke); border-radius: 26px; box-shadow: var(--shadow-lg);
  z-index: 50;
}
.nav-btn {
  flex: 1; border: 0; background: transparent; padding: 6px 4px 7px;
  color: var(--text-600); cursor: pointer; display: flex !important; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; font-family: inherit; border-radius: 18px;
}
.nav-icon {
  width: 40px; height: 32px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid transparent;
  transition: background-color .18s ease, color .18s ease, border-color .18s ease, transform .15s var(--ease);
}
.nav-icon svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.nav-label { font-size: 11px; font-weight: 700; line-height: 1; letter-spacing: .01em; }
.nav-btn:hover .nav-icon { background: var(--green-100); }
.nav-btn.active { color: var(--ink); }
.nav-btn.active .nav-icon { background: var(--green-600); color: #fff; border-color: var(--ink); box-shadow: 2px 2px 0 var(--ink); transform: translateY(-2px); }
.nav-btn:active .nav-icon { transform: translateY(1px) scale(.96); }

/* ── Прогресс, варианты ответа ────────────────────────────────────────── */
.progress { height: 14px; background: #fff; border: var(--stroke); border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.progress-bar {
  height: 100%; width: 0; transition: width .35s var(--ease);
  background: repeating-linear-gradient(-45deg, var(--green-600) 0 10px, #3cb83c 10px 20px);
  border-right: 2px solid var(--ink);
}

.option {
  width: 100%; text-align: left; padding: 13px 15px; border: 2px solid rgba(17, 36, 15, .28);
  border-radius: 16px; background: #fff; margin-bottom: 9px; cursor: pointer; font-size: 15px;
  font-family: inherit; color: var(--ink); transition: border-color .15s, transform .12s var(--ease), box-shadow .15s;
}
.option:hover { border-color: var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.option:active { transform: translate(1px, 1px); }
.option.selected { border-color: var(--green-600); background: var(--green-100); }
.option.correct { border-color: var(--green-600); background: var(--green-100); box-shadow: 2px 2px 0 var(--green-700); }
.option.wrong { border-color: var(--danger); background: #ffe4dd; }

.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--green-700); font-weight: 700; }

/* ── Модальные окна ───────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; background: rgba(17, 36, 15, .5); display: none;
  align-items: center; justify-content: center; padding: 18px; z-index: 100;
}
.modal.show { display: flex; }
.modal-card {
  width: 100%; max-width: 420px; background: var(--bg); border: var(--stroke);
  border-radius: 24px; padding: 20px; box-shadow: var(--shadow-lg); animation: screenIn .3s var(--ease) both;
}
.modal-card h3 { font-family: var(--display); letter-spacing: -.03em; }

.empty {
  text-align: center; color: var(--text-600); padding: 22px; border: 2px dashed rgba(17, 36, 15, .35);
  border-radius: 18px; background: rgba(255, 255, 255, .6); font-size: 14px;
}
.muted { color: var(--text-600); }

/* ── Чаты ─────────────────────────────────────────────────────────────── */
.chat-wrap, .ai-wrap {
  height: 56vh; overflow: auto; border: var(--stroke); border-radius: 20px;
  padding: 12px; background: #fff; margin-bottom: 10px; box-shadow: var(--shadow);
}
.ai-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.ai-chat-list { flex: 1; display: flex; gap: 8px; overflow-x: auto; padding: 2px 4px 4px 0; }
.ai-chat-list .chip { margin-bottom: 0; white-space: nowrap; }
.ai-wrap { height: 50vh; }
.ai-hero { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; color: var(--text-900); }
.ai-hero-logo { width: 96px; height: 96px; object-fit: contain; }
.ai-hero-title { font-family: var(--display); font-size: 24px; font-weight: 800; letter-spacing: -.04em; }
.ai-hero-subtitle { font-size: 14px; font-weight: 500; color: var(--text-600); }
.ai-body { line-height: 1.55; }
.ai-md-h1 { font-size: 18px; font-weight: 800; margin-bottom: 3px; }
.ai-md-h2 { font-size: 16px; font-weight: 800; margin-bottom: 2px; }
.ai-md-h3 { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.ai-md-space { height: 8px; }
.ai-md-li { padding-left: 14px; position: relative; }
.ai-md-li::before { content: "\2022"; position: absolute; left: 0; top: 0; color: var(--green-600); font-weight: 800; }

.msg {
  margin-bottom: 10px; max-width: 86%; border: 2px solid rgba(17, 36, 15, .18);
  border-radius: 16px 16px 16px 5px; padding: 10px 12px; background: #f6f3ea;
  animation: msgIn .25s ease both;
}
.msg.me { margin-left: auto; background: var(--green-100); border-color: rgba(29, 122, 31, .45); border-radius: 16px 16px 5px 16px; }
.msg .time { margin-top: 6px; font-size: 11px; color: var(--text-600); }
.msg .meta { margin-top: 6px; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--text-600); }
.msg .status { font-weight: 700; opacity: .86; }
.msg.pending { opacity: .7; border-style: dashed; }
.reactions-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.reaction-chip { border: 2px solid rgba(17, 36, 15, .2); border-radius: 999px; background: #fff; padding: 2px 8px; font-size: 12px; cursor: pointer; }
.reaction-chip.mine { border-color: var(--green-600); background: var(--green-100); }

.chat-shell { display: flex; gap: 14px; min-height: calc(100dvh - 220px); }
.chat-sidebar { width: 300px; flex-shrink: 0; display: none; }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.conversation-list { border: var(--stroke); border-radius: 18px; overflow: auto; background: #fff; max-height: 56vh; box-shadow: var(--shadow); margin-bottom: 12px; }
.conversation-list:empty { display: none; }
.conversation-item { padding: 11px 13px; border-bottom: 1px solid rgba(17, 36, 15, .1); cursor: pointer; transition: background-color .12s ease; }
.conversation-item:last-child { border-bottom: 0; }
.conversation-item:hover { background: #faf7ee; }
.conversation-item.active { background: var(--green-100); }
.conversation-top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.conversation-name { font-weight: 700; font-size: 14px; }
.conversation-preview { font-size: 12.5px; color: var(--text-600); white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.badge {
  min-width: 20px; height: 20px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; padding: 0 6px; background: var(--coral); color: #fff; border: 2px solid var(--ink);
}
.typing-indicator { font-size: 12px; color: var(--green-700); min-height: 16px; font-weight: 600; }
.conn-pill { font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px; border: 2px solid rgba(17, 36, 15, .25); background: #fff; color: var(--text-600); }
.conn-pill.live { color: var(--green-700); border-color: var(--green-600); background: var(--green-100); }
@keyframes msgIn { from { transform: translateY(6px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.ai-item { margin-bottom: 10px; border: 2px solid rgba(17, 36, 15, .16); border-radius: 16px; padding: 11px 12px; background: #f6f3ea; }
.ai-item.user { background: var(--green-100); border-color: rgba(29, 122, 31, .4); }
.ai-item .who { font-size: 12px; color: var(--text-600); margin-bottom: 4px; font-weight: 800; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: 100px;
  background: var(--ink); color: #fff; font-size: 14px; font-weight: 600; padding: 11px 16px;
  border-radius: 999px; box-shadow: 3px 3px 0 var(--green-600);
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .25s var(--ease); z-index: 500;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 1024px) {
  .app-shell { max-width: 1200px; }
  .screen { padding-left: 32px; padding-right: 32px; }
  .chat-sidebar { display: block; }
  #chat-back-btn { display: none; }
  .chat-wrap { height: calc(100dvh - 350px); }
  .tools { grid-template-columns: repeat(3, 1fr); }
  .tools .t-book { grid-column: span 3; }
}

@media (max-width: 560px) {
  .screen { padding: 18px 16px 116px; }
  .header h2 { font-size: 24px; }
  .title { font-size: 25px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
