:root {
  --bg: #08080f;
  --bg-2: #101024;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f4f5ff;
  --dim: #9a9dc2;
  --dim-2: #6f7296;
  --accent: #6c63ff;
  --good: #17bebb;
  --warn: #facc15;
  --danger: #f43f5e;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over any class that sets a display value —
   without this, .gate and .tab keep their grid display and every screen
   stacks on top of the next. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(900px 600px at 12% -10%, rgba(108, 99, 255, .2), transparent 60%),
    linear-gradient(180deg, var(--bg), var(--bg-2) 60%, var(--bg));
}

h1, h2 { letter-spacing: -.02em; margin: 0 0 6px; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 10px; }
.dim { color: var(--dim); }
.error { color: var(--danger); }
.hint { color: var(--dim-2); font-size: .85rem; }

.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; padding: 3px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
  background: rgba(255, 255, 255, .06);
}
.brand-mark i { border-radius: 3px; }
.brand-mark i:nth-child(1) { background: #3b3ddb; }
.brand-mark i:nth-child(2) { background: #17bebb; }
.brand-mark i:nth-child(3) { background: #facc15; }
.brand-mark i:nth-child(4) { background: #f43f5e; }

/* ---------- gate ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: min(380px, 100%); display: grid; gap: 12px; justify-items: start; }
.gate-card h1 { font-size: 1.5rem; }
.gate-card input, .gate-card button { width: 100%; }

/* ---------- chrome ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 60px;
  background: rgba(8, 8, 15, .78);
  backdrop-filter: blur(16px) saturate(160%);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); text-decoration: none; }
.tabs { display: flex; gap: 4px; }
.tabs button {
  background: none; border: 0; color: var(--dim); font: inherit; font-weight: 600;
  padding: 8px 14px; border-radius: 10px; cursor: pointer;
}
.tabs button:hover { color: var(--text); background: var(--surface); }
.tabs button.active { color: var(--text); background: var(--surface-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.game-pick { display: flex; align-items: center; gap: 7px; width: auto; }
.game-pick span { font-size: .82rem; }
.game-pick select { width: auto; min-width: 160px; font-weight: 650; }

main { max-width: 1180px; margin: 0 auto; padding: 28px 20px 80px; }
.tab { display: grid; gap: 18px; }
.ov-block { display: grid; gap: 18px; }
.ov-block.empty { padding: 28px; }

/* ---------- primitives ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 20px; }

.btn {
  border: 1px solid transparent; border-radius: 11px; padding: 10px 16px;
  font: inherit; font-weight: 650; cursor: pointer; color: var(--text);
  background: var(--surface-2);
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--surface); border-color: var(--border); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 7px 12px; font-size: .88rem; }

input, select, textarea {
  background: rgba(0, 0, 0, .3); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 6px; font-size: .85rem; color: var(--dim); font-weight: 600; }
label.checkbox { display: flex; align-items: center; gap: 10px; color: var(--text); }
label.checkbox input { width: auto; }

/* ---------- overview ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px 18px;
}
.stat .k { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--dim-2); }
.stat .v { font-size: 1.9rem; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }

.two-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

.series { display: flex; align-items: flex-end; gap: 6px; height: 170px; margin-top: 12px; }
.series .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; }
.series .bar { background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.series .bar.games { background: var(--good); opacity: .7; }
.series .lbl { font-size: .62rem; color: var(--dim-2); text-align: center; transform: rotate(-45deg); height: 22px; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--dim); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

.bar-row { display: grid; grid-template-columns: 90px 1fr 44px; align-items: center; gap: 10px; margin-bottom: 8px; font-size: .88rem; }
.bar-row .track { background: var(--surface-2); border-radius: 999px; height: 9px; overflow: hidden; }
.bar-row .fill { background: var(--accent); height: 100%; }
.bar-row .n { text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }

/* ---------- campaigns ---------- */
.section-head { display: flex; align-items: flex-start; gap: 16px; }
.section-head .btn { margin-left: auto; flex: none; }
.campaign-list { display: grid; gap: 12px; }
.campaign {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 18px; display: grid; gap: 10px;
}
.campaign.on { border-color: rgba(23, 190, 187, .5); }
.campaign-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.campaign-head h3 { margin: 0; font-size: 1.05rem; }
.pill { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--dim); }
.pill.on { background: rgba(23, 190, 187, .18); color: var(--good); }
.pill.off { background: rgba(255, 255, 255, .06); color: var(--dim-2); }
.pill.update { background: rgba(108, 99, 255, .2); color: #b3adff; }
.pill.ad { background: rgba(250, 204, 21, .16); color: var(--warn); }
.pill.blocking { background: rgba(244, 63, 94, .18); color: var(--danger); }
.pill.target { background: rgba(23, 190, 187, .16); color: var(--good); }
.campaign .body { color: var(--dim); font-size: .92rem; }
.metrics { display: flex; gap: 20px; flex-wrap: wrap; font-size: .85rem; color: var(--dim); }
.metrics b { color: var(--text); font-variant-numeric: tabular-nums; }
.campaign-actions { display: flex; gap: 8px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: .89rem; margin-top: 8px; }
th { text-align: left; color: var(--dim-2); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; padding-bottom: 8px; }
td { padding: 9px 0; border-top: 1px solid var(--border); color: var(--dim); }
td.strong { color: var(--text); font-weight: 600; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--dim-2); padding: 18px 0; }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 20px; background: #12122a; color: var(--text);
  width: min(620px, calc(100vw - 32px)); padding: 24px;
}
dialog::backdrop { background: rgba(4, 4, 10, .74); backdrop-filter: blur(3px); }
dialog form { display: grid; gap: 14px; }
dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 620px) { dialog .row { grid-template-columns: 1fr; } }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.actions .spacer { flex: 1; }

.detail-row { display: flex; gap: 12px; align-items: center; padding: 9px 0; border-top: 1px solid var(--border); cursor: pointer; }
.detail-row:hover { background: var(--surface); }
.detail-row .k { color: var(--dim-2); width: 130px; font-size: .8rem; }
.detail-row .v { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .84rem; word-break: break-all; }
.detail-row .copied { color: var(--good); font-size: .78rem; }

/* ---------- footer ---------- */
.footer { text-align: center; padding: 20px; }
.version { background: none; border: 0; color: var(--dim-2); font: inherit; font-size: .8rem; cursor: pointer; }
.version:hover { color: var(--text); text-decoration: underline; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #1b1b3d; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 18px; font-size: .9rem; z-index: 100;
}
.toast.bad { border-color: var(--danger); color: #ffd7de; }

/* ---------- apps health ---------- */
.apps-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.app-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px 18px; display: grid; gap: 8px; }
.app-card.down { border-color: rgba(244, 63, 94, .5); }
.app-card .app-head { display: flex; align-items: center; gap: 10px; }
.app-card .app-head h3 { margin: 0; font-size: 1.02rem; }
.dot { width: 9px; height: 9px; border-radius: 999px; background: var(--good); box-shadow: 0 0 0 4px rgba(23,190,187,.15); }
.dot.down { background: var(--danger); box-shadow: 0 0 0 4px rgba(244,63,94,.15); }
.app-meta { display: flex; gap: 16px; flex-wrap: wrap; font-size: .82rem; color: var(--dim); }
.app-meta b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 650; }

/* ---------- inline svg charts ---------- */
.chart { width: 100%; height: auto; display: block; margin-top: 10px; overflow: visible; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .bar { fill: var(--accent); }
.chart .bar.alt { fill: var(--good); }
.chart .lbl { fill: var(--dim-2); font-size: 9px; }
.chart .area { fill: rgba(108, 99, 255, .18); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }

/* ---------- issues ---------- */
.issue-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 11px 0; border-top: 1px solid var(--border); cursor: pointer; }
.issue-row:hover { background: var(--surface); }
.issue-row .t { color: var(--text); font-weight: 600; font-size: .9rem; }
.issue-row .sub { color: var(--dim-2); font-size: .78rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.issue-row .meta { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
#issue-body pre { background: #0b0b18; border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow: auto; font-size: .8rem; max-height: 320px; white-space: pre-wrap; word-break: break-word; }
#issue-body h3 { font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; color: var(--dim-2); margin: 14px 0 4px; }

/* ====================================================================== */
/* Responsive — phones & small tablets. Goal: never overflow the viewport. */
/* ====================================================================== */

.logout-icon { display: none; font-size: 1.1rem; line-height: 1; }

@media (max-width: 760px) {
  /* Top bar collapses to two rows: [logo · game · sign-out], tabs below. */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: 56px;
    gap: 10px;
    row-gap: 8px;
    padding: 8px 14px;
  }
  .brand { order: 1; font-size: 1rem; }
  .topbar-right { order: 2; margin-left: auto; gap: 8px; }
  .tabs {
    order: 3;
    flex-basis: 100%;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding-bottom: 2px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 0 0 auto; min-height: 44px; display: flex; align-items: center; white-space: nowrap; }

  .game-pick span { display: none; }                 /* drop the "Game" caption */
  .game-pick select { min-width: 0; width: auto; max-width: 150px; min-height: 44px; }
  #logout { min-height: 44px; min-width: 44px; padding: 10px; display: flex; align-items: center; justify-content: center; }
  .logout-text { display: none; }
  .logout-icon { display: inline; }

  main { padding: 18px 14px 72px; }

  /* Two cards per row on phones. */
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .apps-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 13px; min-width: 0; }
  .stat .v { font-size: 1.45rem; overflow-wrap: anywhere; }
  .card { padding: 16px; border-radius: 16px; min-width: 0; }
  .tab, .ov-block, .two-col { min-width: 0; }

  /* Issue rows stack: title full width on top, badges wrap below. */
  .issue-row { grid-template-columns: 1fr; gap: 6px; }
  .issue-row .meta { flex-wrap: wrap; white-space: normal; }

  /* Wide data tables scroll inside their card, never widen the page. */
  #accounts-table, #installs-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #accounts-table table, #installs-table table { min-width: 440px; }

  .metrics { gap: 10px 16px; }
  .section-head { flex-wrap: wrap; }
  .section-head .btn { min-height: 44px; }
  .btn.small { min-height: 40px; }
}

@media (max-width: 420px) {
  .stat-grid, .apps-grid { gap: 8px; }
  .stat .v { font-size: 1.28rem; }
  .bar-row { grid-template-columns: 70px 1fr 40px; font-size: .82rem; }
}

/* Full-screen modals on phones with a big, reachable close. */
@media (max-width: 640px) {
  dialog {
    width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh;
    margin: 0; border-radius: 0; border: 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    overflow: auto;
  }
  dialog .row { grid-template-columns: 1fr; }
  dialog .actions {
    position: sticky; bottom: 0; z-index: 1;
    background: #12122a; border-top: 1px solid var(--border);
    padding: 12px 0 2px; margin-top: 14px;
  }
  dialog .actions .spacer { display: none; }
  dialog .actions .btn { min-height: 48px; flex: 1; }
  #issue-body pre { max-height: none; }
}
