/* ==========================================================
   Олимпиады — пастельная тема
   Салатовый, пионовый, лавандовый и персиковый на кремовом фоне
   ========================================================== */

:root {
  --bg: #fff9f4;
  --card: #ffffff;
  --ink: #2d2a3a;
  --ink-2: #5b566b;
  --muted: #8a849a;
  --line: #f1e4ea;
  --line-2: #e8d9e1;

  --peony: #f08fb3;
  --peony-strong: #e26f9b;
  --peony-soft: #fde8f0;
  --peony-ink: #8a2e52;

  --lime: #9bdb8f;
  --lime-soft: #e5f8df;
  --lime-ink: #2f6b2a;

  --lav: #b9a8f5;
  --lav-soft: #efeafe;
  --lav-ink: #4b3a99;

  --peach: #ffb98f;
  --peach-soft: #ffeddf;
  --peach-ink: #8a4520;

  --danger: #e5607a;
  --danger-soft: #fde4e9;
  --danger-ink: #9b2440;

  --radius: 14px;
  --radius-lg: 22px;
  --shadow: 0 1px 2px rgba(138, 46, 82, 0.04), 0 8px 24px rgba(138, 46, 82, 0.06);
  --shadow-hover: 0 2px 4px rgba(138, 46, 82, 0.06), 0 14px 32px rgba(138, 46, 82, 0.1);
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(40rem 28rem at 8% -6%, rgba(155, 219, 143, 0.28), transparent 70%),
    radial-gradient(36rem 26rem at 100% 0%, rgba(240, 143, 179, 0.24), transparent 70%),
    radial-gradient(40rem 30rem at 50% 110%, rgba(185, 168, 245, 0.18), transparent 70%);
  background-attachment: fixed;
}
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.45rem; font-weight: 800; }
h2 { font-size: 1.2rem; font-weight: 800; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--peony-ink); }
code { font-family: var(--mono); font-size: 0.9em; background: var(--lav-soft); color: var(--lav-ink); padding: 0.1em 0.4em; border-radius: 6px; }

/* ---------- Каркас ---------- */
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
.container-sm { max-width: 980px; }
.page { padding-top: 1.5rem; padding-bottom: 3rem; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 249, 244, 0.78);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; padding-top: 0.75rem; padding-bottom: 0.75rem; }
.brand { display: flex; align-items: center; gap: 0.75rem; min-width: 0; text-decoration: none; color: inherit; }
.brand-logo {
  width: 42px; height: 42px; flex: none; border-radius: 14px;
  display: grid; place-items: center; font-weight: 900; font-size: 1.15rem; color: #fff;
  background: linear-gradient(135deg, var(--lime) 0%, var(--peony) 100%);
  box-shadow: 0 6px 16px rgba(240, 143, 179, 0.35);
}
.brand-title { font-weight: 800; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-link { font-size: 0.8rem; color: var(--muted); text-decoration: none; }
.back-link:hover { color: var(--peony-ink); }

/* ---------- Раскладка ---------- */
.stack { display: flex; flex-direction: column; gap: 1rem; }
.stack-sm { display: flex; flex-direction: column; gap: 0.6rem; }
.stack-lg { display: flex; flex-direction: column; gap: 1.5rem; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.row-top { align-items: flex-start; }
.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid-2 { display: grid; gap: 1.25rem; grid-template-columns: 1fr; }
.grid-form { display: grid; gap: 0.75rem; grid-template-columns: 1fr 1fr; }
.grid-editor { display: grid; gap: 1.25rem; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 860px) {
  .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; }
  .grid-editor { grid-template-columns: 2fr 3fr; }
}
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.75rem; }
.bold { font-weight: 800; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.w-full { width: 100%; }
.sticky-top { position: sticky; top: 5.5rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Карточки ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  box-shadow: var(--shadow);
}
.card-tint-lime { background: linear-gradient(180deg, var(--lime-soft), #fff 70%); }
.card-tint-peony { background: linear-gradient(180deg, var(--peony-soft), #fff 70%); }
.card-tint-lav { background: linear-gradient(180deg, var(--lav-soft), #fff 70%); }
.card-sub { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; background: #fff; }
.section-title { display: flex; align-items: center; gap: 0.6rem; }
.icon-dot { width: 2.1rem; height: 2.1rem; border-radius: 12px; display: grid; place-items: center; font-size: 1.05rem; flex: none; }
.icon-lime { background: var(--lime-soft); } .icon-peony { background: var(--peony-soft); }
.icon-lav { background: var(--lav-soft); } .icon-peach { background: var(--peach-soft); }

/* ---------- Формы ---------- */
.label { display: block; font-size: 0.85rem; font-weight: 700; color: var(--ink-2); margin-bottom: 0.35rem; }
.input, .select, .textarea {
  width: 100%; font: inherit; color: var(--ink);
  background: #fff; border: 1.5px solid var(--line-2); border-radius: var(--radius);
  padding: 0.65rem 0.85rem; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { resize: vertical; min-height: 7rem; line-height: 1.5; }
.textarea.code { font-family: var(--mono); font-size: 0.9rem; }
.input:hover, .select:hover, .textarea:hover { border-color: #ddc6d2; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--peony); box-shadow: 0 0 0 4px rgba(240, 143, 179, 0.18); }
.input.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 4px rgba(229, 96, 122, 0.15); }
.input[readonly] { background: #fdf8fa; }
.input-code { font-family: var(--mono); letter-spacing: 0.18em; text-transform: uppercase; font-size: 1.1rem; }
.check {
  display: flex; gap: 0.75rem; align-items: flex-start; cursor: pointer;
  padding: 0.85rem 1rem; border-radius: var(--radius);
  background: var(--lav-soft); border: 1.5px solid transparent;
}
.check:hover { border-color: var(--lav); }
.check input { width: 1.15rem; height: 1.15rem; margin-top: 0.2rem; accent-color: var(--peony-strong); flex: none; }
.file-input { font: inherit; font-size: 0.85rem; color: var(--ink-2); max-width: 100%; }
.file-input::file-selector-button {
  font: inherit; font-weight: 700; margin-right: 0.75rem; cursor: pointer;
  border: 0; border-radius: 999px; padding: 0.45rem 0.9rem;
  background: var(--peach-soft); color: var(--peach-ink);
}

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  font: inherit; font-weight: 800; font-size: 0.92rem; line-height: 1.2;
  padding: 0.68rem 1.2rem; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--line-2); background: #fff; color: var(--ink);
  text-decoration: none; white-space: nowrap;
  transition: transform 0.12s, background-color 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.btn:hover { background: #fdf6f9; }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(240, 143, 179, 0.3); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--peony); border-color: var(--peony); color: #fff; box-shadow: 0 6px 16px rgba(240, 143, 179, 0.35); }
.btn-primary:hover { background: var(--peony-strong); border-color: var(--peony-strong); }
.btn-lime { background: var(--lime); border-color: var(--lime); color: #1e4a1a; box-shadow: 0 6px 16px rgba(155, 219, 143, 0.4); }
.btn-lime:hover { background: #88cf7b; border-color: #88cf7b; }
.btn-soft { background: var(--lav-soft); border-color: transparent; color: var(--lav-ink); }
.btn-soft:hover { background: #e4dcfd; }
.btn-danger { background: #fff; border-color: #f5c2cd; color: var(--danger-ink); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-lg { padding: 0.85rem 1.5rem; font-size: 1rem; }

/* ---------- Метки ---------- */
.pill { display: inline-flex; align-items: center; gap: 0.3rem; border-radius: 999px; padding: 0.22rem 0.7rem; font-size: 0.8rem; font-weight: 700; white-space: nowrap; background: #f5eff3; color: var(--ink-2); }
.pill-lime { background: var(--lime-soft); color: var(--lime-ink); }
.pill-peony { background: var(--peony-soft); color: var(--peony-ink); }
.pill-lav { background: var(--lav-soft); color: var(--lav-ink); }
.pill-peach { background: var(--peach-soft); color: var(--peach-ink); }
.pill-danger { background: var(--danger-soft); color: var(--danger-ink); }
.role-organizer { background: var(--lav-soft); color: var(--lav-ink); }
.role-student { background: var(--lime-soft); color: var(--lime-ink); }
.role-jury { background: var(--peach-soft); color: var(--peach-ink); }
.role-observer { background: var(--peony-soft); color: var(--peony-ink); }
.dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; display: inline-block; background: #d6cfd9; flex: none; }
.dot-on { background: #5cc24a; box-shadow: 0 0 0 3px rgba(92, 194, 74, 0.2); }

/* ---------- Баннеры ---------- */
.banner { border-radius: var(--radius); padding: 0.85rem 1.1rem; font-weight: 600; }
.banner-lime { background: var(--lime-soft); color: var(--lime-ink); }
.banner-peach { background: var(--peach-soft); color: var(--peach-ink); }
.banner-lav { background: var(--lav-soft); color: var(--lav-ink); }
.banner-danger { background: var(--danger-soft); color: var(--danger-ink); }

/* ---------- Таймер ---------- */
.timer { font-family: var(--mono); font-weight: 800; font-size: 1.05rem; padding: 0.45rem 0.95rem; border-radius: 999px; white-space: nowrap; background: #f5eff3; }
.timer-run { background: var(--lime-soft); color: var(--lime-ink); }
.timer-warn { background: var(--danger-soft); color: var(--danger-ink); animation: pulse 1.2s ease-in-out infinite; }
.timer-wait { background: var(--peach-soft); color: var(--peach-ink); }
.timer-done { background: var(--lav-soft); color: var(--lav-ink); }
@keyframes pulse { 50% { opacity: 0.6; } }

/* ---------- Вкладки ---------- */
.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; padding: 0.35rem; background: rgba(255, 255, 255, 0.7); border: 1px solid var(--line); border-radius: 999px; width: fit-content; max-width: 100%; margin-bottom: 1.25rem; }
.tab { font: inherit; font-weight: 800; font-size: 0.9rem; border: 0; background: transparent; color: var(--ink-2); padding: 0.55rem 1.05rem; border-radius: 999px; cursor: pointer; }
.tab:hover { background: var(--peony-soft); color: var(--peony-ink); }
.tab-active, .tab-active:hover { background: var(--ink); color: #fff; }

/* ---------- Приглашения ---------- */
.invite { border-radius: var(--radius); padding: 0.95rem; border: 1px solid var(--line); background: #fff; }
.invite-code { font-family: var(--mono); font-weight: 800; font-size: 1.15rem; letter-spacing: 0.12em; color: var(--peony-ink); }

/* ---------- Задания и ответы ---------- */
.task-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); line-height: 1.6; }
.task-num { display: inline-grid; place-items: center; min-width: 2rem; height: 2rem; border-radius: 10px; background: var(--peony-soft); color: var(--peony-ink); font-weight: 900; padding: 0 0.4rem; }
.file-link { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 700; color: var(--peony-ink); text-decoration: none; overflow-wrap: anywhere; padding: 0.4rem 0.8rem; border-radius: 999px; background: var(--peony-soft); }
.file-link:hover { background: #fbd8e5; }
.answer-text { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 0.82rem; background: #2d2a3a; color: #f4eef8; padding: 0.85rem; border-radius: 12px; margin: 0.5rem 0 0; max-height: 22rem; overflow: auto; }
details > summary { cursor: pointer; color: var(--ink-2); list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; color: var(--peony); }
details[open] > summary::before { content: "▾ "; }
.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; }
.empty-emoji { font-size: 2.2rem; display: block; margin-bottom: 0.4rem; }

/* ---------- Таблица оценок ---------- */
.table-wrap { overflow-x: auto; }
.grade-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.grade-table th { text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 800; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--line); }
.grade-table td { padding: 0.7rem 0.5rem; border-bottom: 1px solid #f7eef2; vertical-align: top; }
.grade-table tr:last-child td { border-bottom: 0; }
.grade-table { table-layout: fixed; min-width: 560px; }
.grade-table th:first-child { width: 28%; }
.grade-table th:last-child { width: 8.5rem; }
.score-input { width: 5.5rem; text-align: center; font-weight: 800; font-size: 1rem; padding: 0.5rem; }
.save-status { display: block; font-size: 0.75rem; margin-top: 0.25rem; min-height: 1em; }
.ok { color: var(--lime-ink); } .err { color: var(--danger-ink); } .wait { color: var(--muted); }

/* ---------- Турнирная таблица ---------- */
.board { width: 100%; border-collapse: separate; border-spacing: 0 0.4rem; }
.board th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 800; padding: 0 0.7rem; text-align: left; }
.board td { padding: 0.8rem 0.7rem; background: #fff; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.board td:first-child { border-left: 1px solid var(--line); border-radius: 14px 0 0 14px; }
.board td:last-child { border-right: 1px solid var(--line); border-radius: 0 14px 14px 0; }
.board tr.place-1 td { background: #fff6dc; } .board tr.place-2 td { background: #f3f1f8; } .board tr.place-3 td { background: #ffeee4; }
.board tr.me td { background: var(--lime-soft); }
.board .place { width: 4rem; font-weight: 900; font-size: 1.1rem; }
.board .total { font-weight: 900; font-size: 1.15rem; text-align: right; color: var(--peony-ink); }
.board-big td { font-size: 1.3rem; padding: 1rem 0.9rem; }
.board-big .total { font-size: 1.6rem; }
.board tr { transition: transform 0.4s; }
.moved-up td { animation: flash-up 1.6s ease-out; }
@keyframes flash-up { 0% { background: #d9f6cf; } 100% { } }
:fullscreen { background: var(--bg); overflow: auto; padding: 2rem; }

/* ---------- Экраны участников ---------- */
.screens-grid { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.screen-card { display: block; width: 100%; text-align: left; padding: 0; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: #fff; cursor: zoom-in; font: inherit; color: inherit; transition: box-shadow 0.15s, transform 0.15s; }
.screen-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.screen-thumb { aspect-ratio: 16 / 9; background: #2d2a3a; display: grid; place-items: center; color: #b7b0c4; font-size: 0.85rem; }
.screen-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.screen-meta { padding: 0.6rem 0.75rem; }

/* ---------- Модальное окно ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(45, 42, 58, 0.88); display: flex; flex-direction: column; padding: 1rem; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; color: #fff; margin-bottom: 0.75rem; }
.modal img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }

/* ---------- Прогресс и уведомления ---------- */
.progress { height: 0.45rem; background: var(--peony-soft); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--lime), var(--peony)); transition: width 0.2s; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(26rem, calc(100vw - 2rem)); }
.toast { padding: 0.8rem 1.1rem; border-radius: 16px; background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 12px 30px rgba(45, 42, 58, 0.25); transition: opacity 0.3s, transform 0.3s; }
.toast-success { background: #4f9e43; }
.toast-error { background: #c94562; }
.toast-hide { opacity: 0; transform: translateY(8px); }
.spinner { width: 2.2rem; height: 2.2rem; border-radius: 50%; border: 4px solid var(--peony-soft); border-top-color: var(--peony); animation: spin 0.9s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.footer { color: var(--muted); font-size: 0.8rem; padding: 0 0 2rem; }

@media (max-width: 560px) {
  .grid-form { grid-template-columns: 1fr; }
  .card { padding: 1.1rem; border-radius: 18px; }
  .brand-sub { white-space: normal; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
