:root {
  --bg: #e9e1fb;
  --surface: rgba(255, 255, 255, 0.62);
  --surface-elevated: rgba(255, 255, 255, 0.76);
  --surface-soft: rgba(255, 255, 255, 0.42);
  --border: rgba(71, 48, 119, 0.14);
  --border-bright: rgba(255, 255, 255, 0.82);
  --text: #2c2052;
  --muted: #746985;
  --twitch: #c62c4e;
  --twitch-hover: #a91e3e;
  --green: #28745a;
  --red: #b92749;
  --amber: #8a661e;
  --telegram: #229ed9;
  --shadow: 0 22px 55px rgba(80, 61, 133, 0.16);
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: "Manrope", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 84%, rgba(255, 254, 249, 0.96), rgba(244, 239, 255, 0.58) 18rem, transparent 27rem),
    radial-gradient(circle at 92% 25%, rgba(255, 254, 249, 0.96), rgba(255, 219, 224, 0.64) 17rem, transparent 27rem),
    linear-gradient(135deg, #e7defb 0%, #f4e8ef 50%, #efd5e1 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  filter: blur(2px);
  pointer-events: none;
}

body::before {
  width: 19rem;
  height: 19rem;
  right: -5rem;
  top: 9rem;
  background: radial-gradient(circle at 38% 30%, #fffef9, rgba(255, 219, 224, 0.78) 46%, rgba(189, 45, 77, 0.17) 73%);
}

body::after {
  width: 24rem;
  height: 24rem;
  left: -7.5rem;
  top: auto;
  bottom: -6rem;
  background: radial-gradient(circle at 38% 30%, #fffef9, rgba(244, 239, 255, 0.82) 46%, rgba(98, 79, 197, 0.16) 73%);
}

code {
  background: rgba(63, 42, 104, 0.08);
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
  font-size: 0.875em;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  margin: 0.25rem 0 0;
}

/* Header */
.topbar {
  background: rgba(255, 255, 255, 0.28);
  border-bottom: 1px solid rgba(255, 255, 255, 0.48);
  backdrop-filter: blur(18px) saturate(135%);
  -webkit-backdrop-filter: blur(18px) saturate(135%);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: none;
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  min-height: 66px;
  padding: 0.75rem 1.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-apple {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #bd2d4d;
  box-shadow: 0 7px 15px rgba(150, 18, 53, 0.22);
  animation: apple-spin 7s linear infinite;
  transform-origin: 50% 50%;
}

.brand-apple img {
  width: 19px;
  height: 19px;
  object-fit: contain;
}

@keyframes apple-spin {
  to {
    transform: rotate(360deg);
  }
}

.tabs {
  display: flex;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.42);
  padding: 0.25rem;
  border-radius: 999px;
  border: 0;
}

.tab-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 400;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.62);
}

.tab-btn.active {
  background: #bd2d4d;
  color: #fff;
  box-shadow: 0 7px 18px rgba(189, 45, 77, 0.24);
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.9rem;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border-bright);
}

.avatar-lg {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.25), 0 14px 28px rgba(60, 35, 120, 0.19);
}

.avatar-story-wrap {
  position: relative;
  width: fit-content;
  margin: 0 auto;
}

.avatar-apple {
  position: absolute;
  right: -12px;
  bottom: 7px;
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  background: #bd2d4d;
  box-shadow: 0 7px 16px rgba(137, 24, 55, 0.2);
  display: grid;
  place-items: center;
}

.avatar-apple img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

/* Main Container */
.container {
  max-width: 1180px;
  margin: 0 auto 4rem;
  padding: 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: relative;
  z-index: 1;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

#panel-welcome {
  min-height: 640px;
  display: grid;
  place-items: center;
  padding: 45px 24px 72px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px) saturate(125%);
  -webkit-backdrop-filter: blur(18px) saturate(125%);
}

.card h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Banners */
.alert-banner {
  background: rgba(185, 39, 73, 0.1);
  border: 1px solid rgba(185, 39, 73, 0.24);
  color: #7f1833;
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.alert-banner.success {
  background: rgba(40, 116, 90, 0.1);
  border-color: rgba(40, 116, 90, 0.25);
  color: #1d6049;
}

.setup-banner {
  background: rgba(231, 191, 99, 0.12);
  border: 1px solid rgba(231, 191, 99, 0.4);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  font-size: 0.92rem;
}

.setup-banner h3 {
  margin: 0 0 0.4rem;
  color: var(--amber);
  font-size: 1rem;
}

/* Welcome Card */
.welcome-stack {
  position: relative;
  width: min(100%, 700px);
}

.welcome-stack.has-invite {
  padding-bottom: 58px;
}

.welcome-card {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(187, 168, 225, 0.06), transparent 17%, transparent 83%, rgba(187, 168, 225, 0.06)),
    linear-gradient(145deg, rgba(255, 255, 255, 0.9), rgba(255, 250, 253, 0.62));
  border: 1px solid rgba(255, 255, 255, 0.88);
  border-radius: 28px 28px 18px 18px;
  padding: 38px 38px 78px;
  text-align: center;
  max-width: none;
  margin: 0;
  width: 100%;
  box-shadow:
    inset 13px 0 25px rgba(102, 76, 151, 0.04),
    inset -13px 0 25px rgba(195, 70, 119, 0.04),
    0 30px 70px rgba(76, 57, 126, 0.2);
  backdrop-filter: blur(21px) saturate(145%);
  -webkit-backdrop-filter: blur(21px) saturate(145%);
}

.welcome-card::before {
  content: none;
}

.welcome-card::after {
  content: none;
}

.welcome-card > * {
  position: relative;
  z-index: 1;
}

.welcome-card h1 {
  margin: 18px 0 10px;
  font-size: clamp(31px, 5vw, 45px);
  font-weight: 500;
  line-height: 1.06;
  letter-spacing: -0.045em;
}

.welcome-subtitle {
  color: var(--muted);
  max-width: 460px;
  margin: 0 auto;
  font-size: 0.94rem;
  line-height: 1.58;
}

.welcome-status {
  display: flex;
  align-items: center;
  width: fit-content;
  gap: 7px;
  margin: 16px auto 0;
  padding: 6px 10px;
  border: 1px solid rgba(74, 85, 184, 0.18);
  border-radius: 999px;
  color: #4a55b8;
  background: rgba(74, 85, 184, 0.08);
  font-size: 0.75rem;
}

.welcome-status svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.welcome-traits {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.welcome-trait {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 11px;
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.4);
  font-size: 0.75rem;
}

.trait-icon {
  width: 16px;
  height: 16px;
  color: #4a55b8;
  flex: 0 0 auto;
}

.trait-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trait-key {
  color: #9a7223;
}

.storybook-motif {
  position: absolute !important;
  z-index: 0 !important;
  display: grid;
  place-items: center;
  color: #9a7223;
  opacity: 0.2;
  pointer-events: none;
}

.storybook-motif svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.storybook-book {
  width: 24px;
  height: 24px;
  left: 36px;
  bottom: 104px;
}

.storybook-castle {
  width: 24px;
  height: 24px;
  right: 38px;
  top: 42px;
  color: #4a55b8;
}

.storybook-star {
  right: 112px;
  top: 45px;
  width: 20px;
  height: 20px;
}

.telegram-invite {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0;
  padding: 19px 21px;
  text-align: left;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.94);
  border-radius: 15px;
  box-shadow: 0 22px 45px rgba(67, 46, 125, 0.18);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
}

.telegram-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 18px;
  background: linear-gradient(145deg, #35b7f1, #168dcc);
  box-shadow: 7px 8px 0 rgba(34, 158, 217, 0.15), 0 13px 25px rgba(34, 158, 217, 0.22);
}

.telegram-mark img {
  width: 29px;
  height: 29px;
}

.telegram-copy {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.12rem;
}

.telegram-copy strong {
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.35;
}

.telegram-copy span {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.58;
}

.btn.btn-telegram {
  flex: 0 0 auto;
  color: #fff;
  white-space: nowrap;
  min-height: 39px;
  padding: 0 14px;
  border-radius: 11px;
  font-weight: 400;
  font-size: 0.875rem;
  line-height: 1;
  background: #229ed9;
  box-shadow: 0 7px 16px rgba(34, 158, 217, 0.18);
}

.btn.btn-telegram:hover {
  background: #168dcc;
  box-shadow: 0 9px 18px rgba(34, 158, 217, 0.24);
}

.telegram-unavailable {
  position: static;
  justify-content: center;
  color: var(--muted);
}

.telegram-unavailable p {
  margin: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-twitch {
  background: linear-gradient(135deg, #c72b47, #8f1129);
  color: #fff;
  box-shadow: 0 9px 20px rgba(81, 4, 20, 0.35);
}

.btn-twitch:hover {
  background: linear-gradient(135deg, #db3b58, #98132d);
  box-shadow: 0 12px 24px rgba(81, 4, 20, 0.48);
}

.btn-twitch-lg {
  font-size: 1.02rem;
  padding: 0.8rem 1.5rem;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.48);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: rgba(174, 31, 68, 0.35);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.32);
  border-color: var(--border);
  color: var(--muted);
  padding: 0.4rem 0.8rem;
  font-size: 0.84rem;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border-bright);
}

.btn-danger {
  background: rgba(179, 24, 53, 0.16);
  border-color: rgba(243, 154, 167, 0.36);
  color: #8b1834;
  padding: 0.4rem 0.8rem;
  font-size: 0.84rem;
}

.btn-danger:hover {
  background: rgba(179, 24, 53, 0.3);
}

/* Token Form */
.token-details {
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
}

.token-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.token-form {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.85rem;
  align-items: end;
}

@media (max-width: 780px) {
  .token-form {
    grid-template-columns: 1fr;
  }
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-group label {
  font-size: 0.82rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="search"],
select {
  background: rgba(255, 255, 255, 0.56);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
}

input:focus,
select:focus {
  outline: none;
  border-color: rgba(174, 31, 68, 0.4);
  box-shadow: 0 0 0 3px rgba(174, 31, 68, 0.1);
}

/* Streamers List */
.streamers-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.streamer-item {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.streamer-meta {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.streamer-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Pills & Badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.pill-connected {
  background: rgba(166, 214, 188, 0.14);
  color: var(--green);
  border-color: rgba(166, 214, 188, 0.35);
}

.pill-connecting {
  background: rgba(231, 191, 99, 0.15);
  color: var(--amber);
  border-color: rgba(231, 191, 99, 0.35);
}

.pill-disconnected {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border-color: var(--border);
}

.pill-error {
  background: rgba(179, 24, 53, 0.18);
  color: #8b1834;
  border-color: rgba(243, 154, 167, 0.4);
}

.pill-live {
  background: #b31835;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.pill-sub {
  background: rgba(231, 191, 99, 0.16);
  color: #765716;
  border-color: rgba(231, 191, 99, 0.42);
}

.pill-role {
  background: rgba(166, 214, 188, 0.12);
  color: var(--green);
  border-color: rgba(166, 214, 188, 0.3);
}

.pill-badge {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-color: var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.73rem;
}

.badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

/* Explorer */
.explorer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.subtabs {
  display: flex;
  gap: 0.5rem;
}

.subtab-btn {
  background: rgba(255, 255, 255, 0.42);
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.subtab-btn.active {
  border-color: rgba(174, 31, 68, 0.35);
  color: var(--text);
  background: rgba(255, 255, 255, 0.68);
}

@media (max-width: 650px) {
  #panel-welcome {
    min-height: 800px;
    padding: 30px 0 108px;
  }

  .welcome-stack.has-invite {
    padding-bottom: 160px;
  }

  .welcome-card {
    padding: 34px 20px 58px;
  }

  .telegram-invite {
    left: 4%;
    right: 4%;
    flex-direction: column;
    text-align: center;
  }

  .btn-telegram {
    width: 100%;
  }

  .storybook-book {
    left: 15px;
  }

  .storybook-castle {
    right: 12px;
    opacity: 0.65;
  }
}

.filters {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.86rem;
  color: var(--muted);
  cursor: pointer;
}

.table-wrap {
  overflow-x: auto;
}

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

.data-table th,
.data-table td {
  padding: 0.7rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

.empty-cell {
  text-align: center !important;
  color: var(--muted);
  padding: 2rem !important;
}

.truncate-msg {
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}

/* Live Messages Feed */
.messages-feed {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 540px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.chat-line {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.45rem;
  font-size: 0.9rem;
}

.chat-time {
  color: var(--muted);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.chat-channel {
  color: var(--muted);
  font-size: 0.78rem;
}

.chat-author {
  font-weight: 700;
}

.chat-text {
  color: var(--text);
  word-break: break-word;
}

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