:root {
  color-scheme: dark;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
  --background: #090909;
  --ink: #f5f5f5;
  --muted: #aaa;
  --detail: #ccc;
  --placeholder: #999;
  --line: #2a2a2a;
  --line-strong: #373737;
  --field-border: #444;
  --panel: #121212;
  --input: #171717;
  --surface-hover: #202020;
  --pill: #252525;
  --accent: #f5f5f5;
  --accent-fill: #f5f5f5;
  --accent-fill-hover: #d6d6d6;
  --accent-ink: #111;
  --accent-light: #222;
  --accent-detail: #ddd;
  --live: #fff;
  --danger: #e3e3e3;
  --danger-line: #5a5a5a;
  --danger-hover: #262626;
  --gold: #090909;
  --gold-surface: #eee;
  --avatar-ring: #444;
  --backdrop: rgb(0 0 0 / 0.7);
}

html[data-theme='light'] {
  color-scheme: light;
  --background: #fff;
  --ink: #151515;
  --muted: #555;
  --detail: #393939;
  --placeholder: #626262;
  --line: #ddd;
  --line-strong: #ccc;
  --field-border: #bcbcbc;
  --panel: #fafafa;
  --input: #fff;
  --surface-hover: #eee;
  --pill: #e8e8e8;
  --accent: #181818;
  --accent-fill: #161616;
  --accent-fill-hover: #343434;
  --accent-ink: #fff;
  --accent-light: #eaeaea;
  --accent-detail: #282828;
  --live: #111;
  --danger: #272727;
  --danger-line: #888;
  --danger-hover: #e7e7e7;
  --gold: #fff;
  --gold-surface: #222;
  --avatar-ring: #ccc;
  --backdrop: rgb(0 0 0 / 0.48);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
a { color: inherit; }
img { filter: grayscale(1); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.dashboard-shell {
  min-height: 100vh;
}
.site-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 3rem minmax(0, 1fr);
  align-items: center;
  gap: 0.65rem;
  min-height: 4.5rem;
  padding: 0.5rem clamp(0.9rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: block;
  width: 3rem;
  height: 3rem;
  border-radius: 0.3rem;
}
.brand-mark {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: inherit;
}
.site-nav { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.site-nav button {
  text-align: start;
  padding: 0.55rem 0.65rem;
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.site-nav button:hover { background: var(--surface-hover); }
.site-nav button[aria-current="page"] { color: var(--ink); background: var(--accent-light); }

.dashboard {
  width: 100%;
  min-width: 0;
  max-width: 82rem;
  margin: 0 auto;
  padding: clamp(1.5rem, 3vw, 2.75rem) clamp(1rem, 4vw, 3rem) 5.5rem;
}
#access-controls { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 0.5rem; min-width: 0; }
.panel { border: 1px solid var(--line); border-radius: 0.5rem; background: var(--panel); }
.roster-summary { margin-top: 0.425rem; color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.toolbar-actions, .sort-control { display: flex; align-items: center; gap: 0.625rem; }
.toolbar-actions { flex-wrap: wrap; }
.sort-control { color: var(--muted); font-size: 0.875rem; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute;
  inset-inline-end: 0.875rem;
  inset-block-start: 50%;
  width: 0.375rem;
  height: 0.375rem;
  border: solid var(--muted);
  border-width: 0 1px 1px 0;
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.sort-control select {
  appearance: none;
  min-height: 2.5rem;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  border: 1px solid var(--field-border);
  border-radius: 0.5rem;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
}
.sort-control select:hover { background: var(--surface-hover); }

h1, h2, p { margin: 0; }
h1 {
  font-size: clamp(1.7rem, 3vw, 2.2rem);
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.03em;
}
h2 { font-size: 1.25rem; font-weight: 640; }

.outline-button, .primary-button, .danger-button {
  min-height: 2.5rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--field-border);
  border-radius: 0.5rem;
  background: transparent;
  color: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}
.outline-button:hover { background: var(--surface-hover); }
.primary-button { color: var(--accent-ink); background: var(--accent-fill); border-color: var(--accent-fill); }
.primary-button:hover { background: var(--accent-fill-hover); border-color: var(--accent-fill-hover); }
.danger-button { color: var(--danger); border-color: var(--danger-line); }
.danger-button:hover { background: var(--danger-hover); }
.theme-switch {
  position: fixed;
  z-index: 8;
  inset-inline-end: max(1rem, env(safe-area-inset-right));
  inset-block-end: max(1rem, env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--field-border);
  border-radius: 0.45rem;
  background: var(--panel);
  color: var(--ink);
  font-size: 0.8125rem;
  cursor: pointer;
}
.theme-switch:hover { background: var(--surface-hover); }
.theme-switch-track { position: relative; width: 1.55rem; height: 0.875rem; border: 1px solid var(--field-border); border-radius: 1rem; background: var(--pill); }
.theme-switch-track::after { content: ""; position: absolute; inset-block-start: 0.125rem; inset-inline-start: 0.125rem; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--ink); }
.theme-switch[aria-checked='true'] .theme-switch-track { background: var(--ink); border-color: var(--ink); }
.theme-switch[aria-checked='true'] .theme-switch-track::after { inset-inline-start: auto; inset-inline-end: 0.125rem; background: var(--background); }
button:disabled { opacity: 0.65; cursor: wait; }

.streamer-table { border-collapse: collapse; table-layout: fixed; width: 100%; }
.col-streamer { width: 22%; }
.col-rank { width: 25%; }
.col-mode { width: 9%; }
.col-servers { width: 15%; }
.col-last-game { width: 13%; }
.col-status { width: 16%; }
.can-edit .col-streamer { width: 21%; }
.can-edit .col-rank { width: 21%; }
.can-edit .col-mode { width: 9%; }
.can-edit .col-servers { width: 13%; }
.can-edit .col-last-game { width: 13%; }
.can-edit .col-status { width: 15%; }
.col-edit { width: 8%; }

th, td { text-align: left; }
thead th {
  padding: 0 1rem 0.75rem 0;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: 1px solid var(--line-strong);
}
tbody th, td {
  padding: 1rem 1rem 1rem 0;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th:last-child, td:last-child, .status-cell, thead th:nth-child(6) { text-align: right; }
th:last-child, td:last-child { padding-right: 0; }
tbody tr:last-child > * { border-bottom: 0; }
.row-edit { padding: 0.35rem 0.4rem; border: 0; border-radius: 0.3rem; color: var(--accent); background: transparent; font-size: 0.875rem; font-weight: 650; cursor: pointer; }
.row-edit:hover { background: var(--accent-light); }

.streamer { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.avatar {
  display: grid;
  place-items: center;
  position: relative;
  inline-size: 2.25rem;
  block-size: 2.25rem;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent-detail);
  font-size: 0.75rem;
  font-weight: 650;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.streamer-name { min-width: 0; overflow-wrap: anywhere; }
.streamer-name a { text-decoration: none; font-weight: 650; }
.streamer-name a:hover, .streamer-name a:focus-visible { text-decoration: underline; text-underline-offset: 0.2em; }
.rank-summary { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 0.375rem; }
.rank-line + .rank-line { margin-top: 0.5rem; }
.rank-tier { font-size: 0.9375rem; font-weight: 620; }
.rank-detail, .activity, .queue-servers, .last-game-cell, .stream-status, .game-mode, .muted, .message, .empty-state { color: var(--muted); }
.rank-detail, .riot-id, .activity, .stream-status, .queue-servers, .last-game-cell, .game-mode { font-size: 0.875rem; line-height: 1.45; }
.riot-id { display: block; color: var(--detail); }
.game-mode { color: var(--detail); }
.mobile-field-label { display: none; }
.rank-detail, .activity, .stream-status { font-variant-numeric: tabular-nums; }
.stream-status { white-space: nowrap; }
.activity { display: block; margin-top: 0.1875rem; }
.stream-status.is-live { display: inline-flex; align-items: center; gap: 0.4375rem; color: var(--live); font-weight: 650; }
.stream-status.is-live::before { content: ""; inline-size: 0.5rem; block-size: 0.5rem; border-radius: 50%; background: currentColor; }
.queue-servers, .last-game-cell, .rank-detail, .riot-id { overflow-wrap: anywhere; }

.message { font-size: 0.875rem; margin: 0 0 1rem; }
.empty-state { padding: 1.25rem 0; }

.add-dialog {
  width: min(28rem, calc(100% - 2rem));
  max-height: calc(100% - 2rem);
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 0.625rem;
  background: var(--panel);
  color: inherit;
}
.add-dialog::backdrop { background: var(--backdrop); }
.add-dialog h2 { margin-bottom: 1.25rem; }
.field { display: block; margin-top: 1rem; font-size: 0.875rem; font-weight: 600; }
.field input, .field select, .field textarea {
  display: block;
  width: 100%;
  margin-top: 0.375rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--field-border);
  border-radius: 0.5rem;
  background: var(--input);
  color: inherit;
  font-size: 1rem;
  font-weight: 400;
}
.field input::placeholder, .field textarea::placeholder { color: var(--placeholder); }
.field-help { color: var(--muted); margin-top: 0.375rem; font-size: 0.875rem; }
.checkbox { display: flex; align-items: baseline; gap: 0.5rem; margin-top: 1rem; font-size: 0.875rem; }
.checkbox input { margin: 0; accent-color: var(--accent); }
.form-error { color: var(--danger); margin-top: 1rem; font-size: 0.875rem; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.5rem; }

.access-role { color: var(--accent); font-size: 0.875rem; font-weight: 650; }
#private-workspace { padding: 1.3rem; }
.private-workspace-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.875rem; margin-bottom: 1rem; }
.private-search { min-height: 2.5rem; max-width: min(20rem, 100%); padding: 0.5rem 0.75rem; border: 1px solid var(--field-border); border-radius: 0.5rem; color: var(--ink); background: var(--input); }
.private-status { margin-top: 1rem; color: var(--muted); font-size: 0.875rem; }
.private-list { padding: 0; margin: 0.75rem 0 0; list-style: none; }
.private-row { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 0.75rem; padding: 0.85rem 0; border-top: 1px solid var(--line); }
.private-row-copy { min-width: 0; overflow-wrap: anywhere; }
.private-row-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.private-note { margin-top: 0.325rem; color: var(--muted); font-size: 0.9rem; white-space: pre-wrap; }
.field textarea { resize: vertical; min-height: 5rem; }
.dodge-identity { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.45rem 0.65rem; }
.dodge-priority { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.16rem 0.4rem; border: 1px solid var(--field-border); border-radius: 0.3rem; color: var(--detail); font-size: 0.75rem; line-height: 1.15; }
.dodge-priority.is-high { border-color: var(--muted); color: var(--ink); }
.dodge-priority.is-extreme { background: var(--ink); color: var(--background); border-color: var(--ink); }
.dodge-name { position: relative; min-width: 0; }
.dodge-trigger { padding: 0; border: 0; background: transparent; color: var(--ink); font-weight: 650; text-align: left; text-decoration: underline dotted var(--field-border); text-underline-offset: 0.28rem; overflow-wrap: anywhere; cursor: pointer; }
.dodge-trigger:hover, .dodge-trigger:focus-visible { text-decoration-color: currentColor; }
.dodge-reason { position: absolute; z-index: 10; inset-block-start: 100%; inset-inline-start: 0; width: max-content; max-width: min(20rem, 65vw); padding: 0.625rem 0.75rem; border: 1px solid var(--line-strong); border-radius: 0.375rem; background: var(--panel); color: var(--ink); font-size: 0.875rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.dodge-rank { color: var(--muted); font-size: 0.875rem; }

.profile-menu { position: relative; min-width: 0; }
.profile-trigger {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.625rem;
  min-height: 2.5rem;
  max-width: min(16rem, 100%);
  padding: 0.25rem 0.75rem 0.25rem 0.25rem;
  border: 1px solid var(--field-border);
  border-radius: 0.65rem;
  background: var(--panel);
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 650;
  cursor: pointer;
}
.profile-trigger:hover, .profile-trigger[aria-expanded='true'] { background: var(--surface-hover); }
.profile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-avatar {
  display: grid;
  place-items: center;
  position: relative;
  inline-size: 1.875rem;
  block-size: 1.875rem;
  flex: none;
  overflow: hidden;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent-detail);
  font-size: 0.75rem;
  font-weight: 720;
  object-fit: cover;
}
.profile-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.profile-popover {
  position: absolute;
  z-index: 5;
  inset-block-start: calc(100% + 0.5rem);
  inset-inline-end: 0;
  display: grid;
  gap: 0.18rem;
  min-width: min(12rem, calc(100vw - 2rem));
  padding: 0.35rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.75rem;
  background: var(--panel);
}
.profile-popover button {
  min-height: 2.4rem;
  padding: 0.45rem 0.65rem;
  border: 0;
  border-radius: 0.45rem;
  background: transparent;
  color: var(--ink);
  font-size: 0.875rem;
  text-align: start;
  white-space: nowrap;
  cursor: pointer;
}
.profile-popover button:hover, .profile-popover button:focus-visible { background: var(--surface-hover); }
#private-workspace.profile-workspace { padding: 0; border: 0; background: transparent; box-shadow: none; }
.profile-page { display: grid; gap: 1rem; min-width: 0; max-width: 74rem; margin-inline: auto; }
.profile-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(0.85rem, 2.25vw, 1.35rem);
  min-width: 0;
  padding: clamp(1.25rem, 3.5vw, 2.25rem);
  border: 1px solid var(--line-strong);
  border-radius: 1rem;
  background: var(--panel);
}
.profile-hero .profile-avatar {
  inline-size: clamp(3.75rem, 8vw, 5.5rem);
  block-size: clamp(3.75rem, 8vw, 5.5rem);
  border: 2px solid var(--avatar-ring);
  font-size: clamp(1.125rem, 3vw, 1.65rem);
}
.profile-identity { min-width: 0; overflow-wrap: anywhere; }
.profile-identity h1 { letter-spacing: -0.035em; }
.profile-identity p { margin-top: 0.45rem; }
.profile-hero > button, .profile-hero-actions { margin-inline-start: auto; }
.profile-layout { display: grid; grid-template-columns: minmax(13rem, 1fr) minmax(0, 2fr); gap: 1rem; }
.profile-card { min-width: 0; padding: clamp(1rem, 2.5vw, 1.5rem); }
.profile-card:nth-child(3) { grid-column: 1; grid-row: 1 / span 2; }
.profile-card:nth-child(-n+2) { grid-column: 2; }
.profile-card h2 { margin-bottom: 0.8rem; font-size: 1.05rem; }
.profile-stat {
  display: block;
  color: var(--accent);
  font-size: clamp(1.75rem, 3.25vw, 2.35rem);
  font-weight: 720;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.profile-time { margin-top: 0.65rem; color: var(--detail); line-height: 1.5; }
.group-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2rem;
  padding: 0.3rem 0.65rem;
  border-radius: 0.5rem;
  background: var(--accent-light);
  color: var(--accent-detail);
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.2;
}
.group-badge::before { content: ""; inline-size: 0.45rem; block-size: 0.45rem; border: 1px solid currentColor; border-radius: 50%; }
.group-badge.is-owner { background: var(--gold-surface); color: var(--gold); }
.group-badge.is-owner::before { border-radius: 1px; transform: rotate(45deg); }
.profile-detail { display: grid; gap: 0; margin: 0; }
.profile-detail > div { display: grid; grid-template-columns: minmax(5rem, 0.3fr) minmax(0, 1fr); align-items: baseline; gap: 0.45rem 0.85rem; padding: 0.75rem 0; border-top: 1px solid var(--line); }
.profile-detail dt { color: var(--muted); font-size: 0.875rem; }
.profile-detail dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.profile-detail code { color: var(--detail); font-size: 0.8125rem; user-select: all; }
.avatar-preview { display: flex; flex-wrap: wrap; align-items: center; gap: 0.9rem; margin-top: 1rem; }
.avatar-preview .profile-avatar { inline-size: 3.5rem; block-size: 3.5rem; font-size: 1.1rem; }
.avatar-preview-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.profile-settings input[type='file'] { max-width: 100%; font-size: 0.875rem; }
.profile-settings input::file-selector-button { margin-inline-end: 0.65rem; padding: 0.3rem 0.55rem; border: 1px solid var(--field-border); border-radius: 0.35rem; background: var(--panel); color: var(--ink); cursor: pointer; }
.profile-settings input::file-selector-button:hover { background: var(--surface-hover); }

@media (max-width: 52rem) {
  .toolbar { margin-bottom: 1.5rem; }
  .streamer-table, .streamer-table tbody { display: block; }
  .streamer-table colgroup { display: none; }
  .streamer-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .streamer-table tbody { border-top: 1px solid var(--line-strong); }
  .streamer-table tbody tr {
    display: grid;
    align-items: start;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "streamer status" "rank mode" "rank servers" "rank last-game";
    column-gap: 0.75rem;
    row-gap: 0.375rem;
    padding: 0.875rem 0;
    border-bottom: 1px solid var(--line);
  }
  .streamer-table tbody th, .streamer-table td { padding: 0; border: 0; }
  .streamer-table.can-edit tbody tr { grid-template-areas: "streamer status" "rank mode" "rank servers" "rank last-game" "rank edit"; }
  .streamer-cell { grid-area: streamer; }
  .rank-cell { grid-area: rank; margin-left: 2.5rem; }
  .mode-cell { grid-area: mode; text-align: right; }
  .queue-servers { grid-area: servers; text-align: right; max-width: 10rem; }
  .last-game-cell { grid-area: last-game; text-align: right; max-width: 10rem; }
  .mobile-field-label { display: inline; color: var(--muted); margin-inline-end: 0.375rem; }
  .status-cell { grid-area: status; align-self: center; }
  .edit-cell { grid-area: edit; }
  .avatar { inline-size: 2rem; block-size: 2rem; }
  .streamer { gap: 0.5rem; }
}

@media (max-width: 35rem) {
  .site-header { grid-template-columns: minmax(0, 1fr) 2.75rem minmax(0, 1fr); gap: 0.4rem; }
  .brand { width: 2.75rem; height: 2.75rem; }
  .site-nav button { padding-inline: 0.4rem; }
  #access-controls > button { min-height: 2.125rem; padding-inline: 0.5rem; }
  .profile-layout { grid-template-columns: minmax(0, 1fr); }
  .profile-card:nth-child(n) { grid-column: auto; grid-row: auto; }
  .profile-hero > button, .profile-hero-actions { margin-inline-start: 0; }
  .profile-detail > div { grid-template-columns: minmax(0, 1fr); }
  .dodge-reason { inset-inline-start: -3rem; }
}

@media (max-width: 24rem) {
  .queue-servers, .last-game-cell { max-width: 7rem; }
  .status-cell { max-width: 7.5rem; }
  .stream-status { white-space: normal; }
}
