:root {
  color-scheme: light dark;
  --bg: #f6f7f3;
  --paper: #ffffff;
  --ink: #1b1c1f;
  --muted: #626871;
  --line: #dde2de;
  --accent: #1e6f68;
  --accent-ink: #ffffff;
  --soft: #e9f2ee;
  --quote-bg: #f0f4f2;
  --quote-border: #9dbfba;
  --topbar-bg: rgba(246, 247, 243, 0.94);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --paper: #1a1f1e;
    --ink: #e4e8e6;
    --muted: #8a9490;
    --line: #2a3330;
    --accent: #2d9e95;
    --accent-ink: #ffffff;
    --soft: #1a2e2b;
    --quote-bg: #1f2a28;
    --quote-border: #2d6b64;
    --topbar-bg: rgba(15, 20, 18, 0.94);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  grid-template-rows: auto auto;
  column-gap: 8px;
  row-gap: 0;
  padding: 10px 12px 0;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.topbar-title {
  text-align: center;
  min-width: 0;
  padding-bottom: 10px;
}

h1 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

p {
  margin: 0;
}

.back-button,
.icon-button {
  padding-bottom: 10px;
}

.breadcrumb {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  white-space: nowrap;
  padding: 6px 0 8px;
  font-size: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

.breadcrumb::-webkit-scrollbar {
  display: none;
}

.breadcrumb-link {
  background: none;
  border: none;
  padding: 2px 4px;
  margin: 0;
  color: var(--accent);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 4px;
  -webkit-tap-highlight-color: transparent;
}

.breadcrumb-link:active {
  background: var(--soft);
}

.breadcrumb-sep {
  color: var(--line);
  font-size: 0.85rem;
  flex-shrink: 0;
  user-select: none;
  padding: 0 1px;
}

.breadcrumb-current {
  color: var(--muted);
  font-size: 0.75rem;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.back-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.back-button:active {
  background: var(--soft);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  justify-self: end;
  -webkit-tap-highlight-color: transparent;
}

.icon-button:active {
  background: var(--soft);
}

main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 12px;
}

.controls {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

input[type="search"] {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 14px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}

input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sort-button {
  flex-shrink: 0;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.sort-button:active {
  background: var(--soft);
}

.status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 22px 6px;
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

.retry-button {
  min-height: 40px;
  padding: 0 20px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.retry-button:active {
  background: var(--soft);
}

.list {
  display: grid;
  gap: 10px;
}

.card {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}

.card:active {
  background: var(--soft);
}

.card h2 {
  margin: 0;
  font-size: 0.97rem;
  line-height: 1.3;
  color: var(--ink);
}

.card p,
.meta {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta span::before {
  content: "·";
  margin-right: 6px;
  opacity: 0.5;
}

.meta span:first-child::before {
  display: none;
}

.subforum-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.subforum-tag {
  display: inline-block;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  color: var(--accent);
  font-size: 0.75rem;
  line-height: 1.4;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  text-align: left;
  font-family: inherit;
  white-space: normal;
  word-break: break-word;
}

.subforum-tag:active {
  background: var(--soft);
  border-color: var(--accent);
}

.detail {
  display: grid;
  gap: 10px;
}

.post {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}

.post header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.post header strong {
  color: var(--accent);
  font-size: 0.9rem;
}

.post header span {
  color: var(--muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}

.post-body {
  font-size: 0.95rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  color: var(--ink);
}

.post-body blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  background: var(--quote-bg);
  border-left: 3px solid var(--quote-border);
  border-radius: 0 6px 6px 0;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: pre-wrap;
}

.post-body blockquote cite {
  display: block;
  font-style: normal;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

.load-more {
  display: flex;
  justify-content: center;
  padding: 16px 0 8px;
}

.load-more button {
  min-height: 44px;
  padding: 0 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--accent);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.load-more button:active {
  background: var(--soft);
}

/* Skeleton loading */
.skeleton-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  display: grid;
  gap: 8px;
}

.skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--line) 25%, color-mix(in srgb, var(--line) 60%, var(--bg)) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

.skeleton-line.short { width: 45%; }
.skeleton-line.medium { width: 70%; }
.skeleton-line.long { width: 90%; }
.skeleton-line.title { height: 18px; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.hidden {
  display: none !important;
}

.invisible {
  visibility: hidden !important;
  pointer-events: none !important;
}

@media (min-width: 700px) {
  main {
    padding-top: 18px;
  }
}
