:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: #11141c;
  --panel-2: #171b25;
  --line: #29303e;
  --text: #f1f4f9;
  --muted: #929cad;
  --violet: #8c79ff;
  --green: #62e6a6;
  --red: #ff6d87;
  --gold: #ffc86a;
  --page-pad: clamp(16px, 3vw, 38px);
  --card-pad: clamp(18px, 2.4vw, 28px);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background: radial-gradient(circle at 20% 0, rgba(140,121,255,.14), transparent 35%), var(--bg);
  color: var(--text);
  font: 15px/1.55 Inter, "Segoe UI", system-ui, sans-serif;
}
button, input, textarea { font: inherit; }

.shell {
  width: min(100%, 1380px);
  min-height: 100dvh;
  margin: auto;
  padding:
    max(var(--page-pad), env(safe-area-inset-top))
    max(var(--page-pad), env(safe-area-inset-right))
    max(var(--page-pad), env(safe-area-inset-bottom))
    max(var(--page-pad), env(safe-area-inset-left));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: clamp(18px, 3vw, 28px);
}
.brand { min-width: 0; }
.eyebrow { color: #a99eff; font-size: 11px; font-weight: 900; letter-spacing: .18em; }
h1 { margin: 7px 0 0; font-size: clamp(28px, 4vw, 38px); line-height: 1.08; letter-spacing: -.035em; }

.connection {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
}
.connection i { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.connection.online i { background: var(--green); box-shadow: 0 0 15px var(--green); }

.status-card, .question-card, .answer-card, .failed, .empty {
  border: 1px solid var(--line);
  border-radius: clamp(16px, 2vw, 20px);
  background: rgba(17,20,28,.95);
  box-shadow: 0 20px 60px rgba(0,0,0,.16);
}
.status-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 18px;
  padding: var(--card-pad);
}
.status-card h2 { margin: 5px 0 0; font-size: clamp(18px, 2.4vw, 23px); line-height: 1.22; overflow-wrap: anywhere; }
.status-card strong { align-self: center; font-size: clamp(18px, 2.5vw, 24px); font-variant-numeric: tabular-nums; }
.status-help { grid-column: 1 / -1; margin: 0; color: var(--muted); }
.progress { grid-column: 1 / -1; height: 8px; overflow: hidden; border-radius: 999px; background: #252a36; }
.progress i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--violet), #b2a6ff); transition: width .5s; }

.empty { margin-top: 20px; padding: clamp(48px, 10vw, 90px) var(--card-pad); text-align: center; }
.empty h2 { margin-bottom: 7px; }
.empty p { max-width: 720px; margin: auto; color: var(--muted); overflow-wrap: anywhere; }
code { color: #d5d0ff; overflow-wrap: anywhere; }
.pulse { width: 18px; height: 18px; margin: auto; border-radius: 50%; background: var(--violet); box-shadow: 0 0 0 0 rgba(140,121,255,.6); animation: pulse 1.5s infinite; }

.question-card { margin-top: 20px; padding: var(--card-pad); }
.question-card h2 { margin: 10px 0 16px; font-size: clamp(22px, 3.2vw, 30px); line-height: 1.25; letter-spacing: -.02em; overflow-wrap: anywhere; }
.options { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
.options span { min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel-2); color: #c9cfda; overflow-wrap: anywhere; }

.answers-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); align-items: stretch; gap: 18px; margin-top: 18px; }
.answer-card { min-width: 0; min-height: 260px; padding: var(--card-pad); }
.answer-card header { display: flex; align-items: center; gap: 11px; min-width: 0; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.answer-card header div { min-width: 0; display: flex; flex-direction: column; }
.answer-card header b, .answer-card header small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.answer-card header small { color: var(--muted); }
.source { flex: 0 0 40px; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: rgba(140,121,255,.16); color: #b3a8ff; font-size: 11px; font-weight: 900; }
.pdf { margin-top: 18px; min-height: 0; border-color: rgba(255,200,106,.34); }
.pdf .source { background: rgba(255,200,106,.13); color: var(--gold); }
.answer-card h2 { margin: 22px 0 10px; font-size: clamp(20px, 2.3vw, 26px); line-height: 1.28; letter-spacing: -.015em; overflow-wrap: anywhere; }
.answer-card p { margin-bottom: 0; color: #bdc5d1; overflow-wrap: anywhere; }
.answer-card em { display: block; margin-top: 20px; color: var(--green); font-size: 12px; font-style: normal; }
.card-loader { margin: 50px 0; color: var(--muted); animation: fade 1s infinite alternate; }
.failed { margin-top: 18px; padding: var(--card-pad); border-color: rgba(255,109,135,.35); }
.hidden { display: none !important; }

@keyframes pulse { 70% { box-shadow: 0 0 0 18px rgba(140,121,255,0); } }
@keyframes fade { to { opacity: .38; } }

/* Телефон: вертикальная ориентация */
@media (max-width: 700px) and (orientation: portrait) {
  :root { --page-pad: 14px; --card-pad: 17px; }
  .shell { padding-top: max(16px, env(safe-area-inset-top)); }
  .topbar { align-items: flex-end; margin-bottom: 15px; }
  .eyebrow { font-size: 9px; letter-spacing: .15em; }
  h1 { max-width: 250px; font-size: clamp(25px, 8vw, 32px); }
  .connection { min-height: 34px; padding: 7px 10px; font-size: 9px; }
  .connection span { max-width: 72px; overflow: hidden; text-overflow: ellipsis; }
  .status-card { position: sticky; z-index: 5; top: max(8px, env(safe-area-inset-top)); gap: 8px 12px; padding: 15px 16px; backdrop-filter: blur(18px); }
  .status-card h2 { font-size: 17px; }
  .status-card strong { font-size: 17px; }
  .status-help { display: none; }
  .progress { height: 6px; }
  .question-card { margin-top: 14px; }
  .question-card h2 { margin-bottom: 13px; font-size: clamp(21px, 6vw, 26px); }
  .options { grid-template-columns: 1fr; gap: 7px; }
  .options span { padding: 9px 10px; font-size: 14px; }
  .pdf, .answers-grid { margin-top: 12px; }
  .answers-grid { grid-template-columns: 1fr; gap: 12px; }
  .answer-card { min-height: 0; }
  .answer-card h2 { font-size: clamp(20px, 5.7vw, 24px); }
  .answer-card p { font-size: 14px; line-height: 1.6; }
  .card-loader { margin: 28px 0; }
}

/* Телефон: горизонтальная ориентация */
@media (max-height: 600px) and (orientation: landscape) {
  :root { --page-pad: 14px; --card-pad: 16px; }
  .shell { width: 100%; max-width: none; }
  .topbar { margin-bottom: 10px; align-items: center; }
  .brand { display: flex; align-items: baseline; gap: 12px; }
  .brand .eyebrow { white-space: nowrap; }
  h1 { margin: 0; font-size: 24px; }
  .connection { min-height: 32px; padding: 6px 10px; }
  .status-card { grid-template-columns: minmax(0,1fr) auto; gap: 7px 12px; padding: 12px 16px; }
  .status-card .eyebrow, .status-help { display: none; }
  .status-card h2 { margin: 0; font-size: 16px; }
  .status-card strong { font-size: 16px; }
  .progress { height: 5px; }
  .question-card { margin-top: 10px; padding: 14px 16px; }
  .question-card h2 { margin: 5px 0 9px; font-size: clamp(18px, 3vw, 24px); }
  .options { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 6px; }
  .options span { padding: 7px 9px; font-size: 13px; }
  .pdf { margin-top: 10px; padding: 14px 16px; }
  .answers-grid { grid-template-columns: repeat(3, minmax(250px,1fr)); gap: 10px; margin-top: 10px; }
  .answer-card { min-height: 0; padding: 14px 16px; }
  .answer-card header { padding-bottom: 9px; }
  .source { flex-basis: 34px; width: 34px; height: 34px; border-radius: 10px; }
  .answer-card h2 { margin: 12px 0 7px; font-size: clamp(17px, 2.4vw, 22px); }
  .answer-card p { font-size: 13px; line-height: 1.45; }
  .answer-card em { margin-top: 10px; }
  .card-loader { margin: 22px 0; }
  .empty { margin-top: 10px; padding: 30px 20px; }
}

/* Очень узкие телефоны */
@media (max-width: 360px) {
  .topbar { align-items: flex-start; }
  h1 { font-size: 24px; }
  .connection { padding-inline: 8px; }
  .connection span { display: none; }
  .status-card { grid-template-columns: minmax(0,1fr) auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
