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

:root {
  --bg-color: #0c0d0e;
  --card-bg: #151618;
  --text-color: #d8dade;
  --text-muted: #8e929b;
  --border-color: #222428;
  --accent-blue: #4f87e2;
  --accent-hover: #659af0;
  --mono-font: ui-monospace, "SF Mono", "Cascadia Code", "Courier New", monospace;
}

/* Everything below is sized in rem, so this single line scales the whole UI:
   14px on phones, ~15px at 1280, ~17px at 1920, ~24px at 3840 CSS px wide. */
html {
  font-size: clamp(14px, 0.35vw + 10.5px, 24px);
  -webkit-text-size-adjust: 100%;
}

html, body {
  height: 100%;
  height: 100dvh;
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: var(--mono-font);
  line-height: 1.5;
  overflow: hidden;
}

body {
  font-size: 1rem;
}

#app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  max-width: 64rem;
  margin: 0 auto;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: calc(0.7rem + env(safe-area-inset-top)) 1rem 0.7rem;
  border-bottom: 1px solid var(--border-color);
  background: #101114;
  flex-shrink: 0;
}

.nav-threads {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.nav-pill {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  background: #1c1e22;
  color: var(--text-color);
  text-decoration: none;
  border: 1px solid var(--border-color);
  border-radius: 0.3rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.nav-pill:hover {
  border-color: var(--accent-blue);
  color: #fff;
}

.nav-pill.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.thread-indicator {
  font-weight: 700;
  color: var(--accent-blue);
  letter-spacing: 0.04rem;
}

/* JSON Syntax Highlighting */
.json-key     { color: var(--accent-blue); font-weight: 600; }
.json-string  { color: #98c379; } /* Soft green */
.json-number  { color: #d19a66; } /* Warm orange */
.json-boolean { color: #c678dd; } /* Purple */
.json-null    { color: #e06c75; } /* Red/Coral */

/* Generic code highlighting (class = "hl-" + token kind) */
.hl-c    { color: #7a8090; font-style: italic; }       /* comment */
.hl-s    { color: #98c379; }                           /* string */
.hl-n    { color: #d19a66; }                           /* number */
.hl-k    { color: #c678dd; }                           /* keyword */
.hl-l    { color: #56b6c2; }                           /* literal / option / entity */
.hl-t    { color: #e5c07b; }                           /* type / tag / section */
.hl-v    { color: #e06c75; }                           /* variable / attribute */
.hl-key  { color: var(--accent-blue); font-weight: 600; }
.hl-add  { color: #98c379; }
.hl-del  { color: #e06c75; }
.hl-hunk { color: #56b6c2; }
.hl-meta { color: var(--text-muted); font-weight: 600; }

/* The wrapper holds the pill so it stays put while the viewport scrolls */
#messages-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#messages-viewport {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem;
  scroll-behavior: smooth;
}

#messages-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem; /* Small gap between messages */
}

.message-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.45rem;
  padding: 0.7rem 0.85rem;
  transition: outline 0.15s ease, background-color 0.15s ease;
}

.message-card:target {
  outline: 1px solid var(--accent-blue);
  background-color: #1e222b !important;
}

.message-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 0.55rem;
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
  user-select: none;
}

.message-header .seq-link {
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
}

.message-header .seq-link:hover {
  color: var(--accent-blue);
  text-decoration: underline;
}

.message-header .author-pid {
  color: #9cb3d9;
}

.message-header .author-nick {
  color: #e5e7eb;
  font-weight: 600;
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-color);
}

.message-body a.quote-link {
  color: var(--accent-blue);
  text-decoration: none;
}

.message-body a.quote-link:hover {
  text-decoration: underline;
}

.deleted-text {
  color: #6b7280;
  font-style: italic;
}

/* Links */
.message-body a.url-link {
  color: var(--accent-blue);
  text-decoration: underline;
  word-break: break-all;
}
.message-body a.url-link:hover {
  color: var(--accent-hover);
}

/* Micro-Markdown */
.md-line {
  min-height: 1.4em; /* Preserves empty newlines */
}

.md-bold {
  font-weight: 700;
  color: #fff;
}

.inline-code {
  background: #18191c;
  border: 1px solid var(--border-color);
  padding: 0.08rem 0.35rem;
  border-radius: 0.2rem;
  font-size: 0.86rem;
  color: #e06c75;
}

.md-code-block {
  background: #090a0c;
  border: 1px solid var(--border-color);
  border-radius: 0.3rem;
  padding: 0.55rem 0.7rem;
  margin: 0.45rem 0;
  font-family: var(--mono-font);
  font-size: 0.86rem;
  overflow-x: auto;
  white-space: pre;
  tab-size: 4;
}

.md-header {
  font-weight: 700;
  margin: 0.3rem 0 0.15rem 0;
}
.md-h1 { font-size: 1.14rem; color: #fff; border-bottom: 1px solid var(--border-color); padding-bottom: 0.15rem; }
.md-h2 { font-size: 1.07rem; color: var(--accent-blue); }
.md-h3 { font-size: 1rem; color: #abb2bf; text-decoration: underline; }

#unread-pill {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-blue);
  color: #fff;
  padding: 0.45rem 1rem;
  border-radius: 1.4rem;
  font-weight: 600;
  font-size: 0.86rem;
  box-shadow: 0 0.3rem 0.85rem rgba(0, 0, 0, 0.5);
  cursor: pointer;
  z-index: 10;
  display: none;
  touch-action: manipulation;
}

#unread-pill:hover {
  background: var(--accent-hover);
}

/* ---- Post bar ----
   Mobile first: a slim nick/counter row on top, then message box + send button
   sharing the full width. Wide screens put all three in one row. */
#post-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--border-color);
  background: #101114;
  padding: 0.6rem 1rem;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "meta meta"
    "msg  send";
  gap: 0.5rem;
  align-items: end;
}

.post-meta {
  grid-area: meta;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

#byte-counter {
  margin-left: auto;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--text-muted);
  user-select: none;
  font-family: var(--mono-font);
}

#nick-input {
  flex: 1 1 8rem;
  min-width: 0;
  max-width: 16rem;
  padding: 0.4rem 0.6rem;
  background: #18191c;
  border: 1px solid var(--border-color);
  border-radius: 0.3rem;
  color: var(--text-color);
  font-family: var(--mono-font);
  font-size: 0.93rem;
}

#nick-input:focus, #msg-input:focus {
  outline: none;
  border-color: var(--accent-blue);
}

#msg-input {
  grid-area: msg;
  min-width: 0;
  min-height: 3.4rem;
  max-height: 40dvh;
  padding: 0.55rem 0.7rem;
  background: #18191c;
  border: 1px solid var(--border-color);
  border-radius: 0.3rem;
  color: var(--text-color);
  font-family: var(--mono-font);
  font-size: 0.93rem;
  line-height: 1.4;
  resize: vertical;
  field-sizing: content; /* auto-grow where supported; otherwise rows="2" + resize handle */
}

#send-btn {
  grid-area: send;
  align-self: stretch;
  padding: 0.55rem 1.1rem;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: 0.3rem;
  font-family: var(--mono-font);
  font-size: 0.93rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

#send-btn:hover {
  background: var(--accent-hover);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#status-line {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.3rem 1rem calc(0.4rem + env(safe-area-inset-bottom));
  background: #101114;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

/* Wide screens: nick + counter column | message | send, all on one row */
@media (min-width: 48rem) {
  #post-bar {
    grid-template-columns: 10rem 1fr auto;
    grid-template-areas: "meta msg send";
  }
  .post-meta {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 0.3rem;
  }
  #byte-counter {
    margin-left: 0;
  }
  #nick-input {
    flex: none;
    max-width: none;
    padding: 0.55rem 0.7rem;
  }
  #msg-input {
    min-height: 5rem;
  }
  #send-btn {
    align-self: end;
  }
}

/* Touch devices: 16px inputs stop iOS from zooming the page on focus,
   and pills get a bigger tap target. */
@media (pointer: coarse) {
  #nick-input, #msg-input {
    font-size: 16px;
  }
  .nav-pill {
    padding: 0.4rem 0.7rem;
  }
}
