:root {
  --bg: #070b11;
  --bg2: #0c121a;
  --card: #111925;
  --ink: #e8eff7;
  --muted: #99abbd;
  --teal: #67dbc9;
  --amber: #f2b56b;
  --red: #f08d8d;
  --line: rgba(255, 255, 255, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(103, 219, 201, 0.15), transparent 58%),
    radial-gradient(900px 500px at 90% 8%, rgba(242, 181, 107, 0.1), transparent 56%),
    linear-gradient(180deg, var(--bg), var(--bg2));
  min-height: 100vh;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 20px 80px;
  display: grid;
  gap: 16px;
}

.hero {
  display: grid;
  gap: 8px;
}

.back-link {
  color: var(--teal);
  text-decoration: none;
  width: fit-content;
}

h1, h2, h3 {
  margin: 0;
  font-family: "Poppins", system-ui, sans-serif;
}

h1 {
  font-size: clamp(28px, 4.2vw, 44px);
}

.lead {
  margin: 0;
  color: var(--muted);
  max-width: 70ch;
}

.panel {
  background: linear-gradient(180deg, rgba(17, 25, 37, 0.94), rgba(17, 25, 37, 0.78));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.controls label {
  font-size: 13px;
  color: var(--muted);
}

.row {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.quality-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: auto minmax(240px, 1fr);
  align-items: center;
  gap: 10px;
}

.quality-row label {
  color: var(--muted);
  font-size: 13px;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  font: inherit;
}

select {
  width: 100%;
  border: 1px solid rgba(103, 219, 201, 0.28);
  border-radius: 10px;
  padding: 10px 40px 10px 12px;
  background-color: rgba(15, 23, 34, 0.92);
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 20 20'%3E%3Cpath fill='%2367dbc9' d='M5.8 7.5 10 11.7l4.2-4.2 1.4 1.4-5.6 5.6-5.6-5.6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat, no-repeat;
  background-position: center, right 12px center;
  background-size: auto, 16px 16px;
  color: var(--ink);
  font: inherit;
  color-scheme: dark;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

select:hover {
  border-color: rgba(103, 219, 201, 0.45);
}

select:focus {
  outline: none;
  border-color: rgba(103, 219, 201, 0.62);
  box-shadow: 0 0 0 3px rgba(103, 219, 201, 0.14);
}

select:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  border-color: rgba(255, 255, 255, 0.14);
}

select option,
select optgroup {
  background-color: #0f1722;
  color: #e8eff7;
}

select option:checked {
  background-color: #1b2a3b;
  color: #ffffff;
}

button {
  border: 1px solid rgba(103, 219, 201, 0.35);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(103, 219, 201, 0.12);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  border-color: rgba(103, 219, 201, 0.55);
}

.status {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}

.oauth-block {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.oauth-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.oauth-head strong {
  font-size: 13px;
  color: #d3deea;
}

.oauth-actions {
  display: inline-flex;
  gap: 8px;
}

.oauth-login-btn {
  border: 1px solid rgba(145, 70, 255, 0.7);
  background: linear-gradient(180deg, rgba(145, 70, 255, 0.95), rgba(124, 58, 237, 0.92));
  color: #ffffff;
  box-shadow: 0 8px 22px rgba(145, 70, 255, 0.32);
}

.oauth-login-btn:hover {
  border-color: rgba(186, 154, 255, 0.95);
}

.oauth-login-btn:disabled {
  cursor: default;
  opacity: 0.92;
  border-color: rgba(145, 70, 255, 0.45);
  background: rgba(145, 70, 255, 0.28);
  box-shadow: none;
}

.oauth-logout-btn {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.05);
  color: #d3deea;
}

.oauth-logout-btn:hover {
  border-color: rgba(255, 255, 255, 0.32);
}

.oauth-list {
  margin-top: 8px;
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}

.oauth-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.oauth-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.oauth-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  flex: 0 0 auto;
}

.oauth-item .meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.oauth-item .meta .name {
  font-size: 13px;
  color: #e8eff7;
  font-weight: 600;
}

.oauth-item .meta .game {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 420px;
}

.oauth-empty {
  font-size: 13px;
  color: var(--muted);
}

.warn-text {
  color: var(--amber);
}

.ok-text {
  color: var(--teal);
}

.player-and-diagnosis {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 12px;
}

.player-shell {
  width: 100%;
  min-height: 340px;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
}

.player-shell > * {
  width: 100% !important;
  height: 100% !important;
}

.player-shell iframe {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.chat-signals {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.chat-signals-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-signals-head h3 {
  font-size: 14px;
  color: #d8e5f2;
}

.chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.chat-toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--teal);
}

.chat-signals-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  max-height: 154px;
  overflow-y: auto;
}

.chat-signals-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  padding: 7px 9px;
  font-size: 13px;
  color: #d3deea;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-meta {
  color: var(--muted);
  font-size: 11px;
  margin-right: 6px;
}

.chat-empty {
  color: var(--muted);
}

.diagnosis-panel {
  display: grid;
  align-content: start;
  gap: 10px;
}

.explain-block {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.explain-block h3 {
  font-size: 13px;
  color: var(--muted);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-weight: 600;
  margin: 0 0 6px;
}

.hint-list {
  margin: 0;
  padding-left: 18px;
  color: #d3deea;
  font-size: 14px;
  line-height: 1.45;
}

.badge {
  width: fit-content;
  border-radius: 999px;
  padding: 6px 10px;
  border: 1px solid;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.badge.good {
  color: var(--teal);
  border-color: rgba(103, 219, 201, 0.5);
  background: rgba(103, 219, 201, 0.12);
}

.badge.warn {
  color: var(--amber);
  border-color: rgba(242, 181, 107, 0.5);
  background: rgba(242, 181, 107, 0.12);
}

.badge.bad {
  color: var(--red);
  border-color: rgba(240, 141, 141, 0.5);
  background: rgba(240, 141, 141, 0.12);
}

.badge.neutral {
  color: var(--muted);
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.04);
}

.diagnosis-text {
  margin: 0;
  color: #d3deea;
  line-height: 1.5;
}

.confidence-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.confidence-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #d3deea;
  font-weight: 600;
}

.confidence-track {
  margin-top: 8px;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f08d8d 0%, #f2b56b 55%, #67dbc9 100%);
  transition: width 180ms ease;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.metrics-grid > .muted {
  grid-column: 1 / -1;
  margin: 0;
}

.metric {
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.metric.good {
  border-color: rgba(103, 219, 201, 0.45);
  box-shadow: 0 0 0 1px rgba(103, 219, 201, 0.16);
}

.metric.warn {
  border-color: rgba(242, 181, 107, 0.45);
  box-shadow: 0 0 0 1px rgba(242, 181, 107, 0.16);
}

.metric.bad {
  border-color: rgba(240, 141, 141, 0.45);
  box-shadow: 0 0 0 1px rgba(240, 141, 141, 0.16);
}

.metric h3 {
  font-size: 13px;
  color: var(--muted);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-weight: 500;
}

.value {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 600;
}

.metric.good .value {
  color: var(--teal);
}

.metric.warn .value {
  color: var(--amber);
}

.metric.bad .value {
  color: var(--red);
}

.metric-help {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.legend-panel h2 {
  font-size: 18px;
}

.legend-row {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.legend-chip {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border: 1px solid;
}

.legend-chip.good {
  color: var(--teal);
  border-color: rgba(103, 219, 201, 0.5);
  background: rgba(103, 219, 201, 0.12);
}

.legend-chip.warn {
  color: var(--amber);
  border-color: rgba(242, 181, 107, 0.5);
  background: rgba(242, 181, 107, 0.12);
}

.legend-chip.bad {
  color: var(--red);
  border-color: rgba(240, 141, 141, 0.5);
  background: rgba(240, 141, 141, 0.12);
}

.graphs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.advanced-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.kv {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.02);
  display: grid;
  gap: 4px;
}

.kv span {
  font-size: 12px;
  color: var(--muted);
}

.kv strong {
  font-size: 13px;
  color: #d7e4f2;
  font-weight: 600;
  word-break: break-word;
}

.na-value {
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px dotted rgba(153, 171, 189, 0.6);
  cursor: help;
}

.graph-card h3 {
  font-size: 14px;
  color: #d8e5f2;
}

.graph {
  width: 100%;
  height: 130px;
  display: block;
  margin-top: 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}

.sanity-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.metric-action-btn {
  margin-top: 10px;
  width: 100%;
}

.metric-inline-status {
  margin-top: 8px;
}

.muted {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 900px) {
  .player-and-diagnosis {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .wrap {
    padding: 20px 12px 60px;
  }

  .row {
    grid-template-columns: 1fr;
  }

  .quality-row {
    grid-template-columns: 1fr;
  }

  .player-shell {
    min-height: 260px;
  }
}
