:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --paper: #ffffff;
  --paper-soft: #fbfcfa;
  --ink: #1b211e;
  --muted: #68716c;
  --line: #d9dfd7;
  --line-strong: #c7d0c5;
  --green: #168556;
  --green-soft: #e4f5ec;
  --red: #c84646;
  --red-soft: #fde8e5;
  --blue: #2f67c5;
  --blue-soft: #e5efff;
  --amber: #b97715;
  --violet: #6c5fd4;
  --shadow: 0 18px 50px rgba(25, 35, 29, 0.1);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(47, 103, 197, 0.08), transparent 340px),
    linear-gradient(180deg, #ffffff 0, var(--bg) 330px);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    background 140ms ease,
    border-color 140ms ease;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(47, 103, 197, 0.26);
  outline-offset: 3px;
}

button:active {
  transform: translateY(1px);
}

a {
  color: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 34px;
}

.is-hidden {
  display: none !important;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 0 20px;
}

.trainer-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 12px 0 20px;
}

.brand,
.trainer-title-block {
  min-width: 0;
}

.brand {
  flex: 1 1 330px;
  min-width: min(100%, 330px);
}

.eyebrow,
.status-label {
  display: block;
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.15rem, 4.7vw, 4.1rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.brand h1 {
  white-space: nowrap;
}

.trainer-title-block h1 {
  font-size: clamp(1.45rem, 3vw, 2.6rem);
  line-height: 1.04;
  max-width: 760px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, 92px);
  flex: 0 0 auto;
  gap: 8px;
}

.summary-item {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 10px 12px;
}

.summary-value {
  display: block;
  font-size: 1.5rem;
  line-height: 1;
  font-weight: 800;
}

.summary-label {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.profile-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  background: var(--ink);
  color: #fff;
  padding: 0 18px;
  box-shadow: 0 12px 26px rgba(27, 33, 30, 0.16);
}

.primary-button:hover {
  background: #303a35;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 0 16px;
}

.secondary-button:hover {
  border-color: var(--line-strong);
  box-shadow: 0 12px 28px rgba(25, 35, 29, 0.08);
}

.danger-button {
  background: var(--red);
  color: #fff;
  padding: 0 16px;
}

.icon-button {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: 1.45rem;
  line-height: 1;
}

.profile-button {
  gap: 9px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 6px 12px 6px 7px;
  box-shadow: 0 10px 26px rgba(25, 35, 29, 0.06);
}

.profile-button:hover {
  border-color: var(--line-strong);
  box-shadow: 0 12px 28px rgba(25, 35, 29, 0.09);
}

.profile-avatar {
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-soft), var(--green-soft));
  color: var(--blue);
  font-size: 0.86rem;
  font-weight: 800;
  text-transform: uppercase;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-label {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-strip {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 14px;
  margin: 4px 0 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 15px 16px;
  box-shadow: var(--shadow);
}

.status-strip strong {
  font-size: 1.08rem;
}

.source-pill {
  border: 1px solid rgba(47, 103, 197, 0.2);
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

.source-control {
  min-width: 250px;
}

.source-switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 250px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2ec;
  padding: 4px;
}

.source-switch-thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(50% - 4px);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 8px 22px rgba(25, 35, 29, 0.12);
  transition: transform 180ms ease;
}

.source-switch[data-source="shkolkovo"] .source-switch-thumb {
  transform: translateX(100%);
}

.source-option {
  position: relative;
  z-index: 1;
  min-height: 34px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.86rem;
  box-shadow: none;
}

.source-option.is-active {
  color: var(--ink);
}

.task-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(258px, 1fr));
  gap: 14px;
}

.battle {
  width: min(100%, 980px);
  margin: 0 auto;
}

.battle-timer {
  display: inline-flex;
  min-width: 82px;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.16rem;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(25, 35, 29, 0.07);
}

.battle-panel {
  display: grid;
  gap: 14px;
}

.battle-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 16px;
  box-shadow: 0 16px 42px rgba(25, 35, 29, 0.08);
}

.battle-card h2 {
  margin: 0 0 8px;
  font-size: 1.32rem;
}

.battle-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.battle-status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.fighter-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 10px;
}

.fighter-avatar {
  display: inline-flex;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-soft), var(--green-soft));
  color: var(--blue);
  font-size: 0.84rem;
  font-weight: 800;
  text-transform: uppercase;
}

.fighter-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fighter-name {
  min-width: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.fighter-state {
  border-radius: 999px;
  background: #eff2ee;
  color: var(--muted);
  padding: 6px 9px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.fighter-state.is-ready {
  background: var(--green-soft);
  color: var(--green);
}

.battle-actions,
.battle-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.battle-answer-form {
  position: sticky;
  bottom: 14px;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border: 1px solid rgba(199, 208, 197, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 10px;
  box-shadow: 0 18px 44px rgba(25, 35, 29, 0.14);
  backdrop-filter: blur(12px);
}

.battle-answer-form input,
.invite-link-input {
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  font-weight: 700;
}

.invite-box {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.round-recap {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 12px;
}

.round-recap-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-weight: 800;
}

.round-recap-row strong {
  color: var(--ink);
}

.battle-result {
  border-color: rgba(47, 103, 197, 0.24);
  background: linear-gradient(180deg, #ffffff, #f6f9ff);
}

.battle-result.is-win {
  border-color: rgba(22, 133, 86, 0.36);
  background: linear-gradient(180deg, #ffffff, #f4fbf7);
}

.battle-result.is-loss {
  border-color: rgba(200, 70, 70, 0.38);
  background: linear-gradient(180deg, #ffffff, #fff7f6);
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 34px auto 0;
  color: rgba(27, 33, 30, 0.62);
}

.footer-rule {
  width: min(110px, 18vw);
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(104, 113, 108, 0.32), transparent);
}

.kaizer-link {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  transition:
    color 140ms ease,
    transform 140ms ease;
}

.kaizer-link:hover {
  color: rgba(27, 33, 30, 0.84);
  transform: translateY(-1px);
}

.kaizer-link:hover .kaizer-mark {
  opacity: 1;
}

.kaizer-mark {
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid rgba(27, 33, 30, 0.08);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(25, 35, 29, 0.12);
  opacity: 0.9;
}

.kaizer-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.kaizer-wordmark {
  font-family: Manrope, Inter, system-ui, sans-serif;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.task-card {
  display: grid;
  min-height: 286px;
  grid-template-rows: auto auto auto auto auto 1fr auto;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 16px;
  box-shadow: 0 12px 34px rgba(25, 35, 29, 0.06);
}

.task-card.is-done {
  border-color: rgba(22, 133, 86, 0.32);
  background: linear-gradient(180deg, #ffffff, #f7fcf9);
}

.task-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.task-num,
.task-state {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.task-num {
  color: var(--blue);
}

.task-state {
  border-radius: 999px;
  background: #eff2ee;
  color: var(--muted);
  padding: 6px 9px;
}

.task-card.is-done .task-state {
  background: var(--green-soft);
  color: var(--green);
}

.task-card h2 {
  min-height: 52px;
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.22;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.task-source {
  min-height: 36px;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.task-progress {
  overflow: hidden;
  height: 12px;
  border-radius: 999px;
  background: #edf1eb;
}

.task-progress-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
  transition: width 180ms ease;
}

.task-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.task-stats div {
  min-width: 0;
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 8px 9px;
}

.task-stats strong,
.task-stats span {
  display: block;
}

.task-stats strong {
  font-size: 1.05rem;
}

.task-stats span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
}

.train-button {
  width: 100%;
  align-self: end;
}

.battle-waiting {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: 8px;
  background: #f3f6f1;
  color: var(--muted);
  padding: 8px 10px;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.battle-waiting strong {
  color: var(--blue);
  font-size: 0.95rem;
}

.task-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  align-self: end;
}

.task-actions .train-button {
  align-self: auto;
}

.skeleton-card {
  min-height: 190px;
}

.trainer {
  width: min(100%, 980px);
  margin: 0 auto;
}

.trainer-header {
  grid-template-columns: auto 1fr auto;
}

.source-link {
  min-width: 102px;
}

.ladder-bar {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 14px;
  box-shadow: var(--shadow);
}

.streak-score {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 86px;
}

.streak-score span {
  font-size: 2.2rem;
  line-height: 1;
  font-weight: 800;
}

.streak-score small {
  color: var(--muted);
  font-weight: 800;
}

.step-rail {
  display: grid;
  grid-template-columns: repeat(10, minmax(13px, 1fr));
  gap: 7px;
}

.step-rail span {
  height: 13px;
  border-radius: 999px;
  background: #e7ece4;
  box-shadow: inset 0 0 0 1px rgba(25, 35, 29, 0.04);
}

.step-rail .is-filled {
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.step-rail .is-current {
  background: var(--amber);
}

.step-rail .is-failed {
  background: var(--red);
}

.question-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 18px;
  box-shadow: 0 16px 42px rgba(25, 35, 29, 0.08);
}

.question-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

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

.battle-code-hidden {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.question-body {
  min-height: 260px;
  color: #222825;
  font-size: 1rem;
  line-height: 1.62;
  overflow-wrap: anywhere;
}

.passage-panel {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  overflow: hidden;
}

.passage-panel summary {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 13px;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.passage-panel summary::-webkit-details-marker {
  display: none;
}

.passage-panel summary strong {
  color: var(--blue);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.passage-panel summary .open-label {
  display: none;
}

.passage-panel[open] summary {
  border-bottom: 1px solid var(--line);
}

.passage-panel[open] summary .closed-label {
  display: none;
}

.passage-panel[open] summary .open-label {
  display: inline;
}

.passage-body {
  max-height: min(58vh, 620px);
  overflow: auto;
  padding: 14px;
  background: #fff;
  color: #222825;
  font-size: 0.98rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.question-body p,
.passage-body p {
  margin: 0 0 0.82em;
}

.question-body img,
.passage-body img {
  max-width: 100%;
  height: auto;
}

.question-body table,
.passage-body table {
  display: block;
  width: 100% !important;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.question-body tbody,
.passage-body tbody {
  display: table;
  min-width: 100%;
}

.question-body td,
.question-body th,
.passage-body td,
.passage-body th {
  border: 1px solid var(--line);
  padding: 7px 8px;
  vertical-align: top;
}

.question-body .left_margin,
.passage-body .left_margin {
  margin-left: 0;
}

.answer-dock {
  position: sticky;
  bottom: 14px;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 14px;
  border: 1px solid rgba(199, 208, 197, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 10px;
  box-shadow: 0 18px 44px rgba(25, 35, 29, 0.14);
  backdrop-filter: blur(12px);
}

.answer-dock input {
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  font-size: 1.02rem;
  font-weight: 700;
}

.feedback-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 16px;
  box-shadow: 0 16px 42px rgba(25, 35, 29, 0.08);
}

.feedback-panel.is-correct {
  border-color: rgba(22, 133, 86, 0.36);
  background: linear-gradient(180deg, #ffffff, #f4fbf7);
}

.feedback-panel.is-wrong {
  border-color: rgba(200, 70, 70, 0.38);
  background: linear-gradient(180deg, #ffffff, #fff7f6);
}

.feedback-head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.result-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 1.35rem;
  font-weight: 800;
}

.feedback-panel.is-correct .result-mark {
  background: var(--green-soft);
  color: var(--green);
}

.feedback-panel.is-wrong .result-mark {
  background: var(--red-soft);
  color: var(--red);
}

.feedback-title,
.feedback-subtitle {
  margin: 0;
}

.feedback-title {
  font-size: 1.25rem;
  font-weight: 800;
}

.feedback-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.answer-reveal {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 11px 12px;
  margin-bottom: 12px;
}

.answer-reveal span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.answer-reveal strong {
  overflow-wrap: anywhere;
}

.solution-body {
  color: #26312d;
  line-height: 1.58;
  overflow-wrap: anywhere;
}

.battle-review-panel {
  margin-top: 14px;
}

.battle-review-question {
  margin: 0 0 12px;
  box-shadow: none;
}

.solution-body p {
  margin: 0 0 0.78em;
}

.solution-body table {
  display: block;
  width: 100% !important;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.solution-body tbody {
  display: table;
  min-width: 100%;
}

.solution-body td,
.solution-body th {
  border: 1px solid var(--line);
  padding: 7px 8px;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(245, 247, 244, 0.72);
  backdrop-filter: blur(8px);
}

.loading-card {
  display: grid;
  width: min(360px, calc(100vw - 40px));
  gap: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.loading-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.loader {
  width: 24px;
  height: 24px;
  border: 3px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 720ms linear infinite;
}

.loading-progress {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #edf1eb;
}

.loading-progress span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
  transition: width 240ms ease;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  max-width: min(380px, calc(100vw - 40px));
  border-radius: 8px;
  background: #1f2925;
  color: #fff;
  padding: 14px 16px;
  box-shadow: 0 20px 46px rgba(0, 0, 0, 0.22);
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.confirm-dialog,
.account-dialog,
.battle-dialog,
.leaderboard-dialog,
.friends-dialog,
.username-dialog,
.admin-dialog {
  width: min(430px, calc(100% - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 26px 76px rgba(0, 0, 0, 0.24);
}

.account-dialog,
.battle-dialog,
.friends-dialog,
.username-dialog {
  width: min(620px, calc(100% - 32px));
}

.leaderboard-dialog,
.admin-dialog {
  width: min(920px, calc(100% - 32px));
}

.confirm-dialog::backdrop,
.account-dialog::backdrop,
.battle-dialog::backdrop,
.leaderboard-dialog::backdrop,
.friends-dialog::backdrop,
.username-dialog::backdrop,
.admin-dialog::backdrop {
  background: rgba(18, 24, 21, 0.44);
}

.confirm-dialog form {
  padding: 22px;
}

.confirm-dialog h2 {
  margin: 0 0 8px;
  font-size: 1.28rem;
}

.confirm-dialog p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.account-shell {
  padding: 20px;
}

.battle-setup,
.leaderboard-shell,
.friends-shell,
.username-shell,
.admin-shell {
  padding: 20px;
}

.dialog-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.dialog-top h2 {
  margin: 0;
  font-size: 1.35rem;
}

.close-dialog-button {
  width: 42px;
  height: 42px;
  min-height: 42px;
  font-size: 1.6rem;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2ec;
  padding: 5px;
  margin-bottom: 14px;
}

.auth-tab {
  min-height: 38px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.auth-tab.is-active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 8px 20px rgba(25, 35, 29, 0.1);
}

.auth-form,
.profile-form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.field input,
.field select {
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 13px;
  font-weight: 700;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 0.86rem;
  font-weight: 800;
}

.profile-head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.avatar-upload {
  position: relative;
  display: grid;
  width: 82px;
  height: 82px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-soft), var(--green-soft));
  color: var(--blue);
  cursor: pointer;
}

.avatar-upload img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-upload.has-photo img {
  display: block;
}

.avatar-upload.has-photo span {
  display: none;
}

.avatar-upload input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.avatar-upload span {
  font-size: 1.6rem;
  font-weight: 800;
  text-transform: uppercase;
}

.profile-name,
.profile-email,
.profile-username {
  margin: 0;
}

.profile-name {
  font-size: 1.3rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.profile-email {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.profile-username {
  margin-top: 4px;
  color: var(--blue);
  font-size: 0.9rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.profile-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  margin-bottom: 14px;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.profile-stats div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 11px;
}

.profile-stats strong,
.profile-stats span {
  display: block;
}

.profile-stats strong {
  font-size: 1.35rem;
}

.profile-stats span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.profile-chart {
  min-height: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  overflow: hidden;
}

.profile-chart svg {
  display: block;
  width: 100%;
  height: 180px;
}

.profile-chart text {
  fill: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.profile-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.dialog-note {
  margin: -4px 0 14px;
  color: var(--muted);
  line-height: 1.45;
  font-weight: 700;
}

.username-shell {
  display: grid;
  gap: 12px;
}

.username-field input {
  font-weight: 800;
  text-transform: lowercase;
}

#friendsButton {
  position: relative;
}

#friendsButton.has-activity::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
}

.friends-login-card {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
  border: 1px solid rgba(47, 103, 197, 0.2);
  border-radius: 8px;
  background: var(--blue-soft);
  padding: 12px;
}

.friends-login-card span,
.friend-status {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.friends-login-card strong {
  color: var(--blue);
  font-size: 1.1rem;
  overflow-wrap: anywhere;
}

.friend-add-form,
.battle-friend-invite {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.friends-sections {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.friends-section {
  display: grid;
  gap: 8px;
}

.friends-section h3 {
  margin: 0;
  font-size: 0.98rem;
}

.friend-list {
  display: grid;
  gap: 8px;
}

.friend-row,
.battle-invite-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 10px;
}

.friend-main {
  min-width: 0;
}

.friend-main strong,
.friend-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friend-main span {
  margin-top: 3px;
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 800;
}

.friend-avatar,
.battle-toast-avatar {
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-soft), var(--green-soft));
  color: var(--blue);
  font-weight: 900;
  text-transform: uppercase;
}

.friend-avatar {
  width: 42px;
  height: 42px;
}

.friend-avatar img,
.battle-toast-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.friend-actions {
  display: flex;
  gap: 7px;
}

.friend-actions button {
  min-height: 36px;
  padding: 0 11px;
  font-size: 0.82rem;
}

.battle-invite-row {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.battle-invite-stack {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 55;
  display: grid;
  gap: 10px;
  width: min(340px, calc(100vw - 36px));
  pointer-events: none;
}

.battle-invite-toast {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  padding: 10px;
  box-shadow: 0 18px 48px rgba(25, 35, 29, 0.18);
  opacity: 0;
  pointer-events: auto;
  transform: translateY(-10px);
  transition:
    opacity 220ms ease,
    transform 220ms ease;
}

.battle-invite-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.battle-invite-toast.is-hiding {
  opacity: 0;
  transform: translateY(-10px);
}

.battle-toast-avatar {
  width: 38px;
  height: 38px;
}

.battle-toast-text {
  min-width: 0;
}

.battle-toast-text strong,
.battle-toast-text span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-toast-text span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.battle-invite-toast button {
  min-height: 34px;
  padding: 0 11px;
  font-size: 0.82rem;
}

.battle-friend-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.battle-friend-panel h3 {
  margin: 0;
  font-size: 0.98rem;
}

.admin-grid {
  display: grid;
  gap: 12px;
}

.admin-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 12px;
}

.admin-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.admin-metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.admin-metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.admin-metric strong,
.admin-metric span {
  display: block;
}

.admin-metric strong {
  font-size: 1.25rem;
}

.admin-metric span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.admin-list {
  display: grid;
  gap: 8px;
  max-height: 330px;
  overflow: auto;
  padding-right: 4px;
}

.admin-user-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(170px, auto);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.admin-user-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.admin-user-stats span,
.admin-event-row span,
.admin-event-row strong {
  border-radius: 999px;
  background: var(--paper-soft);
  padding: 5px 8px;
}

.admin-event-row {
  display: grid;
  grid-template-columns: 120px auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.admin-event-row strong {
  color: var(--blue);
}

.time-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-bottom: 12px;
}

.time-option {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  color: var(--muted);
  box-shadow: none;
}

.time-option.is-active {
  border-color: rgba(47, 103, 197, 0.34);
  background: var(--blue-soft);
  color: var(--blue);
}

.leaderboard-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 12px;
}

.leaderboard-tab {
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--paper-soft);
  color: var(--muted);
  box-shadow: none;
}

.leaderboard-tab.is-active {
  border-color: rgba(47, 103, 197, 0.34);
  background: var(--blue-soft);
  color: var(--blue);
}

.leaderboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.leaderboard-column {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 12px;
}

.leaderboard-column h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.leaderboard-column-wide h3 {
  margin-bottom: 4px;
  font-size: 1.12rem;
}

.leaderboard-column-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.leaderboard-column-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.4;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.leaderboard-row span:nth-child(2) {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-row-detailed {
  grid-template-columns: 34px auto minmax(0, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.leaderboard-rank {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: var(--paper-soft);
  color: var(--muted);
}

.leaderboard-score {
  color: var(--ink);
  white-space: nowrap;
}

.leaderboard-extra {
  grid-column: 3 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.leaderboard-extra span {
  border-radius: 999px;
  background: var(--paper-soft);
  padding: 5px 8px;
}

.flash-correct {
  animation: correctPulse 620ms ease;
}

.flash-wrong {
  animation: wrongShake 560ms ease;
}

@keyframes correctPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(22, 133, 86, 0.28);
    border-color: rgba(22, 133, 86, 0.7);
  }
  100% {
    box-shadow: 0 16px 42px rgba(25, 35, 29, 0.08);
    border-color: var(--line);
  }
}

@keyframes wrongShake {
  0%,
  100% {
    transform: translateX(0);
    border-color: var(--line);
  }
  14%,
  42%,
  70% {
    transform: translateX(-8px);
    border-color: rgba(200, 70, 70, 0.78);
  }
  28%,
  56%,
  84% {
    transform: translateX(8px);
    border-color: rgba(200, 70, 70, 0.78);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 820px) {
  .shell {
    width: min(100% - 22px, 680px);
    padding-top: 16px;
  }

  .app-header,
  .trainer-header {
    grid-template-columns: 1fr;
  }

  .trainer-header {
    grid-template-columns: auto 1fr;
  }

  .source-link {
    grid-column: 1 / -1;
    width: 100%;
  }

  .summary {
    grid-template-columns: repeat(3, 1fr);
  }

  .status-strip,
  .ladder-bar,
  .battle-status-grid,
  .leaderboard-grid,
  .leaderboard-tabs {
    grid-template-columns: 1fr;
  }

  .source-control,
  .source-switch,
  .source-pill {
    width: 100%;
  }

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

  .admin-user-row,
  .admin-event-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .admin-user-stats {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .answer-dock,
  .battle-answer-form {
    grid-template-columns: 1fr;
  }

  .site-footer {
    margin-top: 28px;
  }
}

@media (max-width: 520px) {
  .summary,
  .task-grid,
  .task-stats,
  .task-actions,
  .time-picker {
    grid-template-columns: 1fr;
  }

  .task-card {
    min-height: 0;
  }

  .task-card h2,
  .task-source {
    min-height: 0;
  }

  .step-rail {
    gap: 5px;
  }

  .question-panel,
  .feedback-panel {
    padding: 14px;
  }

  .feedback-actions,
  .dialog-actions,
  .profile-form,
  .profile-stats,
  .friend-add-form,
  .battle-friend-invite {
    display: grid;
    grid-template-columns: 1fr;
  }

  .friend-row,
  .battle-invite-row,
  .battle-invite-toast,
  .leaderboard-row-detailed {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .friend-actions,
  .battle-invite-row .friend-actions,
  .battle-invite-toast button,
  .leaderboard-score,
  .leaderboard-extra,
  .admin-event-row span,
  .admin-event-row strong {
    grid-column: 1 / -1;
  }

  .admin-metrics {
    grid-template-columns: 1fr;
  }

  .site-footer {
    gap: 10px;
  }

  .footer-rule {
    width: 44px;
  }
}
