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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #333;
  --accent: #1d9bf0;
  --accent-hover: #1a8cd8;
  --text: #e7e9ea;
  --text-muted: #71767b;
  --radius: 12px;
  --gap: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 15, 15, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 56px;
  position: relative; /* 検索バーオーバーレイのアンカー */
}

header h1 {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 0;
    gap: 8px;
  }

  header h1 {
    font-size: 16px;
    flex: 0 0 auto;
  }

  .stats {
    order: 3;
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 4px;
  }

  .tabs {
    flex: 1 1 auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

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

  .tab {
    padding: 5px 12px;
    font-size: 13px;
    white-space: nowrap;
  }
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  transition: background .15s, color .15s;
}

.tab:hover { background: var(--surface2); color: var(--text); }
.tab.active { background: var(--accent); color: #fff; }

/* ── Stats ── */
.stats {
  margin-left: auto;
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.stats span { white-space: nowrap; }

/* ── 検索トグルボタン ── */
.search-toggle {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: color .15s, background .15s;
  line-height: 1;
}
.search-toggle:hover { color: var(--text); background: var(--surface2); }

/* ── 検索バーオーバーレイ ──
   position:absolute で .header-inner 全体を覆う。
   ギャラリーのレイアウトは一切変化しない。 */
.search-bar {
  position: absolute;
  inset: 0;
  background: var(--surface);
  display: none;
  align-items: center;
  padding: 0 4px;
  gap: 8px;
  z-index: 10;
  border-radius: 4px;
}
.search-bar.open { display: flex; }

.search-bar form {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.search-bar input[type="text"] {
  flex: 1;
  padding: 8px 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 16px; /* 16px未満だとiOS Safariがフォーカス時に自動ズームするため */
  outline: none;
  transition: border-color .15s;
}
.search-bar input[type="text"]:focus { border-color: var(--accent); }

.search-submit {
  flex-shrink: 0;
  padding: 7px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.search-submit:hover { background: var(--accent-hover); }

.search-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  line-height: 1;
  transition: color .15s, background .15s;
}
.search-close:hover { color: var(--text); background: var(--surface2); }

/* ── 検索結果件数 ── */
.search-result-info {
  padding: 10px 24px 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Gallery ── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 80px 0;
  font-size: 16px;
}

/* Grid layout: left-to-right, then next row */
.gallery {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--gap);
}

@media (max-width: 1200px) { .gallery { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 900px)  { .gallery { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px)  { .gallery { grid-template-columns: repeat(2, 1fr); } }

.card {
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  background: var(--surface);
  transition: transform .2s, box-shadow .2s;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}

.card img {
  width: 100%;
  display: block;
  object-fit: cover;
}

.card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  backdrop-filter: blur(6px);
}
.badge-cooking { background: rgba(255, 120, 20, 0.85); color: #fff; }
.badge-manga   { background: rgba(130, 80, 230, 0.85); color: #fff; }
.badge-both    { background: rgba(29, 155, 240, 0.85); color: #fff; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 200;
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-width: 900px;
  width: 95vw;
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Header: 非スクロール領域 — sticky 不要 */
.modal-header {
  position: relative;
  flex-shrink: 0;
  height: 50px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* Body: スクロール領域 */
.modal-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

@media (min-width: 700px) {
  .modal { max-height: 85vh; }
  .modal-body {
    flex-direction: row;
    overflow-y: hidden;
  }
}

/* Image side */
.modal-images {
  flex: 1 1 50%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 200px;
}

.modal-images img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  display: block;
}

@media (max-width: 699px) {
  .modal-images {
    max-height: 50vh;
    min-height: unset;
  }
  .modal-images img {
    max-height: 50vh;
  }
}

.slide-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,.6);
  border: none;
  color: #fff;
  font-size: 22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  z-index: 1;
}
.slide-btn:hover { background: rgba(0,0,0,.9); }
.slide-btn.prev { left: 8px; }
.slide-btn.next { right: 8px; }
.slide-count {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
}

/* Info side */
.modal-info {
  flex: 1 1 50%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.modal-close:hover { background: var(--border); }

.modal-text {
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  width: fit-content;
  transition: background .15s;
}
.modal-link:hover { background: var(--accent-hover); }
