:root {
  --bg: #0b0f16;
  --bg-main: #10151f;
  --sidebar: #0d111a;
  --card: #161c28;
  --card-border: rgba(148, 163, 184, 0.12);
  --text: #e8eef7;
  --muted: #8b97ab;
  --purple: #7c5cff;
  --purple-dim: rgba(124, 92, 255, 0.22);
  --green: #22c55e;
  --blue: #38bdf8;
  --red: #f43f5e;
  --orange: #fb923c;
  --yellow: #facc15;
  --calm: #22c55e;
  --focused: #38bdf8;
  --excited: #fb923c;
  --stressed: #facc15;
  --frustrated: #f43f5e;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sidebar-w: 220px;
  --sidebar-collapsed: 72px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #0d111a 0%, #0a0e16 100%);
  border-right: 1px solid var(--card-border);
  padding: 1rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
  transition: width 0.2s ease;
}

.app.collapsed .sidebar { width: var(--sidebar-collapsed); }
.app.collapsed .nav-item span { display: none; }
.app.collapsed .nav-item { justify-content: center; padding: 0.85rem; }

.sidebar-toggle {
  width: 42px;
  height: 42px;
  margin: 0 0 1.25rem 0.35rem;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  padding: 8px;
}

.sidebar-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: #c7d0df;
  border-radius: 2px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  color: var(--muted);
  text-decoration: none;
  border-radius: 12px;
  font-weight: 500;
  font-size: 0.95rem;
  transition: background 0.15s, color 0.15s;
  position: relative;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255,255,255,0.04);
}

.nav-item.active {
  color: #fff;
  background: var(--purple-dim);
  box-shadow: inset 3px 0 0 var(--purple);
}

/* Main */
.main {
  flex: 1;
  min-width: 0;
  padding: 1.25rem 1.5rem 2rem;
  background:
    radial-gradient(900px 400px at 80% -10%, rgba(124, 92, 255, 0.12), transparent 55%),
    radial-gradient(700px 360px at 10% 0%, rgba(34, 197, 94, 0.06), transparent 50%),
    var(--bg-main);
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.header-title h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-title p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.25);
  font-size: 0.88rem;
  font-weight: 600;
}

.live-badge.off {
  background: rgba(148, 163, 184, 0.08);
  border-color: rgba(148, 163, 184, 0.2);
  color: var(--muted);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: pulse 1.6s infinite;
}

.live-badge.off .pulse-dot {
  background: #64748b;
  animation: none;
  box-shadow: none;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 10px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.clock {
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.model-chip {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: rgba(124, 92, 255, 0.15);
  border: 1px solid rgba(124, 92, 255, 0.35);
  color: #c4b5fd;
  cursor: pointer;
}

.model-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.95rem;
  margin: 1rem 0 1.25rem;
}

.model-card {
  position: relative;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 1.1rem 1rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}

.model-card:hover {
  border-color: rgba(124, 92, 255, 0.45);
  transform: translateY(-2px);
}

.model-card.selected {
  border-color: var(--purple);
  background: rgba(124, 92, 255, 0.12);
  box-shadow: 0 0 0 1px rgba(124, 92, 255, 0.25);
}

.model-card .mc-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.model-card .mc-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.model-card .mc-short {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.model-card .mc-acc {
  font-family: var(--mono);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--green);
  line-height: 1;
}

.model-card .mc-acc-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.model-card .mc-desc {
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.45;
  margin: 0.75rem 0 0.85rem;
  min-height: 3.6em;
}

.model-card .mc-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}

.model-card .mc-local {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.55rem;
}

.model-card .mc-check {
  position: absolute;
  top: 0.85rem;
  right: 0.85rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--card-border);
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  color: transparent;
}

.model-card.selected .mc-check {
  background: var(--purple);
  border-color: var(--purple);
  color: #fff;
}

.acc-best { color: var(--green); font-weight: 700; }

.model-meta h3 {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
}

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

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.participant-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: -0.35rem 0 1rem;
  padding: 0.75rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--card-border);
  border-radius: 12px;
}

.participant-form.hidden { display: none; }

.participant-form input,
.participant-form select {
  min-width: 120px;
}

select, input, button {
  font: inherit;
  color: var(--text);
  background: #1a2230;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
}

button { cursor: pointer; }

.btn-primary {
  background: linear-gradient(135deg, #7c5cff, #5b3fd4);
  border-color: transparent;
  font-weight: 600;
}

.btn-ghost:hover, .btn-primary:hover { filter: brightness(1.08); }

.view { display: none; }
.view.active { display: block; }

/* Status cards */
.status-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
  margin-bottom: 0.95rem;
}

.status-card {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 0.95rem 1rem;
}

.status-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.status-icon svg { width: 22px; height: 22px; }
.status-icon.user { background: rgba(124, 92, 255, 0.15); color: #a78bfa; }
.status-icon.game { background: rgba(56, 189, 248, 0.12); color: #38bdf8; }
.status-icon.link { background: rgba(34, 197, 94, 0.12); color: #22c55e; }
.status-icon.batt { background: rgba(250, 204, 21, 0.12); color: #facc15; }

.status-label { font-size: 0.88rem; line-height: 1.35; }
.status-sub { font-size: 0.8rem; color: var(--muted); margin-top: 0.2rem; }
.status-card-body { min-width: 0; flex: 1; }
.rank-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.rank-select-wrap select {
  font-size: 0.78rem;
  padding: 0.25rem 0.45rem;
  border-radius: 8px;
  background: #1a2230;
  color: var(--text);
  border: 1px solid var(--card-border);
  max-width: 100%;
}
.ok { color: var(--green); }

/* Content grid */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 0.95rem;
}

.content-grid .span-full {
  grid-column: 1 / -1;
}

.card {
  background: linear-gradient(180deg, #182030 0%, #141b28 100%);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 1rem 1.1rem 1.15rem;
  min-width: 0;
}

.card.full { width: 100%; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}

.card-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.card-link {
  color: var(--purple);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}

.muted { color: var(--muted); font-weight: 500; }

/* Emotion card */
.emotion-hero {
  text-align: center;
  padding: 0.5rem 0 1rem;
}

.emotion-face {
  width: 110px;
  height: 110px;
  margin: 0 auto 0.75rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 3.4rem;
  background: radial-gradient(circle at 40% 35%, rgba(34, 197, 94, 0.35), rgba(34, 197, 94, 0.08) 60%, transparent 70%);
  box-shadow: 0 0 40px rgba(34, 197, 94, 0.18);
  transition: box-shadow 0.3s, background 0.3s;
}

.emotion-face.focused { background: radial-gradient(circle at 40% 35%, rgba(56,189,248,0.35), transparent 70%); box-shadow: 0 0 40px rgba(56,189,248,0.2); }
.emotion-face.excited { background: radial-gradient(circle at 40% 35%, rgba(251,146,60,0.35), transparent 70%); box-shadow: 0 0 40px rgba(251,146,60,0.2); }
.emotion-face.stressed { background: radial-gradient(circle at 40% 35%, rgba(250,204,21,0.35), transparent 70%); box-shadow: 0 0 40px rgba(250,204,21,0.2); }
.emotion-face.frustrated { background: radial-gradient(circle at 40% 35%, rgba(244,63,94,0.35), transparent 70%); box-shadow: 0 0 40px rgba(244,63,94,0.2); }
.emotion-face.relaxed, .emotion-face.calm { background: radial-gradient(circle at 40% 35%, rgba(34,197,94,0.35), transparent 70%); box-shadow: 0 0 40px rgba(34,197,94,0.2); }

.emotion-name {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.emotion-name.relaxed, .emotion-name.calm { color: var(--calm); }
.emotion-name.focused { color: var(--focused); }
.emotion-name.excited { color: var(--excited); }
.emotion-name.stressed { color: var(--stressed); }
.emotion-name.frustrated { color: var(--frustrated); }

.emotion-conf {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.conf-bar {
  width: min(260px, 80%);
  height: 8px;
  margin: 0.75rem auto 0;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}

.conf-bar span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  transition: width 0.4s ease;
}

.emotion-probs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  border-top: 1px solid var(--card-border);
  padding-top: 0.85rem;
}

.prob-item {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
}

.prob-item .emoji { font-size: 1.25rem; display: block; margin-bottom: 0.2rem; }
.prob-item strong { display: block; color: var(--text); font-size: 0.82rem; margin-top: 0.15rem; }

/* Mini signals */
.mini-signal {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.75rem;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

.mini-signal:last-child { border-bottom: 0; }

.mini-label { display: block; color: var(--muted); font-size: 0.78rem; margin-bottom: 0.2rem; }
.mini-value { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.mini-value.hr { color: var(--red); }
.mini-value.gsr { color: var(--blue); }
.mini-value.temp { color: var(--green); }

.mini-chart { height: 56px; }

.chart-box { height: 240px; position: relative; }
.chart-box.tall { height: 340px; }

/* Performance */
.perf-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.perf-item {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 0.65rem 0.55rem;
}

.pi-icon { font-size: 1.05rem; }
.pi-val { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.pi-lab { font-size: 0.72rem; color: var(--muted); }

.events-title {
  margin: 0 0 0.55rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

.events {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 160px;
  overflow: auto;
}

.events li {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.45rem 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  font-size: 0.85rem;
}

.events .ts {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  min-width: 72px;
}

.live-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.live-summary > div {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 0.75rem;
}

.live-summary .muted { display: block; font-size: 0.75rem; margin-bottom: 0.25rem; }
.live-summary strong { font-size: 1.15rem; text-transform: capitalize; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.split h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
  margin-bottom: 0.85rem;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 0.65rem 0.4rem;
  border-bottom: 1px solid var(--card-border);
}

.data-table th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel-copy { color: var(--muted); line-height: 1.5; }
.settings-list { color: var(--muted); line-height: 1.8; }
.settings-list code, .panel-copy code {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: rgba(255,255,255,0.06);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  color: #c4b5fd;
}

@media (max-width: 1100px) {
  .status-row { grid-template-columns: 1fr 1fr; }
  .content-grid { grid-template-columns: 1fr; }
  .perf-stats { grid-template-columns: repeat(3, 1fr); }
  .emotion-probs { grid-template-columns: repeat(5, 1fr); }
  .split, .live-summary, .form-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar {
    position: relative;
    height: auto;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem;
  }
  .sidebar-nav { flex-direction: row; overflow-x: auto; flex: 1; }
  .nav-item span { display: none; }
  .nav-item { padding: 0.65rem; }
  .status-row, .perf-stats, .emotion-probs, .split, .live-summary, .form-grid {
    grid-template-columns: 1fr;
  }
  .mini-signal { grid-template-columns: 1fr; }
}
