:root {
  --bg: var(--tg-theme-bg-color, #f3f5f7);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #18212b);
  --muted: var(--tg-theme-hint-color, #718096);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2563eb);
  --border: color-mix(in srgb, var(--muted) 24%, transparent);
  --danger: var(--tg-theme-destructive-text-color, #d14343);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

button, input { font: inherit; }
button { color: inherit; }

.shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(1.65rem, 7vw, 2.2rem); line-height: 1.1; }
h2 { margin-bottom: 3px; font-size: 1.05rem; }
.muted { color: var(--muted); }
.topbar .muted { margin-bottom: 0; font-size: 0.9rem; }

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-size: 1.45rem;
  cursor: pointer;
}

.search-panel {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
}

.search-panel label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.82rem;
  font-weight: 700;
}

.search-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--bg);
}

.search-row input {
  width: 100%;
  min-width: 0;
  padding: 12px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.search-row input::placeholder { color: var(--muted); }
.search-row button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.35rem;
  cursor: pointer;
}

.topic-chips {
  display: flex;
  gap: 8px;
  margin: 14px -16px 4px;
  padding: 2px 16px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.topic-chips::-webkit-scrollbar { display: none; }

.topic-chip {
  flex: 0 0 auto;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}

.topic-chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 2px 10px;
}
.section-heading p { margin-bottom: 0; font-size: 0.82rem; }

.badge {
  padding: 5px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
}

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

.archive-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 17px;
  background: var(--surface);
}

.archive-open {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.archive-open:active { background: color-mix(in srgb, var(--accent) 8%, transparent); }

.archive-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  font-size: 1.25rem;
}

.archive-content { display: grid; min-width: 0; gap: 4px; }
.archive-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.archive-meta { color: var(--muted); font-size: 0.8rem; }
.archive-arrow { color: var(--muted); font-size: 1.8rem; }

.notice {
  display: grid;
  gap: 5px;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 17px;
  color: var(--muted);
  text-align: center;
}
.notice strong { color: var(--text); }
.notice.error { border-style: solid; border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }

.load-more {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
}

@media (min-width: 640px) {
  .archive-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
