/* ===== App Layout ===== */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  padding: 0 var(--safe-left) var(--safe-bottom) var(--safe-right);
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: var(--safe-top) var(--safe-right) 0 var(--safe-left);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  max-width: 720px;
  margin: 0 auto;
}

.header-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-tagline {
  font-size: 11px;
  color: var(--text-muted);
  display: none;
}

.header-settings {
  color: var(--text-secondary);
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.header-settings:active {
  background: var(--bg-card-hover);
}

/* ===== Loading ===== */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 16px;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 14px;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Error ===== */
.error-message {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-secondary);
}

.error-message p {
  margin-bottom: 16px;
}

.btn {
  display: inline-block;
  padding: 8px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active {
  opacity: 0.8;
  transform: scale(0.97);
}

/* ===== Page Header ===== */
.page-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.breadcrumb {
  display: inline-block;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 4px;
  background: none;
  border: none;
  padding: 4px 0;
  touch-action: manipulation;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  word-break: break-word;
}

.page-info {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Home Page ===== */
.home-page {
  max-width: 720px;
  margin: 0 auto;
}

.category {
  padding: 0;
}

.category-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 16px 16px 8px;
  position: sticky;
  top: 45px;
  background: var(--bg);
  z-index: 10;
}

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

.forum-card {
  display: block;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  transition: background 0.15s;
  touch-action: manipulation;
}

.forum-card:active {
  background: var(--bg-card-hover);
}

.forum-card-title {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
}

.forum-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.forum-card-subs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.sub-tag {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 3px;
}

/* ===== Box Page ===== */
.box-page {
  max-width: 720px;
  margin: 0 auto;
}

.thread-section {
  display: flex;
  flex-direction: column;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 10px 16px 6px;
  background: var(--bg);
}

.thread-row {
  display: block;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  touch-action: manipulation;
}

.thread-row:active {
  background: var(--bg-card-hover);
}

.thread-row-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.thread-prefix {
  font-size: 11px;
  font-weight: 500;
  color: var(--prefix-text);
  background: var(--prefix-bg);
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.thread-title {
  font-size: 14px;
  font-weight: 400;
  line-height: 1.4;
  word-break: break-word;
}

.thread-row-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-muted);
}

.thread-author {
  color: var(--text-secondary);
  font-weight: 500;
}

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

/* ===== Thread Page ===== */
.thread-page {
  max-width: 720px;
  margin: 0 auto;
}

.posts {
  display: flex;
  flex-direction: column;
}

.post {
  border-bottom: 1px solid var(--border);
  padding: 0;
}

.post-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-card);
  gap: 8px;
}

.post-author-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.post-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.post-author {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.post-number {
  font-size: 11px;
  color: var(--text-muted);
}

.post-date {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.post-content {
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: break-word;
  overflow-x: auto;
}

/* Post content inner styles - handle Voz HTML */
.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 4px 0;
}

.post-content a {
  color: var(--accent);
  word-break: break-all;
}

.post-content blockquote,
.post-content .bbCodeBlock {
  border-left: 3px solid var(--border-light);
  background: var(--bg-card);
  padding: 8px 12px;
  margin: 8px 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  color: var(--text-secondary);
  overflow-x: auto;
}

.post-content .bbCodeBlock-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.post-content pre,
.post-content code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, monospace;
  font-size: 12px;
  background: var(--bg-card);
  padding: 2px 4px;
  border-radius: 3px;
  overflow-x: auto;
}

.post-content pre {
  padding: 10px 12px;
  margin: 8px 0;
}

.post-content ul,
.post-content ol {
  padding-left: 20px;
  margin: 6px 0;
}

.post-content .bbImage {
  max-width: 100%;
  height: auto;
}

/* Spoiler blocks */
.post-content .bbCodeSpoiler-button {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.post-content iframe,
.post-content video {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

.post-reactions {
  padding: 6px 16px 10px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 16px;
  flex-wrap: wrap;
}

.pagination-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  font-size: 14px;
  color: var(--text-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pagination-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

.pagination-btn:active {
  transform: scale(0.95);
}

.pagination-ellipsis {
  padding: 0 4px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ===== Responsive: Tablets & larger ===== */
@media (min-width: 480px) {
  .header-tagline {
    display: inline;
  }

  .page-title {
    font-size: 20px;
  }

  .thread-title {
    font-size: 15px;
  }

  .post-content {
    padding: 14px 20px;
    font-size: 15px;
  }

  .post-header {
    padding: 10px 20px;
  }

  .post-avatar {
    width: 32px;
    height: 32px;
  }
}

@media (min-width: 768px) {
  .header-inner {
    padding: 12px 24px;
  }

  .forum-card {
    padding: 14px 24px;
  }

  .thread-row {
    padding: 12px 24px;
  }

  .page-header {
    padding: 16px 24px;
  }

  .post-content {
    padding: 16px 24px;
  }

  .post-header {
    padding: 12px 24px;
  }

  .category-title {
    padding: 20px 24px 10px;
  }

  .forum-card:hover {
    background: var(--bg-card-hover);
  }

  .thread-row:hover {
    background: var(--bg-card-hover);
  }

  .pagination-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
  }

  .pagination-btn.active:hover {
    background: var(--accent-dim);
  }
}

/* ===== Utilities ===== */
/* Hide scrollbar but keep scrollable */
.post-content::-webkit-scrollbar {
  height: 3px;
}

.post-content::-webkit-scrollbar-track {
  background: transparent;
}

.post-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Pull-to-refresh touch area */
@supports (padding: max(0px)) {
  .header {
    padding-top: max(var(--safe-top), 0px);
  }
}

/* ===== Settings Page ===== */
.settings-page {
  max-width: 720px;
  margin: 0 auto;
}

.settings-content {
  padding: 0 16px 24px;
}

.settings-section {
  margin-top: 20px;
}

.settings-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.connection-status.connected {
  border-color: #2d7a3a;
  color: #5cb85c;
}

.connection-status.disconnected {
  border-color: #7a3a2d;
  color: #e0a050;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.connected .status-dot {
  background: #5cb85c;
  box-shadow: 0 0 6px #5cb85c88;
}

.disconnected .status-dot {
  background: #e0a050;
  box-shadow: 0 0 6px #e0a05088;
}

.cookie-preview {
  margin-top: 8px;
  padding: 6px 10px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cookie-preview code {
  font-family: "SF Mono", "Fira Code", Menlo, monospace;
}

.settings-help {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 12px;
}

.settings-help ol {
  padding-left: 20px;
  margin: 8px 0;
}

.settings-help li {
  margin-bottom: 4px;
}

.settings-help kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 11px;
  font-family: inherit;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  color: var(--text);
}

.settings-help code {
  font-family: "SF Mono", "Fira Code", Menlo, monospace;
  font-size: 12px;
  background: var(--bg-card);
  padding: 1px 4px;
  border-radius: 3px;
  color: var(--accent);
}

.settings-note {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

.cookie-textarea {
  width: 100%;
  padding: 10px 12px;
  font-family: "SF Mono", "Fira Code", Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  min-height: 80px;
  outline: none;
}

.cookie-textarea:focus {
  border-color: var(--accent);
}

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

.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

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

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
}

.settings-message {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.settings-message.ok {
  background: #1a3a1a;
  color: #5cb85c;
  border: 1px solid #2d7a3a;
}

.settings-message.err {
  background: #3a1a1a;
  color: #e74c3c;
  border: 1px solid #7a2d2d;
}

/* Cloudflare warning banner */
.cf-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #2a2010;
  border-bottom: 1px solid #5a4520;
  font-size: 13px;
  color: #e0a050;
}

.cf-warning a {
  color: var(--accent);
  font-weight: 500;
}

/* Dark mode only — this IS the default, but just in case */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f5f5;
    --bg-card: #ffffff;
    --bg-card-hover: #f0f0f0;
    --bg-header: rgba(255, 255, 255, 0.92);
    --text: #1a1a1a;
    --text-secondary: #555;
    --text-muted: #999;
    --accent: #0066cc;
    --accent-dim: #004d99;
    --border: #e0e0e0;
    --border-light: #d0d0d0;
    --sticky-bg: #fffff0;
    --prefix-bg: #e8e8e8;
    --prefix-text: #555;
  }
}

/* ===== Swipe Gesture Indicators ===== */
.swipe-indicator {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 200;
  pointer-events: none;
  transition: opacity 0.15s ease-out;
}

.swipe-indicator--right {
  left: 0;
}

.swipe-indicator--left {
  right: 0;
}

.swipe-indicator-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 0 var(--radius) var(--radius) 0;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.swipe-indicator--left .swipe-indicator-inner {
  border-radius: var(--radius) 0 0 var(--radius);
}

.swipe-indicator-icon {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.swipe-indicator-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Swipe-enabled page containers */
.box-page,
.thread-page {
  position: relative;
}

/* ===== Loading Bar ===== */
.nav-loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: var(--accent);
  z-index: 9999;
  transition: opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
}

.nav-loading-bar.running {
  opacity: 1;
  animation: nav-progress 2.5s cubic-bezier(0.1, 0.7, 0.3, 1) forwards;
}

@keyframes nav-progress {
  0%   { width: 0%; }
  30%  { width: 40%; }
  60%  { width: 70%; }
  85%  { width: 88%; }
  100% { width: 95%; }
}
