:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #111827;
  --muted: #6b7280;
  --border: #d8dee9;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --danger: #ef4444;
  --success: #10b981;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

html[data-theme="dark"] {
  --bg: #0b0d12;
  --surface: #141821;
  --surface-2: #1c2230;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --border: #2a3142;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    --bg: #0b0d12;
    --surface: #141821;
    --surface-2: #1c2230;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: #2a3142;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
}

img {
  max-width: 100%;
  display: block;
}

.hidden {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  border-bottom: 1px solid var(--border);
}

.topbar-inner,
.page-shell,
.landing-inner {
  width: min(1100px, calc(100% - 2rem));
  margin: 0 auto;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
}

.brand {
  color: var(--text);
  display: inline-flex;
  align-items: center;
}

.logo-svg {
  width: min(180px, 42vw);
  height: auto;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nav-link {
  color: var(--text);
  font-weight: 500;
}

.btn,
button.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font: inherit;
  border-radius: 999px;
  padding: 0.65rem 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  font-size: 0.9rem;
}

.icon-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.theme-icon-dark {
  display: none;
}

html[data-theme="dark"] .theme-icon-light,
html[data-theme="system"] .theme-icon-light {
  display: none;
}

html[data-theme="dark"] .theme-icon-dark {
  display: inline;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .theme-icon-light {
    display: none;
  }
  html[data-theme="system"] .theme-icon-dark {
    display: inline;
  }
}

.landing {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 0;
}

.landing-card {
  width: min(720px, calc(100% - 2rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 8px);
  box-shadow: var(--shadow);
  padding: clamp(2rem, 5vw, 3.5rem);
  text-align: center;
}

.landing-card .logo-svg {
  width: min(420px, 80vw);
  margin: 0 auto 1.5rem;
}

.landing-card h1 {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  margin: 0 0 0.75rem;
}

.landing-card p {
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0 auto 2rem;
  max-width: 34rem;
}

.landing-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.page-shell {
  padding: 1.5rem 0 3rem;
  display: grid;
  grid-template-columns: 1fr min(680px) 1fr;
  gap: 1.5rem;
}

.sidebar {
  position: sticky;
  top: 5rem;
  align-self: start;
}

.sidebar-card,
.compose-card,
.post-card,
.auth-card,
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sidebar-card,
.compose-card,
.auth-card,
.profile-card {
  padding: 1.25rem;
}

.feed-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.compose-card textarea,
.auth-card input,
.auth-card textarea,
.profile-card input,
.profile-card textarea,
.comment-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font: inherit;
  resize: vertical;
}

.compose-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.85rem;
}

.file-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  color: var(--muted);
}

.file-label input {
  display: none;
}

.preview-wrap {
  margin-top: 0.85rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.post-card {
  overflow: hidden;
}

.post-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0.5rem;
  flex-wrap: wrap;
}

.post-author {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  object-fit: cover;
  background: var(--surface-2);
}

.author-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.handle,
.muted {
  color: var(--muted);
  font-size: 0.92rem;
}

.post-header time {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.post-content {
  padding: 0 1rem 0.75rem;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.post-media img {
  width: 100%;
  max-height: 520px;
  object-fit: cover;
}

.post-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem 1rem;
  border-top: 1px solid var(--border);
}

.action-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 0.55rem;
  cursor: pointer;
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.action-btn:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.action-btn.active {
  color: var(--accent);
}

.action-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.comments-panel {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border);
}

.comments-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1rem 0;
}

.comment-item {
  display: flex;
  gap: 0.65rem;
}

.comment-item .avatar {
  width: 32px;
  height: 32px;
}

.comment-body {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  flex: 1;
}

.comment-body strong {
  display: block;
  margin-bottom: 0.15rem;
}

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 0;
}

.auth-card {
  width: min(420px, calc(100% - 2rem));
}

.auth-card h1,
.profile-card h1 {
  margin-top: 0;
}

.form-grid {
  display: grid;
  gap: 0.85rem;
}

.form-grid label {
  display: grid;
  gap: 0.35rem;
  font-weight: 500;
}

.alert {
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.alert-error {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

.alert-success {
  background: color-mix(in srgb, var(--success) 15%, transparent);
  color: var(--success);
  border: 1px solid color-mix(in srgb, var(--success) 35%, transparent);
}

.profile-hero {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.profile-hero .avatar {
  width: 80px;
  height: 80px;
}

.role-badge {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.role-badge.admin {
  color: #fff;
  background: var(--accent);
}

.theme-picker {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.theme-picker label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}

.theme-picker input {
  accent-color: var(--accent);
}

@media (max-width: 960px) {
  .page-shell {
    grid-template-columns: 1fr;
  }

  .sidebar-right {
    display: none;
  }
}

@media (max-width: 640px) {
  .topbar-nav .nav-link {
    display: none;
  }

  .topbar-nav .nav-link[href="/admin.php"] {
    display: inline;
  }

  .post-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.inline-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form select {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  font: inherit;
}

.admin-post-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
}

.admin-post-row p {
  margin: 0.35rem 0 0;
}
