:root,
html[data-theme="dark"] {
  --bg: #070b14;
  --bg-glow: #152038;
  --card: rgba(18, 24, 38, 0.88);
  --line: rgba(90, 108, 148, 0.28);
  --text: #f4f7fb;
  --muted: #9aa8c3;
  --accent: #4c8dff;
  --accent-text: #ffffff;
  --ok: #3dd68c;
  --warn: #ff6b7a;
  --header: rgba(7, 11, 20, 0.86);
  --chip: #0b1220;
  --panel: rgba(8, 13, 24, 0.72);
  --shadow: none;
  --icon-blend: lighten;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #eef2f8;
  --bg-glow: #dce6f7;
  --card: rgba(255, 255, 255, 0.9);
  --line: rgba(24, 39, 72, 0.1);
  --text: #121826;
  --muted: #5d6b82;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --ok: #0f9d68;
  --warn: #d6455d;
  --header: rgba(238, 242, 248, 0.9);
  --chip: #111827;
  --panel: #f5f8fd;
  --shadow: none;
  --icon-blend: normal;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Manrope, "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at top, var(--bg-glow) 0%, var(--bg) 42%);
  color: var(--text);
}

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(36px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: -16px -16px 18px;
  padding: 14px max(16px, env(safe-area-inset-right)) 14px max(16px, env(safe-area-inset-left));
  background: var(--header);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.brand {
  min-width: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 3.6vw, 1.9rem);
  letter-spacing: -0.03em;
}

h2 {
  font-size: 1.02rem;
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.theme-switch {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
}

.theme-switch button {
  min-height: 36px;
  padding: 6px 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.theme-switch button.is-active {
  background: var(--accent);
  color: var(--accent-text);
}

.utc-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.short {
  display: none;
}

.col-label {
  display: inline;
}

button,
select,
input {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  min-height: 44px;
}

button {
  cursor: pointer;
}

#refresh-btn {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
  font-weight: 700;
  white-space: nowrap;
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.calendar-card {
  margin-bottom: 16px;
}

.calendar-card.is-collapsed .cal-body {
  display: none;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.cal-nav strong {
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}

.cal-nav button {
  min-height: 40px;
  padding: 8px 14px;
  font-weight: 700;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal-weekday {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cal-day {
  min-height: 42px;
  padding: 0;
  border-radius: 12px;
  font-weight: 700;
  background: transparent;
}

.cal-day.is-muted {
  opacity: 0.35;
}

.cal-day.has-data {
  background: rgba(61, 214, 140, 0.18);
  color: var(--ok);
  border-color: rgba(61, 214, 140, 0.55);
}

.cal-day.is-today {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.cal-day.is-selected {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}

.cal-day.has-data.is-selected {
  background: var(--ok);
  color: #04210f;
}

#cal-toggle {
  min-height: 40px;
  padding: 8px 14px;
  font-weight: 700;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.graph-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 12px 14px;
  text-align: left;
  border-radius: 18px;
  background: var(--card);
}

.graph-btn.is-open {
  border-color: var(--accent);
}

.graph-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.graph-copy strong {
  font-size: 0.95rem;
}

.graph-copy small {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.mini-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 28px;
}

.mini-bar {
  width: 7px;
  min-height: 4px;
  border-radius: 4px;
  background: var(--accent);
}

.mini-bar.is-peak {
  background: var(--ok);
}

.hours-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hour-row {
  display: grid;
  grid-template-columns: 86px 1fr 36px;
  gap: 8px;
  align-items: center;
}

.hour-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.hour-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel);
}

.hour-bar {
  display: block;
  height: 100%;
  min-width: 0;
  border-radius: 999px;
  background: var(--accent);
}

.hour-row.is-peak .hour-bar {
  background: var(--ok);
}

.hour-row strong {
  font-size: 0.85rem;
  text-align: right;
}

.all-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.all-stat {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.all-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.all-stat strong {
  font-size: 1.2rem;
}

.all-days {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 4px;
}

.all-days-title {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.all-day {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.88rem;
}

#hours-card.is-collapsed,
#all-stats-card.is-collapsed {
  display: none;
}

@media (min-width: 720px) {
  .action-row {
    grid-template-columns: 1fr 1fr;
  }
}

.kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.kpis article,
.card,
.event {
  background: var(--card);
  border: 1px solid var(--line);
}

.kpis article {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 18px;
  padding: 14px;
}

.icon-chip {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 16px;
  background: var(--chip);
  overflow: hidden;
}

.kpi-icon,
.th-icon,
.stat-icon,
.event-icon {
  display: block;
  object-fit: contain;
  mix-blend-mode: var(--icon-blend);
}

.kpi-icon {
  width: 46px;
  height: 46px;
}

.th-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  vertical-align: middle;
  margin-right: 6px;
  mix-blend-mode: normal;
  background: var(--chip);
  border-radius: 6px;
}

.stat-cell {
  white-space: nowrap;
}

.stat-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  vertical-align: middle;
  margin-right: 6px;
  background: var(--chip);
  border-radius: 5px;
  mix-blend-mode: normal;
}

.kpis span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.kpis strong {
  font-size: 1.55rem;
  letter-spacing: -0.04em;
}

.card {
  border-radius: 20px;
  padding: 16px;
  margin-bottom: 16px;
}

.card-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.player-link {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  text-align: left;
}

.player-link:hover,
.player-link.is-open {
  text-decoration: underline;
}

.rank-main.is-open td {
  border-bottom: 0;
}

.rank-detail td {
  padding: 0 10px 12px;
  border-bottom: 1px solid var(--line);
}

.player-history {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.history-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: start;
  color: var(--text);
  font-size: 0.88rem;
}

.history-item img {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  object-fit: contain;
}

.history-item time {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

.pager button {
  min-height: 40px;
  padding: 8px 14px;
  font-weight: 700;
}

.pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

.pager span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  min-width: 7.5rem;
  text-align: center;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border-radius: 14px;
  padding: 12px;
}

.event-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  background: var(--chip);
  border-radius: 10px;
  mix-blend-mode: normal;
}

.event-body {
  min-width: 0;
}

.event small {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.launch {
  color: var(--ok);
  font-weight: 600;
}

.cancel {
  color: var(--warn);
  font-weight: 600;
}

.status {
  color: var(--muted);
  font-size: 0.82rem;
}

.empty {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 720px) {
  .col-label,
  .full,
  .short {
    display: none;
  }

  .th-icon {
    margin-right: 0;
  }

  .stat-icon {
    display: none;
  }

  table {
    min-width: 0;
  }

  th,
  td {
    padding: 10px 6px;
    font-size: 0.86rem;
  }

  th:nth-child(1),
  td:nth-child(1) {
    width: 1.5rem;
    padding-left: 4px;
    padding-right: 4px;
  }

  th:nth-child(n + 3),
  td.stat-cell {
    width: 2.6rem;
    text-align: center;
  }
}

@media (max-width: 640px) {
  .filters {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  #refresh-btn,
  .theme-switch {
    width: 100%;
    justify-content: center;
  }
}

@media (min-width: 720px) {
  .page {
    padding: 24px;
  }

  .topbar {
    margin: 0 0 22px;
    padding: 0 0 16px;
    position: static;
    background: transparent;
    border-bottom: 0;
    backdrop-filter: none;
  }

  .kpis {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1100px) {
  .page {
    padding: 32px 0 48px;
  }
}
