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

html, body {
  overflow: hidden;
  overscroll-behavior: none;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-weight: 700;
  font-size: 17px;
  line-height: 1.7;
  color: #e8eaed;
  background: #0f1115;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

header {
  flex: 0 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  background: #161922;
  border-bottom: 1px solid #2a2f3a;
}

h1 {
  font-size: 20px;
  letter-spacing: 0.08em;
  color: #8ab4ff;
  margin-bottom: 10px;
}

#q {
  width: 100%;
  font: inherit;
  font-size: 17px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid #3a4152;
  background: #0f1115;
  color: #e8eaed;
}
#q:focus { outline: none; border-color: #8ab4ff; }

#filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior: none;
  padding: 10px 0 2px;
  -webkit-overflow-scrolling: touch;
}
.chip {
  flex: 0 0 auto;
  font: inherit;
  font-size: 15px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 2px solid #3a4152;
  background: transparent;
  color: #b8bcc6;
  white-space: nowrap;
  cursor: pointer;
}
.chip.active { background: #8ab4ff; border-color: #8ab4ff; color: #0f1115; }

#stat { font-size: 14px; color: #8b909c; padding-top: 6px; }

main {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
}

.card {
  background: #161922;
  border: 1px solid #2a2f3a;
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
  cursor: pointer;
  display: flex;
  gap: 14px;
}
.card:active { border-color: #8ab4ff; }
.card .cover {
  flex: 0 0 auto;
  width: 56px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  background: #2a2f3a;
}
.card .body { min-width: 0; flex: 1 1 auto; }
.card h2 { font-size: 18px; color: #e8eaed; margin-bottom: 6px; }
.card .meta { font-size: 14px; color: #8b909c; margin-bottom: 8px; }
.card .meta span { margin-right: 12px; }
.card .snip { font-size: 15px; color: #c7cad2; font-weight: 400; }

mark { background: #ffd54a; color: #0f1115; border-radius: 3px; padding: 0 2px; }

.empty { text-align: center; color: #8b909c; padding: 48px 0; font-size: 16px; }

#detail.hidden { display: none; }
#detail {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
.sheet {
  background: #12151d;
  width: 100%;
  max-width: 760px;
  max-height: 92dvh;
  border-radius: 18px 18px 0 0;
  padding: 20px 20px calc(28px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: none;
  position: relative;
}
#close {
  position: sticky;
  top: 0;
  float: right;
  font-size: 26px;
  line-height: 1;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #2a2f3a;
  color: #e8eaed;
  cursor: pointer;
}
#detail-body .cover {
  float: right;
  width: 96px;
  height: auto;
  margin: 0 0 10px 14px;
  border-radius: 6px;
}
#detail-body h2 { font-size: 21px; margin-bottom: 8px; padding-right: 48px; }
#detail-body .meta { font-size: 14px; color: #8b909c; margin-bottom: 4px; }
#detail-body .meta a { color: #8ab4ff; }
#detail-body .body {
  margin-top: 16px;
  font-weight: 400;
  font-size: 16px;
  white-space: pre-wrap;
  word-break: break-word;
}
#detail-body .body h1, #detail-body .body h2, #detail-body .body h3 {
  font-weight: 700;
  margin: 18px 0 6px;
  font-size: 18px;
  color: #cfe0ff;
}

@media (prefers-color-scheme: light) {
  body { color: #1a1c20; background: #f4f5f7; }
  header { background: #fff; border-color: #e2e4e8; }
  #q { background: #fff; color: #1a1c20; border-color: #cfd2d8; }
  .card, .sheet { background: #fff; border-color: #e2e4e8; }
  #detail-body .body { color: #1a1c20; }
  .card .snip, .card h2 { color: #1a1c20; }
}
