/* Shared components. Every page loads this file. */

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: var(--h-md); padding: 0 var(--s4);
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); color: var(--text-strong);
  font: 500 14px/1 var(--font-sans); white-space: nowrap; cursor: pointer;
  transition: background var(--fast), border-color var(--fast), color var(--fast), transform var(--fast), filter var(--fast);
}
.btn:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text-strong); background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.ghost.danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn.small { height: var(--h-sm); padding: 0 var(--s3); font-size: 13px; }
.btn.big { height: var(--h-lg); padding: 0 var(--s5); font-size: 15px; }
.btn.icon { width: var(--h-md); padding: 0; }
.btn.block { width: 100%; }
a.btn { border-bottom: 1px solid var(--line); }
a.btn.primary { border-color: var(--accent); }
a.btn.ghost { border-color: transparent; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: var(--s2); }
.field + .field { margin-top: var(--s4); }
.grid-2 > .field + .field, .row > .field + .field { margin-top: 0; }
.field.grow { flex: 1; min-width: 0; }
input[type="text"], input[type="number"], input[type="url"], select, textarea {
  width: 100%; height: var(--h-md); padding: 0 var(--s3);
  background: var(--surface); color: var(--text-strong);
  border: 1px solid var(--line); border-radius: var(--r);
  font: 14px var(--font-sans);
  transition: border-color var(--fast), box-shadow var(--fast);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
textarea { height: auto; min-height: 88px; padding: var(--s3); resize: vertical; font-family: var(--font-mono); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input.mono { font-family: var(--font-mono); }
input.lg { height: var(--h-lg); font-size: 15px; }
input.code-input { text-transform: uppercase; letter-spacing: .12em; }
.check { display: flex; align-items: center; gap: var(--s2); min-height: var(--h-md); color: var(--text); font-size: 14px; cursor: pointer; margin: 0; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
.segmented {
  display: inline-flex; height: var(--h-md); padding: 3px; gap: 2px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.segmented button {
  height: 100%; padding: 0 var(--s4); border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--muted); white-space: nowrap;
  font: 500 13px var(--font-sans); cursor: pointer; transition: background var(--fast), color var(--fast);
}
.segmented button:hover { color: var(--text-strong); }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--text-strong); box-shadow: 0 0 0 1px var(--line-strong) inset; }
.hint { font-size: 13px; color: var(--muted); }
.inline-form { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.inline-form input { flex: 1 1 140px; width: auto; min-width: 0; }
.inline-form.code input { flex: 0 1 168px; }
.error-box { color: var(--danger); background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent); border-radius: var(--r); padding: var(--s3) var(--s4); font-size: 14px; }
.note { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s3) var(--s4); font-size: 14px; }

/* ---------- banners & action rows ---------- */
.actions { display: flex; gap: var(--s3); flex-wrap: wrap; align-items: center; }
.banner {
  display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap;
  min-height: 52px; padding: var(--s2) var(--s2) var(--s2) var(--s4);
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface);
  font-size: 14px; color: var(--text-strong);
}
.banner > .grow { flex: 1; min-width: 12ch; }
.banner.freeze { background: var(--surface-2); }
.banner.bad { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.banner.good { color: var(--text-strong); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.banner.good .pulse { background: var(--accent); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; box-shadow: 0 0 0 0 var(--glow); animation: pulse 2s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }

/* ---------- surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s5); box-shadow: var(--shadow);
}
a.card { display: block; color: inherit; border-bottom: 1px solid var(--line); }
a.card, .card.clickable { transition: border-color var(--fast), background var(--fast), transform var(--fast); }
a.card:hover, .card.clickable:hover { border-color: var(--line-strong); background: var(--surface-hover); }
a.card:active { transform: translateY(1px); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s4); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }
/* One header height for every panel (56px), whether it holds a link, a button or nothing. */
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); padding: var(--s2) var(--s5); border-bottom: 1px solid var(--line); min-height: 56px; }
.panel-head:has(p) { padding-top: var(--s4); padding-bottom: var(--s4); }
.panel-head h2 { font-size: 15px; }
.panel-head a { font-size: 13px; color: var(--muted); border-bottom-color: transparent; }
.panel-head a:hover { color: var(--text-strong); }
.panel-body { padding: var(--s5); }
.panel-list { list-style: none; margin: 0; padding: 0; }
/* Panels in a row share a height: .panel-fill takes the spare room (and centers an empty state),
   .panel-foot sits on the bottom edge. */
.grid-2.equal > .panel { display: flex; flex-direction: column; }
/* titled sections side by side: the boxes under the titles end on the same line */
.equal-cols > section { display: flex; flex-direction: column; }
.equal-cols > section > :last-child { flex: 1; }
.equal-cols .empty-state.boxed { align-content: center; }
.panel-fill { flex: 1; display: grid; align-content: center; }
.panel-fill > .panel-list { align-self: start; }
.panel-foot { margin: auto 0 0; padding: var(--s3) var(--s5); border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); background: color-mix(in srgb, var(--surface-2) 40%, transparent); }
.panel-list > li { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 52px; padding: var(--s2) var(--s5); border-bottom: 1px solid var(--line); }
.panel-list > li:last-child { border-bottom: 0; }
.panel-list .meta { font-size: 13px; color: var(--muted); }

/* Mode cards: icon + tag on top, text, and the call to action pinned to the bottom so rows line up. */
a.card.mode-card, .mode-card { display: grid; grid-template-rows: auto auto 1fr auto; gap: var(--s2); padding: var(--s4) var(--s4) var(--s4); }
.mode-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s2); }
.mode-card .mode-icon {
  display: grid; place-items: center; width: 36px; height: 36px;
  border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); color: var(--accent);
  transition: border-color var(--fast);
}
.mode-card .mode-icon svg { width: 18px; height: 18px; }
.mode-tag { font: 500 11px var(--font-mono); color: var(--muted); letter-spacing: .02em; white-space: nowrap; }
.mode-card h2 { font-size: 15px; }
.mode-card p { font-size: 13px; line-height: 1.5; color: var(--muted); }
.mode-card .go { display: flex; align-items: center; justify-content: space-between; margin-top: var(--s2); padding-top: var(--s3); border-top: 1px solid var(--line); font-size: 13px; font-weight: 500; color: var(--text-strong); }
.mode-card .go .arrow { color: var(--muted); transition: transform var(--fast), color var(--fast); }
a.mode-card:hover .mode-icon { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
a.mode-card:hover .go .arrow { color: var(--accent); transform: translateX(3px); }

/* Mode grids are sized for their card count, so a row never ends with a lone orphan.
   5 cards: one row of 5, then 3 + 2 (wider) on tablets, then a list on phones. */
.mode-grid.n5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.mode-grid.n4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) {
  .mode-grid.n5 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .mode-grid.n5 > * { grid-column: span 2; }
  .mode-grid.n5 > :nth-child(n + 4) { grid-column: span 3; }
  .mode-grid.n4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .mode-grid.n5, .mode-grid.n4 { grid-template-columns: minmax(0, 1fr); gap: var(--s3); }
  .mode-grid.n5 > *, .mode-grid.n5 > :nth-child(n + 4) { grid-column: auto; }
  /* compact on phones: icon beside the text */
  a.card.mode-card, .mode-card { grid-template-columns: 36px minmax(0, 1fr); grid-template-rows: auto auto; column-gap: var(--s4); row-gap: 2px; }
  .mode-top { grid-row: span 2; margin: 0; align-self: start; }
  .mode-tag, .mode-card .go { display: none; }
}

.section-title { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0; margin: 0; }
h2.section-title { font-size: 13px; }

.chip {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; white-space: nowrap; border: 1px solid transparent;
}
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.chip.avoid { background: var(--danger-soft); color: var(--danger); text-decoration: line-through; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
button.chip { height: 32px; padding: 0 12px; cursor: pointer; font: inherit; font-size: 13px; border-color: var(--line); background: var(--surface); transition: border-color var(--fast), background var(--fast), color var(--fast); }
button.chip:hover { border-color: var(--line-strong); color: var(--text-strong); }
button.chip.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--accent); }
button.chip.avoid { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }

.kpi { font-family: var(--font-mono); font-size: 28px; font-weight: 500; color: var(--text-strong); line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 12px; color: var(--muted); margin-top: var(--s1); }
.kpis { display: flex; flex-wrap: wrap; gap: var(--s4) var(--s7); }

/* ---------- handles in Codeforces colors ---------- */
.handle { font-family: var(--font-mono); font-weight: 600; border: 0; }
a.handle:hover { text-decoration: underline; text-underline-offset: 3px; }
.r-gray { color: var(--cf-gray); }
.r-green { color: var(--cf-green); }
.r-cyan { color: var(--cf-cyan); }
.r-blue { color: var(--cf-blue); }
.r-violet { color: var(--cf-violet); }
.r-orange { color: var(--cf-orange); }
.r-red { color: var(--cf-red); }
.r-legend::first-letter { color: var(--text-strong); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 500; font-size: 12px; color: var(--muted); background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--font-mono); }
td.rank { width: 48px; color: var(--muted); }
.table-wrap tr.me td { background: var(--accent-soft); }

/* ---------- standings cells & verdicts (match page and the home preview) ---------- */
.cell { min-width: 52px; display: grid; place-items: center; height: 44px; border-radius: var(--r-sm); font-family: var(--font-mono); font-size: 13px; line-height: 1.15; }
.cell .t { font-size: 11px; color: var(--muted); }
.cell.ok { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cell.ok .t { color: color-mix(in srgb, var(--accent) 70%, var(--muted)); font-weight: 400; }
.cell.ok-late { color: var(--muted); }
.cell.wrong { background: var(--danger-soft); color: var(--danger); }
.cell.testing { color: var(--muted); background: var(--surface-2); }
.cell.frozen { background: var(--surface-2); color: var(--muted); }
.cell.empty-cell { border: 1px dashed var(--line); }
.cell.flip { animation: flip 420ms ease-out; }
@keyframes flip {
  0% { transform: rotateX(90deg); background: var(--accent); color: var(--accent-ink); }
  60% { transform: rotateX(0); background: var(--accent); color: var(--accent-ink); }
  100% { transform: rotateX(0); }
}
.verdict { font-family: var(--font-mono); font-size: 12px; }
.verdict.ok { color: var(--accent); }
.verdict.bad { color: var(--danger); }
.verdict.neutral { color: var(--muted); }

/* ---------- toast ---------- */
.toast-box { position: fixed; bottom: var(--s5); left: 50%; transform: translateX(-50%); display: grid; gap: var(--s2); z-index: 50; width: min(440px, calc(100% - 32px)); }
.toast {
  background: var(--surface-2); color: var(--text-strong); border: 1px solid var(--line-strong);
  border-radius: var(--r); padding: var(--s3) var(--s4); font-size: 14px;
  box-shadow: 0 16px 40px -12px rgba(0,0,0,.45); animation: toast-in 220ms var(--ease);
  overflow-wrap: anywhere;
}
.toast.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- empty states ---------- */
.empty { color: var(--muted); padding: var(--s6) var(--s4); text-align: center; font-size: 14px; }
.empty-state {
  display: grid; justify-items: center; gap: var(--s2); text-align: center;
  padding: var(--s6) var(--s5); color: var(--muted); font-size: 14px;
}
.empty-state .empty-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); color: var(--muted); margin-bottom: var(--s1); }
.empty-state strong { color: var(--text-strong); font-weight: 600; }
.empty-state p { max-width: 36ch; }
.empty-state .btn { margin-top: var(--s2); }
.card .empty-state, .panel .empty-state { padding: var(--s5); }
.table-wrap + .empty-state, .empty-state.boxed { border: 1px dashed var(--line); border-radius: var(--r-lg); }

.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; vertical-align: -2px; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.row > select, .row > input { width: auto; flex: 0 0 auto; min-width: 96px; }
.narrow-section { max-width: 560px; }

/* ---------- chart ---------- */
.chart { position: relative; }
.chart-tip {
  position: absolute; transform: translateX(-50%); pointer-events: none;
  background: var(--surface-2); color: var(--text-strong); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding: 4px 8px; font: 12px var(--font-mono); white-space: nowrap;
}
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); display: inline-block; margin-right: 8px; flex: none; vertical-align: middle; }
.online-dot.on { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- player lists ---------- */
.lobby-players { display: grid; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); box-shadow: var(--shadow); }
.lobby-player { display: flex; justify-content: space-between; align-items: center; min-height: 56px; padding: var(--s2) var(--s4); gap: var(--s3); border-bottom: 1px solid var(--line); }
.lobby-player:last-child { border-bottom: 0; }
.lobby-player .who { display: inline-flex; align-items: center; gap: var(--s2); min-width: 0; flex-wrap: wrap; }
.lobby-player .side { display: inline-flex; align-items: center; gap: var(--s3); }
.ready-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); display: inline-block; flex: none; }
.ready-dot.on { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* ---------- matchmaking radar (queue page) ---------- */
.radar { position: relative; width: 184px; height: 184px; margin: var(--s4) auto; display: grid; place-items: center; }
.radar::before, .radar::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 1px solid var(--accent); opacity: 0; animation: ping 2.4s ease-out infinite;
}
.radar::after { animation-delay: 1.2s; }
.radar-core {
  width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  font-family: var(--font-mono); color: var(--accent); font-size: 18px; font-variant-numeric: tabular-nums;
}
.radar.idle::before, .radar.idle::after { animation: none; }
.radar.idle::before { opacity: .25; transform: scale(.9); }
@keyframes ping { 0% { transform: scale(.5); opacity: .7; } 100% { transform: scale(1.15); opacity: 0; } }

@media (max-width: 720px) {
  .card { padding: var(--s4); }
  .panel-head, .panel-body { padding-left: var(--s4); padding-right: var(--s4); }
  .panel-list > li { padding-left: var(--s4); padding-right: var(--s4); }
  .panel-foot { padding-left: var(--s4); padding-right: var(--s4); }
  th, td { padding: 10px 12px; }
}

.panel > table tr.me td { background: var(--accent-soft); }
.panel > table td:first-child, .panel > table th:first-child { padding-left: var(--s5); }
.panel > table td:last-child, .panel > table th:last-child { padding-right: var(--s5); }
.panel > .panel-body.small { border-top: 1px solid var(--line); padding-top: var(--s4); padding-bottom: var(--s4); }
.profile-name { display: flex; align-items: center; gap: var(--s1); }
.profile-name .online-dot { width: 10px; height: 10px; }
.panel-head p { margin-top: 2px; max-width: 64ch; }
.verify-task { padding: var(--s4); border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-2); }
.login-head > * + * { margin-top: var(--s2); }
.queue-lede { margin: var(--s2) auto 0; }
.queue-card { max-width: 420px; margin-left: auto; margin-right: auto; }
.queue-card .btn.big { min-width: 200px; }
/* small text links still get a 40px tap target */
.panel-head a, .match-code { display: inline-flex; align-items: center; min-height: var(--h-md); padding: 0 var(--s2); margin-right: calc(-1 * var(--s2)); }

/* ---------- team colors (team duels) ---------- */
.team-a { --team: var(--team-a); --team-soft: var(--team-a-soft); }
.team-b { --team: var(--team-b); --team-soft: var(--team-b-soft); }
.team-badge {
  display: inline-grid; place-items: center; flex: none; width: 20px; height: 20px; border-radius: var(--r-sm);
  font: 600 11px/1 var(--font-mono); color: var(--team); background: var(--team-soft);
  border: 1px solid color-mix(in srgb, var(--team) 35%, transparent);
}
.team-badge.team-a, .team-badge.team-b { color: var(--team); }
.team-name { display: inline-flex; align-items: center; gap: var(--s2); }
.chip.you { height: 18px; padding: 0 6px; font-size: 11px; }
