/* ── Reset ──────────────────────────────────────────────────────────────────── */

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

:root {
  --bg:           #eef2ff;
  --op-bg:        #f0e0d6;
  --reply-bg:     #d6daf0;
  --nav-bg:       #af0a0f;
  --nav-border:   #7a0000;
  --border:       #b7c5d9;
  --border-form:  #c0a090;
  --text:         #000000;
  --muted:        #666666;
  --subject:      #0f0c5d;
  --name:         #117743;
  --tripcode:     #228854;
  --quotelink:    #d00000;
  --greentext:    #789922;
  --link:         #34345c;
  --red:          #af0a0f;
  --red-dark:     #800000;
  --gold:         #c8922a;
  --form-lbl:     #ea8c7f;
  --form-lbl-c:   #800000;
  --form-bg:      #f0e0d6;
}

html {
  font-size: 15px;
  font-family: arial, helvetica, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
}

a { color: var(--link); text-decoration: underline; }
a:hover { color: var(--quotelink); }

/* ── Nav ────────────────────────────────────────────────────────────────────── */

#nav {
  background: var(--nav-bg);
  border-bottom: 2px solid var(--nav-border);
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 32px;
}

#nav .brand {
  font-weight: bold;
  font-size: 1.05rem;
  color: #fff;
  text-decoration: none;
  flex-shrink: 0;
}

#nav .brand span { color: #ffaaaa; }

.nav-links {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}

.nav-links a {
  color: #ffcccc;
  font-size: 0.82rem;
  text-decoration: none;
  padding: 2px 4px;
}

.nav-links a:hover  { color: #fff; text-decoration: underline; }
.nav-links a.active { color: #fff; font-weight: bold; }

.nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-shrink: 0;
}

#walletBtn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 2px;
  color: #fff;
  font-size: 0.78rem;
  padding: 3px 10px;
  cursor: pointer;
  font-family: inherit;
}
#walletBtn:hover    { background: rgba(255,255,255,0.25); }
#walletBtn.connected { color: #aaffaa; border-color: rgba(170,255,170,0.4); }

.polipass-badge {
  font-size: 0.72rem;
  font-weight: bold;
  padding: 2px 7px;
  text-decoration: none;
  border-radius: 2px;
  white-space: nowrap;
}
.polipass-badge:hover { opacity: 0.85; text-decoration: none; }
.polipass-tier-1 { background: #8B0000; color: #ffffff; }
.polipass-tier-2 { background: #1e0a3c; color: #d4b8ff; }
.polipass-tier-3 { background: #0d001a; color: #ffd700; }

/* ── App shell ──────────────────────────────────────────────────────────────── */

#app {
  max-width: 1400px;
  margin: 0;
  padding: 10px 24px 60px;
}

/* ── Board index ────────────────────────────────────────────────────────────── */

.page-title {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--red);
  text-align: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.board-list-section { margin-bottom: 22px; }

.board-list-group-header {
  font-size: 0.8rem;
  font-weight: bold;
  color: var(--red-dark);
  padding: 3px 0;
  border-bottom: 1px solid var(--red-dark);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.board-list-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 6px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.board-list-row:hover { background: rgba(0,0,0,0.04); }

.board-list-uri   { font-weight: bold; color: var(--red); width: 200px; flex-shrink: 0; font-size: 0.85rem; }
.board-list-name  { font-size: 0.85rem; flex: 1; }
.board-list-stats { font-size: 0.75rem; color: var(--muted); }

/* ── Board header ───────────────────────────────────────────────────────────── */

.board-header {
  text-align: center;
  padding: 10px 24px;
  border-bottom: 2px solid var(--border);
  margin: 0 -24px 10px;
  width: 100vw;
}

.board-header h1 {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--red);
  font-style: italic;
}

.board-header .board-uri-label { font-size: 0.85rem; color: var(--muted); }
.board-header .board-desc      { font-size: 0.85rem; color: var(--muted); margin-top: 3px; }
.board-actions { display: flex; justify-content: center; gap: 8px; margin-top: 8px; }

/* ── Posting form ───────────────────────────────────────────────────────────── */

.post-form-section {
  margin-bottom: 14px;
  text-align: center;
  width: 100vw;
  margin-left: -24px;
}

.post-form-section .submit-btn {
  margin-left: 0;
  padding: 6px 18px;
  font-size: 0.85rem;
}

.post-form-wrap {
  display: inline-block;
  background: var(--form-bg);
  border: 1px solid var(--border-form);
  text-align: left;
}

table.post-form {
  border-collapse: collapse;
  font-size: 0.85rem;
}

table.post-form td {
  padding: 3px 6px;
  border: 1px solid var(--border-form);
  vertical-align: middle;
}

table.post-form .lbl {
  background: var(--form-lbl);
  color: var(--form-lbl-c);
  font-weight: bold;
  text-align: right;
  white-space: nowrap;
  padding: 3px 10px;
  font-size: 0.82rem;
}

table.post-form input[type="text"],
table.post-form textarea {
  font-family: inherit;
  font-size: 0.85rem;
  border: 1px solid #999;
  padding: 2px 4px;
  background: #fff;
  width: 300px;
}

table.post-form textarea {
  resize: vertical;
  min-height: 80px;
  width: 300px;
  vertical-align: top;
}

table.post-form input[type="file"] { font-size: 0.82rem; }

table.post-form input[type="submit"],
table.post-form input[type="button"],
.submit-btn,
.submit-btn-cancel {
  display: inline-block;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  padding: 5px 14px;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  line-height: 1.4;
  white-space: nowrap;
}

/* Primary action — Post / Submit */
table.post-form input[type="submit"],
.submit-btn {
  background: var(--red);
  color: #fff;
  border-color: var(--red-dark);
  margin-left: 6px;
}
table.post-form input[type="submit"]:hover,
.submit-btn:hover {
  background: var(--red-dark);
  border-color: #600;
}

/* Secondary action — Cancel */
table.post-form input[type="button"],
.submit-btn-cancel {
  background: #e8ddd5;
  color: var(--red-dark);
  border-color: #c0a090;
  margin-left: 6px;
}
table.post-form input[type="button"]:hover,
.submit-btn-cancel:hover {
  background: #d9cdc4;
  border-color: #a08878;
}

.form-note {
  font-size: 0.78rem;
  color: var(--red);
  padding: 3px 6px;
}

#nt-form-wrap, #rp-form-wrap {
  display: none;
  margin-bottom: 10px;
  text-align: center;
}

/* ── Thread / Post layout ───────────────────────────────────────────────────── */

.thread-view { margin-top: 6px; }

/* OP post */
.post.op {
  background: var(--op-bg);
  padding: 8px 10px;
  margin-bottom: 6px;
  overflow: hidden; /* clearfix */
}

/* Reply posts */
.reply-container {
  clear: both;
  margin: 2px 0;
  padding: 2px 0;
  border-top: 1px solid rgba(0,0,0,0.06);
}

.post.reply {
  background: var(--reply-bg);
  padding: 5px 8px;
  margin-left: 20px;
  display: inline-block;
  max-width: calc(100% - 20px);
  overflow: hidden;
}

.post.mod-post { border-left: 3px solid var(--gold); }

/* Post info line */
.postInfo {
  font-size: 0.82rem;
  margin-bottom: 5px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px;
  clear: both;
}

.post.op .postInfo { clear: none; }

.post-subject  { color: var(--subject); font-weight: bold; font-size: 0.9rem; }
.post-name     { color: var(--name); font-weight: bold; }
.post-tripcode { color: var(--tripcode); font-size: 0.8rem; }
.post-date     { color: var(--muted); font-size: 0.8rem; }

.post-id {
  color: var(--link);
  font-size: 0.8rem;
  font-weight: bold;
  text-decoration: none;
  cursor: pointer;
}
.post-id:hover { color: var(--quotelink); text-decoration: underline; }

.post-inline-link {
  color: var(--link);
  font-size: 0.8rem;
  text-decoration: none;
  cursor: pointer;
}
.post-inline-link:hover { color: var(--quotelink); text-decoration: underline; }

.post-flair {
  background: rgba(200,146,42,0.12);
  border: 1px solid rgba(200,146,42,0.3);
  border-radius: 2px;
  padding: 0 4px;
  font-size: 0.72rem;
  color: var(--gold);
}

.post-mod-label { color: var(--gold); font-weight: bold; font-size: 0.8rem; }

.post-source-tag { font-size: 0.75rem; font-weight: bold; }
.source-tier-1   { color: #117743; }
.source-tier-2   { color: var(--link); }
.source-tier-3   { color: var(--gold); }
.source-tier-4   { color: var(--muted); }

.badge-pinned    { color: var(--gold); font-weight: bold; font-size: 0.8rem; }
.badge-locked    { color: var(--muted); font-size: 0.8rem; }
.badge-bump-limit { color: var(--quotelink); font-size: 0.8rem; }

/* File / media */
.post-file {
  float: left;
  margin: 0 14px 6px 0;
  text-align: center;
  max-width: 50%;
}

.file-info {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 3px;
  word-break: break-all;
}

.file-info a { color: var(--link); font-size: 0.75rem; }

.post-file img,
.post-file video {
  display: block;
  max-width: 300px;
  max-height: 300px;
  cursor: pointer;
  border: 1px solid var(--border);
  object-fit: contain;
}

.post-file.expanded {
  float: none;
  max-width: 100%;
  margin: 0 0 8px 0;
  clear: both;
}

.post-file.expanded img,
.post-file.expanded video,
img.expanded {
  max-width: min(800px, 100%);
  max-height: none;
}

.video-controls {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.vid-btn {
  background: var(--reply-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  padding: 2px 8px;
  cursor: pointer;
  font-family: inherit;
}

.vid-btn:hover {
  color: var(--text);
  border-color: var(--muted);
}

.index-img-float.expanded {
  float: none;
  margin: 0 0 8px 0;
  clear: both;
}

.index-img-float.expanded img {
  max-width: min(800px, 100%);
  max-height: none;
}

/* Post body */
.postMessage {
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
  overflow: hidden;
  display: block;
}

.postMessage .greentext     { color: var(--greentext); }
.postMessage .word-filtered { color: #c77d3e; }

.postMessage .quotelink {
  color: var(--quotelink);
  font-weight: bold;
  text-decoration: none;
}
.postMessage .quotelink:hover { text-decoration: underline; }

.postMessage a { color: var(--link); text-decoration: none; }
.postMessage a:hover { text-decoration: underline; }

/* Embeds */
.post-embed {
  margin-top: 8px;
  max-width: 560px;
}

.yt-embed {
  position: relative;
  width: 480px;
  max-width: 100%;
  height: 270px;
}

.yt-embed iframe {
  width: 100%;
  height: 100%;
}

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

.post-embed audio {
  width: 100%;
  margin-top: 4px;
}

/* Post footer */
.post-footer {
  font-size: 0.75rem;
  color: var(--muted);
  clear: both;
  margin-top: 5px;
}

.post-footer a, .post-footer .post-action {
  color: var(--muted);
  text-decoration: none;
  background: none;
  border: none;
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  padding: 0;
}

.post-footer a:hover, .post-footer .post-action:hover {
  color: var(--quotelink);
  text-decoration: underline;
}

.mod-controls { margin-left: 6px; }
.mod-del  { color: var(--quotelink) !important; }
.mod-ban  { color: var(--gold) !important; }
.mod-pin  { color: var(--tripcode) !important; }
.mod-lock { color: #888 !important; }

/* ── Poll ───────────────────────────────────────────────────────────────────── */

.poll {
  margin-top: 10px;
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--border);
  padding: 10px;
  clear: both;
}

.poll-question {
  font-size: 0.85rem;
  font-weight: bold;
  margin-bottom: 8px;
}

.poll-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}

.poll-bar-wrap {
  flex: 1;
  height: 5px;
  background: rgba(0,0,0,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.poll-bar {
  height: 100%;
  background: var(--link);
  border-radius: 2px;
  transition: width 0.3s;
}

.poll-label { font-size: 0.82rem; min-width: 120px; }
.poll-pct   { font-size: 0.75rem; color: var(--muted); min-width: 36px; text-align: right; }

/* ── View toggle ────────────────────────────────────────────────────────────── */

.board-actions {
  margin-top: 6px;
  font-size: 0.8rem;
}

.view-toggle-btn {
  color: var(--link);
  text-decoration: none;
}
.view-toggle-btn:hover  { color: var(--quotelink); text-decoration: underline; }
.view-toggle-btn.active { color: var(--red); font-weight: bold; text-decoration: none; }

/* ── Index view ─────────────────────────────────────────────────────────────── */

/* Outer thread container: clearfixes the floating image */
.index-thread {
  padding: 8px 0 6px;
  overflow: hidden;
}

hr.index-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0;
}

/* Thumbnail floated explicitly at the thread level */
.index-img-float {
  float: left;
  margin: 0 10px 4px 0;
}

.index-img-float .file-info {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 3px;
  word-break: break-all;
}

.index-img-float img {
  display: block;
  max-width: 300px;
  max-height: 300px;
  object-fit: contain;
  border: 1px solid var(--border);
  cursor: pointer;
}

.index-main {
  overflow: hidden; /* BFC — locks this block to the right of the float */
}

/* OP info block inside the main column */
.index-op-header {
  margin-bottom: 4px;
}

.index-op-header .postInfo {
  flex-wrap: nowrap;
  overflow: hidden;
}

/* Replies beside the OP (first 2) */
.index-aside .reply-container {
  clear: none;
  border-top: 1px solid rgba(0,0,0,0.06);
  padding: 1px 0;
}

.index-aside .reply-container:first-child { border-top: none; }

.index-aside .post.reply,
.index-replies-below .post.reply {
  display: block;
  margin-left: 0;
  max-width: 100%;
}

.index-replies-below .reply-container {
  clear: none;
  border-top: 1px solid rgba(0,0,0,0.06);
  padding: 1px 0;
}

.index-replies-below .reply-container:first-child { border-top: none; }

.index-omitted {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 2px 0;
}

.index-omitted a { color: var(--link); font-size: 0.8rem; }

/* Below replies — outside the BFC, cleared below the image float */
.index-replies-below {
  clear: both;
  margin-top: 2px;
}

/* ── Catalog ────────────────────────────────────────────────────────────────── */

.catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.catalog-card {
  background: var(--reply-bg);
  border: 1px solid var(--border);
  padding: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.catalog-card:hover { border-color: var(--link); }
.catalog-card.pinned { border-color: var(--gold); }

.catalog-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: rgba(0,0,0,0.06);
}

.catalog-thumb-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 1.8rem;
}

.catalog-subject {
  font-size: 0.82rem;
  font-weight: bold;
  color: var(--subject);
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.catalog-excerpt {
  font-size: 0.75rem;
  color: var(--text);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.catalog-meta {
  display: flex;
  gap: 8px;
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: auto;
}

.catalog-meta .replies { color: var(--link); font-weight: bold; }

/* ── Breadcrumb ─────────────────────────────────────────────────────────────── */

.breadcrumb {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.breadcrumb a     { color: var(--link); font-size: 0.8rem; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep  { color: var(--muted); }

/* ── Reply form (bottom of thread) ─────────────────────────────────────────── */

.reply-form-wrap {
  margin-top: 14px;
  text-align: center;
}

.reply-form-wrap .form-section-title {
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--red-dark);
  margin-bottom: 6px;
}

/* ── Quick reply box ────────────────────────────────────────────────────────── */

#qr {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--form-bg);
  border: 1px solid var(--border-form);
  padding: 10px;
  z-index: 200;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.25);
  display: none;
  min-width: 320px;
}

#qr.open { display: block; }

#qr-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: bold;
  font-size: 0.85rem;
  color: var(--red-dark);
}

#qr-header button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  line-height: 1;
  padding: 0;
}

/* ── Buttons (for non-form contexts) ────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  border: 1px solid #999;
  background: #f0f0f0;
  color: #000;
  border-radius: 2px;
}

.btn:hover { background: #e0e0e0; }

.btn-primary { background: var(--nav-bg); color: #fff; border-color: var(--nav-border); }
.btn-primary:hover { background: var(--nav-border); }

.btn-ghost { background: rgba(0,0,0,0.04); border-color: var(--border); color: var(--muted); }
.btn-ghost:hover { background: rgba(0,0,0,0.08); color: var(--text); }

.btn-danger { background: rgba(211,0,0,0.08); border-color: rgba(211,0,0,0.3); color: var(--quotelink); }
.btn-danger:hover { background: rgba(211,0,0,0.15); }

/* ── Misc ───────────────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  padding: 50px 0;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */

@media (max-width: 680px) {
  #app { padding: 8px 6px 60px; }
  .catalog { grid-template-columns: 1fr 1fr; }
  table.post-form input[type="text"],
  table.post-form textarea { width: 180px; }
  .post.reply { margin-left: 8px; max-width: calc(100% - 8px); }
  .post-file { max-width: 40%; }
  .post-file img, .post-file video { max-width: 120px; max-height: 120px; }
  #qr { min-width: calc(100vw - 20px); right: 10px; bottom: 10px; }
  .nav-links { display: none; }
}
