:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f5f4f0;
  --surface-2: #ecebe6;
  --text: #1b1b1a;
  --muted: #605e59;
  --line: #e2e0da;
  --accent: #b3243f;
  --accent-strong: #8f1d33;
  --focus: #1a56db;
  --viewer-bg: #000000;
  --viewer-text: #ffffff;
  --viewer-muted: #d9d8d3;
  --viewer-panel: calc(196px + env(safe-area-inset-bottom));
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0 auto;
  min-height: 100dvh;
  max-width: 430px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, a { font: inherit; }

button, a { -webkit-tap-highlight-color: transparent; }

button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.icon {
  display: block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

/* ---------- ヘッダー ---------- */

/* 固定ヘッダー（2026-09-03 吉田さま決定）: ブランド行＋チップ行だけを画面上部に固定する */
.site-header {
  position: sticky;
  z-index: 15;
  top: 0;
  border-bottom: 1px solid var(--line);
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
}
.site-intro { padding: 12px 16px 0; }

.site-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  display: block;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  color: var(--text);
}

.site-header h1 {
  overflow: hidden;
  margin: 0;
  font-size: clamp(15.5px, 4.4vw, 19px);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions { display: flex; flex: 0 0 auto; gap: 6px; }

.header-action {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}
.header-action .icon { width: 16px; height: 16px; }
.header-action:active { background: var(--surface); }
.header-action[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-toggle .icon-on { display: none; }
.icon-toggle.is-on .icon-on { display: block; }
.icon-toggle.is-on .icon-off { display: none; }

.site-tagline {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.site-facts {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 6px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

/* 切り口のチップ（注目・新着・人気・いいね）。JS が固定ヘッダーの末尾に作る */
.cut-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  margin: 8px 0 0;
}
.cut-chip {
  display: inline-flex;
  min-height: 44px;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}
.cut-chip:active { background: var(--surface); }
.cut-chip.is-selected {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
}
.view-summary {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

/* 検索: 一致した部分の強調と、結果カードの印 */
mark.hit {
  border-radius: 2px;
  padding: 0 1px;
  background: #fff1a8;
  color: inherit;
}
.card-flag {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

/* ---------- 検索画面 ---------- */

.search-header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: calc(56px + env(safe-area-inset-top));
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: max(8px, env(safe-area-inset-top)) 12px 8px 8px;
  background: rgba(255, 255, 255, .96);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.search-header h1 { margin: 0; font-size: 17px; font-weight: 700; }
.search-back {
  display: inline-flex;
  min-height: 44px;
  min-width: 44px;
  align-items: center;
  gap: 4px;
  border: 0;
  padding: 0 8px;
  background: transparent;
  color: var(--text);
  font-weight: 700;
}

.search-controls { padding: 16px 16px 4px; }
.search-input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
}
.search-input::placeholder { color: var(--muted); }
.tag-visibility { margin: 22px 0 0; border: 0; padding: 0; }
.service-visibility { margin-top: 18px; }
.untagged-option { border-top: 1px solid var(--line); margin-top: 6px; }
.tag-visibility legend { margin-bottom: 6px; padding: 0; font-size: 14px; font-weight: 700; }
.tag-list { border-top: 1px solid var(--line); }
.tag-option {
  display: grid;
  min-height: 48px;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 14px;
}
.tag-option input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.tag-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.untagged-notice { margin: 12px 0 6px; color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.search-result-count {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 16px 12px;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.search-result-count::before,
.search-result-count::after { height: 1px; flex: 1; background: var(--line); content: ""; }

/* ---------- 状態 ---------- */

.loading, .empty-state { margin: 48px 20px; color: var(--muted); text-align: center; line-height: 1.7; }
.empty-state h2 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.empty-state p { margin: 0; }
.list-end {
  margin: 8px 16px 8px;
  padding: 18px 24px 6px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
  text-align: center;
  text-wrap: balance;
}

/* ---------- 一覧 ---------- */

.work-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 12px;
  padding: 12px 16px 8px;
}

.work-card {
  display: block;
  position: relative;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.card-media {
  display: block;
  position: relative;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  background: var(--surface-2);
}
.card-rank {
  position: absolute;
  top: 8px;
  left: 8px;
  display: grid;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  place-items: center;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.card-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.work-card:active .card-media { opacity: .85; }

.card-detail {
  display: block;
  padding: 7px 0 0;
}
.card-title {
  display: block;
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-tag {
  margin-right: 3px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}
.card-meta {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 6px;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.card-service { flex: 0 0 auto; }
.card-creator {
  overflow: hidden;
  min-width: 0;
  flex: 1 1 auto;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-creator::before { content: "・"; }
.card-duration { flex: 0 0 auto; margin-left: auto; font-variant-numeric: tabular-nums; }

.work-card.is-viewed .card-media { opacity: .55; }
.work-card.is-viewed .card-title { color: var(--muted); font-weight: 600; }

/* ---------- フッター ---------- */

footer {
  margin: 24px 16px 0;
  border-top: 1px solid var(--line);
  padding: 22px 0 calc(40px + env(safe-area-inset-bottom));
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}
footer p { margin: 0 0 4px; }
footer a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
footer a.footer-link { display: inline-block; min-height: 44px; padding-top: 10px; }
.footer-operator strong { font-weight: 700; }
.footer-note { color: var(--text); }
.footer-clear { margin: 14px 0 16px; }
.text-button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 14px;
  background: var(--bg);
  color: var(--text);
  font-weight: 700;
}
.text-button:active { background: var(--surface); }
.footer-sub { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
#clearHistoryResult { margin: 6px 0 0; color: var(--accent); font-weight: 700; }

/* ---------- 年齢確認 ---------- */

.age-gate {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  min-height: 100dvh;
  padding: 22px;
  place-items: center;
  background: rgba(27, 27, 26, .6);
}

.age-card {
  width: min(100%, 360px);
  border-radius: 16px;
  padding: 24px 22px 22px;
  background: var(--bg);
  color: var(--text);
}
.age-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  font-size: 15px;
  font-weight: 700;
}
.age-brand .brand-mark { width: 22px; height: 22px; }
.age-chip {
  display: inline-block;
  border: 1.5px solid var(--text);
  border-radius: 6px;
  padding: 1px 8px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 1.5;
}
.age-card h2 { margin: 12px 0 10px; font-size: 22px; font-weight: 700; line-height: 1.35; }
.age-card > p { margin: 0 0 8px; color: var(--text); font-size: 14px; line-height: 1.7; }
.age-actions { display: grid; gap: 10px; margin-top: 20px; }

.primary, .secondary, .close-button {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
}
.primary { background: var(--accent); color: #fff; }
.primary:active { background: var(--accent-strong); }
.secondary, .close-button { border-color: var(--line); background: var(--bg); color: var(--text); }
.secondary:active { background: var(--surface); }

/* ---------- ビューア（黒のまま） ---------- */

.viewer {
  --viewer-top: calc(0px + env(safe-area-inset-top));
  position: fixed;
  z-index: 20;
  inset: 0;
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: scroll;
  overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  background: var(--viewer-bg);
  color: var(--viewer-text);
}

.viewer::-webkit-scrollbar { display: none; }
.viewer-open { overflow: hidden; }
.viewer-slides { min-height: 100%; }
.viewer-close-sentinel,
.viewer-slide {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  scroll-snap-align: start;
  scroll-snap-stop: normal;
  background: var(--viewer-bg);
}
.viewer-close-sentinel { background: var(--bg); }
.slide-media {
  position: absolute;
  top: var(--viewer-top);
  right: 0;
  bottom: var(--viewer-panel);
  left: 0;
  overflow: hidden;
  background: var(--viewer-bg);
}
.slide-placeholder,
.slide-video,
.slide-video-background { width: 100%; height: 100%; }
.slide-placeholder,
.slide-video { object-fit: contain; }
.slide-placeholder { display: block; opacity: .44; }
.slide-video-background {
  position: absolute;
  z-index: 0;
  inset: 0;
  object-fit: cover;
  filter: blur(24px) brightness(.5);
  transform: scale(1.1);
  pointer-events: none;
}
.slide-video { position: absolute; z-index: 1; inset: 0; background: transparent; }
.viewer-slide.is-active .slide-placeholder { visibility: hidden; }

.viewer-topbar {
  position: fixed;
  z-index: 22;
  top: 0;
  right: 0;
  left: 0;
  height: 0;
  background: transparent;
}
.viewer-topbar .viewer-icon-button {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
}
.viewer-side-actions {
  position: fixed;
  z-index: 22;
  right: 16px;
  bottom: calc(var(--viewer-panel) + 12px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.viewer-icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  padding: 0;
  place-items: center;
  background: rgba(18, 18, 20, .55);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  color: #fff;
}
.viewer-icon-button:active { background: rgba(18, 18, 20, .75); }
.viewer-icon-button .icon { width: 22px; height: 22px; }
.viewer-icon-button[aria-pressed="true"] .icon-on { color: var(--accent); }

.viewer-panel {
  position: fixed;
  z-index: 22;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  align-content: end;
  padding: 28px 16px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top,
    rgba(0, 0, 0, .96) 0%,
    rgba(0, 0, 0, .88) 55%,
    rgba(0, 0, 0, 0) 100%);
}

.seek-row { display: flex; min-width: 0; align-items: center; gap: 10px; }
.seek { min-width: 0; height: 44px; margin: 0; flex: 1; accent-color: var(--accent); }
.seek-time { flex: 0 0 auto; color: var(--viewer-muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.viewer-count { margin: 0 0 2px; color: var(--viewer-muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.viewer-service { margin: 0 0 2px; color: var(--viewer-muted); font-size: 12.5px; font-weight: 700; letter-spacing: .02em; }
.viewer-panel h2 {
  overflow: hidden;
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cta {
  display: grid;
  min-height: 50px;
  border-radius: 12px;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}
.cta:active { background: var(--accent-strong); }
.affiliate-label { margin: 8px 0 0; color: var(--viewer-text); text-align: center; font-size: 14px; line-height: 1.5; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- _stats（運用者向け） ---------- */

.stats-list { margin: 18px 16px 48px; border-top: 1px solid var(--line); }
.stats-list div { display: contents; }
.stats-list dt { padding: 18px 0 4px; color: var(--muted); }
.stats-list dd { margin: 0; padding: 0 0 18px; border-bottom: 1px solid var(--line); font-size: 1.5rem; font-weight: 800; }
.build-status h2 { margin: 0 16px; font-size: 1rem; }
.build-stats-list { margin-bottom: 24px; }
.build-gap.is-stale { color: var(--accent); }

body[data-page="stats"] .site-header h1 { font-size: 20px; }
body[data-page="stats"] .analytics-empty,
body[data-page="stats"] .analytics-section { margin: 0 16px 32px; }
body[data-page="stats"] .analytics-section h2 { margin: 0 0 10px; font-size: 1rem; }
body[data-page="stats"] .analytics-section > p { color: var(--muted); line-height: 1.6; }
body[data-page="stats"] .analytics-table-wrap { overflow-x: auto; }
body[data-page="stats"] .analytics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .75rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
body[data-page="stats"] .analytics-table th,
body[data-page="stats"] .analytics-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: right;
}
body[data-page="stats"] .analytics-table th:first-child,
body[data-page="stats"] .analytics-table td:first-child { padding-left: 0; text-align: left; }
body[data-page="stats"] .analytics-table th:last-child,
body[data-page="stats"] .analytics-table td:last-child { padding-right: 0; }
body[data-page="stats"] .analytics-table thead th { color: var(--muted); font-weight: 700; }
body[data-page="stats"] .analytics-stats-list { margin: 0; }
body[data-page="stats"] .inventory-days.is-stale,
body[data-page="stats"] .analytics-gap.is-stale { color: var(--accent); font-weight: 800; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
