/* ===== テーマ =====
   data-theme が無いときは OS の設定に合わせる（システム準拠）。
   設定ページで選ぶと <html data-theme="light|dark|sakura"> になる。 */
:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #f3efe6;
  --text: #221c16;
  --muted: #5e564c;
  --sub: #8a7b6a;
  --field: #fffdf8;
  --field-border: #cfc6b8;
  --panel: #ffffff;
  --line: #ece4d8;
  --accent: #c4512c;
  --accent-text: #fffaf6;
  --thumb-bg: #e7e0d4;
  --hover: #f6f0e6;
  --overlay: rgba(34, 28, 22, 0.45);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #17140f;
  --text: #ece4d8;
  --muted: #b8ad9e;
  --sub: #958979;
  --field: #221d17;
  --field-border: #463d32;
  --panel: #1e1a14;
  --line: #322b23;
  --accent: #e2774f;
  --accent-text: #1a120d;
  --thumb-bg: #2c261f;
  --hover: #28221b;
  --overlay: rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #17140f;
    --text: #ece4d8;
    --muted: #b8ad9e;
    --sub: #958979;
    --field: #221d17;
    --field-border: #463d32;
    --panel: #1e1a14;
    --line: #322b23;
    --accent: #e2774f;
    --accent-text: #1a120d;
    --thumb-bg: #2c261f;
    --hover: #28221b;
    --overlay: rgba(0, 0, 0, 0.6);
  }
}

[data-theme="sakura"] {
  color-scheme: light;
  --bg: #fdf2f6;
  --text: #3d2e38;
  --muted: #7a5a68;
  --sub: #9a7080;
  --field: #fff8fa;
  --field-border: #ecc3d1;
  --panel: #fffafc;
  --line: #f5dce5;
  --accent: #c44d6e;
  --accent-text: #fff8fa;
  --thumb-bg: #f6e1e8;
  --hover: #fcebf1;
  --overlay: rgba(61, 46, 56, 0.4);
}

:root {
  color: var(--text);
  background: var(--bg);
  font-family: "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.5;
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 860px;
  padding: 32px 20px 0;
}

a { color: var(--accent); }

/* ===== ヘッダー ===== */
.site-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
}

.brand {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.3;
}

.brand a {
  color: inherit;
  text-decoration: none;
}

.site-header .lead {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
}

.menu-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--field-border);
  border-radius: 999px;
  background: var(--field);
  color: var(--text);
  cursor: pointer;
}

.menu-button:hover { border-color: var(--accent); color: var(--accent); }

.menu-button svg,
.drawer-close svg {
  width: 20px;
  height: 20px;
}

/* ===== 検索欄 ===== */
form { margin-top: 24px; }

.query-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.query-row {
  display: flex;
  gap: 8px;
}

input[type="search"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--field-border);
  border-radius: 8px;
  background: var(--field);
  color: inherit;
  font: inherit;
  padding: 12px 14px;
}

input[type="search"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  padding: 0 18px;
  white-space: nowrap;
  cursor: pointer;
}

button:disabled { opacity: 0.6; cursor: wait; }

.status {
  min-height: 1.5em;
  margin: 22px 0 8px;
}

.status:empty {
  min-height: 0;
  margin: 0;
}

/* ===== Google の結果枠 =====
   Google の部品が持つ白い背景や青いリンクを、テーマの色に合わせる。
   「ENHANCED BY Google」などの表示は消さない（色だけ合わせる）。 */
#google-results.has-search { margin-top: 16px; }

#google-results .gsc-control-cse,
#google-results .gsc-webResult.gsc-result,
#google-results .gsc-results .gsc-cursor-box,
#google-results .gsc-above-wrapper-area {
  background: var(--panel);
  border-color: var(--line);
}

#google-results .gsc-control-cse {
  border-radius: 10px;
}

/* 外枠と二重の線にならないよう、内側の結果枠の線は消す。 */
#google-results .gsc-webResult.gsc-result {
  border: 0;
}

#google-results .gsc-wrapper,
#google-results .gsc-thinWrapper,
#google-results .gsc-wrapper.gsc-thinWrapper {
  max-width: none;
  width: 100%;
  float: none;
  border: 0;
}

#google-results .gsc-adBlockVertical {
  display: none;
}

#google-results:not(.has-search) .gsc-control-cse {
  background: transparent;
  border: 0;
  padding: 0;
}

#google-results .gsc-result-info,
#google-results .gsc-orderby-label,
#google-results .gsc-selected-option,
#google-results .gs-spelling,
#google-results .gs-no-results-result .gs-snippet,
#google-results .gcsc-more-maybe-branding-root,
#google-results .gcsc-find-more-on-google,
#google-results .gcsc-branding-text {
  color: var(--sub);
}

#google-results .gs-spelling a,
#google-results .gcsc-find-more-on-google,
#google-results .gcsc-find-more-on-google-query {
  color: var(--accent);
}

#google-results .gcsc-find-more-on-google-magnifier {
  fill: var(--accent);
}

#google-results .gs-no-results-result .gs-snippet {
  background: var(--panel);
  border-color: var(--line);
}

#google-results .gsc-selected-option-container {
  background: var(--field);
  border-color: var(--field-border);
  color: var(--text);
}

#google-results .gsc-option-menu {
  background: var(--panel);
  border-color: var(--field-border);
}

#google-results .gsc-option-menu-item {
  color: var(--text);
}

#google-results .gsc-option-menu-item-highlighted {
  background: var(--hover);
}

#google-results,
#google-results * {
  overflow-anchor: none;
}

/* ===== 結果は1列。1件1行で、サムネを左、文字を右に置く。 ===== */
.results,
.more-row {
  width: 100%;
}

.results {
  display: flex;
  flex-direction: column;
}

.card {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}

.card:first-child { padding-top: 4px; }

.thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 8px;
  background: var(--thumb-bg);
}

.card-body { min-width: 0; }

.kind {
  margin: 0 0 4px;
  color: var(--sub);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
}

.card h2 {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.card:hover h2 {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.meta {
  display: -webkit-box;
  margin: 6px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.more-row { margin-top: 16px; text-align: center; }

.more-row button {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  padding: 10px 18px;
}

.gsc-cursor,
.gsc-cursor-box { display: none; }

/* ===== フッター =====
   右下の「Powered by Netlify」が重ならないよう、下に余白を取る。 */
.site-footer {
  margin-top: 40px;
  padding: 20px 0 88px;
  border-top: 1px solid var(--line);
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
}

.footer-nav a {
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}

.footer-nav a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ===== ドロワーメニュー ===== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: var(--overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1101;
  display: flex;
  flex-direction: column;
  width: min(300px, 86vw);
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  box-shadow: -2px 0 16px rgba(0, 0, 0, 0.18);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.25s, visibility 0.25s;
}

.drawer-open .drawer-overlay { opacity: 1; visibility: visible; }
.drawer-open .drawer { transform: none; visibility: visible; }
.drawer-open { overflow: hidden; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 14px 20px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.drawer-close {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.drawer-close:hover { background: var(--hover); color: var(--text); }

.drawer-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.drawer-list li { border-bottom: 1px solid var(--line); }

.drawer-list a {
  display: block;
  padding: 16px 20px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.drawer-list a:hover,
.drawer-list a[aria-current="page"] {
  background: var(--hover);
  color: var(--accent);
}

.drawer-share {
  padding: 16px;
}

.share-x {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  background: #000;
  color: #fff;
  font-weight: 600;
}

.share-x:hover { background: #333; }

.share-x svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ===== 説明ページ（このサイトについて・利用規約・プライバシー・お問い合わせ・設定） ===== */
.page {
  margin-top: 28px;
  padding: 28px 32px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.page h1 {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 1.5rem;
}

.page h2 {
  margin: 28px 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--line);
  font-size: 1.1rem;
}

.page p,
.page li {
  color: var(--muted);
  line-height: 1.9;
}

.page ul,
.page ol { padding-left: 1.3em; }

.page .back {
  margin-top: 28px;
  font-weight: 700;
}

.page .updated {
  margin-top: 18px;
  color: var(--sub);
  font-size: 0.85rem;
}

/* ===== 設定ページのテーマ選択 ===== */
.theme-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 16px 0 0;
  padding: 0;
  border: 0;
}

.theme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.theme-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-preview {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 10px;
}

.theme-option input:checked + .theme-preview {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

.theme-option input:focus-visible + .theme-preview {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.theme-preview-bar {
  display: block;
  height: 22%;
  border-bottom: 2px solid;
}

.theme-preview-body {
  display: flex;
  flex-direction: column;
  gap: 8%;
  height: 78%;
  padding: 10% 10%;
}

.theme-preview-row {
  display: block;
  flex: 1;
  border-radius: 4px;
}

.theme-label {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}

.theme-preview.is-light .theme-preview-bar { background: #fffdf8; border-color: #c4512c; }
.theme-preview.is-light .theme-preview-body { background: #f3efe6; }
.theme-preview.is-light .theme-preview-row { background: #ffffff; border: 1px solid #ece4d8; }

.theme-preview.is-dark .theme-preview-bar { background: #221d17; border-color: #e2774f; }
.theme-preview.is-dark .theme-preview-body { background: #17140f; }
.theme-preview.is-dark .theme-preview-row { background: #1e1a14; border: 1px solid #322b23; }

.theme-preview.is-sakura .theme-preview-bar { background: #fff8fa; border-color: #c44d6e; }
.theme-preview.is-sakura .theme-preview-body { background: #fdf2f6; }
.theme-preview.is-sakura .theme-preview-row { background: #fffafc; border: 1px solid #f5dce5; }

.theme-preview.is-system .theme-preview-bar {
  background: linear-gradient(90deg, #fffdf8 50%, #221d17 50%);
  border-color: #8a7b6a;
}
.theme-preview.is-system .theme-preview-body { background: linear-gradient(90deg, #f3efe6 50%, #17140f 50%); }
.theme-preview.is-system .theme-preview-row { background: linear-gradient(90deg, #ffffff 50%, #1e1a14 50%); }

@media (max-width: 640px) {
  body { padding: 16px 12px 0; }
  .brand { font-size: 1.5rem; }
  .menu-button { width: 38px; height: 38px; }
  form { margin-top: 18px; }
  .query-row > button { padding: 0 16px; }
  #google-results.has-search { margin-top: 12px; }
  #google-results .gsc-webResult.gsc-result { padding: 12px 10px; }
  .card {
    grid-template-columns: 48% minmax(0, 1fr);
    gap: 10px;
    padding: 10px 0;
  }
  .thumb { border-radius: 6px; }
  .kind { margin-bottom: 2px; font-size: 0.68rem; }
  .card h2 {
    font-size: 0.88rem;
    line-height: 1.4;
    -webkit-line-clamp: 3;
  }
  .meta {
    margin-top: 4px;
    font-size: 0.74rem;
    line-height: 1.45;
    -webkit-line-clamp: 2;
  }
  .page {
    margin-top: 18px;
    padding: 20px 16px;
  }
  .theme-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
