:root {
  color-scheme: dark;
  --bg: #07100f;
  --panel: rgba(13, 27, 25, .92);
  --line: rgba(132, 230, 191, .16);
  --text: #e8fff6;
  --muted: #8fa9a0;
  --accent: #66e6b6;
  --danger: #ff6f75;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: radial-gradient(circle at 30% 0, #17342d 0, var(--bg) 38%); color: var(--text); font-family: Inter, "Segoe UI", sans-serif; }
body { display: flex; flex-direction: column; }
header { width: 100%; min-height: 58px; flex: 0 0 58px; padding: 7px 14px; border-bottom: 1px solid var(--line); background: rgba(5, 16, 14, .96); display: grid; grid-template-columns: minmax(190px, 1fr) auto minmax(190px, 1fr); align-items: center; gap: 18px; }
h1 { margin: 3px 0 0; font-size: clamp(24px, 3vw, 38px); letter-spacing: -.03em; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .18em; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid rgba(102,230,182,.38); border-radius: 10px; color: var(--accent); background: rgba(102,230,182,.08); font-weight: 900; }
.brand strong { display: block; margin-top: 2px; font-size: 14px; letter-spacing: .06em; }
.header-stats { display: flex; align-items: center; height: 40px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: rgba(255,255,255,.02); }
.header-stats > div { min-width: 105px; padding: 5px 14px; border-left: 1px solid var(--line); }
.header-stats > div:first-child { border-left: 0; }
.header-stats span { display: block; color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: .12em; }
.header-stats strong { display: block; margin-top: 1px; font-size: 16px; line-height: 1.1; }
.header-actions { justify-self: end; display: flex; gap: 8px; align-items: center; }
.mobile-player-count { display: none; }
.connection { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; }
.connection.online { color: var(--accent); background: rgba(102, 230, 182, .1); }
.connection.offline { color: var(--danger); }
button, input { font: inherit; }
button { cursor: pointer; }
.ghost { padding: 8px 12px; border: 1px solid var(--line); color: var(--text); background: rgba(255,255,255,.03); border-radius: 9px; }
.action-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap; }
.icon-button { width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center; font-size: 17px; }
main { width: 100%; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 370px); flex: 1; min-height: 0; }
.map-panel, .roster-panel { min-height: 0; overflow: hidden; background: var(--panel); }
.map-panel { display: flex; flex-direction: column; }
.panel-title { min-height: 48px; padding: 7px 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.panel-title .map-title span { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.map-title { flex: 0 0 auto; }
.map-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; min-width: 0; }
.layer-controls { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.layer-toggle { padding: 5px 8px; display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: rgba(255,255,255,.025); font-size: 10px; }
.layer-toggle.is-active { color: #041812; border-color: rgba(102,230,182,.7); background: var(--accent); }
.panel-title .layer-toggle span { display: inline; margin: 0; color: inherit; font-size: inherit; }
.layer-toggle.is-active i, .layer-toggle.is-active span { color: #041812; }
.map-reset-button { min-height: 27px; padding: 5px 8px; gap: 5px; border-radius: 7px; font-size: 10px; }
.map-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #061318; }
#map-canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map-canvas.dragging { cursor: grabbing; }
.dino-summary { position: absolute; top: 12px; left: 12px; z-index: 2; width: min(250px, calc(100% - 24px)); max-height: min(42%, 320px); overflow: hidden; border: 1px solid rgba(102,230,182,.28); border-radius: 11px; background: rgba(4,13,12,.9); box-shadow: 0 12px 36px rgba(0,0,0,.3); backdrop-filter: blur(7px); }
.dino-summary-head { min-height: 34px; padding: 8px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); }
.dino-summary-head strong { color: var(--accent); font-size: 10px; letter-spacing: .09em; }
.dino-summary-head span { color: var(--muted); font-size: 9px; white-space: nowrap; }
.dino-summary-toggle { min-width: 0; padding: 0; display: flex; align-items: center; gap: 6px; border: 0; color: inherit; background: transparent; }
.dino-summary-toggle strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dino-summary-chevron { color: var(--accent) !important; font-size: 9px !important; transition: transform .16s ease; }
.dino-summary.collapsed .dino-summary-chevron { transform: rotate(-90deg); }
.dino-summary.collapsed .dino-summary-tools, .dino-summary.collapsed .dino-summary-list { display: none; }
.dino-summary-tools { min-height: 29px; padding: 4px 7px; display: flex; align-items: center; gap: 5px; border-bottom: 1px solid var(--line); }
.dino-summary-tools button { padding: 3px 7px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: rgba(255,255,255,.035); font-size: 9px; }
.dino-summary-tools button:hover { border-color: rgba(102,230,182,.55); }
.dino-summary-tools span { margin-left: auto; color: var(--muted); font-size: 8px; }
.dino-summary-list { max-height: 270px; overflow: auto; padding: 5px; scrollbar-width: thin; }
.dino-summary-row { min-height: 27px; padding: 3px 6px; display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; align-items: center; gap: 7px; border-radius: 6px; font-size: 11px; cursor: pointer; }
.dino-summary-row:nth-child(odd) { background: rgba(255,255,255,.025); }
.dino-summary-row:hover { background: rgba(102,230,182,.08); }
.dino-summary-row input { width: 13px; height: 13px; margin: 0; accent-color: var(--accent); }
.dino-summary-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dino-summary-row strong { min-width: 26px; padding: 2px 6px; border-radius: 999px; color: #06140f; background: var(--accent); text-align: center; font-size: 10px; }
.dino-summary-row.is-hidden { opacity: .45; }
.selected-card { position: absolute; left: 14px; bottom: 14px; z-index: 3; width: min(580px, calc(100% - 28px)); max-height: calc(100% - 28px); padding: 12px 14px; overflow: auto; border: 1px solid rgba(102,230,182,.35); border-radius: 10px; background: rgba(4, 13, 12, .94); box-shadow: 0 12px 40px rgba(0,0,0,.35); font-size: 12px; scrollbar-width: thin; }
.selected-card strong { color: var(--accent); }
.player-card-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.player-card-title > div { min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.player-card-title strong { font-size: 15px; }
.player-card-title span { color: var(--muted); }
.player-card-close { flex: 0 0 34px; width: 34px; height: 34px; margin: -5px -6px 0 0; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: rgba(255,255,255,.04); font-size: 16px; line-height: 1; }
.player-card-close:hover { color: var(--danger); border-color: rgba(255,111,117,.45); }
.player-card-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; margin-bottom: 8px; }
.player-card-stat { padding: 6px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.025); }
.player-card-stat span { display: block; color: var(--muted); font-size: 8px; text-transform: uppercase; }
.player-card-stat strong { display: block; margin-top: 2px; font-size: 11px; }
.player-card-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 12px; color: var(--muted); font-size: 10px; }
.player-card-meta b { color: var(--text); font-weight: 600; }
.player-card-meta .prime-yes { color: #f7d774; }
.mutation-groups { margin-top: 9px; padding-top: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 7px 10px; border-top: 1px solid var(--line); }
.mutation-group > strong { display: block; margin-bottom: 4px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .05em; }
.mutation-group > div { display: flex; flex-wrap: wrap; gap: 4px; }
.mutation-chip { padding: 3px 6px; border: 1px solid rgba(102,230,182,.2); border-radius: 6px; color: var(--text); background: rgba(102,230,182,.055); font-size: 9px; }
.mutation-chip b { margin-right: 3px; color: var(--accent); }
.mutation-empty { color: var(--muted); font-size: 9px; }
.hidden { display: none; }
.roster-panel { display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.search-wrap { position: relative; margin: 12px; }
.search-wrap > i { position: absolute; left: 12px; top: 50%; translate: 0 -50%; color: var(--muted); font-size: 11px; pointer-events: none; }
.search { width: 100%; padding: 10px 12px 10px 32px; border: 1px solid var(--line); border-radius: 9px; background: rgba(0,0,0,.23); color: var(--text); outline: none; }
.search:focus { border-color: var(--accent); }
.table-wrap { overflow: auto; min-height: 0; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { position: sticky; top: 0; z-index: 1; padding: 9px 11px; text-align: left; color: var(--muted); background: #10231f; }
td { padding: 10px 11px; border-top: 1px solid rgba(255,255,255,.045); vertical-align: top; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: rgba(102,230,182,.07); }
.steam { color: var(--muted); font-size: 10px; margin-top: 2px; }
.login-layer { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(2,8,7,.94); backdrop-filter: blur(10px); }
.login-layer.hidden { display: none; }
.login-card { width: min(420px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 16px; background: #0d1d1a; box-shadow: 0 25px 90px rgba(0,0,0,.45); }
.login-card p { color: var(--muted); }
.login-card input { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: rgba(0,0,0,.25); }
.login-card button { width: 100%; margin-top: 12px; padding: 12px; border: 0; border-radius: 9px; color: #032018; background: var(--accent); font-weight: 800; }
.error { min-height: 20px; margin-top: 10px; color: var(--danger); font-size: 12px; }
.discord-login { width: 100%; margin-top: 16px; padding: 12px; display: block; border-radius: 9px; color: #fff; background: #5865f2; text-align: center; text-decoration: none; font-weight: 800; }
.discord-login:hover { background: #6975f5; }
.current-user { max-width: 150px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.modal-layer { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(2,8,7,.88); backdrop-filter: blur(8px); }
.modal-layer.hidden { display: none; }
.permission-card { width: min(620px, 100%); max-height: min(760px, 90vh); padding: 22px; overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: #0d1d1a; box-shadow: 0 25px 90px rgba(0,0,0,.5); }
.permission-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.permission-head h2 { margin: 4px 0 0; }
.permission-form { margin-top: 18px; display: grid; grid-template-columns: 1.2fr 1fr auto; align-items: end; gap: 9px; }
.permission-form label { color: var(--muted); font-size: 10px; }
.permission-form input { width: 100%; margin-top: 5px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: rgba(0,0,0,.24); outline: none; }
.permission-form input:focus { border-color: var(--accent); }
.permission-form button { padding: 11px 15px; border: 0; border-radius: 8px; color: #032018; background: var(--accent); font-weight: 800; }
.permission-list { margin-top: 12px; display: grid; gap: 7px; }
.permission-row { padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.025); }
.permission-row strong, .permission-row span { display: block; }
.permission-row div > span { margin-top: 2px; color: var(--muted); font-family: Consolas, monospace; font-size: 10px; }
.owner-badge { padding: 5px 8px; border-radius: 999px; color: var(--accent); background: rgba(102,230,182,.1); font-size: 9px; font-weight: 800; }
.remove-access { padding: 7px 9px; border: 1px solid rgba(255,111,117,.3); border-radius: 7px; color: var(--danger); background: rgba(255,111,117,.07); font-size: 10px; }
@media (max-width: 900px) {
  html, body { height: 100%; overflow: hidden; }
  body { padding: 0; display: flex; }
  header { min-height: 52px; flex-basis: 52px; padding: 6px 10px; grid-template-columns: 1fr auto; gap: 8px; }
  .brand-mark { width: 32px; height: 32px; }
  .brand strong { font-size: 12px; }
  .eyebrow { font-size: 9px; }
  .current-user, .connection { display: none; }
  .header-actions { gap: 5px; }
  .mobile-player-count { height: 34px; min-width: 48px; padding: 0 9px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); border-radius: 9px; color: var(--accent); background: rgba(102,230,182,.08); font-size: 12px; }
  .mobile-player-count strong { color: var(--text); font-size: 13px; }
  .header-actions .ghost { width: 34px; height: 34px; padding: 0; font-size: 14px; }
  .header-actions .action-button span { display: none; }
  main { display: flex; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(55vh, 1.4fr) minmax(210px, .8fr); height: 100%; }
  .map-panel { height: auto; min-height: 0; }
  .roster-panel { height: auto; min-height: 0; border-top: 1px solid var(--line); border-left: 0; }
  .panel-title { min-height: 40px; padding: 6px 9px; align-items: center; gap: 8px; }
  .map-title span { display: none; }
  .map-toolbar { min-height: 82px; padding: 6px 8px; display: grid; grid-template-columns: 1fr auto; grid-template-rows: 34px 32px; align-items: center; }
  .map-actions { display: contents; }
  .map-title { grid-column: 1; grid-row: 1; }
  #reset-map { grid-column: 2; grid-row: 1; justify-self: end; width: 34px; height: 34px; padding: 0; }
  #reset-map span { display: none; }
  .layer-controls { grid-column: 1 / -1; grid-row: 2; width: 100%; max-width: none; padding-bottom: 2px; overflow-x: auto; flex-wrap: nowrap; justify-content: flex-start; scrollbar-width: none; }
  .layer-toggle { flex: 0 0 auto; }
  .dino-summary { top: 8px; left: 8px; width: min(220px, calc(100% - 16px)); max-height: 38%; }
  .selected-card { position: fixed; inset: auto 8px 8px 8px; z-index: 15; width: auto; max-height: min(68vh, 620px); padding: 12px; border-radius: 12px; box-shadow: 0 18px 70px rgba(0,0,0,.65); }
  .search-wrap { margin: 7px 9px; }
  .search { padding: 8px 10px 8px 30px; }
  th, td { padding: 8px 9px; }
}
@media (max-width: 1100px) {
  header { grid-template-columns: minmax(170px, 1fr) auto; }
  .header-stats { display: none; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .workspace { min-height: 0; }
  .header-actions { align-items: center; flex-direction: row; }
  .player-card-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .player-card-meta { grid-template-columns: 1fr; }
  .mutation-groups { grid-template-columns: 1fr; }
  .player-card-title > div { display: block; }
  .player-card-title span { display: block; margin-top: 2px; }
  .permission-form { grid-template-columns: 1fr; }
}


/* v2: foldable roster + visual polish */
.workspace { transition: grid-template-columns .22s ease; }
body.roster-collapsed .workspace { grid-template-columns: minmax(0, 1fr) 54px; }
.roster-panel { background: linear-gradient(180deg, rgba(15,31,28,.98), rgba(8,20,18,.96)); box-shadow: -18px 0 45px rgba(0,0,0,.12); transition: width .22s ease, min-width .22s ease; }
.roster-head { flex: 0 0 auto; background: linear-gradient(180deg, rgba(102,230,182,.055), rgba(255,255,255,.01)); }
.roster-title { min-width: 0; display: inline-flex; align-items: center; gap: 8px; letter-spacing: .015em; }
.roster-title i { color: var(--accent); }
.roster-toggle { width: 31px; height: 31px; flex: 0 0 31px; border-color: rgba(102,230,182,.18); color: var(--accent); transition: background .16s ease, border-color .16s ease, transform .16s ease; }
.roster-toggle:hover { border-color: rgba(102,230,182,.48); background: rgba(102,230,182,.09); }
.roster-body { display: flex; flex: 1; min-height: 0; flex-direction: column; overflow: hidden; }
.roster-panel.collapsed .roster-body { display: none; }
.roster-panel.collapsed .roster-head { height: 100%; min-height: 0; padding: 10px 0; flex-direction: column; justify-content: flex-start; gap: 12px; border-bottom: 0; }
.roster-panel.collapsed .roster-title span { display: none; }
.roster-panel.collapsed .roster-title { justify-content: center; font-size: 16px; }
.roster-panel.collapsed .roster-toggle { margin-top: 2px; }
.search-wrap { margin: 10px 10px 7px; }
.search { border-color: rgba(102,230,182,.13); background: rgba(0,0,0,.27); box-shadow: inset 0 1px 0 rgba(255,255,255,.025); }
.search:focus { border-color: rgba(102,230,182,.58); box-shadow: 0 0 0 3px rgba(102,230,182,.07); }
.table-wrap { flex: 1; padding: 0 7px 8px; scrollbar-width: thin; }
.roster-panel table { border-collapse: separate; border-spacing: 0 5px; }
.roster-panel thead th { position: sticky; top: 0; z-index: 1; padding: 7px 9px; color: var(--muted); background: #0b1c19; font-size: 9px; letter-spacing: .08em; text-transform: uppercase; }
.roster-panel tbody tr { cursor: pointer; transition: transform .12s ease, filter .12s ease; }
.roster-panel tbody tr:hover { transform: translateY(-1px); filter: brightness(1.1); }
.roster-panel tbody td { padding: 9px 9px; border-top: 1px solid rgba(102,230,182,.09); border-bottom: 1px solid rgba(102,230,182,.09); background: rgba(255,255,255,.026); }
.roster-panel tbody td:first-child { border-left: 1px solid rgba(102,230,182,.09); border-radius: 8px 0 0 8px; }
.roster-panel tbody td:last-child { border-right: 1px solid rgba(102,230,182,.09); border-radius: 0 8px 8px 0; color: var(--accent); font-weight: 700; }
.roster-panel .steam { opacity: .72; }

@media (max-width: 900px) {
  body.roster-collapsed .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(calc(100vh - 106px), 1fr) 48px; }
  .roster-panel.collapsed { min-height: 48px; height: 48px; }
  .roster-panel.collapsed .roster-head { height: 48px; padding: 6px 10px; flex-direction: row; justify-content: space-between; border-top: 1px solid var(--line); }
  .roster-panel.collapsed .roster-title span { display: inline; }
  .roster-panel.collapsed .roster-toggle { margin: 0; }
  .roster-panel.collapsed .roster-toggle i { transform: rotate(90deg); }
}

.discord-id { margin-top: 2px; color: #8ea9ff; font-size: 9px; font-family: Consolas, monospace; opacity: .9; }


/* v4: refined player roster */
#roster .roster-row { cursor: pointer; }
.roster-panel table { table-layout: fixed; border-spacing: 0 7px; }
.roster-panel thead th:first-child { width: 52%; }
.roster-panel thead th:nth-child(2) { width: 28%; }
.roster-panel thead th:nth-child(3) { width: 20%; text-align: right; }
.roster-panel tbody td { vertical-align: middle; padding: 8px 8px; background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.018)); border-color: rgba(102,230,182,.10); }
.roster-panel tbody tr:hover td { background: linear-gradient(180deg, rgba(102,230,182,.09), rgba(102,230,182,.035)); border-color: rgba(102,230,182,.24); }
.roster-player { min-width: 0; display: flex; align-items: center; gap: 9px; }
.roster-avatar { width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center; border: 1px solid rgba(102,230,182,.26); border-radius: 9px; color: var(--accent); background: radial-gradient(circle at 30% 20%, rgba(102,230,182,.18), rgba(102,230,182,.045)); font-size: 12px; font-weight: 900; box-shadow: inset 0 1px 0 rgba(255,255,255,.05); }
.roster-player-text { min-width: 0; }
.roster-player-name { display: block; overflow: hidden; color: var(--text); font-size: 12px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.roster-ids { margin-top: 4px; display: grid; gap: 2px; min-width: 0; }
.roster-panel .steam, .roster-panel .discord-id { display: block; margin: 0; overflow: hidden; font-family: Consolas, monospace; font-size: 8.5px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.roster-panel .steam { color: var(--muted); opacity: .78; }
.roster-panel .discord-id { color: #9cabff; opacity: .9; }
.roster-dino-cell { overflow: hidden; }
.roster-dino-badge { display: inline-block; max-width: 100%; padding: 4px 7px; overflow: hidden; border: 1px solid rgba(102,230,182,.16); border-radius: 999px; color: #c9f8e7; background: rgba(102,230,182,.065); font-size: 9px; font-weight: 700; line-height: 1; text-overflow: ellipsis; white-space: nowrap; }
.roster-growth-cell { text-align: right; }
.roster-growth { min-width: 0; display: grid; justify-items: end; gap: 5px; }
.roster-growth > strong { color: var(--accent); font-size: 10px; font-variant-numeric: tabular-nums; }
.roster-growth-track { width: 100%; max-width: 70px; height: 4px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.07); }
.roster-growth-fill { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, rgba(102,230,182,.55), var(--accent)); box-shadow: 0 0 8px rgba(102,230,182,.22); }
@media (max-width: 560px) {
  .roster-avatar { width: 28px; height: 28px; flex-basis: 28px; border-radius: 8px; }
  .roster-player { gap: 7px; }
  .roster-panel thead th:first-child { width: 50%; }
  .roster-panel thead th:nth-child(2) { width: 30%; }
  .roster-panel thead th:nth-child(3) { width: 20%; }
  .roster-dino-badge { padding: 3px 5px; font-size: 8px; }
  .roster-growth-track { max-width: 52px; }
}
