/* ── Reset & tokens ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --bg-card:   #161b22;
  --bg-input:  #0d1117;
  --border:    #30363d;
  --border-hi: #58a6ff;

  --text:      #e6edf3;
  --text-2:    #8b949e;
  --text-3:    #484f58;

  --green:     #3fb950;
  --green-dim: #1a4226;
  --red:       #f85149;
  --red-dim:   #3d1a19;
  --amber:     #d29922;
  --amber-dim: #2d2208;
  --blue:      #58a6ff;

  --mono: 'JetBrains Mono', 'Courier New', monospace;
  --sans: 'Inter', system-ui, sans-serif;

  --radius: 6px;
  --radius-lg: 10px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ───────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.5px;
}
.logo-dot { color: var(--green); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-link {
  color: var(--text-2);
  font-size: 14px;
  text-decoration: none;
  transition: color .15s;
}
.nav-link:hover { color: var(--text); text-decoration: none; }
.nav-link--muted { color: var(--text-3); }
.nav-link--muted:hover { color: var(--text-2); }

/* ── Main layout ──────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 24px;
}

.footer {
  border-top: 1px solid var(--border);
  padding: 16px 32px;
  text-align: center;
  font-size: 13px;
  color: var(--text-3);
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity .15s, background .15s;
  text-decoration: none;
}
.btn:hover { opacity: .85; text-decoration: none; }

.btn--primary { background: var(--green); color: #0d1117; }
.btn--sm      { padding: 5px 12px; font-size: 13px; }
.btn--outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn--outline:hover { border-color: var(--text-2); }
.btn--danger { background: var(--red); color: #fff; }
.btn--full { width: 100%; justify-content: center; }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

/* ── Page header ──────────────────────────────────────────────────────── */
.page-header { margin-bottom: 32px; }
.page-header h1 {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.3px;
}
.page-header p { color: var(--text-2); margin-top: 6px; }

/* ── Topic list ───────────────────────────────────────────────────────── */
.topics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.topic-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  text-decoration: none;
  color: var(--text);
  /* Добавили shadow в transition для мягкого свечения */
  transition: border-color .15s, transform .15s, box-shadow .15s; 
  display: block;
}

.topic-card:hover {
  /* Если переменная --theme-color задана (юзер вошел), подставится она. 
     Если её нет, сработает дефолтная подсветка var(--border) или var(--text) */
  border-color: var(--theme-color, var(--text)); 
  text-decoration: none;
  transform: translateY(-2px);
  
  /* Необязательно, но круто: легкое свечение в цвет прогресса при наведении */
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.05), 0 2px 8px var(--theme-color, transparent);
}

.topic-card__title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 8px;
}

.topic-card__meta {
  font-size: 13px;
  color: var(--text-2);
  display: flex;
  gap: 16px;
}

.topic-card__progress {
  margin-top: 14px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.topic-card__progress-fill {
  height: 100%;
  /* Берем динамический цвет. Если юзера нет, полоса не покажется, 
     но на всякий случай фолбек — var(--green) */
  background: var(--theme-color, var(--green));
  border-radius: 2px;
  transition: width .3s;
}
/* ── Task list ────────────────────────────────────────────────────────── */
.task-list { list-style: none; }
.task-list__item {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.task-list__item:last-child { border-bottom: none; }

.task-num {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-3);
  text-align: right;
}
.task-link { color: var(--text); font-weight: 500; text-decoration: none; }
.task-link:hover { color: var(--blue); text-decoration: none; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
}
.badge--ac      { background: var(--green-dim); color: var(--green); }
.badge--wa      { background: var(--red-dim);   color: var(--red);   }
.badge--tle     { background: var(--amber-dim); color: var(--amber); }
.badge--pending { background: #1c2128;           color: var(--text-3); }
.badge--running { background: #1c2128;           color: var(--blue); }
.badge--ce      { background: var(--red-dim);   color: var(--red); }
.badge--re      { background: var(--red-dim);   color: var(--red); }
.badge--mle     { background: var(--amber-dim); color: var(--amber); }

/* ── Task page ────────────────────────────────────────────────────────── */
.task-layout {
  display: grid;
  grid-template-columns: 1fr 420px;
  gap: 32px;
  align-items: start;
}
@media (max-width: 900px) {
  .task-layout { grid-template-columns: 1fr; }
}

/* Statement markdown styles */
.statement { line-height: 1.75; }
.statement h1 { font-size: 22px; font-weight: 600; margin-bottom: 20px; }
.statement h2 { font-size: 17px; font-weight: 600; margin: 28px 0 10px; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; font-size: 12px; }
.statement p  { margin-bottom: 12px; }
.statement table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
  font-size: 14px;
}
.statement th, .statement td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.statement th { background: #1c2128; color: var(--text-2); font-weight: 500; }
.statement code {
  font-family: var(--mono);
  font-size: 13px;
  background: #1c2128;
  padding: 1px 5px;
  border-radius: 3px;
}
.statement pre {
  background: #1c2128;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 16px 0;
}
.statement pre code { background: none; padding: 0; }

/* KaTeX (МОШ): скрываем MathML-копию, иначе буквы дублируются */
.statement .katex-mathml {
  position: absolute;
  clip: rect(1px, 1px, 1px, 1px);
  padding: 0;
  border: 0;
  height: 1px;
  width: 1px;
  overflow: hidden;
}
.statement .katex { font-size: 1.05em; }
.statement .katex-display { margin: 1em 0; overflow-x: auto; }
.statement .katex .msupsub { text-align: left; }
.statement .input-output-copier { display: none !important; }
.statement .sample-tests pre,
.statement table pre {
  margin: 0;
}

/* Task meta */
.task-meta {
  display: flex;
  gap: 20px;
  margin-bottom: 24px;
  font-size: 13px;
  color: var(--text-2);
}
.task-meta span { display: flex; align-items: center; gap: 5px; }

/* ── Code editor ──────────────────────────────────────────────────────── */
.editor-panel { position: sticky; top: 76px; }
.editor-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.editor-panel__header h3 { font-size: 14px; font-weight: 600; }

.code-editor {
  width: 100%;
  height: 380px;
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 14px;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
.code-editor:focus { border-color: var(--border-hi); }

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

.lang-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  font-family: var(--mono);
  cursor: pointer;
}

/* ── Submissions ──────────────────────────────────────────────────────── */
.submissions-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.submissions-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
.submissions-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 13px;
}
.submissions-table tr:last-child td { border-bottom: none; }

/* ── Code block in submission ─────────────────────────────────────────── */
.code-block {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  white-space: pre;
}

/* ── Forms ────────────────────────────────────────────────────────────── */
.form-card {
  max-width: 420px;
  margin: 60px auto;
}
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-2);
}
.form-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  font-family: var(--sans);
  outline: none;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--border-hi); }
.form-error {
  background: var(--red-dim);
  border: 1px solid var(--red);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 18px;
}
.form-footer {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-2);
  text-align: center;
}

/* ── Profile stats ────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
}
.stat-card__value {
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--green);
}
.stat-card__label {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Verdict detail ───────────────────────────────────────────────────── */
.verdict-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.verdict-badge {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: var(--radius);
}
.error-block {
  background: var(--red-dim);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  margin-top: 16px;
}

/* ── Polling indicator ────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Breadcrumb ───────────────────────────────────────────────────────── */
.breadcrumb {
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.breadcrumb a { color: var(--text-2); }
.breadcrumb a:hover { color: var(--text); }

/* ── Task page v2 (fullwidth layout) ─────────────────────────────────── */

/* Убираем старый grid-layout для страницы задачи */
.task-layout { display: block; }

/* Компактные ограничения */
.task-limits {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.limit-badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text-2);
}

/* Секция посылок */
.submissions-section {
  margin-top: 40px;
  margin-bottom: 32px;
}

/* Метка секции */
.section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 12px;
  display: block;
}

/* Редактор снизу */
.editor-section {
  margin-top: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.editor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.char-count {
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--mono);
}

/* Кнопка загрузки файла */
.file-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color .15s, color .15s;
  background: transparent;
  user-select: none;
}
.file-upload-btn:hover {
  border-color: var(--text-2);
  color: var(--text);
}

/* Примеры из условия — копирование */
.example-block {
  position: relative;
  background: #1c2128;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 8px 0 16px;
  overflow: hidden;
}
.example-block__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: #21262d;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-3);
}
.example-block__copy {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}
.example-block__copy:hover { color: var(--text); background: var(--border); }
.example-block pre {
  margin: 0;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  overflow-x: auto;
  white-space: pre;
}
/* ── Import progress cards ────────────────────────────────────────────── */
.import-progress-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 12px;
  transition: border-color .3s;
}
.import-progress-card:has(.import-progress-bar[style*="background: var(--green)"]),
.import-progress-card:has(.import-progress-bar[style*="background:var(--green)"]) {
  border-color: var(--green-dim);
}
.import-progress-card:has(.import-progress-bar[style*="background: var(--red)"]),
.import-progress-card:has(.import-progress-bar[style*="background:var(--red)"]) {
  border-color: var(--red-dim);
}

.import-progress-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.import-progress-filename {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.import-progress-status {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--blue);
  font-weight: 600;
  white-space: nowrap;
}

.import-progress-bar-wrap {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}
.import-progress-bar {
  height: 100%;
  background: var(--blue);
  border-radius: 3px;
  transition: width .4s ease, background .3s;
  min-width: 0;
}

.import-progress-message {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.4;
}

.import-progress-subs {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.import-progress-subs:empty {
  display: none;
}
