:root {
  --bg: #0a0e1a;
  --panel: #141a2b;
  --panel-2: #1f2638;
  --border: #2a3142;
  --text: #e8eaed;
  --muted: #8a92a3;
  --accent: #ff6b35;
  --accent-2: #f7c948;
  --gold: #ffd060;
  --win: #4ade80;
  --loss: #f87171;
  --warn: #facc15;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter",
    Roboto, sans-serif;
  background:
    radial-gradient(ellipse at top, #1a1f3a 0%, var(--bg) 50%) no-repeat,
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

header {
  text-align: center;
  padding: 3rem 2rem 2rem;
}

header h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 0.5rem;
}

.subtitle { color: var(--muted); max-width: 640px; margin: 0 auto; }

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 2rem 4rem;
}

#analyze-form {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

#url-input {
  flex: 1;
  padding: 0.9rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.15s;
}
#url-input:focus { outline: none; border-color: var(--accent); }

button {
  padding: 0.9rem 1.75rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s, background 0.15s;
}
button:hover:not(:disabled) { opacity: 0.92; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
}
button.ghost-btn:hover:not(:disabled) {
  background: var(--panel-2);
  border-color: var(--gold);
}

/* --- Profile card -------------------------------------------------------- */

#profile-card {
  background:
    linear-gradient(135deg, rgba(255,107,53,0.1), rgba(247,201,72,0.05)),
    var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem 2rem;
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}
.profile-name { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.5rem; }
.stat-pill {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  margin-right: 0.5rem;
}
.profile-record { text-align: right; }
.profile-record .big {
  font-size: 1.8rem;
  font-weight: 800;
  font-feature-settings: "tnum";
}
.profile-record .sub { color: var(--muted); font-size: 0.9rem; }

/* --- Main Set card ------------------------------------------------------- */

.main-set-card {
  background:
    radial-gradient(ellipse at top right, rgba(255, 208, 96, 0.18), transparent 60%),
    radial-gradient(ellipse at bottom left, rgba(255, 107, 53, 0.12), transparent 60%),
    linear-gradient(180deg, #1d2336, #14192a);
  border: 1px solid rgba(255, 208, 96, 0.35);
  border-radius: 16px;
  padding: 1.75rem 2rem;
  margin-bottom: 1.5rem;
  box-shadow:
    0 0 0 1px rgba(255, 208, 96, 0.08),
    0 8px 32px rgba(255, 208, 96, 0.08);
  position: relative;
  overflow: hidden;
}
.main-set-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 90% 10%, rgba(255, 208, 96, 0.2), transparent 30%);
  pointer-events: none;
  opacity: 0.6;
}

.main-set-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.main-set-card h2 {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, var(--gold), #fff5d0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 0.2rem;
}
.main-set-subtitle {
  color: var(--muted);
  font-size: 0.95rem;
}
.main-set-subtitle b { color: var(--gold); }

.ms-loading {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  padding: 1.5rem 0;
}
.spinner.small {
  width: 28px;
  height: 28px;
  border-width: 3px;
  margin: 0;
}

.ms-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}
@media (max-width: 900px) { .ms-grid { grid-template-columns: 1fr; } }

.ms-block h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.ms-hero {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 208, 96, 0.15);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
}
.ms-hero img {
  width: 56px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.ms-hero-noicon {
  width: 56px;
  height: 32px;
  background: var(--panel-2);
  border-radius: 4px;
  flex-shrink: 0;
}
.ms-hero-name { font-weight: 600; font-size: 0.95rem; }
.ms-hero-why {
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.4;
  margin-top: 0.15rem;
}

.ms-item {
  background: rgba(255, 255, 255, 0.03);
  border-left: 3px solid var(--gold);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.5rem;
}
.ms-item-name { font-weight: 600; }
.ms-item-context {
  color: var(--muted);
  font-size: 0.83rem;
  margin-top: 0.15rem;
  line-height: 1.4;
}
.ms-item-for {
  color: var(--gold);
  font-size: 0.78rem;
  margin-top: 0.15rem;
  opacity: 0.85;
}

#ms-actions {
  list-style: none;
  counter-reset: ms-step;
}
#ms-actions li {
  counter-increment: ms-step;
  position: relative;
  padding: 0.55rem 0.75rem 0.55rem 2.4rem;
  margin-bottom: 0.4rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  font-size: 0.92rem;
  line-height: 1.4;
}
#ms-actions li::before {
  content: counter(ms-step);
  position: absolute;
  left: 0.65rem;
  top: 0.55rem;
  width: 1.5rem;
  height: 1.5rem;
  background: var(--gold);
  color: #1a1300;
  font-weight: 800;
  font-size: 0.85rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Generic viz containers --------------------------------------------- */

.viz-container {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.viz-container h2 {
  font-size: 1.4rem;
  margin-bottom: 0.4rem;
  font-weight: 700;
}
.hint { color: var(--muted); font-size: 0.9rem; margin-bottom: 1rem; }
.legend-gold { color: var(--gold); font-weight: 600; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.grid-2 .viz-container { margin-bottom: 0; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }

/* --- Hero galaxy --------------------------------------------------------- */

#hero-galaxy {
  width: 100%;
  height: 560px;
  background:
    radial-gradient(circle at center, rgba(255,107,53,0.05), transparent 70%),
    var(--bg);
  border-radius: 10px;
  cursor: grab;
  position: relative;
  overflow: hidden;
}
#hero-galaxy:active { cursor: grabbing; }

#hero-galaxy .tooltip {
  position: absolute;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  pointer-events: none;
  display: none;
  font-size: 0.85rem;
  z-index: 10;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  white-space: nowrap;
}

/* --- Match timeline ----------------------------------------------------- */

#match-timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.match-cell {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
  cursor: default;
  transition: transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.match-cell:hover { transform: scale(1.08); z-index: 2; }
.match-cell.win { background: var(--win); }
.match-cell.loss { background: var(--loss); }
.match-cell .match-icon {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.85;
}
.match-cell .match-letter {
  position: relative;
  z-index: 1;
  font-size: 0.8rem;
  font-weight: 800;
  color: white;
  text-shadow: 0 0 6px rgba(0,0,0,0.85), 0 0 2px rgba(0,0,0,1);
  background: rgba(0,0,0,0.35);
  padding: 0 0.3rem;
  border-radius: 3px;
}

/* --- Averages tiles ----------------------------------------------------- */

#averages {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
.stat-tile {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
}
.stat-tile .label { color: var(--muted); font-size: 0.85rem; }
.stat-tile .value {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

/* --- Hero list cards ---------------------------------------------------- */

#top-heroes-list, #meta-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.75rem;
}

.hero-card {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 0;
  display: flex;
  overflow: hidden;
  transition: transform 0.1s;
}
.hero-card:hover { transform: translateY(-2px); }
.hero-card-img {
  width: 90px;
  height: 60px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}
.hero-card-img.placeholder { background: var(--bg); }
.hero-card-body {
  flex: 1;
  padding: 0.6rem 0.75rem;
  min-width: 0;
}
.hero-card .name {
  font-weight: 600;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hero-card .meta {
  color: var(--muted);
  font-size: 0.85rem;
}
.hero-card .winrate-bar {
  height: 5px;
  border-radius: 3px;
  margin-top: 0.4rem;
  background: var(--bg);
  overflow: hidden;
}
.hero-card .winrate-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s;
}

/* --- Spinner ------------------------------------------------------------ */

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading { text-align: center; color: var(--muted); }

#error {
  background: rgba(248,113,113,0.1);
  border: 1px solid var(--loss);
  color: var(--loss);
  padding: 1rem;
  border-radius: 10px;
  margin-bottom: 1.5rem;
}

/* --- Markdown анализа --------------------------------------------------- */

#analysis-text {
  margin-top: 0.5rem;
  line-height: 1.7;
  color: #d8dce3;
}
#analysis-text:empty { display: none; }
#analysis-text h2 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-size: 1.2rem;
  color: var(--accent);
}
#analysis-text h2:first-child { margin-top: 0; }
#analysis-text h3 {
  margin-top: 1rem;
  margin-bottom: 0.4rem;
  font-size: 1rem;
  color: var(--accent-2);
}
#analysis-text ul, #analysis-text ol { margin-left: 1.5rem; margin-top: 0.5rem; }
#analysis-text p { margin-bottom: 0.75rem; }
#analysis-text strong { color: var(--text); }
#analysis-text code {
  background: var(--panel-2);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.9em;
}
#analysis-text pre {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.75rem 0;
}
#analysis-text pre code { background: transparent; padding: 0; }
