:root {
  --bg: #0d0d0f;
  --surface: #16161a;
  --border: #2a2a32;
  --text: #e8e8ed;
  --muted: #8b8b9a;
  --accent: #c44b4b;
  --accent-hover: #d65f5f;
  --up: #4caf82;
  --down: #c44b4b;
  --radius: 10px;
  --control-height: 1.75rem;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(13, 13, 15, 0.92);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.site-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.site-brand:hover .logo {
  color: var(--text);
}

.site-brand:hover .logo span {
  color: var(--accent-hover);
}

.site-logo-icon {
  width: 2.75rem;
  height: 2.75rem;
  flex-shrink: 0;
  border-radius: 8px;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.logo {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo span {
  color: var(--accent);
}

.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.75rem 0 0.35rem;
}

input[type="text"],
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.65rem 0.75rem;
  font: inherit;
}

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

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.form-status {
  min-height: 1.25rem;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.form-status.error {
  color: var(--down);
}

.form-status.success {
  color: var(--up);
}

.form-status.pending {
  color: var(--muted);
}

.form-progress-label {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.form-progress {
  display: block;
  width: 100%;
  height: 6px;
  margin: 0 0 0.25rem;
  border: none;
  border-radius: 3px;
  overflow: hidden;
  appearance: none;
  background: var(--bg);
}

.form-progress::-webkit-progress-bar {
  background: var(--bg);
  border-radius: 3px;
}

.form-progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.25s ease;
}

.form-progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 3px;
}

.btn {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: var(--control-height);
  min-height: var(--control-height);
  padding: 0 1rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  appearance: none;
  -webkit-appearance: none;
  transition: background 0.15s, border-color 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

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

.post-card {
  margin-bottom: 1rem;
}

.post-footer {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.4rem 0.75rem;
}

.post-date {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 0;
  white-space: nowrap;
}

.feed-toolbar {
  margin-bottom: 1rem;
}

.feed-sort {
  display: flex;
  align-items: stretch;
  width: 100%;
  height: var(--control-height);
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 0;
  overflow: hidden;
}

.feed-sort-option {
  flex: 1;
  margin: 0;
  height: 100%;
  min-height: 0;
  padding: 0 0.5rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.feed-sort-option:hover:not(.is-active) {
  color: var(--text);
}

.feed-sort-option.is-active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

@media (max-width: 599px) {
  .post-footer {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    column-gap: 0.75rem;
    row-gap: 0.35rem;
  }

  .post-footer .post-pseudonym {
    grid-column: 1;
    grid-row: 1;
  }

  .post-footer .post-date {
    grid-column: 1 / -1;
    grid-row: 2;
    white-space: normal;
  }

  .post-footer .post-votes {
    grid-column: 2;
    grid-row: 1;
    margin-left: 0;
  }

  .comment-footer {
    row-gap: 0.5rem;
  }

  .comment-meta {
    flex: 1 1 100%;
    min-width: 0;
  }

  .comment-votes {
    flex: 1 1 100%;
    justify-content: flex-end;
  }

  .comment-meta .post-date {
    white-space: normal;
  }
}

@media (max-width: 480px) {
  .feed-sort-option {
    font-size: 0.7rem;
    padding: 0 0.25rem;
  }
}

.post-pseudonym {
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.post-footer .post-votes {
  flex-shrink: 0;
  margin-left: auto;
}

.post-message {
  margin: 0 0 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.post-votes {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-shrink: 0;
}

.vote-btn {
  padding: 0 0.5rem;
  font-size: 0.85rem;
  line-height: 1;
}

.vote-btn.vote-down {
  width: var(--control-height);
  height: var(--control-height);
  min-width: var(--control-height);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.comment-reply-btn {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

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

.vote-btn.active-up {
  border-color: var(--up);
  color: var(--up);
}

.vote-btn.active-down {
  border-color: var(--down);
  color: var(--down);
}

.post-score.vote-total-score {
  font-weight: 600;
  min-width: 1.75rem;
  text-align: center;
  font-size: 0.85rem;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.page-info {
  font-size: 0.9rem;
  color: var(--muted);
}

.site-footer {
  text-align: center;
  padding: 1.5rem;
  border-top: 1px solid var(--border);
}

.offline-page {
  text-align: center;
  padding: 4rem 1.5rem;
}

.offline-page h1 {
  color: var(--accent);
}

.post-comment-count {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.post-comment-count:hover {
  color: var(--text);
}

.post-comment-count-static {
  cursor: default;
}

.post-comment-count-static:hover {
  color: var(--muted);
}

.post-open-trigger {
  cursor: pointer;
}

body.modal-open {
  overflow: hidden;
}

.post-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}

.post-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.post-modal-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 640px;
  margin: 2rem auto 3rem;
  max-height: none;
}

.post-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.post-modal-title {
  margin: 0;
  font-size: 1.1rem;
}

.post-modal-close {
  font-size: 1.4rem;
  line-height: 1;
  height: auto;
  min-height: auto;
  min-width: 2.5rem;
  padding: 0.25rem 0.5rem;
}

.post-modal-comments {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.comments-toolbar {
  margin-bottom: 1rem;
}

.sort-toolbar {
  display: flex;
  align-items: stretch;
  width: 100%;
  height: var(--control-height);
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 0;
  overflow: hidden;
}

.sort-option {
  flex: 1;
  margin: 0;
  height: 100%;
  min-height: 0;
  padding: 0 0.5rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sort-option:hover:not(.is-active) {
  color: var(--text);
}

.sort-option.is-active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.comment {
  padding: 0.75rem 0 0.75rem calc(min(var(--depth, 0), 6) * 1.25rem);
  border-bottom: 1px solid var(--border);
}

.comment:last-child {
  border-bottom: none;
}

.comment-message {
  margin: 0 0 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
}

.comment-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.comment-meta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-width: 0;
}

.comment-votes {
  margin-bottom: 0;
  flex-shrink: 0;
  margin-left: auto;
}

.comment-replies {
  margin-top: 0.5rem;
}

.comment-reply-form {
  margin: 0.5rem 0;
}

.comment-form,
.comment-reply-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.comment-form input,
.comment-form textarea,
.comment-reply-form input,
.comment-reply-form textarea {
  width: 100%;
}

.comment-form textarea,
.comment-reply-form textarea {
  min-height: auto;
}

.comment-form .form-actions,
.comment-reply-form .form-actions {
  margin-top: 0;
  align-items: center;
  flex-wrap: wrap;
}

.comment-form .form-actions .form-status,
.comment-reply-form .form-actions .form-status {
  margin: 0;
  display: flex;
  align-items: center;
  min-height: var(--control-height);
  line-height: 1;
}

.btn-sm {
  padding: 0 0.6rem;
  font-size: 0.85rem;
}

.comment-form {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

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

@media (max-width: 480px) {
  .sort-option {
    font-size: 0.7rem;
    padding: 0 0.25rem;
  }
}
