:root {
  --paper: #f5f8fc;
  --grid: #dde6f2;
  --grid-strong: #c5d3e8;
  --ink: #16224a;
  --pencil: #66728d;
  --marker: #ffe14d;
  --marker-edge: #e8c400;
  --red: #cf3434;
  --white: #ffffff;
  --display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --text: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  color: var(--ink);
  font-family: var(--text);
  font-size: 16px;
  line-height: 1.4;
}
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* ---------- Экран ---------- */
.screen {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: clamp(12px, 2.2vh, 32px);
  padding: clamp(16px, 3vh, 44px) clamp(16px, 4vw, 80px);
}
.head { display: flex; justify-content: space-between; align-items: baseline; gap: 24px; flex-wrap: wrap; }
.head h1 { font-family: var(--display); font-weight: 700; font-size: clamp(20px, 2.2vw, 40px); margin: 0; letter-spacing: -0.01em; }
.head .case { color: var(--pencil); font-size: clamp(16px, 1.4vw, 26px); margin: 4px 0 0; }
.status { font-size: clamp(16px, 1.4vw, 26px); font-weight: 500; text-align: right; }
.status .tag { display: inline-block; margin-left: 12px; padding: 2px 12px; border: 2px solid currentColor; border-radius: 4px; color: var(--red); font-weight: 700; }

.clock { display: grid; gap: clamp(12px, 2.4vh, 32px); }
.time {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(64px, min(14vw, 17vh), 260px);
  line-height: 0.82;
  letter-spacing: -0.03em;
  display: flex;
}
.time .d { display: inline-block; width: 0.74em; text-align: center; }
.time .c { display: inline-block; width: 0.3em; text-align: center; }
.time.warn { color: var(--red); }
.time.idle { color: var(--pencil); }
.stage-now { font-size: clamp(18px, min(1.8vw, 3.2vh), 34px); margin: 0 0 6px; }
.stage-now b { font-family: var(--display); font-weight: 700; }

/* Линейка: два этапа в масштабе 60:30 */
.ruler { position: relative; padding-top: 34px; }
.ruler .bar { display: flex; height: clamp(24px, 3.4vh, 44px); border: 2px solid var(--ink); background: var(--white); position: relative; }
.ruler .seg { position: relative; overflow: hidden; }
.ruler .seg + .seg { border-left: 2px solid var(--ink); }
.ruler .fill { position: absolute; inset: 0 auto 0 0; background: var(--marker); }
.ruler .seg.flash .fill { animation: flash 1.2s ease-out 2; }
@keyframes flash { 50% { background: var(--marker-edge); } }
.ruler .names { display: flex; margin-top: 6px; }
.ruler .seg-name { min-width: 0; padding-left: 4px; font-weight: 700; font-size: clamp(13px, 1.1vw, 20px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ruler .ticks { position: absolute; left: 0; right: 0; top: 0; height: 34px; }
.ruler .tick { position: absolute; bottom: 0; width: 2px; height: 10px; background: var(--ink); transform: translateX(-1px); }
.ruler .tick.major { height: 18px; }
.ruler .tick span { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); font-size: clamp(11px, 0.9vw, 16px); color: var(--pencil); white-space: nowrap; }
/* Крайние подписи не выходят за край шкалы */
.ruler .tick.first span { left: 0; transform: none; }
.ruler .tick.last span { left: auto; right: 0; transform: none; }
.ruler .cursor { position: absolute; top: -8px; bottom: -2px; width: 4px; background: var(--ink); transform: translateX(-2px); }

/* Таблица команд: у каждой команды свой таймер в ячейке текущего задания */
.board { align-self: start; width: 100%; border-collapse: separate; border-spacing: 0; background: var(--white); border: 2px solid var(--ink); table-layout: fixed; }
.board th, .board td { border-bottom: 1px solid var(--grid-strong); padding: clamp(6px, 1.1vh, 16px) clamp(10px, 1.2vw, 22px); text-align: left; vertical-align: middle; }
.board tr:last-child td { border-bottom: 0; }
.board thead th { font-weight: 700; font-size: clamp(14px, min(1.2vw, 2.2vh), 22px); border-bottom: 2px solid var(--ink); }
.board thead th small { display: block; color: var(--pencil); font-weight: 500; font-size: 0.8em; }
.board .team-h { width: 30%; color: var(--pencil); font-weight: 500; }
.board .team { font-family: var(--display); font-weight: 700; font-size: clamp(16px, min(1.8vw, 3.2vh), 34px); line-height: 1.15; }
/* Длинное название — не больше двух строк, полное видно в подсказке */
.board .team .nm { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.board .team .lag { display: block; font-family: var(--text); font-weight: 500; font-size: 0.5em; color: var(--pencil); }
.board .sep { border-left: 2px solid var(--ink); }
.cell { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; min-height: clamp(40px, 6.2vh, 80px); font-size: clamp(15px, min(1.3vw, 2.4vh), 24px); }
.cell.live .tt { font-family: var(--display); font-weight: 800; font-size: clamp(28px, min(4vw, 6.4vh), 76px); line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.cell.live.warn .tt { color: var(--red); }
.cell .tag { padding: 2px 10px; border: 2px solid var(--red); border-radius: 4px; color: var(--red); font-weight: 700; font-size: 0.8em; }
/* Сданное задание: маркером закрашивается вся ячейка таблицы */
.board td.is-done { background: var(--marker); }
.cell.done { font-weight: 700; }
.cell.done svg { width: 1.6em; height: 1.6em; flex: none; }
.cell.done.fresh path { stroke-dasharray: 30; animation: tick 0.6s ease-out; }
@keyframes tick { from { stroke-dashoffset: 30; } }
.cell.wait { color: var(--pencil); opacity: 0.6; font-family: var(--display); font-weight: 700; }
.cell.late { color: var(--red); font-weight: 700; }
.foot { color: var(--pencil); font-size: 14px; }
.offline { position: fixed; right: 16px; bottom: 16px; background: var(--red); color: var(--white); padding: 8px 14px; border-radius: 4px; font-weight: 700; }

/* ---------- Админка ---------- */
.admin { max-width: 980px; margin: 0 auto; padding: 24px 16px 64px; display: grid; gap: 20px; }
.panel { background: var(--white); border: 2px solid var(--ink); border-radius: 6px; padding: 16px; }
.panel h2 { font-family: var(--display); font-weight: 700; font-size: 18px; margin: 0 0 12px; }
.admin-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.admin-top h1 { font-family: var(--display); font-size: 22px; margin: 0; }
.admin-top a { color: var(--ink); }
.readout { display: flex; flex-wrap: wrap; align-items: baseline; gap: 16px; }
.readout .t { font-family: var(--display); font-weight: 800; font-size: 56px; line-height: 1; font-variant-numeric: tabular-nums; }
.readout .s { color: var(--pencil); }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.btn {
  min-height: 44px; padding: 8px 16px; border: 2px solid var(--ink); border-radius: 6px;
  background: var(--white); font-weight: 700; cursor: pointer;
}
.btn.main { background: var(--ink); color: var(--white); }
.btn.warn { border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:hover:not(:disabled) { background: var(--marker); color: var(--ink); }
.team-card { display: grid; gap: 10px; padding: 12px 0; border-top: 1px solid var(--grid-strong); }
.team-card:first-of-type { border-top: 0; padding-top: 0; }
.team-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.team-head input { flex: 1 1 200px; min-height: 44px; padding: 6px 10px; border: 2px solid var(--grid-strong); border-radius: 6px; font-weight: 700; font-size: 18px; background: var(--paper); }
.checks { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chk { min-height: 48px; padding: 8px 14px; border: 2px solid var(--ink); border-radius: 6px; background: var(--white); font-weight: 700; cursor: pointer; }
.chk[aria-pressed="true"] { background: var(--marker); }
.team-line { margin: 0; color: var(--pencil); font-variant-numeric: tabular-nums; }
.input { flex: 1 1 200px; min-height: 44px; padding: 6px 10px; border: 2px solid var(--grid-strong); border-radius: 6px; background: var(--paper); }
.field { display: grid; gap: 4px; }
.field input { min-height: 44px; padding: 6px 10px; border: 2px solid var(--grid-strong); border-radius: 6px; background: var(--paper); width: 100%; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.login { width: calc(100% - 32px); max-width: 380px; margin: 18vh auto; padding: 20px; display: grid; gap: 12px; }
.login .err { margin: 0; }
.login h1 { font-family: var(--display); font-size: 22px; margin: 0; }
.login .btn { justify-self: start; }
.login .hint { margin: 0; }
.err { color: var(--red); font-weight: 700; min-height: 1.4em; }
.err:empty { display: none; }
.hint { color: var(--pencil); font-size: 14px; margin: 6px 0 0; }

@media (max-width: 900px) {
  .board .team-h { width: 34%; }
  .cell.live .tt { font-size: 26px; }
}
@media (max-width: 600px) {
  .team-head input { flex-basis: 100%; }
  .readout .t { font-size: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
