:root {
  --bg: #0f1117;            /* page */
  --panel: #151926;         /* cards */
  --panel-2: #1b2132;       /* alt cards */
  --text: #e6ebff;          /* body text */
  --muted: #abb3d4;         /* secondary */
  --line: #27314a;          /* borders */
  --brand: #7c5cff;         /* accent */
  --brand-2: #21d4fd;       /* gradient */
  --win: #2ecc71;
  --loss: #ff5c7c;
  --chip: #11162a;
  --shadow: 0 10px 30px rgba(2, 8, 23, 0.35);
  --radius: 18px;
}

* { box-sizing: border-box; }

/* Background covers viewport and stays fixed while scrolling */
html {
  height: 100%;
  background:
    radial-gradient(1200px 700px at 20% -10%, rgba(124, 92, 255, 0.18), transparent 60%),
    radial-gradient(900px 600px at 120% 10%, rgba(33, 212, 253, 0.16), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  background-repeat: no-repeat;
  background-size: cover;
}

body {
  margin: 0; min-height: 100vh; background: transparent; color: var(--text);
  font: 16px/1.55 Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  letter-spacing: .2px;
}

.container { max-width: 1100px; margin: 0 auto; padding: 42px 22px 80px; }

header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.title { display: flex; align-items: center; gap: 14px; }
.logo { width: 44px; height: 44px; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.logo img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }
h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: .4px; }

/* Search */
.search { position: relative; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search input {
  width: 280px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  outline: none; background: #0f1426; color: var(--text); font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(124, 92, 255, .06);
}
.btn { padding: 12px 16px; border-radius: 12px; border: 1px solid transparent; cursor: pointer; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #081120; font-weight: 700; box-shadow: var(--shadow); opacity: .8; }

/* Toast / Alerts */
#healthAlert { display: none; background: var(--loss); color: #fff; padding: 10px; text-align: center; font-weight: bold; }
#toast { position: fixed; top: -100px; left: 50%; transform: translateX(-50%); min-width: 300px; max-width: 600px; background: var(--loss); color: #fff; padding: 12px 20px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.3); font-weight: 500; transition: top .5s ease; z-index: 9999; text-align: center; }
#toast.show { top: 20px; }
#toast.success { background: #4caf50; }
#toast.warning { background: #ff9800; }

/* Layout */
.grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; margin-top: 16px; }
.card { background: linear-gradient(180deg, rgba(255,255,255,.02), transparent 60%), var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);}
.card h2 { margin: 0 0 8px; font-size: 18px; }

.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 10px; }
.kpi { background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.kpi b { display: block; font-size: 20px; margin-bottom: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { padding: 7px 10px; background: var(--chip); border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-weight: 600; font-size: 12px; }

/* Boss history grid */
.subgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 12px; }
.boss { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-2); }
.boss header { display: flex; justify-content: space-between; align-items: center; margin: 0 0 6px; }
.boss h3 { margin: 0; font-size: 16px; }
.lvl { font: 700 12px/1.1 Inter; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 13px; }

.pill { padding: 4px 8px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.02); font-weight: 700; }
.win { color: var(--win); } .loss { color: var(--loss); }

/* Buttons */
.btn-gradient { background: linear-gradient(135deg, #7b2ff7, #00c6ff); border: none; border-radius: 12px; padding: 8px 16px; color: #000; font-weight: 600; font-size: 14px; cursor: pointer; transition: transform .1s ease, opacity .2s ease; }
.btn-gradient:hover { opacity: .9; transform: translateY(-1px); }
.btn-gradient:disabled { background: #555; color: #ccc; opacity: .7; cursor: not-allowed; transform: none; }

/* Tables */
table { width: 100%; border-collapse: separate; border-spacing: 0 10px; margin-top: 6px; }
thead th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .7px; text-align: left; padding: 0 12px; }
tbody tr { background: var(--panel-2); }
tbody td { padding: 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
tbody tr td:first-child { border-left: 1px solid var(--line); border-top-left-radius: 12px; border-bottom-left-radius: 12px; }
tbody tr td:last-child { border-right: 1px solid var(--line); border-top-right-radius: 12px; border-bottom-right-radius: 12px; }
.names { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; font-size: 12px; color: var(--muted); }
.clickable-row { cursor: pointer; }

/* Search suggest */
.suggest { position: absolute; left: 0; right: 0; top: calc(100% + 6px); background: #0f1420; border: 1px solid #2a2e39; border-radius: 12px; overflow: hidden; z-index: 50; }
.suggest .s-item { padding: 8px 12px; border-bottom: 1px solid #1b2130; cursor: pointer; }
.suggest .s-item:last-child { border-bottom: none; }
.suggest .s-item.active { background: #1a2333; }

/* Responsive */
@media (max-width: 980px) { .grid { grid-template-columns: 1fr; } .subgrid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .summary { grid-template-columns: 1fr 1fr; } .subgrid { grid-template-columns: 1fr; } .search input { width: 100%; } }

/* Horizontales Scrolling nur für schmale Screens */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}



/* Mobile Optimierungen */
@media (max-width: 640px) {
  /* KPIs in Overview: schmaler paddings, kleinere Schrift */
  .summary .kpi {
    padding: 10px;
  }
  .summary .kpi b {
    font-size: 16px;
  }

  /* Ranking-Table: Spalten schmaler machen */
  #rank-tbody td,
  #rank-tbody th {
    padding: 8px 6px;
    font-size: 13px;
  }

  /* Boss Results Table: gleiche Optimierung */
  #boss-tbody td,
  #boss-tbody th {
    padding: 8px 6px;
    font-size: 13px;
  }

  /* Generell: Tabelle nicht zu breit ziehen */
  table {
    table-layout: auto;
    width: 100%;
  }
  /* Search-Box unter dem Titel, aber Input + Button nebeneinander */
  .search {
    width: 100%;
    display: flex;
    gap: 8px;                       /* kleiner Abstand zwischen Input und Button */
  }
  .search input {
    flex: 1;                        /* füllt die ganze Breite */
  }
  .search .btn {
    flex: 0 0 auto;                 /* bleibt in normaler Größe */
  }
}

/* --- HARD mobile tighten (<=480px) --- */
@media (max-width: 480px) {
  html, body { overflow-x: hidden; }            /* keine Quer-Scrolls */
  * { min-width: 0; }                           /* verhindert Flex-Überlauf */

  .container { padding: 16px 10px 60px; }       /* weniger Rand */
  .card { padding: 12px; border-radius: 12px; } /* kompaktere Cards */
  .grid { grid-template-columns: 1fr; gap: 12px; }

  /* KPIs: in 2 Spalten und kleiner */
  .summary { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary .kpi { padding: 10px; }
  .summary .kpi b { font-size: 16px; }

  /* Tabellen kompakter + dürfen umbrechen */
  table { width: 100%; table-layout: auto; }
  thead th { width: auto !important; }          /* überschreibt Inline-Widths */
  #rank-tbody td, #rank-tbody th,
  #boss-tbody td, #boss-tbody th {
    padding: 6px 4px;
    font-size: 12px;
    white-space: normal;                         /* darf umbrechen */
    word-break: break-word;
  }

  /* Badges/Kapseln: schmaler */
  .pill { padding: 3px 6px; font-size: 12px; }
  .chip { padding: 6px 8px; font-size: 11px; }
  .lvl { font-size: 11px; }
  h2 { font-size: 16px; }
}

/* Logo fix, nicht quetschen */
.logo { flex: 0 0 56px; }
.logo, .logo img { width: 56px; height: 56px; }

/* Auf schmalen Screens */
@media (max-width: 640px) {
  header {
    flex-direction: column;         /* Header stapeln */
    align-items: flex-start;
    gap: 12px;
  }

  .title {
    width: 100%;
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 12px;
    align-items: center;
  }

  /* Search-Box unter dem Titel, aber Input + Button nebeneinander */
  .search {
    width: 100%;
    display: flex;
    gap: 8px;                       /* kleiner Abstand zwischen Input und Button */
  }
  .search input {
    flex: 1;                        /* füllt die ganze Breite */
  }
  .search .btn {
    flex: 0 0 auto;                 /* bleibt in normaler Größe */
  }
}