/* Rank Mirror — iOS-first design system
   Single source of truth. Dark system appearance, grouped inset lists,
   restrained glass for navigation/toolbars/sheets only. */

:root {
  color-scheme: dark;
  --bg: #000;
  --card: #1c1c1e;
  --card-raised: #2c2c2e;
  --fill: rgba(118, 118, 128, 0.2);
  --fill-strong: rgba(118, 118, 128, 0.32);
  --sep: rgba(84, 84, 88, 0.6);
  --text: #f2f2f7;
  --text-2: rgba(235, 235, 245, 0.62);
  --text-3: rgba(235, 235, 245, 0.34);
  --blue: #0a84ff;
  --green: #30d158;
  --red: #ff453a;
  --orange: #ff9f0a;
  --yellow: #ffd60a;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --glass-bg: rgba(30, 30, 32, 0.68);
  --glass-line: rgba(255, 255, 255, 0.09);
  --segment-thumb: #48484a;
  --segment-thumb-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
  --spring: cubic-bezier(0.3, 0.7, 0, 1);
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-raised: #e5e5ea;
  --fill: rgba(118, 118, 128, 0.12);
  --fill-strong: rgba(118, 118, 128, 0.2);
  --sep: rgba(60, 60, 67, 0.29);
  --text: #000;
  --text-2: rgba(60, 60, 67, 0.6);
  --text-3: rgba(60, 60, 67, 0.3);
  --blue: #007aff;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --yellow: #ffcc00;
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-line: rgba(0, 0, 0, 0.08);
  --segment-thumb: #fff;
  --segment-thumb-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

a { -webkit-tap-highlight-color: transparent; }

img { -webkit-user-drag: none; }

/* ---------- Navigation bar ---------- */

.nav-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: calc(10px + var(--safe-top)) max(12px, var(--safe-right)) 10px max(12px, var(--safe-left));
}

.nav-inner {
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 1050px;
  margin: 0 auto;
  padding: 8px 10px;
  border-radius: 26px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: saturate(190%) blur(30px);
  backdrop-filter: saturate(190%) blur(30px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.42), inset 0 0 0 1px var(--glass-line);
}

.nav-inner::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0) 46%);
  pointer-events: none;
}

.token-field {
  display: flex;
  align-items: center;
  flex: 1 1 150px;
  min-width: 0;
  max-width: none;
  height: 44px;
  border-radius: 999px;
  background: var(--fill);
  transition: box-shadow 0.18s ease, background 0.18s ease;
}

.token-field:focus-within {
  background: var(--fill-strong);
  box-shadow: inset 0 0 0 1.5px var(--blue);
}

.token-field input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 4px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.22em;
}

.token-field input::placeholder {
  color: var(--text-3);
  letter-spacing: 0.06em;
}

.icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.icon-btn:hover { background: var(--fill); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }

.token-eye { width: 42px; height: 44px; border-radius: 999px 0 0 999px; }
.token-eye svg { width: 22px; height: 16px; }

.season-btn {
  flex: none;
  height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--fill);
  color: var(--blue);
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.12s ease;
}

.season-btn:hover { background: var(--fill-strong); }
.season-btn:active { transform: scale(0.97); }
.season-btn:disabled { opacity: 0.45; cursor: wait; }

.btn-connect {
  flex: none;
  height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.15s ease, transform 0.12s ease;
}

.btn-connect:hover { opacity: 0.9; }
.btn-connect:active { transform: scale(0.97); opacity: 0.8; }
.btn-connect.is-scanning { opacity: 0.55; pointer-events: none; }

.settings-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linejoin: round;
}

/* ---------- Toast (in-app banner) ---------- */

.status-toast {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(calc(100vw - 24px), 420px);
  min-height: 48px;
  padding: 10px 10px 10px 16px;
  transform: translateX(-50%);
  border-radius: 18px;
  background: rgba(44, 44, 46, 0.9);
  -webkit-backdrop-filter: saturate(190%) blur(30px);
  backdrop-filter: saturate(190%) blur(30px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.07), inset 0 0 0 1px var(--glass-line);
  color: var(--text);
  font-size: 14px;
  transition: opacity 0.26s var(--spring), transform 0.26s var(--spring);
}

.status-toast.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
}

.status-toast.toast-invalid {
  background: rgba(66, 27, 29, 0.92);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 69, 58, 0.35);
}

.status-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.toast-invalid .status-dot { background: var(--red); }

#toastText { flex: 1; min-width: 0; }

.toast-close {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0 0 2px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-3);
  font-size: 20px;
  line-height: 1;
}

.toast-close:hover { background: var(--fill); color: var(--text); }

.toast-progress { display: none; }

/* ---------- Settings sheet ---------- */

.settings-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 70;
  width: 240px;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(44, 44, 46, 0.94);
  -webkit-backdrop-filter: saturate(190%) blur(30px);
  backdrop-filter: saturate(190%) blur(30px);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.07), inset 0 0 0 1px var(--glass-line);
  animation: popIn 0.2s var(--spring);
  transform-origin: top right;
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.settings-popover[hidden] { display: none; }

.popover-title {
  margin: 0 0 12px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  font-size: 15px;
}

/* iOS segmented control */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 2px;
  border-radius: 10px;
  background: var(--fill);
}

.segment {
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.18s var(--spring), box-shadow 0.18s var(--spring);
}

.segment[aria-pressed="true"] {
  background: var(--segment-thumb);
  box-shadow: var(--segment-thumb-shadow);
  font-weight: 600;
}

.popover-title-spaced { margin-top: 16px; }

/* iOS switch */
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 16px;
  background: var(--fill-strong);
  cursor: pointer;
  transition: background 0.2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease;
}

.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }

/* ---------- Page ---------- */

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px max(16px, var(--safe-right)) calc(104px + var(--safe-bottom)) max(16px, var(--safe-left));
}

.page-head { margin: 6px 0 22px; }

.large-title {
  margin: 0 0 4px;
  font-size: clamp(30px, 5.5vw, 38px);
  font-weight: 700;
  letter-spacing: -0.022em;
  line-height: 1.1;
}

.page-sub {
  margin: 0;
  color: var(--text-2);
  font-size: 15px;
}

.season-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--fill);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  vertical-align: 1px;
}

/* ---------- Grouped board ---------- */

.board {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
}

@media (min-width: 980px) {
  .board { grid-template-columns: 1fr 1fr; align-items: start; }
}

.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 8px;
}

.group-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot-ally { background: var(--blue); }
.dot-enemy { background: var(--red); }

.group-count {
  color: var(--text-3);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.list {
  overflow: hidden;
  border-radius: 16px;
  background: var(--card);
}

.list > * + * { border-top: 1px solid var(--sep); }

.list-empty {
  padding: 22px 16px;
  color: var(--text-3);
  font-size: 14px;
  text-align: center;
}

/* Player row */
.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 11px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background 0.15s ease;
}

.player-row:hover { background: rgba(118, 118, 128, 0.09); }
.player-row:active { background: rgba(118, 118, 128, 0.16); }

.player-row.row-pulse { animation: rowPulse 1.1s ease; }

@keyframes rowPulse {
  0%, 100% { background: transparent; }
  30% { background: rgba(10, 132, 255, 0.14); }
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--card-raised);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-fallback {
  color: var(--text-2);
  font-size: 16px;
  font-weight: 600;
}

.player-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.player-name {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.badge {
  flex: none;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--fill);
  color: var(--text-2);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.player-sub {
  overflow: hidden;
  color: var(--text-2);
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.player-win {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  flex: none;
  text-align: right;
}

.win-value {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.win-record {
  color: var(--text-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chevron {
  flex: none;
  width: 8px;
  height: 8px;
  margin-left: 2px;
  border-right: 1.6px solid var(--text-3);
  border-bottom: 1.6px solid var(--text-3);
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
}

.player-row[aria-expanded="true"] .chevron { transform: rotate(45deg); }

/* Expanded detail */
.player-detail {
  padding: 2px 14px 16px 66px;
  animation: detailIn 0.24s var(--spring);
}

.player-detail[hidden] { display: none; }

@keyframes detailIn {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: translateY(0); }
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 20px;
  margin: 0;
}

.detail-item { min-width: 0; }

.detail-item dt {
  margin: 0 0 2px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.detail-item dd {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  margin: 0;
  color: var(--text);
  font-size: 14px;
  word-break: break-word;
}

.hicon {
  flex: none;
  border-radius: 5px;
  background: var(--card-raised);
  object-fit: cover;
}

.stars {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--yellow);
}

.star-ico {
  flex: none;
  color: var(--yellow);
  vertical-align: -1px;
}

.star-line {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
}

.player-sub .hicon {
  margin-right: 3px;
  vertical-align: -2px;
  background: transparent;
}

/* Compact density */
.page.compact-mode .player-row { min-height: 52px; padding: 7px 14px; }
.page.compact-mode .avatar { width: 32px; height: 32px; }
.page.compact-mode .player-name { font-size: 15px; }
.page.compact-mode .player-sub { font-size: 12px; }

/* ---------- Footer ---------- */

.page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 26px;
  padding: 0 6px;
  color: var(--text-3);
  font-size: 13px;
}

.footer-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--blue);
  font-weight: 500;
  text-decoration: none;
}

.footer-link .chevron {
  border-color: var(--blue);
  width: 6px;
  height: 6px;
}

/* ---------- Floating tab bar ---------- */

.tab-bar {
  position: fixed;
  left: 50%;
  bottom: calc(10px + var(--safe-bottom));
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
  transform: translateX(-50%);
  border-radius: 26px;
  background: var(--glass-bg);
  -webkit-backdrop-filter: saturate(190%) blur(30px);
  backdrop-filter: saturate(190%) blur(30px);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.07), inset 0 0 0 1px var(--glass-line);
}

.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 44px;
  padding: 0 18px;
  border-radius: 20px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  transition: color 0.18s ease, background 0.18s ease, transform 0.12s ease;
}

.tab svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--blue);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.tab:active { transform: scale(0.97); }

/* ---------- Empty state ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52vh;
  padding: 40px 20px;
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 6px;
  border-radius: 50%;
  background: var(--card);
  color: var(--text-2);
}

.empty-icon svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.empty-state p {
  max-width: 320px;
  margin: 0;
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.45;
}

/* ================= Tactical Map ================= */

body.map-live {
  overflow: hidden;
  background: #050606;
}

body.map-live .nav-bar { display: none; }

.map-fullscreen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #050606;
}

.map-stage {
  position: relative;
  width: 100%;
  max-width: 760px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 18px;
  background: #0c0d0d;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.map-fullscreen .map-stage {
  width: 100vmax;
  height: 100vmax;
  max-width: none;
  aspect-ratio: auto;
  border-radius: 0;
  box-shadow: none;
}

.map-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.map-stage.is-flipped .map-img { transform: rotate(180deg); }

.map-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
}

/* HUD */
.map-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) max(10px, var(--safe-right)) 0 max(10px, var(--safe-left));
  pointer-events: none;
}

.map-hud-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  pointer-events: auto;
}

.map-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  background: rgba(28, 28, 30, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 0 0 1px var(--glass-line);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.map-status .status-dot { width: 7px; height: 7px; background: var(--text-3); }

.map-status.is-live { color: #c9f7e9; }
.map-status.is-live .status-dot { background: var(--green); }

.map-status.is-stale { color: #ffe1a8; }
.map-status.is-stale .status-dot { background: var(--orange); }

.map-status.is-off { color: var(--text-2); }

.map-status.season-status { color: var(--text-2); font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; }
.map-status.season-status .status-dot { background: var(--blue); }

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 13px;
  border: 0;
  border-radius: 999px;
  background: rgba(28, 28, 30, 0.72);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 0 0 1px var(--glass-line);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.chip:hover { color: var(--text); }
.chip:active { transform: scale(0.96); }

.chip input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.chip:has(input:checked) {
  background: rgba(10, 132, 255, 0.26);
  color: #b9dbff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.1), inset 0 0 0 1px rgba(10, 132, 255, 0.4);
}

.chip.icon-chip {
  width: 36px;
  padding: 0;
}

.chip.icon-chip svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chip[aria-pressed="false"] { opacity: 0.55; }

/* HUD collapse */
.map-hud-group > * {
  transition: opacity 0.24s var(--spring), transform 0.24s var(--spring);
}

.map-hud.hud-collapsed .map-hud-group > *:not(#hudToggle) {
  opacity: 0;
  visibility: hidden;
  transform: scale(0.9);
  pointer-events: none;
  transition: opacity 0.24s var(--spring), transform 0.24s var(--spring), visibility 0s 0.24s;
}

#hudToggle svg { transition: transform 0.28s var(--spring); }
.map-hud.hud-collapsed #hudToggle { opacity: 1; }
.map-hud.hud-collapsed #hudToggle svg { transform: rotate(180deg); }

/* Markers */
.mk {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 5;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.65));
  transition: left 0.3s var(--spring), top 0.3s var(--spring);
}

.mk-orb {
  position: relative;
  width: clamp(28px, 3.6vmin, 42px);
  height: clamp(28px, 3.6vmin, 42px);
  padding: 3px;
  border-radius: 50%;
  background: conic-gradient(from -90deg, #30d158 calc(var(--hp, 0) * 1%), rgba(12, 14, 14, 0.72) 0);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
}

.mk-orb img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: #0e1010;
}

.mk-enemy .mk-orb {
  background: conic-gradient(from -90deg, #ff453a calc(var(--hp, 0) * 1%), rgba(12, 14, 14, 0.72) 0);
}

.mk-monster .mk-orb {
  width: clamp(22px, 2.8vmin, 32px);
  height: clamp(22px, 2.8vmin, 32px);
  background: conic-gradient(from -90deg, #ff9f0a calc(var(--hp, 0) * 1%), rgba(12, 14, 14, 0.72) 0);
}

.mk-label {
  max-width: 100px;
  margin-top: 3px;
  padding: 2px 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(28, 28, 30, 0.78);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: var(--text);
  font-size: 10px;
  line-height: 14px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mk-monster .mk-label { color: #ffd9a3; font-size: 9px; }

/* Side sheet */
.map-fullscreen .map-side {
  position: absolute;
  top: calc(56px + var(--safe-top));
  right: max(10px, var(--safe-right));
  bottom: calc(10px + var(--safe-bottom));
  z-index: 25;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 236px;
  overflow: auto;
  scrollbar-width: none;
  transition: transform 0.32s var(--spring), opacity 0.32s var(--spring);
}

.map-fullscreen .map-side::-webkit-scrollbar { display: none; }

.map-fullscreen .map-side.is-hidden {
  transform: translateX(calc(100% + 20px));
  opacity: 0;
  pointer-events: none;
}

.map-side-grabber { display: none; }

.map-card {
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(28, 28, 30, 0.78);
  -webkit-backdrop-filter: saturate(190%) blur(30px);
  backdrop-filter: saturate(190%) blur(30px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 0 0 1px var(--glass-line);
}

.map-card .popover-kicker {
  margin: 0 0 8px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.map-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 238px;
  overflow: auto;
  scrollbar-width: none;
}

.map-fullscreen .map-list { max-height: none; }
.map-list::-webkit-scrollbar { display: none; }

.map-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 52px 32px;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
}

.map-row img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--card-raised);
  object-fit: cover;
}

.map-row .mk-ring {
  display: block;
  width: 26px;
  height: 26px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--card-raised);
}

.map-row b {
  overflow: hidden;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.map-row.is-ally b { color: #a9c6ff; }
.map-row.is-enemy b { color: #ffb3ae; }

.map-row-hp {
  display: block;
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(118, 118, 128, 0.28);
}

.map-row-hp i {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--green);
}

.map-row.is-enemy .map-row-hp i { background: var(--red); }
.map-row.is-monster .map-row-hp i { background: var(--orange); }

.map-row em {
  color: var(--text-3);
  font-size: 11px;
  font-style: normal;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.map-empty { color: var(--text-3); font-size: 13px; }

/* ---------- Light appearance surfaces ---------- */

html[data-theme="light"] .nav-inner,
html[data-theme="light"] .tab-bar {
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.12), inset 0 0 0 1px var(--glass-line);
}

html[data-theme="light"] .status-toast {
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 0 0 1px var(--glass-line);
}

html[data-theme="light"] .status-toast.toast-invalid {
  background: rgba(255, 241, 240, 0.95);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.14), inset 0 0 0 1px rgba(255, 59, 48, 0.35);
}

html[data-theme="light"] .toast-invalid #toastText { color: #b3261e; }

html[data-theme="light"] .settings-popover {
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 0 0 1px var(--glass-line);
}

html[data-theme="light"] .tab.is-active {
  background: rgba(0, 0, 0, 0.06);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.04);
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .nav-bar { padding-left: max(10px, var(--safe-left)); padding-right: max(10px, var(--safe-right)); }
  .nav-inner { gap: 8px; padding: 8px; border-radius: 24px; }
  .token-field { flex: 1 1 120px; }
  .season-btn { padding: 0 13px; font-size: 13px; }
  .btn-connect { padding: 0 15px; }

  .map-fullscreen .map-side {
    left: max(10px, var(--safe-left));
    right: max(10px, var(--safe-right));
    top: auto;
    bottom: calc(10px + var(--safe-bottom));
    width: auto;
    max-height: 44vh;
    padding: 8px;
    border-radius: 22px;
    background: rgba(28, 28, 30, 0.86);
    -webkit-backdrop-filter: saturate(180%) blur(28px);
    backdrop-filter: saturate(180%) blur(28px);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.07);
  }

  .map-fullscreen .map-side.is-hidden {
    transform: translateY(calc(100% + 20px));
  }

  .map-side-grabber {
    display: block;
    width: 36px;
    height: 5px;
    margin: 2px auto 6px;
    border-radius: 3px;
    background: rgba(235, 235, 245, 0.3);
  }

  .map-fullscreen .map-card {
    background: transparent;
    box-shadow: none;
    padding: 8px 10px;
  }
}

@media (max-width: 480px) {
  .token-field { flex: 1 1 calc(100% - 96px); }
  .btn-connect { margin-left: auto; }
}

@media (max-width: 420px) {
  .detail-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}