/* ── Design tokens (совпадают с Android ProboTut) ── */
:root {
  --indigo:      #6366F1;
  --indigo-dark: #4F46E5;
  --mint:        #34D399;
  --bg-tint:     #EEEFFD;
  --hatch:       #C7C9F9;
  --ink:         #1F2240;
  --muted:       #8587C9;
  --line:        #E1E2F8;
  --paper:       #FFFFFF;
  --red:         #EA4335;
  --green:       #34A853;
  --radius:      14px;
  --radius-sm:   8px;
  --shadow:      0 2px 12px rgba(99,102,241,.10);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-tint);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
a { color: var(--indigo); }
img, svg { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; }

/* ── Hatch background (как в Android) ── */
.hatch-bg {
  background-image: repeating-linear-gradient(
    135deg,
    var(--hatch) 0px, var(--hatch) 1.5px,
    transparent 1.5px, transparent 9px
  );
}

/* ── App shell ── */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  /* Учитываем системную область для iOS */
  padding-bottom: env(safe-area-inset-bottom);
  /* Для старых версий Safari */
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Bottom safe area spacer ── */
.bottom-safe {
  height: env(safe-area-inset-bottom);
}

/* ── Top bar ── */
.top-bar {
  background: linear-gradient(135deg, var(--indigo) 0%, var(--indigo-dark) 100%);
  color: #fff;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  /* Учитываем системную область для iOS */
  padding-top: env(safe-area-inset-top);
  padding-top: constant(safe-area-inset-top);
  height: calc(56px + env(safe-area-inset-top));
  height: calc(56px + constant(safe-area-inset-top, 0px));
}
.top-bar h1 {
  font-family: 'Manrope', sans-serif;
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  flex: 1;
}
.top-bar .back-btn {
  background: none;
  border: none;
  color: #fff;
  padding: 8px;
  margin-left: -8px;
  display: flex;
  align-items: center;
}

/* ── Card ── */
.card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }

/* ── Sheet (контент страницы) ── */
.sheet {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}


/* ── Camera container ── */
.camera-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius);
  overflow: hidden;
  /* Учитываем системную область для iOS */
  margin-top: env(safe-area-inset-top, 0px);
}

/* ── Camera container ── */
.camera-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--radius);
  overflow: hidden;
  /* Учитываем системную область для iOS */
  margin-top: env(safe-area-inset-top);
  /* Убираем лишний отступ, чтобы камера не уехала ниже положенного */
  margin-top: max(env(safe-area-inset-top), 0px);
}

/* ── Form elements ── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; color: var(--ink); }

.input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: var(--paper);
  transition: border-color .15s;
  outline: none;
  -webkit-appearance: none;
  /* Учитываем системную область для iOS */
  padding-top: calc(env(safe-area-inset-top) / 2);
  padding-bottom: calc(env(safe-area-inset-bottom) / 2);
}
.input:focus { border-color: var(--indigo); }
.input.error { border-color: var(--red); }

textarea.input { resize: vertical; min-height: 80px; }

/* ── Buttons ── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
  /* Учитываем системную область для iOS */
  margin-bottom: env(safe-area-inset-bottom);
}
.btn:active { transform: scale(.98); opacity: .9; }

.btn-primary {
  background: linear-gradient(135deg, var(--indigo) 0%, var(--indigo-dark) 100%);
  color: #fff;
}
.btn-primary:disabled {
  opacity: .45;
  pointer-events: none;
}
.btn-ghost {
  background: transparent;
  color: var(--indigo);
  font-weight: 600;
}
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--indigo);
  color: var(--indigo);
}

/* ── Checkbox row ── */
.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.check-row input[type=checkbox] {
  width: 20px; height: 20px;
  flex-shrink: 0;
  accent-color: var(--indigo);
  margin-top: 1px;
}
.check-row label { font-size: 14px; line-height: 1.5; }
.check-row a { color: var(--indigo); font-weight: 600; }

/* ── Error / hint text ── */
.hint     { font-size: 13px; color: var(--muted); }
.err-text { font-size: 13px; color: var(--red); }

/* ── Logo block (auth pages) ── */
.logo-block {
  text-align: center;
  padding: 24px 0 8px;
}
.logo-block .logo-text {
  font-family: 'Manrope', sans-serif;
  font-size: 28px;
  font-weight: 800;
  color: var(--indigo);
}
.logo-block .logo-text span { color: var(--mint); }
.logo-block p {
  font-size: 14px;
  color: var(--muted);
  margin: 4px 0 0;
}

/* ── Divider ── */
.divider {
  height: 1.5px;
  background: var(--line);
  border: none;
  margin: 4px 0;
}

/* ── Result states ── */
.status-icon {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  margin: 0 auto 8px;
}
.status-icon.ok  { background: #E8F5E9; color: var(--green); }
.status-icon.err { background: #FDECEA; color: var(--red); }

.result-label {
  font-family: 'Manrope', sans-serif;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
}
.result-label.ok  { color: var(--green); }
.result-label.err { color: var(--red); }

/* ── Error box ── */
.error-box {
  background: #FDECEA;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
}
.error-box .error-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--red);
  margin: 0 0 4px;
}
.error-box p { margin: 0; font-size: 15px; }

/* ── Teacher feedback ── */
.feedback-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--indigo);
  margin: 0 0 8px;
}
.feedback-body { font-size: 15px; line-height: 1.65; margin: 0; }

/* ── Task list ── */
.task-list { padding-left: 20px; margin: 0; }
.task-list li { font-size: 15px; line-height: 1.65; margin-bottom: 6px; }

/* ── Loader / spinner ── */
.loader-card {
  text-align: center;
  padding: 32px 20px;
}
.loader-icon {
  width: 64px; height: 64px;
  border-radius: 18px;
  background: var(--bg-tint);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  margin: 0 auto 16px;
}
.loader-stage {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
}
.loader-sub { font-size: 13px; color: var(--muted); margin: 0 0 20px; }

.progress-bar-wrap {
  height: 6px;
  background: var(--bg-tint);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 16px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--indigo);
  border-radius: 3px;
  animation: progress-pulse 1.8s ease-in-out infinite alternate;
}
@keyframes progress-pulse {
  from { opacity: .6; }
  to   { opacity: 1; }
}

.stage-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.stage-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--bg-tint);
  transition: background .3s, transform .3s;
}
.stage-dot.active {
  background: var(--indigo);
  transform: scale(1.3);
}
.stage-dot.done { background: var(--indigo); opacity: .4; }

/* ── Camera preview ── */
.camera-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 3/4;
  max-height: 55dvh;
}
.camera-wrap video,
.camera-wrap img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.camera-overlay {
  position: absolute; inset: 0;
  border: 3px solid var(--indigo);
  border-radius: var(--radius);
  pointer-events: none;
}

/* ── Scan page count badge ── */
.page-badge {
  position: absolute;
  top: 10px; right: 10px;
  background: var(--indigo);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}

/* ── Bottom safe area ── */
.bottom-safe {
  height: env(safe-area-inset-bottom, 16px);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .25s;
  z-index: 9999;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Limits bar ── */
.limits-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--paper);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
}
.limits-bar .count { font-weight: 700; color: var(--indigo); }

/* ── History list ── */
.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
}
.history-item:last-child { border-bottom: none; }
.history-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.history-dot.ok  { background: var(--green); }
.history-dot.err { background: var(--red); }
.history-text { flex: 1; }
.history-text .name { font-weight: 600; font-size: 15px; }
.history-text .date { font-size: 13px; color: var(--muted); }

/* ── Responsive ── */
@media (min-width: 520px) {
  .sheet { padding: 20px 0; }
}
