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

:root {
  --bg: #0a0a0f;
  --bg-card: #12121c;
  --bg-card-hover: #181828;
  --bg-header: #0e0e16;
  --accent: #0ea5e9;
  --accent-dim: rgba(14, 165, 233, 0.12);
  --purple: #8b5cf6;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-muted: #64748b;
  --border: #1e293b;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --radius: 14px;
  --radius-sm: 8px;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.hidden {
  display: none !important;
}

/* ── Landing ── */
#landing,
#error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  gap: 1rem;
  text-align: center;
}

.landing-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.error-icon {
  background: rgba(239, 68, 68, 0.1);
}

.landing-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.landing-desc,
#error-page-desc {
  color: var(--text-dim);
  font-size: 1rem;
  max-width: 400px;
}

.landing-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 4px 4px 16px;
  margin-top: 1rem;
  width: 100%;
  max-width: 420px;
  transition: border-color 0.2s;
}

.landing-input-wrap:focus-within {
  border-color: var(--accent);
}

.landing-prefix {
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  user-select: none;
}

.landing-input-wrap input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  padding: 10px 8px;
  min-width: 0;
}

.landing-input-wrap button,
#error-go-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.landing-input-wrap button:hover {
  background: #0284c7;
}

.landing-input-wrap button:active {
  transform: scale(0.97);
}

/* ── Channel view ── */
#channel-view {
  max-width: 700px;
  margin: 0 auto;
  padding: 0 16px 80px;
}

/* ── Header ── */
#channel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

#channel-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-dim);
  flex-shrink: 0;
  overflow: hidden;
}

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

.avatar-placeholder {
  background: linear-gradient(135deg, var(--accent-dim), rgba(139, 92, 246, 0.15));
}

.header-info {
  min-width: 0;
}

#channel-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.counters {
  display: flex;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 2px;
}

.counters span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.back-btn {
  color: var(--text-dim);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.back-btn:hover {
  color: var(--text);
  background: var(--bg-card);
}

.landing-hint {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-dim);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text);
  border-color: var(--accent);
}

.icon-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Settings ── */
#settings-panel {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease, opacity 0.2s;
  opacity: 0;
}

#settings-panel.expanded {
  max-height: 120px;
  opacity: 1;
}

.settings-inner {
  display: flex;
  gap: 16px;
  padding: 14px 0;
  flex-wrap: wrap;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 160px;
}

.setting-group label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.setting-group select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 8px 12px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.setting-group select:focus {
  border-color: var(--accent);
}

/* ── Description bar ── */
#description-bar {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

#channel-description {
  color: var(--text-dim);
  font-size: 0.85rem;
  line-height: 1.5;
}

/* ── Messages ── */
#messages-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 16px;
}

.message-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: background 0.15s, border-color 0.15s, transform 0.3s ease, opacity 0.3s ease;
  animation: messageIn 0.35s ease-out both;
}

.message-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(14, 165, 233, 0.2);
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-text {
  font-size: 0.95rem;
  line-height: 1.65;
  word-break: break-word;
  overflow-wrap: break-word;
}

.msg-text a {
  color: var(--accent);
  text-decoration: none;
}

.msg-text a:hover {
  text-decoration: underline;
}

.msg-text b,
.msg-text strong {
  font-weight: 600;
  color: #fff;
}

.msg-text code {
  background: rgba(139, 92, 246, 0.12);
  color: var(--purple);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
}

.msg-text pre {
  background: #0e0e18;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 0.85rem;
  line-height: 1.5;
}

.msg-media {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.msg-media img {
  max-width: 100%;
  border-radius: 10px;
  display: block;
  opacity: 0;
  transition: opacity 0.3s;
}

.msg-media img.loaded {
  opacity: 1;
}

.msg-video-wrap {
  position: relative;
  display: inline-block;
  border-radius: 10px;
  overflow: hidden;
  max-width: 100%;
}

.msg-video-wrap img {
  display: block;
  max-width: 100%;
  border-radius: 10px;
}

.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 10px;
  transition: background 0.15s;
}

.play-overlay:hover {
  background: rgba(0, 0, 0, 0.5);
}

.play-overlay svg {
  width: 48px;
  height: 48px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4));
}

.msg-link-preview {
  margin-top: 12px;
  padding: 12px 16px;
  background: rgba(14, 165, 233, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.msg-link-preview .lp-site {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  font-weight: 600;
}

.msg-link-preview .lp-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: 2px;
  color: var(--text);
}

.msg-link-preview .lp-desc {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 4px;
  line-height: 1.5;
}

.msg-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.msg-footer span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.msg-footer svg {
  width: 14px;
  height: 14px;
  opacity: 0.6;
}

.msg-footer .msg-author {
  color: var(--purple);
  font-weight: 500;
}

/* ── Error banner ── */
#error-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(234, 179, 8, 0.12);
  border-bottom: 1px solid rgba(234, 179, 8, 0.25);
  color: var(--yellow);
  text-align: center;
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  backdrop-filter: blur(10px);
}

/* ── Status bar ── */
#status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-header);
  border-top: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.status-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.dot.online {
  background: var(--green);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.dot.error {
  background: var(--red);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.dot.polling {
  animation: pulse 1s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Skeleton ── */
#skeleton {
  max-width: 700px;
  margin: 0 auto;
  padding: 24px 16px;
}

.skeleton-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
}

.skeleton-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-line {
  height: 14px;
  border-radius: 6px;
}

.skeleton-card {
  height: 120px;
  border-radius: var(--radius);
  margin-bottom: 10px;
}

.shimmer {
  background: linear-gradient(
    90deg,
    var(--bg-card) 0%,
    var(--bg-card-hover) 40%,
    var(--bg-card) 80%
  );
  background-size: 400% 100%;
  animation: shimmer 1.5s ease infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Responsive ── */
@media (max-width: 520px) {
  #channel-header {
    padding: 14px 0 10px;
  }

  #channel-title {
    font-size: 1.05rem;
  }

  .message-card {
    padding: 14px 16px;
    border-radius: 10px;
  }

  .settings-inner {
    flex-direction: column;
  }

  .landing-title {
    font-size: 1.5rem;
  }
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
