/* LessonBuilder — дизайн-система лендинга ProboTut (landing-v2) */

:root {
  --paper: #F7F4EE;
  --paper-deep: #EFEAE0;
  --card: #FFFDF8;
  --ink: #171A21;
  --ink-soft: #5C6068;
  --ink-faint: #8A8E96;
  --line: #DED7C9;
  --rule: rgba(70, 100, 160, .28);
  --brand: #2B2BDF;
  --brand-deep: #1F1FC4;
  --pen: #C93A21;
  --pen-stroke: #D9432C;
  --green: #2F7D51;
  --purple: #A626C4;
  --hl: #F3C63F;
  --serif: "Playfair Display", Georgia, serif;
  --sans: "Golos Text", -apple-system, "Segoe UI", sans-serif;
  --hand: "Caveat", cursive;
  --shadow-sm: 0 1px 2px rgba(23, 26, 33, .05), 0 2px 8px rgba(23, 26, 33, .05);
  --shadow-md: 0 4px 10px rgba(23, 26, 33, .06), 0 12px 32px rgba(23, 26, 33, .10);
  --r-lg: 18px;
  --r-md: 14px;
  --r-sm: 10px;
}

* { box-sizing: border-box; }

/* атрибут hidden должен пересекать любой display из классов */
[hidden] { display: none !important; }

html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%; /* iOS: без авто-зума текста */
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(43, 43, 223, .05), transparent 60%),
    radial-gradient(900px 420px at -10% 30%, rgba(166, 38, 196, .04), transparent 60%),
    var(--paper);
  min-height: 100vh;
  min-height: 100dvh; /* iOS standalone: стабильная высота */
  font-size: 16px; /* поля ввода наследуют 16px — iOS не зумит при фокусе */
  line-height: 1.5;
  overscroll-behavior-y: contain; /* ощущение приложения: без перетяжки всей страницы */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

::selection { background: rgba(43, 43, 223, .18); }

button { font: inherit; }

/* topbar */
.topbar {
  height: calc(68px + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px); /* iOS: вырез/динамический остров */
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, .75);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .wrap {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.brand .mark { width: 34px; height: 34px; flex-shrink: 0; }
.brand .name { font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.brand .name b { color: var(--brand); font-weight: 700; }
.brand .sub {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-left: 6px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.health {
  font-size: .82rem;
  font-weight: 600;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
}
.health.ok { border-color: rgba(47, 125, 81, .4); color: var(--green); background: rgba(47, 125, 81, .06); }
.health.bad { border-color: rgba(201, 58, 33, .4); color: var(--pen); background: rgba(201, 58, 33, .06); }

/* layout */
.layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 24px calc(64px + env(safe-area-inset-bottom, 0px)); /* iOS: home-индикатор */
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.sidebar { display: grid; gap: 24px; position: sticky; top: 92px; }

.content { min-width: 0; display: grid; gap: 24px; grid-template-columns: minmax(0, 1fr); }

/* cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow-sm);
}

.kicker {
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--pen);
  margin-bottom: 10px;
}

.card h2, .section-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.45rem;
  letter-spacing: -.01em;
  margin: 0 0 6px;
}

.card h2 { margin-bottom: 18px; }

.section-title { margin-bottom: 14px; }

/* form */
.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}

textarea { resize: vertical; min-height: 96px; line-height: 1.55; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%235C6068' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

input::placeholder, textarea::placeholder { color: var(--ink-faint); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(43, 43, 223, .14);
}

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: .95rem;
  line-height: 1;
  padding: 14px 24px;
  border-radius: var(--r-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, color .12s ease, border-color .12s ease;
  user-select: none;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-deep); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn.primary:active:not(:disabled) { transform: translateY(0); box-shadow: none; }

.btn.danger { background: transparent; color: var(--pen); border-color: rgba(201, 58, 33, .35); }
.btn.danger:hover:not(:disabled) { background: rgba(201, 58, 33, .06); border-color: var(--pen); }

.btn.small { padding: 11px 18px; font-size: .9rem; }

#new-lesson-form .btn { width: 100%; }

.note { font-size: .88rem; color: var(--ink-soft); margin: 14px 0 0; min-height: 1.2em; }
.note.busy { color: var(--brand); font-weight: 500; }
.note.error { color: var(--pen); font-weight: 500; }

/* history */
.history { list-style: none; margin: 0; padding: 0; }
.history .muted { padding: 4px 2px; }

.history-item {
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.history-item:hover { border-color: var(--line); background: #fff; }
.history-item.active { border-color: var(--brand); background: rgba(43, 43, 223, .05); box-shadow: var(--shadow-sm); }
.history-item:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.history-title { font-weight: 600; font-size: .95rem; letter-spacing: -.005em; }
.history-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: .8rem; color: var(--ink-faint); }

/* empty */
.empty { padding: 44px 36px; }
.empty-title { font-family: var(--serif); font-size: 1.6rem; font-weight: 600; letter-spacing: -.01em; margin: 0 0 14px; }
.empty p { margin: 0 0 12px; }

.muted { color: var(--ink-soft); }
.small { font-size: .88rem; }

/* lesson view */
#lesson-view { display: grid; gap: 24px; align-content: start; grid-template-columns: minmax(0, 1fr); }
/* все flex/grid-элементы урока могут сжиматься — урок не должен выталкивать страницу */
#lesson-view * { min-width: 0; }
#lesson-view > .card { padding: 32px; }

.lesson-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding: 32px 32px 0;
}
/* заголовок занимает доступную ширину, действия — справа на той же строке */
.lesson-head > div:first-child { flex: 1 1 300px; min-width: 0; }

.lesson-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.7rem, 3vw, 2.3rem);
  line-height: 1.12;
  letter-spacing: -.015em;
  margin: 0 0 14px;
  text-wrap: balance;
}

.lesson-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.lesson-actions { flex-shrink: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: .82rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  white-space: normal;
  overflow-wrap: break-word;
}

.badge.type-open { border-color: rgba(43, 43, 223, .45); color: var(--brand-deep); background: rgba(43, 43, 223, .05); }
.badge.type-closed { border-color: var(--line); color: var(--ink); }
.badge.mode-individual { border-color: rgba(43, 43, 223, .45); color: var(--brand-deep); background: rgba(43, 43, 223, .05); }
.badge.mode-pair { border-color: rgba(47, 125, 81, .5); color: var(--green); background: rgba(47, 125, 81, .06); }
.badge.mode-team { border-color: rgba(166, 38, 196, .45); color: var(--purple); background: rgba(166, 38, 196, .06); }
.badge.mode-whole_class { border-color: rgba(201, 58, 33, .45); color: var(--pen); background: rgba(201, 58, 33, .05); }

.objective { font-size: 1.05rem; max-width: 72ch; margin: 0; }
.objective strong { font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.outcomes-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.outcome-box { border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px 18px; background: #fff; }
.outcome-box h4 {
  margin: 0 0 8px;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.outcome-box ul { margin: 0; padding-left: 18px; color: var(--ink-soft); font-size: .92rem; }
.outcome-box li { margin: 5px 0; }

/* stages */
.stage { border-top: 1px solid var(--line); padding: 22px 0; }
.stage:first-of-type { border-top: none; padding-top: 4px; }

.stage-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.stage-index {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
}
.stage-name { font-family: var(--serif); font-weight: 600; font-size: 1.2rem; letter-spacing: -.01em; }
.stage-purpose { margin: 8px 0 0; color: var(--ink-soft); font-size: .97rem; max-width: 78ch; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.action-box { background: #F3EFE6; border-radius: var(--r-md); padding: 14px 16px; font-size: .92rem; color: var(--ink); }
.action-box h4 {
  margin: 0 0 6px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.regulative {
  margin-top: 14px;
  padding: 12px 16px;
  border: 1px dashed var(--rule);
  border-radius: var(--r-md);
  background: rgba(43, 43, 223, .04);
  font-size: .92rem;
  color: var(--brand-deep);
}

.tasks { margin-top: 14px; display: grid; gap: 12px; }

.task { border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px 18px; background: #fff; }
.task-head { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.task-text { margin: 0; font-size: 1rem; line-height: 1.55; }
.task-note { margin: 10px 0 0; font-size: .9rem; color: var(--ink-soft); }
.task-note strong { color: var(--ink); font-weight: 600; }

.task-note.selfcheck {
  margin-top: 12px;
  padding: 10px 14px;
  border-left: 3px solid var(--hl);
  border-radius: 0 10px 10px 0;
  background: rgba(243, 198, 63, .16);
  color: var(--ink);
}
.task-note.selfcheck strong { color: #6B540F; }

/* warnings / self assessment */
.warnings { border: 1px solid rgba(201, 58, 33, .4); background: rgba(201, 58, 33, .06); border-radius: var(--r-md); padding: 18px 20px; }
.warnings h3 { margin: 0 0 10px; font-size: 1rem; color: var(--pen); }
.warnings ul { margin: 0; padding-left: 20px; font-size: .92rem; color: var(--ink); }
.warnings li { margin: 4px 0; }

.self-assessment { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px 24px; background: #fff; box-shadow: var(--shadow-sm); }
.self-assessment h3 { margin: 0 0 10px; font-family: var(--serif); font-size: 1.15rem; font-weight: 600; }
.self-assessment p { margin: 0; font-size: .97rem; color: var(--ink-soft); }

/* edit box */
.editbox textarea { min-height: 110px; }
.editbox-row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
#edit-note { font-size: .88rem; }

.edit-log { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 16px; }
.edit-log .section-title { font-size: 1.15rem; }
.edit-entry { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.edit-entry:last-child { border-bottom: none; }
.edit-entry .who {
  font-family: var(--hand);
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--brand);
  margin-bottom: 4px;
}
.edit-entry p { margin: 0; font-size: .95rem; }
.edit-entry .summary { color: var(--green); font-size: .9rem; }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 48px));
  background: var(--ink);
  color: var(--paper);
  font-size: .92rem;
  font-weight: 500;
  padding: 13px 20px;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  z-index: 50;
}
.toast.error { background: var(--pen); color: #fff; }

/* a11y + responsive */
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .actions { grid-template-columns: 1fr; }
  .outcomes-grid { grid-template-columns: 1fr; }
  .brand .sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ── auth: вход / подписка ───────────────────────────────────── */
.auth-view { padding: 48px 0 calc(64px + env(safe-area-inset-bottom, 0px)); }
.auth-view .narrow { max-width: 520px; margin: 0 auto; }
.auth-card { padding: 30px 32px 32px; }
.auth-title { font-family: var(--serif); font-size: 1.7rem; font-weight: 600; margin: 6px 0 10px; letter-spacing: -.01em; }
.auth-card .muted { margin: 0 0 18px; line-height: 1.6; }
.auth-card .field { display: block; margin-bottom: 14px; }
.auth-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.auth-actions .btn { width: auto; }

.user-chip { display: inline-flex; align-items: center; gap: 10px; }
.user-email {
  font-size: .88rem; color: var(--ink-soft); font-weight: 500;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); padding: 8px 14px; }
.btn.ghost:hover:not(:disabled) { border-color: var(--ink-soft); color: var(--ink); background: var(--card); }
@media (max-width: 640px) {
  .user-chip { flex-direction: column; align-items: flex-end; gap: 6px; }
}
