:root {
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;

  /* Layout Constants */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 32px;

  --max-width: 1000px;
  --header-height: 70px;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  background-image:
    radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.08), transparent 25%),
    radial-gradient(circle at 85% 30%, rgba(139, 92, 246, 0.08), transparent 25%);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.page-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
}

/* Header */
.masthead {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  height: var(--header-height);
  display: flex;
  align-items: center;
  margin-bottom: 2rem;
  padding: 0 1.5rem;
}

.masthead-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.logo {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text-main);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: opacity 0.2s;
}

.logo:hover {
  opacity: 0.8;
}

.logo img {
  border: 2px solid var(--border-light);
}

/* Typography */
h1,
h2,
h3 {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

p {
  color: var(--text-muted);
}

small {
  font-size: 0.875rem;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.card:hover {
  border-color: var(--border-hover);
}

.glass-card {
  background: var(--bg-card-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.form-control {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  transition: all 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  background: rgba(0, 0, 0, 0.3);
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  text-decoration: none;
  gap: 0.5rem;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  white-space: nowrap;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.btn-danger {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* Thread Media Grid */
.thread-media-container {
  margin-bottom: 1rem;
}

.thread-image-main {
  width: 100%;
  max-width: 100%;
  height: 300px;
  object-fit: contain;
  border-radius: var(--radius-md);
  display: block;
  background: var(--bg-surface-alt);
  margin: 0 auto;
}

.thread-media-thumbnails {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.thread-image-thumb {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  display: block;
  cursor: pointer;
  background: var(--bg-surface);
  transition: opacity 0.2s;
}

.thread-image-thumb:hover {
  opacity: 0.8;
}

.file-preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  color: var(--text-main);
  text-align: center;
}

.file-preview-placeholder.main {
  height: 250px;
  border-radius: var(--radius-md);
}

.file-preview-placeholder.thumb {
  height: 100px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

.file-icon-large {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.file-icon-small {
  font-size: 1.5rem;
}

/* Compact Theme Overrides for Media */
[data-theme="compact"] .thread-image-main {
  max-height: 250px;
  height: auto;
  margin-bottom: 4px;
}

[data-theme="compact"] .thread-image-thumb {
  height: 60px;
}

[data-theme="compact"] .thread-media-thumbnails {
  gap: 4px;
  margin-top: 4px;
}

/* Thread List */
.thread-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

.thread-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden; /* Prevent content from spilling out */
}

.thread-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  background: var(--bg-surface);
}

.thread-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.thread-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.thread-preview {
  font-size: 0.9375rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 1rem;
}

/* Thread Detail */
.thread-detail {
  max-width: 800px;
  margin: 0 auto;
}

.post-full-image {
  max-width: 100%;
  border-radius: var(--radius-lg);
  margin: 1.5rem 0;
  box-shadow: var(--shadow-lg);
}

/* Replies */
.replies-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 2rem;
}

.reply-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.reply-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
}

.reply-author {
  font-weight: 600;
  color: var(--text-main);
}

.reply-date {
  color: var(--text-dim);
}

.reply-message, .thread-message-large, .thread-preview {
  white-space: pre-wrap;
  color: var(--text-main);
}

/* Markdown Styles */
.reply-message blockquote,
.thread-message-large blockquote,
.thread-preview blockquote {
  color: #789922; /* Traditional greentext color */
  margin: 0;
  padding: 0;
  border: none;
}

[data-theme="dark"] .reply-message blockquote,
[data-theme="dark"] .thread-message-large blockquote,
[data-theme="dark"] .thread-preview blockquote {
  color: #a8c05f; /* Lighter green for dark mode */
}

.reply-message p,
.thread-message-large p {
  margin-bottom: 0.5rem;
}

.reply-message p:last-child,
.thread-message-large p:last-child {
  margin-bottom: 0;
}

.post-link {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

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

.highlight-post {
  animation: highlight 2s ease-out;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

@keyframes highlight {
  0% { background-color: var(--bg-surface); }
  10% { background-color: var(--bg-surface-glass); border-color: var(--primary); }
  100% { background-color: var(--bg-surface); }
}

/* Utilities */
.stack {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.text-center {
  text-align: center;
}

.mt-4 {
  margin-top: 1rem;
}

.mb-4 {
  margin-bottom: 1rem;
}

/* HTMX Indicator */
.htmx-indicator {
  opacity: 0;
  transition: opacity 0.2s ease-in;
}

.htmx-request .htmx-indicator {
  opacity: 1;
}

.htmx-request.htmx-indicator {
  opacity: 1;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fade-in {
  animation: fadeIn 0.4s ease-out forwards;
}

/* Responsive */
@media (max-width: 640px) {
  :root {
    --header-height: 60px;
  }

  .masthead {
    padding: 0.5rem 1rem;
    height: auto;
    margin-bottom: 1rem;
  }

  .masthead-content {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
  }

  .masthead-content .cluster {
    width: auto;
    flex: 1;
    justify-content: flex-end;
  }

  .logo {
    flex: 1;
  }

  .card {
    padding: 1.25rem;
  }

  .thread-grid {
    grid-template-columns: 1fr;
  }
}

/* Forms */
.form-group {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.form-input,
.file-input,
textarea {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  font-family: inherit;
  transition: all 0.2s ease;
}

.form-input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Pagination & Search */
.actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.search-form {
  flex: 1;
  max-width: 300px;
  min-width: 200px;
}

.search-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  transition: all 0.3s ease;
}

.search-input:focus {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
  outline: none;
}

/* Thread Grid Images */
.thread-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
}

/* Spacing Utilities */
.hero {
  margin-bottom: 3rem;
}

.actions-bar {
  margin-top: 2rem;
}

.form-card {
  margin-bottom: 3rem;
}

/* Search Form Layout */
.search-form {
  display: flex;
  gap: 0.5rem;
}

.search-form input {
  flex: 1;
}

/* File Icons */
.file-icon-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  text-align: center;
}

.file-icon-large {
  font-size: 3rem;
}

.file-type-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.file-count-indicator {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* Reply Files */
.reply-files {
  margin-top: 1rem;
}

.reply-files figure {
  margin-top: 1rem;
}

.reply-files video {
  max-width: 100%;
  max-height: 300px;
  margin-top: 1rem;
}

.file-download-link {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  text-decoration: none;
}

/* Thread Detail Files */
.thread-files-detail video {
  max-width: 100%;
  margin-bottom: 1rem;
}

.thread-detail-file-link {
  display: inline-block;
  margin: 0.5rem 0;
  padding: 0.75rem 1.5rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  text-decoration: none;
}

/* Inline style replacements */
.no-margin {
  margin: 0;
}

.no-padding-left {
  padding-left: 0;
}

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

.badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: rgba(139, 92, 246, 0.2);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
}

.badge-mod {
  color: var(--accent);
}

.thread-header {
  align-items: flex-start;
  margin-bottom: 1rem;
}

.thread-title-large {
  font-size: 1.5rem;
  margin: 0;
}

.thread-message-large {
  font-size: 1.1rem;
  color: var(--text-main);
  white-space: pre-wrap;
}

.thread-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
}

.reply-footer {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
  font-size: 0.875rem;
}

.gap-quarter {
  gap: 0.25rem;
}

.gap-half {
  gap: 0.5rem;
}

.font-small {
  font-size: 0.875rem;
}

.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 400px;
}

.login-header {
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

.login-title {
  font-size: 1.75rem;
}

.login-subtitle {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.error-box {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  padding: 0.75rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  text-align: center;
}

.warning {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  padding: 0.75rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
}

.btn-full-width {
  width: 100%;
  margin-top: 1rem;
}

.login-footer {
  margin-top: 1.5rem;
}

.search-empty {
  text-align: center;
  padding: 3rem;
}

.search-empty-link {
  margin-top: 1rem;
}

.pagination {
  margin-top: 2rem;
  text-align: center;
}

.pagination-item {
  margin: 0 0.25rem;
}

.footer {
  margin-top: 4rem;
  padding-bottom: 2rem;
}

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

.btn-small {
  font-size: 0.8rem;
  padding: 0.4rem 0.8rem;
}

.reply-image {
  max-height: 300px;
  object-fit: contain;
}

.thread-files-margin {
  margin-top: 1rem;
}

.thread-card-actions {
  margin-top: auto;
  padding-top: 1rem;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.delete-code-small {
  margin-top: 0.5rem;
  font-size: 0.7rem;
  flex-basis: 100%;
}

.full-width-card {
  grid-column: 1 / -1;
}

.ban-expired {
  opacity: 0.6;
  border-color: var(--text-dim);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  padding: 1rem;
  overflow-y: auto;
}

.modal-content {
  animation: fadeIn 0.3s ease-out;
}

/* Banned user indicator */
.badge-banned {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.country-iso {
  font-size: 0.85em;
  color: var(--text-muted);
  margin-left: 0.25rem;
  font-weight: 500;
}