:root {
  color-scheme: dark;
  --ink: #071a40;
  --navy: #08265d;
  --blue: #0d3b83;
  --blue-bright: #1478d4;
  --gold: #ffb000;
  --gold-light: #ffd970;
  --white: #f8fbff;
  --muted: #a9bcdb;
  --line: rgba(255, 255, 255, 0.15);
  --glass: rgba(7, 26, 64, 0.82);
  --shadow: 0 24px 70px rgba(0, 6, 24, 0.42);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--ink); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--white);
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at 50% 12%, rgba(19, 116, 210, 0.36), transparent 34%),
    linear-gradient(120deg, rgba(2, 18, 52, 0.98), rgba(4, 42, 100, 0.9)),
    url("/assets/diplom.png") center 42% / cover fixed;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 8% 18%, var(--gold) 0 2px, transparent 3px),
    radial-gradient(circle at 93% 14%, #fff 0 2px, transparent 3px),
    radial-gradient(circle at 86% 76%, var(--gold) 0 2px, transparent 3px),
    radial-gradient(circle at 13% 82%, #fff 0 2px, transparent 3px);
  opacity: 0.72;
}

button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.shell {
  width: min(1800px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(18px, 2.4vw, 44px);
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: clamp(18px, 2vw, 30px);
}

.brand { display: flex; align-items: center; gap: 15px; min-width: 0; }
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: none;
  border: 2px solid var(--gold);
  border-radius: 50%;
  color: var(--gold);
  font-size: 23px;
  box-shadow: inset 0 0 0 5px rgba(255, 176, 0, 0.08), 0 0 28px rgba(255, 176, 0, 0.16);
}
.brand h1 { margin: 0; font-size: clamp(25px, 2.2vw, 40px); letter-spacing: -0.03em; line-height: 1; }
.brand p { margin: 7px 0 0; color: var(--muted); font-size: 14px; letter-spacing: .09em; text-transform: uppercase; }
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(4, 25, 63, .72);
  color: #d8e7ff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #43df7d; box-shadow: 0 0 0 5px rgba(67, 223, 125, .12); }
.live-pill.offline .live-dot { background: #f36c6c; box-shadow: 0 0 0 5px rgba(243, 108, 108, .12); }

.glass {
  border: 1px solid rgba(255, 255, 255, .16);
  background: linear-gradient(145deg, rgba(9, 40, 91, .93), rgba(4, 24, 62, .87));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.score-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 24vw, 410px);
  gap: clamp(16px, 2vw, 28px);
  align-items: stretch;
}

.scoreboard { border-radius: 24px; padding: clamp(14px, 1.7vw, 26px); min-width: 0; }
.board-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 7px; color: var(--gold-light); font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.board-heading h2 { margin: 0; font-size: clamp(22px, 2vw, 32px); }
.round-now { color: var(--muted); font-size: 14px; }
.round-now strong { color: var(--white); }

.score-grid {
  --score-columns: minmax(165px, 1.65fr) repeat(6, minmax(52px, .68fr)) minmax(78px, .85fr);
  display: grid;
  grid-template-columns: var(--score-columns);
  gap: 8px;
  align-items: stretch;
}
.team-score-row {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: var(--score-columns);
  gap: 8px;
  position: relative;
  isolation: isolate;
}
.grid-head {
  min-height: 40px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: clamp(11px, .85vw, 14px);
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.grid-head:first-child { place-items: center start; padding-left: 16px; }
.grid-head.total-head { color: var(--gold-light); }
.grid-head.current { color: #fff; background: rgba(20, 120, 212, .25); border-radius: 10px; }
.team-cell, .score-cell, .total-cell {
  min-height: clamp(68px, 7.2vh, 88px);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .045);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.team-cell {
  justify-content: flex-start;
  gap: 13px;
  padding: 12px 15px;
  border-left: 4px solid var(--team);
  background: linear-gradient(90deg, color-mix(in srgb, var(--team) 22%, transparent), rgba(255,255,255,.035));
}
.team-cell .rank { color: var(--muted); width: 18px; text-align: center; font-weight: 800; font-size: 13px; }
.team-swatch { width: 11px; height: 36px; flex: none; border-radius: 5px; background: var(--team); box-shadow: 0 0 20px color-mix(in srgb, var(--team) 55%, transparent); }
.team-name { min-width: 0; font-size: clamp(16px, 1.35vw, 23px); font-weight: 800; line-height: 1.1; }
.score-cell { font-size: clamp(20px, 2vw, 32px); font-weight: 750; font-variant-numeric: tabular-nums; }
.score-cell.empty { color: rgba(255,255,255,.22); font-weight: 400; }
.score-cell.current { border-color: rgba(67, 176, 255, .5); background: rgba(16, 111, 195, .14); }
.total-cell {
  border-color: rgba(255, 190, 50, .35);
  background: linear-gradient(145deg, rgba(255, 176, 0, .18), rgba(255, 176, 0, .06));
  color: #ffe49b;
  font-size: clamp(25px, 2.4vw, 40px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.total-cell.score-updated { animation: scoreGlow .85s ease-out; }
@keyframes scoreGlow {
  0% { transform: scale(.94); background: rgba(255, 215, 100, .48); box-shadow: 0 0 34px rgba(255, 190, 50, .38); }
  100% { transform: scale(1); }
}
.team-row-leading .team-cell { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--team) 55%, transparent); }
.team-row-leading .rank { color: var(--gold); }

.timer-panel {
  border-radius: 24px;
  padding: clamp(20px, 2vw, 30px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 100%;
  overflow: hidden;
  position: relative;
}
.timer-panel::after {
  content: "";
  position: absolute;
  width: 260px;
  height: 260px;
  border: 1px solid rgba(255, 176, 0, .14);
  border-radius: 50%;
  top: 18%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 28px rgba(255, 176, 0, .035), 0 0 0 58px rgba(255, 176, 0, .02);
  pointer-events: none;
}
.timer-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.timer-title h2 { margin: 0; font-size: 19px; }
.round-badge { padding: 7px 10px; border-radius: 8px; background: rgba(255,176,0,.13); color: var(--gold-light); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.timer-display {
  position: relative;
  z-index: 1;
  margin: clamp(24px, 5vh, 58px) 0 clamp(20px, 3vh, 36px);
  text-align: center;
  font-size: clamp(68px, 7vw, 118px);
  line-height: .9;
  letter-spacing: -.06em;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 42px rgba(29, 145, 255, .28);
}
.timer-display.warning { color: #ffcf59; animation: pulse 1s ease-in-out infinite; }
.timer-display.finished { color: #ff6f66; animation: alarmPulse .55s ease-in-out infinite alternate; }
@keyframes pulse { 50% { opacity: .72; } }
@keyframes alarmPulse { to { transform: scale(1.03); text-shadow: 0 0 44px rgba(255, 80, 70, .5); } }
.duration-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.duration-btn, .secondary-btn, .primary-btn, .icon-btn, .round-tab {
  min-height: 44px;
  border: 1px solid var(--line);
  touch-action: manipulation;
  border-radius: 11px;
  background: rgba(255,255,255,.055);
  cursor: pointer;
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
.duration-btn:hover, .secondary-btn:hover, .icon-btn:hover, .round-tab:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.28); }
button:active { transform: translateY(1px); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid rgba(255, 201, 68, .6); outline-offset: 2px; }
.duration-btn.active { color: #08265d; background: var(--gold); border-color: var(--gold); font-weight: 900; }
.timer-actions { display: grid; grid-template-columns: 1fr .75fr; gap: 10px; }
.primary-btn {
  border-color: var(--gold);
  background: linear-gradient(135deg, #ffc23e, #f2a000);
  color: #092250;
  font-weight: 900;
  box-shadow: 0 12px 30px rgba(255, 176, 0, .18);
}
.primary-btn:hover { filter: brightness(1.07); }
.secondary-btn { font-weight: 800; }
.sound-note { margin: 14px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

.bottom-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
}
.bottom-nav nav { display: flex; gap: 10px; }
.text-link { text-decoration: none; padding: 9px 11px; border-radius: 8px; }
.text-link:hover { color: #fff; background: rgba(255,255,255,.07); }

.page-narrow { width: min(1180px, 100%); }
.control-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(340px, .95fr); gap: 22px; }
.panel { border-radius: 22px; padding: clamp(20px, 2.5vw, 34px); }
.panel h2 { margin: 0; font-size: 24px; }
.panel-lead { margin: 8px 0 24px; color: var(--muted); line-height: 1.5; }
.control-timer { font-size: clamp(80px, 10vw, 142px); margin: 38px 0 32px; }
.control-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.control-actions .primary-btn, .control-actions .secondary-btn { min-height: 54px; }
.round-picker { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 18px 0 28px; }
.round-tab { font-weight: 800; }
.round-tab.active { background: var(--gold); color: #092250; border-color: var(--gold); }
.mini-teams { display: grid; gap: 10px; }
.mini-team { display: grid; grid-template-columns: 14px 1fr auto; gap: 12px; align-items: center; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.035); }
.mini-team-dot { width: 10px; height: 34px; border-radius: 4px; background: var(--team); }
.mini-team strong { font-size: 17px; }
.mini-team span:last-child { color: var(--gold-light); font-size: 25px; font-weight: 900; }
.action-links { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.action-card { padding: 16px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.045); text-decoration: none; }
.action-card:hover { border-color: rgba(255,190,50,.45); background: rgba(255,176,0,.08); }
.action-card strong { display: block; margin-bottom: 5px; }
.action-card span { color: var(--muted); font-size: 12px; }

.game-settings { margin-top: 22px; }
.settings-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.settings-heading h2 { margin: 0; }
.settings-note { color: var(--muted); font-size: 13px; }
.manage-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 24px; }
.manage-grid h3 { margin: 0; font-size: 19px; }
.settings-copy { margin: 7px 0 16px; color: var(--muted); font-size: 13px; }
.team-name-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.team-name-field {
  display: grid;
  grid-template-columns: 11px minmax(78px, .65fr) minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.035);
}
.team-name-dot { width: 10px; height: 34px; border-radius: 4px; background: var(--team); }
.team-name-caption { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.name-input {
  min-width: 0;
  width: 100%;
  height: 40px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 9px;
  padding: 0 11px;
  background: rgba(1,14,42,.5);
  color: #fff;
  font-weight: 700;
}
.name-input:hover { border-color: rgba(255,255,255,.3); }
.settings-save { min-height: 48px; margin-top: 12px; padding: 0 22px; }
.danger-zone {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 22px;
  border: 1px solid rgba(255, 111, 102, .25);
  border-radius: 16px;
  padding: 20px;
  background: linear-gradient(145deg, rgba(255, 91, 83, .09), rgba(255,255,255,.025));
}
.danger-zone h3 { margin: 12px 0 7px; }
.danger-zone p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.danger-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: rgba(255, 111, 102, .12); color: #ffaaa4; font-size: 23px; }
.danger-btn {
  width: 100%;
  min-height: 48px;
  border: 1px solid rgba(255, 122, 113, .48);
  border-radius: 11px;
  background: rgba(255, 100, 90, .1);
  color: #ffc3bf;
  font-weight: 900;
  cursor: pointer;
  transition: .16s ease;
}
.danger-btn:hover { background: rgba(255, 100, 90, .17); border-color: rgba(255, 150, 143, .7); }
.danger-btn.confirm { background: #e55750; border-color: #ff8b84; color: #fff; }
.danger-btn:disabled { cursor: wait; opacity: .65; }
.confirm-hint { min-height: 20px; margin-top: 8px !important; text-align: center; }

.mobile-shell { width: min(660px, 100%); padding-bottom: 110px; }
.mobile-shell .topbar { align-items: flex-start; }
.mobile-shell .brand h1 { font-size: 27px; }
.round-card { border-radius: 20px; padding: 20px; margin-bottom: 14px; }
.round-card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.round-card h2 { margin: 0; font-size: 22px; }
.round-card .round-picker { margin: 17px 0 0; }
.score-form { display: grid; gap: 12px; }
.score-input-card {
  --team: #fff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--team);
  border-radius: 18px;
  padding: 17px;
  background: linear-gradient(100deg, color-mix(in srgb, var(--team) 17%, rgba(5,29,70,.93)), rgba(5,29,70,.92));
  box-shadow: 0 14px 36px rgba(0,8,30,.18);
}
.score-input-label { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; }
.score-input-label strong { font-size: 19px; }
.score-input-label span { color: var(--muted); font-size: 12px; }
.stepper { display: grid; grid-template-columns: 52px 1fr 52px; gap: 9px; }
.icon-btn { font-size: 26px; font-weight: 400; }
.score-input {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(255,255,255,.23);
  border-radius: 11px;
  background: rgba(1,14,42,.52);
  color: #fff;
  text-align: center;
  font-size: 26px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.sticky-save { position: fixed; z-index: 5; left: 50%; bottom: 18px; transform: translateX(-50%); width: min(calc(100% - 32px), 628px); }
.save-btn { width: 100%; min-height: 58px; font-size: 17px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  z-index: 10;
  transform: translate(-50%, 15px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 17px;
  border-radius: 12px;
  background: #f7fbff;
  color: #092250;
  font-weight: 800;
  box-shadow: 0 16px 44px rgba(0,0,0,.35);
  transition: .22s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.connection-label { color: var(--muted); font-size: 12px; }

@media (max-width: 1050px) {
  .score-layout { grid-template-columns: 1fr; }
  .timer-panel { min-height: auto; }
  .timer-display { margin: 28px 0; font-size: 90px; }
  .score-grid { --score-columns: minmax(150px, 1.45fr) repeat(6, minmax(48px, .6fr)) minmax(72px, .75fr); }
}

@media (max-width: 820px) {
  .shell { padding: 16px; }
  .topbar { align-items: flex-start; }
  .brand p { display: none; }
  .scoreboard { overflow-x: auto; }
  .score-grid { min-width: 820px; }
  .control-grid { grid-template-columns: 1fr; }
  .manage-grid { grid-template-columns: 1fr; }
  .bottom-nav { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 560px) {
  .brand-mark { width: 42px; height: 42px; }
  .brand h1 { font-size: 23px; }
  .live-pill { padding: 9px 11px; font-size: 11px; }
  .round-picker { gap: 5px; }
  .round-tab { min-height: 40px; }
  .action-links { grid-template-columns: 1fr; }
  .settings-heading { align-items: flex-start; flex-direction: column; }
  .team-name-list { grid-template-columns: 1fr; }
  .team-name-field { grid-template-columns: 11px minmax(70px, .55fr) minmax(0, 1fr); }
}

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