:root {
  color-scheme: dark;
  --bg: #0e0b13;
  --ink: #f5effb;
  --ink-soft: #d8cde5;
  --muted: #aaa0b8;
  --line: #352740;
  --panel: #191320;
  --panel-strong: #21172b;
  --field: #120e18;
  --nav: #241034;
  --nav-hover: #3a1852;
  --accent: #9b5cff;
  --accent-hover: #b06cff;
  --accent-soft: #29183e;
  --pink: #ff4db8;
  --pink-soft: #3a1430;
  --blue: var(--accent);
  --green: #22c55e;
  --red: #ff5c8a;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
  --chart-bg: #120e18;
  --chart-axis: #493653;
  --chart-grid: #2a2233;
  --chart-grid-strong: #463650;
  --chart-label: #b4a8c4;
  --cf-gray: #a8adb7;
  --cf-green: #35d36f;
  --cf-cyan: #20d8cf;
  --cf-blue: #6ea8ff;
  --cf-violet: #d66bff;
  --cf-orange: #ff9f1a;
  --cf-red: #ff4d4d;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Lato", "Helvetica Neue", Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.4285;
}

html {
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

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

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

button,
input {
  min-width: 0;
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 17px;
  background: var(--panel-strong);
  color: var(--ink-soft);
  font-weight: 700;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: #564166;
  filter: brightness(1.08);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

body.app-busy button:disabled {
  cursor: wait;
}

button.primary {
  background: var(--accent);
  color: #ffffff;
}

button.positive {
  background: var(--green);
  color: #ffffff;
}

button.negative {
  background: var(--pink);
  color: #ffffff;
}

input[type="date"],
input[type="text"],
input:not([type]) {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 12px;
  background: var(--field);
  color: var(--ink);
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(155, 92, 255, 0.22);
  outline: 0;
}

.top-menu {
  display: flex;
  align-items: stretch;
  width: 100%;
  min-height: 40px;
  background: var(--nav);
  color: #ffffff;
}

.top-menu a {
  display: flex;
  align-items: center;
  color: #ffffff;
  text-decoration: none;
}

.brand-item,
.menu-item {
  min-height: 40px;
  padding: 0 16px;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-item {
  background: rgba(255, 77, 184, 0.34);
  font-weight: 700;
}

.menu-item:hover,
.brand-item:hover {
  background: var(--nav-hover);
}

.menu-item.active {
  background: #4a1d68;
  box-shadow: inset 0 -3px 0 var(--pink);
  font-weight: 700;
}

.menu-item.disabled {
  color: rgba(255, 255, 255, 0.42);
  cursor: default;
}

.menu-item.disabled:hover {
  background: transparent;
}

.nav-spacer {
  flex: 1 1 auto;
}

.nav-auth-btn,
.nav-sign-out-btn,
.nav-admin-toggle {
  min-height: 40px;
  border: 0;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0;
  background: rgba(255, 77, 184, 0.3);
  color: #ffffff;
  padding: 0 16px;
}

.nav-auth-btn:hover:not(:disabled),
.nav-sign-out-btn:hover:not(:disabled),
.nav-admin-toggle:hover:not(:disabled) {
  background: rgba(255, 77, 184, 0.44);
  filter: none;
}

.nav-admin-toggle.active {
  background: var(--pink);
  color: #ffffff;
}

.nav-user {
  display: flex;
  min-width: 0;
  align-items: stretch;
  margin-left: auto;
}

.nav-user-link {
  max-width: 220px;
  min-height: 40px;
  overflow: hidden;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0 14px;
  color: #ffffff !important;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-user-link:hover {
  background: var(--nav-hover);
  text-decoration: none;
}

.page {
  flex: 1 0 auto;
  width: min(920px, calc(100% - 48px));
  margin: 0 auto;
  padding: 82px 0 70px;
}

.view.hidden {
  display: none;
}

.hero {
  position: relative;
  margin-bottom: 24px;
}

.hero.compact {
  margin-bottom: 16px;
}

.hero h1 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 900;
}

.hero h1 span {
  color: var(--pink);
}

.cf-unrated,
.cf-gray {
  color: var(--cf-gray) !important;
}

.cf-green {
  color: var(--cf-green) !important;
}

.cf-cyan {
  color: var(--cf-cyan) !important;
}

.cf-blue {
  color: var(--cf-blue) !important;
}

.cf-violet {
  color: var(--cf-violet) !important;
}

.cf-orange {
  color: var(--cf-orange) !important;
}

.cf-red {
  color: var(--cf-red) !important;
}

.cf-legendary-first {
  color: #ffffff;
  text-shadow: 0 0 2px rgba(255, 77, 77, 0.72);
}

.cf-legendary-tail {
  color: var(--cf-red);
}

.cf-tourist-first {
  color: var(--cf-red);
  text-shadow: 0 0 2px rgba(255, 77, 77, 0.72);
}

.cf-tourist-tail {
  color: #ffffff;
}

.mobile-break {
  display: none;
}

.hero p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.segment {
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.account-segment,
.notice-segment,
.profile-actions,
.virtual-contests-section,
.summary-section,
.profiles-section {
  padding: 15px;
}

.notice-segment ol {
  margin: 0;
  padding-left: 22px;
}

.notice-segment li + li {
  margin-top: 5px;
}

.segment-title {
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 900;
}

.link-form label {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-soft);
  font-weight: 700;
}

.check-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin: 12px 0 0 !important;
  color: var(--ink-soft) !important;
  font-weight: 400 !important;
}

.check-row input {
  width: 16px;
  height: 16px;
}

.signed-out-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.signed-in-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  border: 1px solid rgba(155, 92, 255, 0.38);
  border-radius: 4px;
  padding: 10px 12px;
  background: var(--accent-soft);
  color: var(--ink-soft);
}

.profile-link-form {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.auth-required {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.auth-required:empty {
  display: none;
}

.button-row {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.status {
  min-height: 21px;
  margin-top: 10px;
  color: var(--muted);
}

.status:empty {
  display: none;
}

.status.error {
  color: var(--red);
  font-weight: 700;
}

.status.ok {
  color: var(--green);
}

.progress-panel {
  position: sticky;
  top: 10px;
  z-index: 20;
  margin: 10px 0 14px;
  border: 1px solid rgba(155, 92, 255, 0.34);
  border-radius: 4px;
  background: var(--panel);
  padding: 11px 12px;
  box-shadow: var(--shadow);
}

.progress-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.progress-label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

.progress-message {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.progress-count {
  flex: 0 0 auto;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 900;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--field);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--pink));
  transition: width 180ms ease;
}

.progress-panel.indeterminate .progress-bar {
  width: 100%;
  background: linear-gradient(
    90deg,
    rgba(155, 92, 255, 0.28),
    var(--accent),
    var(--pink),
    rgba(255, 77, 184, 0.28)
  );
  background-size: 220% 100%;
  animation: progress-sweep 1.1s linear infinite;
}

.progress-panel.complete .progress-bar {
  background: var(--green);
}

.progress-panel.error {
  border-color: rgba(255, 92, 138, 0.42);
}

.progress-panel.error .progress-label,
.progress-panel.error .progress-message,
.progress-panel.error .progress-count {
  color: var(--red);
}

.progress-panel.error .progress-bar {
  background: var(--red);
}

@keyframes progress-sweep {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -120% 0;
  }
}

.profile-summary {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.profile-summary.empty {
  color: var(--muted);
}

.profile-summary.empty .avatar {
  display: none;
}

.profile-notice {
  display: grid;
  gap: 4px;
  border-color: rgba(255, 77, 184, 0.36);
  background: var(--pink-soft);
  padding: 12px 14px;
}

.profile-notice strong {
  color: var(--ink);
  font-size: 14px;
}

.profile-notice span {
  color: var(--ink-soft);
  font-size: 13px;
}

.identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 14px;
}

.avatar {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  object-fit: cover;
  background: var(--panel-strong);
}

.handle {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 26px;
  font-weight: 900;
}

.rank {
  margin-top: 2px;
  color: var(--muted);
  font-size: 16px;
}

.rating-block {
  min-width: 120px;
  text-align: right;
}

.rating-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.rating {
  font-size: 36px;
  font-weight: 900;
  line-height: 1.05;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 14px 0;
}

.stat {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.stat:first-child {
  border-left: 3px solid var(--accent);
}

.stat:nth-child(3) {
  border-left: 3px solid var(--pink);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 20px;
}

.chart-segment {
  padding: 8px;
}

.chart-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 2px 10px;
}

.chart-toolbar button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.chart-toolbar #chart-reset-btn {
  width: auto;
  min-width: 76px;
  padding: 0 14px;
  font-size: 13px;
}

#rating-chart {
  display: block;
  width: 100%;
  height: 290px;
  touch-action: none;
  user-select: none;
}

.chart-tooltip {
  position: absolute;
  z-index: 1000;
  max-width: 280px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  background: var(--nav);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.42);
  color: #ffffff;
  padding: 9px 10px;
  pointer-events: none;
  font-size: 12px;
  line-height: 1.35;
}

.chart-tooltip .tooltip-title {
  overflow-wrap: anywhere;
  font-weight: 900;
}

.chart-tooltip .tooltip-row {
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.78);
}

.chart-tooltip .rating-value {
  font-weight: 900;
}

.chart-tooltip strong {
  color: #ffffff;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.summary span {
  border: 1px solid rgba(155, 92, 255, 0.32);
  border-radius: 4px;
  padding: 5px 8px;
  background: var(--accent-soft);
  color: var(--ink-soft);
  font-size: 13px;
}

.summary .warn {
  border-color: rgba(255, 92, 138, 0.42);
  color: var(--red);
}

body.modal-open {
  overflow: hidden;
}

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 5, 12, 0.78);
  backdrop-filter: blur(4px);
}

.confirm-modal {
  position: relative;
  width: min(456px, 100%);
  border: 1px solid rgba(255, 77, 184, 0.4);
  border-radius: 6px;
  padding: 20px;
  background: linear-gradient(180deg, var(--panel-strong), var(--panel));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.58);
}

.confirm-kicker {
  color: var(--pink);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.confirm-modal h2 {
  margin: 5px 0 8px;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.15;
}

.confirm-modal p {
  margin: 0 0 16px;
  color: var(--ink-soft);
}

.modal-fields {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.confirm-label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.confirm-actions button:disabled {
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 10px 9px;
  text-align: left;
  vertical-align: middle;
}

thead th {
  border-top: 0;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

td {
  color: var(--ink-soft);
  font-size: 14px;
}

td.numeric,
th.numeric {
  text-align: right;
}

.admin-column {
  display: none;
  white-space: nowrap;
}

body.admin-mode .admin-column {
  display: table-cell;
}

tr.ignored-contest td {
  color: var(--muted);
}

tr.ignored-contest td:first-child {
  border-left: 3px solid var(--pink);
}

.ignore-toggle {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.problem-badges {
  display: flex;
  min-width: 104px;
  flex-wrap: wrap;
  gap: 4px;
}

.problem-badge {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: #ffffff;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.problem-badge.solved {
  background: #23bd63;
  border-color: rgba(57, 233, 127, 0.28);
}

.problem-badge.attempted {
  background: #d84c5f;
  border-color: rgba(255, 111, 136, 0.32);
}

.problem-badge.unattempted {
  background: #68616f;
  border-color: rgba(255, 255, 255, 0.12);
  color: #f0e9f7;
}

.delta-up {
  color: var(--green);
  font-weight: 900;
}

.delta-down {
  color: var(--red);
  font-weight: 900;
}

.profiles-list {
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.profiles-list .muted {
  padding: 12px;
}

.profile-pill {
  display: grid;
  grid-template-columns: minmax(42px, auto) minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  padding: 10px 12px;
  color: var(--ink-soft);
  text-align: left;
}

.profile-pill:last-child {
  border-bottom: 0;
}

.profile-pill.active {
  background: var(--accent-soft);
}

.profile-rank-number {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-align: right;
}

.profile-pill .profile-handle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-pill strong {
  justify-self: end;
  color: var(--accent);
}

.footer {
  flex-shrink: 0;
  margin-top: auto;
  background: var(--nav);
  color: #ffffff;
}

.footer-inner {
  width: min(1024px, calc(100% - 32px));
  min-height: 96px;
  margin: 0 auto;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  display: grid;
  place-items: center;
}

.footer a {
  border: 1px solid rgba(255, 255, 255, 0.48);
  border-radius: 4px;
  padding: 9px 17px;
  color: #ffffff;
  text-decoration: none;
}

@media (max-width: 720px) {
  .top-menu {
    overflow-x: auto;
  }

  .brand-item,
  .menu-item,
  .nav-auth-btn,
  .nav-sign-out-btn,
  .nav-user {
    flex: 0 0 auto;
  }

  .nav-spacer {
    flex: 1 0 12px;
  }

  .nav-user-link {
    max-width: 150px;
  }

  .page {
    width: calc(100% - 24px);
    padding: 42px 0 52px;
  }

  .hero h1 {
    font-size: 23px;
  }

  .mobile-break {
    display: block;
  }

  .button-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .chart-toolbar {
    display: flex;
  }

  .signed-in-panel {
    display: grid;
    grid-template-columns: 1fr;
  }

  .profile-summary {
    align-items: flex-start;
    flex-direction: column;
  }

  .rating-block {
    width: 100%;
    text-align: left;
  }

  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .page {
    width: min(366px, calc(100vw - 24px));
    margin: 0 12px;
  }
}

@media (max-width: 460px) {
  .page {
    width: calc(100vw - 18px);
    margin: 0 9px;
  }

  .stats-row {
    grid-template-columns: 1fr;
  }

  .chart-toolbar {
    justify-content: stretch;
  }

  .chart-toolbar button {
    flex: 1;
  }

  .confirm-modal {
    padding: 16px;
  }

  .confirm-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}
