:root {
  --bg: #0f1115;
  --card: #1a1d24;
  --card2: #22262f;
  --text: #e8eaf0;
  --muted: #9aa0ae;
  --accent: #6c8cff;
  --accent2: #4bd2a0;
  --danger: #ff6b6b;
  --radius: 16px;
}
* { box-sizing: border-box; margin: 0; }
html { -webkit-tap-highlight-color: transparent; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  max-width: 680px; margin: 0 auto; padding: 0 16px 90px;
}
@media (min-width: 900px) {
  body { max-width: 780px; }
  .cont-card:hover, .dropzone:hover { border-color: var(--accent); }
  .cont-card { transition: border-color .15s; cursor: pointer; }
}

/* --- шапка --- */
.topbar { text-align: center; padding: 28px 0 18px; }
.logo {
  font-size: 2rem; font-weight: 800; letter-spacing: .5px;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo span { font-weight: 300; }
.tagline { color: var(--muted); font-size: .85rem; margin-top: 4px; }

.page { display: none; }
.page.active { display: block; }

/* --- карточки предметов --- */
.cont-card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  margin-bottom: 10px; cursor: pointer; border: 1px solid #23262f;
  transition: border-color .15s, transform .1s;
}
.cont-card:active { transform: scale(.985); border-color: var(--accent); }
.cont-name { font-weight: 700; font-size: 1.05rem; }
.cont-sub { color: var(--muted); font-size: .8rem; margin-top: 4px; }

/* --- плавающий плюс --- */
.fab {
  position: fixed; right: 22px; bottom: 26px; width: 60px; height: 60px;
  border-radius: 50%; border: 0; font-size: 2rem; color: #fff;
  background: linear-gradient(135deg, var(--accent), #4a6cf7);
  box-shadow: 0 6px 20px rgba(76,108,247,.4); cursor: pointer; z-index: 10;
}

/* --- строка навигации --- */
.navrow { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.navrow h2 { flex: 1; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back, .mini {
  border: 0; background: var(--card); color: var(--text); border-radius: 10px;
  padding: 8px 13px; font-size: 1.1rem; cursor: pointer;
}
.mini.danger { color: var(--danger); }

/* --- зона фото --- */
.photo-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.dropzone {
  display: block; text-align: center; padding: 26px 12px;
  border: 2px dashed #3a4050; border-radius: var(--radius);
  background: var(--card); cursor: pointer; transition: border-color .2s;
}
.dropzone.half { flex: 1 1 150px; }
.dropzone:active, .dropzone:hover { border-color: var(--accent); }
.dropzone input { display: none; }
.dz-icon { font-size: 1.8rem; }
.dz-title { font-weight: 700; margin-top: 8px; font-size: .95rem; overflow-wrap: break-word; }
@media (max-width: 480px) { .dz-title { font-size: .86rem; } }
.dz-sub { color: var(--muted); font-size: .75rem; margin-top: 2px; }
#preview { width: 100%; border-radius: var(--radius); margin-top: 14px; }

/* --- камера --- */
.camera-box {
  position: fixed; inset: 0; background: #000;
  display: flex; flex-direction: column; overflow: hidden;
}
#cam-video { flex: 1; min-height: 0; width: 100%; object-fit: contain; background: #000; }

/* --- захват экрана: превью в половину вкладки --- */
.screen-box {
  position: relative; overflow: hidden;
  background: var(--card); border-radius: var(--radius);
  width: min(94vw, 1100px); max-height: 92vh; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
#screen-video {
  display: block; width: 100%; height: auto; max-height: 72vh;
  object-fit: contain; background: #000; border-radius: 10px;
}
#screen-wrap { position: relative; line-height: 0; }
#crop {
  position: absolute; border: 2px dashed var(--accent);
  background: rgba(108, 140, 255, .12); border-radius: 6px;
  cursor: move; touch-action: none; z-index: 3;
}
#crop-handle {
  position: absolute; right: -10px; bottom: -10px; width: 22px; height: 22px;
  background: var(--accent); border-radius: 50%; cursor: nwse-resize;
  touch-action: none;
}
/* --- плавающая панель живой трансляции --- */
#live-bar {
  position: fixed; right: 18px; bottom: 96px; z-index: 50;
  display: flex; flex-direction: column; gap: 10px;
}
#live-bar[hidden] { display: none; }
#live-bar button {
  width: 52px; height: 52px; border-radius: 50%; border: 0; font-size: 1.35rem;
  background: var(--card2); color: var(--text); cursor: pointer;
  box-shadow: 0 3px 12px rgba(0,0,0,.5);
}
#live-bar #live-shot { background: linear-gradient(135deg, var(--accent), #4a6cf7); color: #fff; }
.screen-controls {
  position: relative; z-index: 2; background: var(--card);
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 6px 6px; flex-shrink: 0;
}
.screen-controls .mini { background: var(--card2); }
.camera-controls {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 26px 30px; background: #000;
  flex-shrink: 0; position: relative; z-index: 5;
}
.camera-controls .mini { background: var(--card2); }
.shutter-wrap { text-align: center; }
.shutter {
  width: 72px; height: 72px; border-radius: 50%;
  border: 6px solid #fff; background: #fff; cursor: pointer;
  box-shadow: 0 0 0 4px rgba(255,255,255,.35);
}
.shutter:active { transform: scale(.92); }
.shutter-hint { color: #cfd3dc; font-size: .8rem; margin-top: 10px; }

.divider {
  display: flex; align-items: center; gap: 12px; color: var(--muted);
  font-size: .8rem; margin: 18px 0 12px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: #2a2e39; }

/* --- формы --- */
textarea, input[type=text] {
  width: 100%; padding: 13px 14px; margin-bottom: 10px;
  background: var(--card); border: 1px solid #2a2e39; border-radius: 12px;
  color: var(--text); font: inherit; resize: vertical; outline: none;
}
textarea:focus, input[type=text]:focus { border-color: var(--accent); }
::placeholder { color: #5b616f; }

button.primary {
  width: 100%; padding: 15px; border: 0; border-radius: 12px;
  background: linear-gradient(120deg, var(--accent), #4a6cf7);
  color: #fff; font: inherit; font-weight: 700; cursor: pointer;
}
button.primary:active { opacity: .85; }
button.ghost {
  width: 100%; padding: 13px; margin-top: 14px; border-radius: 12px;
  background: transparent; border: 1px solid #3a4050; color: var(--muted);
  font: inherit; cursor: pointer;
}
.file-btn {
  display: block; padding: 13px; margin-bottom: 10px; text-align: center;
  background: var(--card2); border-radius: 12px; cursor: pointer; color: var(--muted);
}
.file-btn input { display: none; }

/* --- статус и ответ --- */
.status { text-align: center; color: var(--muted); padding: 14px; }
.status.error { color: var(--danger); }
.card { background: var(--card); border-radius: var(--radius); padding: 18px; margin-top: 16px; }
.card-label {
  color: var(--muted); font-size: .75rem; text-transform: uppercase;
  letter-spacing: 1px; margin: 14px 0 8px;
}
.card-label:first-child { margin-top: 0; }
#answer-text { font-size: 1.15rem; font-weight: 700; line-height: 1.5; }
.variant {
  padding: 12px 14px; border-radius: 12px; margin-top: 8px;
  background: var(--card2); border: 1px solid transparent;
}
.variant.correct { border-color: var(--accent2); background: rgba(75,210,160,.12); font-weight: 600; }
.variant.correct::before { content: "✓ "; color: var(--accent2); }

/* --- соответствие: две колонки с линиями --- */
.match-wrap { position: relative; display: flex; justify-content: space-between; gap: 48px; }
.match-col { flex: 1; display: flex; flex-direction: column; gap: 8px; position: relative; z-index: 1; }
.match-item {
  padding: 10px 12px; background: var(--card2); border-radius: 10px;
  font-size: .92rem; line-height: 1.4; border: 1px solid transparent;
}
.match-item.matched { border-color: var(--accent2); }
.match-lines { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.match-line {
  stroke: var(--accent2); stroke-width: 2.5; fill: none; opacity: .85;
  stroke-linecap: round;
}
#sources { list-style: none; }
#sources li {
  padding: 8px 12px; background: var(--card2); border-radius: 10px;
  margin-bottom: 6px; font-size: .9rem;
}
details { margin-top: 12px; color: var(--muted); font-size: .9rem; }
summary { cursor: pointer; color: var(--accent); }
#recognized { white-space: pre-wrap; margin-top: 8px; }

/* --- документы --- */
.doc-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card2); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
}
.doc-item .meta { min-width: 0; }
.doc-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-item .sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.doc-item .del {
  border: 0; background: transparent; color: var(--danger); font-size: 1.2rem;
  cursor: pointer; padding: 4px 8px; flex-shrink: 0;
}
#doc-add { margin-top: 12px; }

/* --- модалка входа --- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--card); border-radius: var(--radius); padding: 24px;
  width: min(90vw, 380px);
}
.modal-box h3 { margin-bottom: 6px; }
.modal-box .muted { color: var(--muted); font-size: .85rem; margin-bottom: 14px; }
