:root {
  --bg: #0f1419;
  --surface: #1a222d;
  --surface-elevated: #243040;
  --border: #2e3d52;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3dd6c8;
  --accent-dim: #2a9d92;
  --accent-glow: rgba(61, 214, 200, 0.35);
  --warning: #f0b429;
  --danger: #f07178;
  --self: #7c9cff;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(61, 214, 200, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(124, 156, 255, 0.08), transparent);
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(12px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  max-width: 480px;
  margin: 0 auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 24px;
}

.header__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.header__logo {
  font-size: 1.5rem;
  color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.header__title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header__subtitle {
  margin: 6px 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Profile */
.profile-panel {
  margin-bottom: 20px;
}

.profile-panel__label {
  display: block;
  margin: 0 0 8px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.profile-panel__input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
}

.profile-panel__input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.profile-panel__check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 12px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.4;
  cursor: pointer;
}

.profile-panel__check input {
  margin-top: 3px;
  accent-color: var(--accent);
}

.mode-badge {
  display: inline-block;
  margin-bottom: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: rgba(61, 214, 200, 0.12);
  border: 1px solid rgba(61, 214, 200, 0.25);
}

.mode-badge--off {
  color: var(--text-muted);
  background: var(--surface);
  border-color: var(--border);
}

.scan-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.permission-btn {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0 auto 12px;
  padding: 12px 20px;
  border: 2px solid var(--warning);
  border-radius: 12px;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--warning);
  background: rgba(240, 180, 41, 0.08);
  cursor: pointer;
}

.permission-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.permission-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.permission-btn[hidden] {
  display: none;
}

.ble-hint {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-muted);
  background: rgba(240, 180, 41, 0.1);
  border: 1px solid rgba(240, 180, 41, 0.35);
}

.ble-hint:empty {
  display: none;
}

.connect-btn {
  margin-top: 10px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.8125rem;
  font-family: inherit;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  width: 100%;
  max-width: 280px;
}

.connect-btn:hover:not(:disabled) {
  border-color: var(--accent-dim);
  color: var(--text);
}

.connect-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hint-code {
  font-size: 0.6875rem;
  color: var(--accent-dim);
  word-break: break-all;
}

/* Scan */
.scan-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.scan-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 28px;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--bg);
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  box-shadow: 0 4px 24px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.scan-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.scan-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.scan-btn--scanning .scan-btn__icon {
  animation: pulse-ring 1.2s ease-in-out infinite;
}

.scan-btn__icon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}

@keyframes pulse-ring {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.4);
    opacity: 0.5;
  }
}

.status {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
  min-height: 1.25em;
}

.status--active {
  color: var(--accent);
}

.status--error {
  color: var(--danger);
}

/* Arena */
.arena__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 16px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.arena__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.arena__track {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 4px;
  min-height: 200px;
  padding: 20px 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}

.arena__track::before {
  content: "";
  position: absolute;
  bottom: 48px;
  left: 12%;
  right: 12%;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--border) 15%,
    var(--accent-dim) 50%,
    var(--border) 85%,
    transparent
  );
  opacity: 0.6;
}

.player--self {
  flex-shrink: 0;
  z-index: 2;
  text-align: center;
  padding: 0 8px;
}

.arena__side {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 6px;
  min-width: 0;
  min-height: 120px;
}

.arena__side--left {
  flex-direction: row-reverse;
  justify-content: flex-start;
  padding-right: 4px;
}

.arena__side--right {
  justify-content: flex-start;
  padding-left: 4px;
}

.arena__side--empty::after {
  content: "—";
  color: var(--border);
  font-size: 0.75rem;
  align-self: center;
  width: 100%;
  text-align: center;
  opacity: 0.5;
}

/* Player card */
.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: player-in 0.45s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

@keyframes player-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.85);
  }
}

.player__ring {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: width 0.35s ease, height 0.35s ease, box-shadow 0.35s ease;
}

.player__ring--self {
  width: 72px;
  height: 72px;
  background: radial-gradient(circle, rgba(124, 156, 255, 0.25), transparent 70%);
  box-shadow: 0 0 0 3px var(--self), 0 0 20px rgba(124, 156, 255, 0.3);
}

.player__ring--near {
  box-shadow: 0 0 0 2px var(--accent), 0 0 16px var(--accent-glow);
}

.player__ring--mid {
  box-shadow: 0 0 0 2px var(--warning);
  opacity: 0.95;
}

.player__ring--far {
  box-shadow: 0 0 0 2px var(--border);
  opacity: 0.75;
}

.player__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-elevated);
  border: 2px solid var(--border);
}

.player__ring--self .player__avatar {
  background: linear-gradient(145deg, #4a6fd4, #7c9cff);
  border-color: var(--self);
  font-size: 1.125rem;
}

.player__name {
  margin: 8px 0 0;
  font-size: 0.75rem;
  font-weight: 600;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player__meta {
  margin: 2px 0 0;
  font-size: 0.625rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.arena__hint {
  margin: 12px 0 0;
  font-size: 0.75rem;
  line-height: 1.45;
  color: var(--text-muted);
  text-align: center;
}

/* Footer */
.footer {
  margin-top: auto;
  padding-top: 20px;
}

.footer__note {
  margin: 0;
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

/* Empty state */
.arena__empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
}

.main {
  flex: 1;
}
