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

:root,
[data-theme="dark"] {
  --bg: #15202b;
  --surface: #192734;
  --border: #38444d;
  --text: #e7e9ea;
  --muted: #8899a6;
  --accent: #1d9bf0;
  --accent-hover: #1a8cd8;
  --error: #f4212e;
  --header-bg: rgba(21, 32, 43, 0.85);
  --ad-bg: #0f1419;
  --quote-bg: rgba(29, 155, 240, 0.08);
  --radius: 16px;
}

[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f7f9fa;
  --border: #cfd9de;
  --text: #0f1419;
  --muted: #536471;
  --accent: #1d9bf0;
  --accent-hover: #1a8cd8;
  --error: #f4212e;
  --header-bg: rgba(255, 255, 255, 0.9);
  --ad-bg: #eef3f6;
  --quote-bg: rgba(29, 155, 240, 0.1);
}

[data-theme="superdark"] {
  --bg: #000000;
  --surface: #0a0a0a;
  --border: #1f1f1f;
  --text: #f0f0f0;
  --muted: #666666;
  --accent: #1d9bf0;
  --accent-hover: #1a8cd8;
  --error: #f4212e;
  --header-bg: rgba(0, 0, 0, 0.92);
  --ad-bg: #050505;
  --quote-bg: rgba(29, 155, 240, 0.12);
}

[data-theme="rainbow"] {
  --bg: #1a1033;
  --surface: rgba(20, 10, 40, 0.75);
  --border: rgba(255, 255, 255, 0.2);
  --text: #ffffff;
  --muted: #ddd6fe;
  --accent: #ff6bcb;
  --accent-hover: #ff4db8;
  --error: #ff6b6b;
  --header-bg: rgba(26, 16, 51, 0.8);
  --ad-bg: rgba(0, 0, 0, 0.3);
  --quote-bg: rgba(255, 255, 255, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

html[data-theme="rainbow"] body {
  background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab, #8e44ad, #f39c12);
  background-size: 400% 400%;
  animation: rainbowBg 12s ease infinite;
}

@keyframes rainbowBg {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

[hidden] {
  display: none !important;
}

.page-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 28px;
  padding: 20px 16px;
  min-height: 100vh;
  width: 100%;
}

.ads-column {
  width: 180px;
  flex: 0 0 180px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 20px;
}

.ad-slot {
  min-height: 160px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px dashed var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-slot.has-ad {
  border-style: solid;
  min-height: 0;
}

.ad-placeholder {
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
  padding: 12px;
}

.ad-slot img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 260px;
  object-fit: contain;
  background: var(--ad-bg);
}

.app {
  flex: 0 1 600px;
  width: 100%;
  max-width: 600px;
  min-width: 0;
  min-height: 100vh;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--bg);
}

[data-theme="rainbow"] .app {
  background: var(--surface);
  backdrop-filter: blur(8px);
}

.header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header h1 {
  flex: 1;
  min-width: 0;
  font-size: clamp(1rem, 2.5vw, 1.35rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.theme-switcher {
  flex-shrink: 0;
}

.theme-switcher select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9999px;
  color: var(--text);
  font: inherit;
  font-size: 0.8125rem;
  padding: 8px 12px;
  cursor: pointer;
  outline: none;
}

.theme-switcher select:focus {
  border-color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.tagline {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

.compose {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.required {
  color: var(--accent);
}

input[type="text"],
textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
}

input[type="text"]:focus,
textarea:focus {
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.counter {
  display: block;
  text-align: right;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

.file-field input[type="file"] {
  display: none;
}

.file-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 8px 0;
}

.file-label:hover {
  color: var(--accent-hover);
}

.error {
  color: var(--error);
  font-size: 0.875rem;
  margin-bottom: 10px;
}

.submit-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 9999px;
  font: inherit;
  font-weight: 700;
  font-size: 0.9375rem;
  padding: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.submit-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.feed {
  padding-bottom: 24px;
}

.feed-title {
  font-size: 1.1rem;
  font-weight: 700;
  padding: 16px 16px 8px;
}

.feed-list {
  display: flex;
  flex-direction: column;
}

.loading,
.empty {
  color: var(--muted);
  text-align: center;
  padding: 32px 16px;
  font-size: 0.9375rem;
}

.post {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7856ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
  color: #fff;
}

.post-body {
  flex: 1;
  min-width: 0;
}

.post-header {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.post-name {
  font-weight: 700;
  font-size: 0.9375rem;
}

.post-time {
  color: var(--muted);
  font-size: 0.8125rem;
}

.post-text {
  margin-top: 4px;
  font-size: 0.9375rem;
  white-space: pre-wrap;
  word-break: break-word;
}

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

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

.hint {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

.compose-actions {
  margin-bottom: 12px;
}

.toggle-poll-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 9999px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
}

.toggle-poll-btn:hover {
  background: var(--surface);
}

.poll-fields {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--surface);
}

.poll-fields input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
  margin-bottom: 8px;
  outline: none;
}

.poll-fields input[type="text"]:focus {
  border-color: var(--accent);
}

.poll-fields .poll-opt {
  margin-top: 0;
}

.poll {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.poll-question {
  font-weight: 700;
  font-size: 0.9375rem;
  margin-bottom: 10px;
}

.poll-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.poll-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
}

.poll-option:hover {
  border-color: var(--accent);
}

.poll-option.voted {
  border-color: var(--accent);
  font-weight: 600;
}

.poll-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: rgba(29, 155, 240, 0.15);
  border-radius: 9999px;
  transition: width 0.3s ease;
  z-index: 0;
}

.poll-label,
.poll-meta {
  position: relative;
  z-index: 1;
}

.poll-meta {
  color: var(--muted);
  font-size: 0.8125rem;
  flex-shrink: 0;
}

.poll-total {
  margin-top: 8px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.reaction-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: transparent;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.reaction-btn:hover {
  background: var(--surface);
  border-color: var(--accent);
}

.reaction-btn.active {
  background: rgba(29, 155, 240, 0.15);
  border-color: var(--accent);
}

.reaction-count {
  font-size: 0.75rem;
  color: var(--muted);
}

.reply-preview {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--quote-bg);
}

.reply-preview-body {
  flex: 1;
  min-width: 0;
}

.reply-preview-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.reply-preview-body p {
  font-size: 0.875rem;
  margin-top: 4px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
}

.reply-preview-close:hover {
  color: var(--text);
}

.reply-quote {
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--quote-bg);
  font-size: 0.875rem;
}

.reply-quote-name {
  display: block;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 2px;
}

.reply-quote-text {
  color: var(--muted);
}

.post-actions {
  margin-top: 8px;
}

.reply-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  padding: 4px 0;
}

.reply-btn:hover {
  color: var(--accent);
}

.post-attachment {
  margin-top: 10px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.post-attachment img {
  display: block;
  max-width: 100%;
  max-height: 400px;
  object-fit: contain;
  background: var(--ad-bg);
}

.post-attachment video {
  display: block;
  max-width: 100%;
  max-height: 400px;
}

.post-attachment audio {
  width: 100%;
  padding: 8px;
  background: var(--surface);
}

.file-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.875rem;
}

.file-link:hover {
  text-decoration: underline;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 20px 16px;
  border-top: 1px solid var(--border);
}

@media (max-width: 1100px) {
  .page-layout {
    padding: 0;
    gap: 0;
  }

  .ads-column {
    display: none;
  }

  .app {
    max-width: none;
    flex: 1 1 auto;
    border: none;
  }
}
