:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --bg-soft: #eef2f7;
  --panel: #ffffff;
  --panel-strong: #fefefe;
  --text: #111827;
  --muted: #667085;
  --line: #d8dee8;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --good: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1117;
  --bg-soft: #171b24;
  --panel: #1f2430;
  --panel-strong: #252b38;
  --text: #f4f7fb;
  --muted: #a7b0c0;
  --line: #323a49;
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
  --good: #34d399;
  --warn: #f59e0b;
  --bad: #f87171;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.16), transparent 34rem),
    linear-gradient(135deg, var(--bg), var(--bg-soft));
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
select,
input,
textarea {
  border-radius: 8px;
}

button {
  border: 0;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
  padding: 0.78rem 1rem;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover {
  background: var(--accent-strong);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.24);
  transform: translateY(-2px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  padding: 0.78rem 0.85rem;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
}

label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.app-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 22px;
}

.topbar h1,
.section-title h2,
.queue-card h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(2rem, 5vw, 4.5rem);
  line-height: 0.95;
}

.eyebrow {
  margin: 0 0 0.4rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 16px;
}

.panel {
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.match-panel {
  grid-column: span 2;
}

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

.title-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title h2 {
  font-size: 1.25rem;
}

.status-pill,
.mode-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel-strong);
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0.35rem 0.7rem;
  white-space: nowrap;
}

.icon-button {
  width: 46px;
  height: 46px;
  padding: 0;
  border-radius: 999px;
  font-size: 1.1rem;
}

.info-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--accent);
  font-weight: 900;
}

.info-button:hover {
  color: white;
}

.inline-form,
.duel-form {
  display: grid;
  gap: 10px;
}

.local-login {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.helper-text {
  min-height: 1.3rem;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.info-dialog {
  width: min(520px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 18px;
}

.info-dialog::backdrop {
  background: rgba(15, 17, 23, 0.62);
}

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

.dialog-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.steps-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text);
}

.steps-list li {
  line-height: 1.45;
}

.callback-box {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  margin-top: 14px;
  padding: 12px;
}

.callback-box span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.callback-box code {
  overflow-wrap: anywhere;
  color: var(--accent);
  font-size: 0.84rem;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.profile-card,
.queue-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 16px;
  padding: 14px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--good));
  color: white;
  font-weight: 900;
  overflow: hidden;
  flex: 0 0 auto;
}

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

.avatar-small {
  width: 30px;
  height: 30px;
  font-size: 0.8rem;
}

.profile-card {
  justify-content: flex-start;
}

.muted,
#selectedModeMeta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.mini-list {
  margin-top: 16px;
}

.mini-list-title {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.profile-button,
.list-item,
.request-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  border-radius: 8px;
  margin-top: 8px;
  padding: 10px;
}

.profile-button {
  width: 100%;
  color: var(--text);
  background: var(--panel-strong);
  font-weight: 700;
  justify-content: flex-start;
}

.profile-button:hover {
  color: white;
}

.queue-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tab-button {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  color: var(--text);
  min-height: 46px;
}

.tab-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

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

.rank-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  border-radius: 8px;
  padding: 11px;
}

.rank {
  color: var(--accent);
  font-weight: 900;
}

.elo {
  font-weight: 900;
}

.match-card {
  border: 1px solid var(--line);
  background: var(--panel-strong);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}

.match-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding: 14px;
}

.versus {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  font-weight: 900;
}

.match-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 14px;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.score-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.score-box strong {
  display: block;
  font-size: 1.6rem;
  margin-top: 4px;
}

.winner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chat-box {
  display: grid;
  grid-template-rows: minmax(160px, 1fr) auto;
  gap: 10px;
}

.chat-log {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  overflow: auto;
  max-height: 220px;
}

.chat-message {
  margin-bottom: 8px;
}

.chat-message strong {
  color: var(--accent);
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.danger {
  background: var(--bad);
}

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.ghost:hover {
  color: white;
}

.notice {
  color: var(--warn);
  font-weight: 800;
}

@media (max-width: 980px) {
  .grid,
  .match-body {
    grid-template-columns: 1fr;
  }

  .match-panel {
    grid-column: span 1;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1240px);
    padding: 18px 0;
  }

  .topbar {
    align-items: flex-start;
  }

  .input-row,
  .chat-form,
  .queue-tabs {
    grid-template-columns: 1fr;
  }

  .queue-card,
  .match-header {
    align-items: stretch;
    flex-direction: column;
  }
}
