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

:root {
  --bg: #d6ccb4;
  --fg: #241c0e;
  --muted: #7a6a52;
  --border: #bfb59e;
  --max: 680px;
  --font: 'Roboto', sans-serif;
  --mono: 'Courier New', monospace;
  --code-bg: #ccc3aa;
  --table-head: #ccc3aa;
  --table-stripe: #d0c8b0;
  --sources-color: #a09080;
  --sources-head: #b0a090;
}

[data-theme="dark"] {
  --bg: #141414;
  --fg: #e8e8e8;
  --muted: #666;
  --border: #2a2a2a;
  --code-bg: #1e1e1e;
  --table-head: #1e1e1e;
  --table-stripe: #181818;
  --sources-color: #555;
  --sources-head: #444;
}

html { font-size: 18px; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  line-height: 1.7;
  padding: 0 1.5rem;
}

/* ── Layout ── */
header {
  max-width: var(--max);
  margin: 0 auto;
  padding: 3rem 0 2rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

header a.site-title {
  font-size: 1.1rem;
  font-weight: bold;
  letter-spacing: -.02em;
  text-decoration: none;
  color: var(--fg);
  padding-top: .15rem;
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .6rem;
}

nav {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  font-size: 0.85rem;
}

nav a {
  color: var(--muted);
  text-decoration: none;
  transition: color .15s;
}

nav a:hover { color: var(--fg); }

.header-search {
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: .15rem 0;
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--fg);
  outline: none;
  width: 160px;
  text-align: right;
  transition: border-color .15s, width .2s;
}

.header-search::placeholder { color: var(--muted); }
.header-search:focus {
  border-color: var(--fg);
  width: 200px;
}

.header-search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  display: none;
}

.lang-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .2rem .6rem;
  font-size: 0.78rem;
  font-family: var(--mono);
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
  letter-spacing: .05em;
}

.lang-toggle:hover {
  color: var(--fg);
  border-color: var(--fg);
}

/* ── Dark mode toggle switch ── */
.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 48px;
  height: 26px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--border);
  border: 1px solid var(--border);
  transition: background .25s, border-color .25s;
}

[data-theme="dark"] .toggle-track {
  background: #333;
  border-color: #444;
}

.toggle-thumb {
  position: absolute;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg);
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .25s, background .25s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

[data-theme="dark"] .toggle-thumb {
  transform: translateX(22px);
  background: #555;
}

main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 3rem 0 6rem;
}

footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 2rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  font-family: var(--mono);
}

footer a {
  color: #4a7fb5;
  text-decoration: none;
}

footer a:hover { opacity: .7; }

[data-theme="dark"] footer a {
  color: #e8e8e8;
}

/* ── Index: post list ── */
.post-list { list-style: none; }

.post-list li {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: .5rem 1.5rem;
  padding: 1.4rem 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}

.post-list li:first-child { border-top: 1px solid var(--border); }

.post-date {
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--muted);
  padding-top: .15rem;
}

.post-title {
  font-size: 1rem;
  font-weight: normal;
  text-decoration: none;
  color: var(--fg);
  transition: opacity .15s;
}

.post-title:hover { opacity: .55; }

.post-tag { display: none; }

/* ── Toolbar (search + sort) ── */
.toolbar {
  display: flex;
  gap: .75rem;
  margin-bottom: 2rem;
  align-items: center;
}

.search-input {
  flex: 1;
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .35rem .75rem;
  font-size: 0.82rem;
  font-family: var(--mono);
  color: var(--fg);
  outline: none;
  transition: border-color .15s;
}

.search-input::placeholder { color: var(--muted); }
.search-input:focus { border-color: var(--fg); }

.sort-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .35rem .85rem;
  font-size: 0.78rem;
  font-family: var(--mono);
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
  transition: all .15s;
}

.sort-btn:hover {
  color: var(--fg);
  border-color: var(--fg);
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.page-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .3rem .9rem;
  font-size: 0.78rem;
  font-family: var(--mono);
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}

.page-btn:hover:not(:disabled) {
  color: var(--fg);
  border-color: var(--fg);
}

.page-btn:disabled {
  opacity: .3;
  cursor: default;
}

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

/* ── Return badge ── */
.return-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-family: var(--mono);
  padding: .1rem .35rem;
  border-radius: 3px;
  vertical-align: middle;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  letter-spacing: .02em;
}

.return-badge.ret-pos {
  color: #4caf7d;
  border-color: #4caf7d44;
  background: #4caf7d11;
}

.return-badge.ret-neg {
  color: #e05c5c;
  border-color: #e05c5c44;
  background: #e05c5c11;
}

.post-date-col {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  align-items: center;
}

.return-wrap {
  width: 100%;
  text-align: center;
}

.return-label {
  display: block;
  font-size: 0.62rem;
  font-family: var(--mono);
  color: var(--muted);
  opacity: .6;
  margin-top: .2rem;
}

.return-badge--post {
  font-size: 0.75rem;
  padding: .15rem .45rem;
}

/* ── Filter tags ── */
.tag-filter {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: 2.5rem;
}

.tag-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: .2rem .7rem;
  font-size: 0.75rem;
  font-family: var(--mono);
  cursor: pointer;
  color: var(--muted);
  transition: all .15s;
}

.tag-btn:hover, .tag-btn.active {
  color: var(--fg);
  border-color: var(--fg);
}

/* ── Single post ── */
.post-header { margin-bottom: 3rem; }

.post-header h1 {
  font-size: 1.6rem;
  font-weight: bold;
  letter-spacing: -.02em;
  line-height: 1.3;
  margin-bottom: .75rem;
}

.post-meta {
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--muted);
}

.post-sources {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--sources-color);
}

.post-sources h2 {
  font-size: 0.78rem;
  color: var(--sources-head);
  margin-bottom: .75rem;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.post-sources p { margin-bottom: .5rem; }

.post-sources a {
  color: var(--sources-color);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.post-sources a:hover { color: var(--muted); }

.post-disclaimer {
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--muted);
  border-left: 2px solid var(--border);
  padding-left: 1rem;
  margin-bottom: 2.5rem;
  line-height: 1.6;
}

.post-body { max-width: var(--max); }

.post-body p { margin-bottom: 1.4rem; }

.post-body h2 {
  font-size: 1.1rem;
  margin: 2.5rem 0 .8rem;
  letter-spacing: -.01em;
}

.post-body h3 {
  font-size: 1rem;
  margin: 2rem 0 .6rem;
  color: var(--muted);
}

.post-body blockquote {
  border-left: 2px solid var(--fg);
  padding-left: 1.2rem;
  margin: 1.5rem 0;
  color: var(--muted);
  font-style: italic;
}

.post-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-family: var(--mono);
  margin-bottom: 1.4rem;
}

.post-body th, .post-body td {
  border: 1px solid var(--border);
  padding: .45rem .75rem;
  text-align: left;
}

.post-body th {
  background: var(--table-head);
  font-weight: bold;
}

.post-body tr:nth-child(even) td { background: var(--table-stripe); }

.post-body a { color: var(--fg); }
.post-body a:hover { opacity: .55; }

.post-body ul, .post-body ol {
  padding-left: 1.4rem;
  margin-bottom: 1.4rem;
}

.post-body li { margin-bottom: .4rem; }

.post-body code {
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--code-bg);
  padding: .1rem .3rem;
  border-radius: 2px;
}

.back-link {
  display: inline-block;
  font-size: 0.82rem;
  font-family: var(--mono);
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 2.5rem;
  transition: color .15s;
}

.back-link:hover { color: var(--fg); }

/* ── About page ── */
.about-body { max-width: var(--max); }
.about-body p { margin-bottom: 1.4rem; }

/* ── Responsive ── */
@media (max-width: 520px) {
  html { font-size: 16px; }

  .post-list li {
    grid-template-columns: 1fr;
    gap: .2rem;
    text-align: center;
  }

  .post-tag { grid-column: 1; }
}
