.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  max-height: min(90vh, 640px);
  overflow: auto;
}

.modal.modal--wide {
  max-width: 640px;
}

.modal.modal--xl {
  max-width: 720px;
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.modal p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.modal .score-big {
  font-size: 2.75rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  text-align: center;
  margin: 8px 0 4px;
  color: var(--accent);
}

.modal .score-big span {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--muted);
}

.modal-stats {
  display: grid;
  gap: 8px;
  margin: 16px 0 20px;
}

.modal-stats .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.9rem;
}

.modal-stats .row strong {
  font-weight: 700;
}

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

.modal-actions .btn {
  border: 0;
  border-radius: 14px;
  padding: 11px 16px;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.modal-actions .btn-primary {
  background: var(--text);
  color: var(--bg);
}

html[data-theme="dark"] .modal-actions .btn-primary {
  background: var(--accent);
  color: #0f1419;
}

.modal-actions .btn-secondary {
  background: var(--border);
  color: var(--text);
}

.modal-actions .btn-home {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.modal-actions .btn-home:hover {
  background: var(--accent-soft);
}

.modal-actions {
  justify-content: space-between;
}

.modal-actions .modal-actions__end {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-left: auto;
}

.modal-history {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
  max-height: 200px;
  overflow: auto;
}

.modal-history .item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.85rem;
}
