/* ハクニュース (IWAI LAB NEWS) - base stylesheet
   参考サイト(news.nullevi.app)のレイアウト・余白・文字サイズ構成を再現しつつ、
   配色・ブランドは独自のもの。 */

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

:root {
  /* ハクの画像(ヘッドフォンの青・白いボディ)から採った配色 */
  --accent: #4f86d6;
  --accent-light: #8fc3f0;
  --bg: #f3f8fd;
  --card: #fff;
  --text: #2b2f38;
  --muted: #7a8496;
  --border: #d9e6f5;
  --summary-color: #4b5768;
  --section-p: #46505f;
  --haku-p: #333a44;
  --haku-bg: #eef6fd;
  --input-bg: #fff;
  --header-grad: linear-gradient(135deg, #4f86d6, #8fc3f0);
  --tag-bg: #e6f0fb;
}

[data-theme="dark"] {
  --accent: #7fb4f0;
  --accent-light: #a9d0f7;
  --bg: #0b0f1a;
  --card: #121826;
  --text: #e7edf7;
  --muted: #8b93a8;
  --border: #26344a;
  --summary-color: #b7c2d6;
  --section-p: #a7b2c8;
  --haku-p: #d9e2f2;
  --haku-bg: #16202f;
  --input-bg: #121826;
  --header-grad: linear-gradient(135deg, #0d1730, #17233d);
  --tag-bg: #16233a;
}

html, body { width: 100%; overflow-x: hidden; }

body {
  font-family: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .3s, color .3s;
  line-height: 1.6;
}

a { color: inherit; }

/* ---------- header ---------- */
header {
  background: var(--header-grad);
  color: #fff;
  padding: 24px 20px;
  text-align: center;
  position: relative;
}
header .header-inner {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  max-width: 640px; margin: 0 auto; flex-wrap: wrap;
}
header .header-avatar {
  width: 64px; height: 64px; border-radius: 50%; flex-shrink: 0;
  border: 3px solid rgba(255,255,255,0.65);
  background: rgba(255,255,255,0.18);
  box-shadow: 0 3px 10px rgba(0,0,0,0.15);
  object-fit: cover;
}
header .header-text { text-align: left; }
header h1 { font-size: 1.6rem; font-weight: 900; letter-spacing: .02em; }
header .site-en { font-size: 0.68rem; opacity: .82; letter-spacing: .1em; margin-top: 2px; }
header p.tagline { font-size: 0.82rem; opacity: 0.92; margin-top: 6px; }
[data-theme="dark"] header { box-shadow: 0 0 40px rgba(127,180,240,0.18); }

/* 記事個別ページのヘッダー(戻るリンク付き、アバターは小さめ) */
header.article-header .header-inner { justify-content: center; }
header.article-header .header-avatar { width: 40px; height: 40px; }
header.article-header h1 { font-size: 1.2rem; }

.rss-btn {
  position: absolute; top: 16px; left: 16px;
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(255,255,255,0.18); border: 2px solid rgba(255,255,255,0.35);
  color: #fff; font-family: inherit; font-size: 0.78rem; font-weight: 700;
  padding: 6px 12px; border-radius: 999px; text-decoration: none;
  transition: background .2s; backdrop-filter: blur(4px);
}
.rss-btn:hover { background: rgba(255,255,255,0.3); }

.back-link {
  position: absolute; top: 20px; left: 16px;
  color: #fff; text-decoration: none; font-size: 0.85rem; font-weight: 700;
  background: rgba(255,255,255,0.18); border: 2px solid rgba(255,255,255,0.35);
  padding: 6px 14px; border-radius: 999px;
}
.back-link:hover { background: rgba(255,255,255,0.3); }

/* ---------- settings FAB / panel ---------- */
.settings-fab {
  position: fixed; top: 14px; right: 14px; width: 44px; height: 44px;
  border-radius: 50%; border: 2px solid rgba(255,255,255,0.45);
  background: rgba(255,92,122,0.92); color: #fff; font-size: 1.3rem; line-height: 1;
  cursor: pointer; z-index: 100; box-shadow: 0 4px 12px rgba(255,92,122,0.35);
  transition: transform .2s, background .2s; backdrop-filter: blur(4px);
}
.settings-fab:hover { transform: rotate(30deg) scale(1.05); background: var(--accent); }
.settings-fab.is-hidden { opacity: 0; pointer-events: none; transform: scale(0.7); }
[data-theme="dark"] .settings-fab { background: rgba(90,140,210,0.85); box-shadow: 0 4px 16px rgba(90,140,210,0.4); }

.settings-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.25); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 98;
}
.settings-backdrop.open { opacity: 1; pointer-events: auto; }

.settings-panel {
  position: fixed; top: 0; right: 0; width: min(320px, 90vw); height: 100vh;
  background: var(--card); border-left: 2px solid var(--border);
  box-shadow: -6px 0 24px rgba(255,92,122,0.18); padding: 24px 20px; z-index: 99;
  transform: translateX(110%); transition: transform .3s cubic-bezier(0.4,0,0.2,1);
  overflow-y: auto; font-family: inherit;
}
.settings-panel.open { transform: translateX(0); }
.settings-header { display: flex; justify-content: space-between; align-items: center; font-size: 1.05rem; font-weight: 900; color: var(--accent); margin-bottom: 18px; }
.settings-close { background: transparent; border: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); line-height: 1; padding: 0 6px; }
.settings-close:hover { color: var(--accent); }
.settings-section { margin-bottom: 22px; }
.settings-label { font-size: 0.85rem; font-weight: 900; color: var(--text); margin-bottom: 10px; }

.difficulty-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.diff-btn, .theme-opt {
  background: var(--bg); border: 2px solid var(--border); color: var(--text);
  font-family: inherit; font-size: 0.78rem; font-weight: 700; padding: 10px 8px;
  border-radius: 12px; cursor: pointer; transition: all .2s;
}
.diff-btn:hover, .theme-opt:hover { border-color: var(--accent); color: var(--accent); }
.diff-btn.active, .theme-opt.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.diff-hint { font-size: 0.72rem; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.theme-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- first-visit difficulty modal ---------- */
.diff-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 200; padding: 16px;
}
.diff-modal.open { display: flex; }
.diff-modal-card {
  background: var(--card); border: 2px solid var(--border); border-radius: 24px;
  padding: 28px 22px; max-width: 440px; width: 100%;
  box-shadow: 0 12px 40px rgba(255,92,122,0.25); text-align: center;
}
.diff-modal-card h2 { font-size: 1.25rem; font-weight: 900; color: var(--accent); margin-bottom: 8px; }
.diff-modal-desc { font-size: 0.82rem; color: var(--summary-color); line-height: 1.7; margin-bottom: 18px; }
.diff-modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.diff-modal-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  background: var(--bg); border: 2px solid var(--border); border-radius: 14px;
  padding: 12px 14px; font-family: inherit; text-align: left; cursor: pointer;
  transition: all .2s; color: var(--text);
}
.diff-modal-btn:hover { border-color: var(--accent); background: var(--haku-bg); transform: translateY(-2px); }
.diff-modal-title { font-size: 0.95rem; font-weight: 900; color: var(--accent); }
.diff-modal-sub { font-size: 0.72rem; color: var(--muted); line-height: 1.4; }

/* ---------- layout ---------- */
.container { max-width: 800px; margin: 0 auto; padding: 24px 16px; }

/* ---------- search / tag filter ---------- */
.search-bar { margin-bottom: 12px; }
.search-input {
  width: 100%; padding: 10px 16px; border: 2px solid var(--border); border-radius: 999px;
  font-family: inherit; font-size: 0.85rem; outline: none; transition: border-color .2s;
  background: var(--input-bg); color: var(--text);
}
.search-input:focus { border-color: var(--accent); }

.tag-toggle {
  background: none; border: 2px solid var(--border); color: var(--muted);
  font-family: inherit; font-size: 0.8rem; font-weight: 700; padding: 6px 16px;
  border-radius: 999px; cursor: pointer; transition: all .2s;
  display: inline-flex; align-items: center; gap: 4px;
}
.tag-toggle:hover { border-color: var(--accent); color: var(--accent); }
.tag-toggle.has-active { border-color: var(--accent); color: var(--accent); }

.tag-filter { display: none; flex-wrap: wrap; gap: 6px; margin-top: 10px; margin-bottom: 8px; }
.tag-filter.open { display: flex; }
.tag-btn {
  background: var(--card); border: 2px solid var(--border); color: var(--muted);
  font-family: inherit; font-size: 0.72rem; font-weight: 700; padding: 4px 12px;
  border-radius: 999px; cursor: pointer; transition: all .2s;
}
.tag-btn:hover { border-color: var(--accent); color: var(--accent); }
.tag-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.result-count { font-size: 0.75rem; color: var(--muted); margin: 10px 0 4px; }

/* ---------- article cards ---------- */
.card {
  background: var(--card); border: 2px solid var(--border); border-radius: 20px;
  padding: 24px; margin-bottom: 24px;
  filter: drop-shadow(0 2px 4px rgba(255,92,122,0.08));
  transition: background .3s, border-color .3s, filter .35s, transform .35s;
}
.card:hover, .card:focus-within {
  filter: drop-shadow(0 14px 28px rgba(255,92,122,0.25)) drop-shadow(0 4px 10px rgba(255,92,122,0.14));
  transform: translateY(-4px);
  border-color: var(--accent);
}
@media (hover: none) {
  .card:hover { transform: none; filter: drop-shadow(0 2px 4px rgba(255,92,122,0.08)); }
}
[data-theme="dark"] .card { box-shadow: 0 2px 16px rgba(123,90,200,0.12); }

.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: var(--tag-bg); color: var(--accent); font-size: 0.72rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.date { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }

.new-badge {
  background: var(--accent); color: #fff; font-size: 0.65rem; font-weight: 900;
  padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle;
}

.demo-badge {
  display: inline-block; font-size: 0.65rem; font-weight: 900; color: var(--muted);
  border: 1px dashed var(--border); padding: 1px 8px; border-radius: 999px; margin-left: 6px;
  vertical-align: middle;
}

h2.card-title { font-size: 1.2rem; font-weight: 900; margin-bottom: 10px; line-height: 1.5; overflow-wrap: anywhere; }
h2.card-title a { color: var(--text); text-decoration: none; }
h2.card-title a:hover { color: var(--accent); }

.summary {
  font-size: 0.9rem; color: var(--summary-color); line-height: 1.75; margin-bottom: 16px;
  padding-left: 12px; border-left: 3px solid var(--accent-light);
  overflow-wrap: anywhere;
}

.card-section { margin-bottom: 14px; }
.card-section h3 { font-size: 0.85rem; font-weight: 900; color: var(--accent); margin-bottom: 4px; }
.card-section p { font-size: 0.85rem; line-height: 1.75; color: var(--section-p); overflow-wrap: anywhere; }

.card-technical { margin-bottom: 14px; }
.card-technical h3 { font-size: 0.85rem; font-weight: 900; color: var(--accent); margin-bottom: 4px; }
.card-technical p { font-size: 0.82rem; line-height: 1.75; color: var(--section-p); overflow-wrap: anywhere; }

.haku-comment {
  display: flex; align-items: flex-start; gap: 12px; margin: 16px 0;
  background: var(--haku-bg); border: 2px solid var(--accent-light); border-radius: 16px;
  padding: 16px; transition: background .3s;
}
[data-theme="dark"] .haku-comment { box-shadow: 0 0 12px rgba(255,148,102,0.1); }
.haku-icon {
  width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--accent);
  flex-shrink: 0; object-fit: cover; background: var(--card);
}
.haku-bubble { position: relative; flex: 1; min-width: 0; }
.haku-label { font-size: 0.72rem; font-weight: 900; color: var(--accent); margin-bottom: 6px; }
.haku-bubble p { font-size: 0.85rem; line-height: 1.75; color: var(--haku-p); overflow-wrap: anywhere; word-break: break-word; }

.sources { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 0.75rem; }
.sources-label { color: var(--muted); margin-right: 6px; }
.sources a { color: var(--accent); text-decoration: none; }
.sources a:hover { text-decoration: underline; }
.sources .no-source { color: var(--muted); }

.no-results { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 0.9rem; }
.no-results-icon {
  width: 72px; height: 72px; border-radius: 50%; object-fit: cover;
  border: 3px solid var(--border); opacity: 0.85; margin-bottom: 12px;
}

.footer { text-align: center; padding: 24px; color: var(--muted); font-size: 0.75rem; }
.footer a { color: var(--accent); text-decoration: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- difficulty visibility rules ---------- */
body[data-difficulty="easy"] .card-section { display: none; }
body[data-difficulty="easy"] .card-technical { display: none; }
body[data-difficulty="easy"] .sources { display: none; }
body[data-difficulty="easy"] .summary { font-size: 0.98rem; border-left-width: 4px; }

body[data-difficulty="normal"] .card-technical { display: none; }

body[data-difficulty="hard"] .card-technical { display: none; }
body[data-difficulty="hard"] .sources {
  background: var(--haku-bg); padding: 12px; border-radius: 10px; border: 1px dashed var(--border);
}

body[data-difficulty="veryhard"] .card-sections-wrap {
  max-height: 460px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; margin-bottom: 12px; background: var(--haku-bg);
}
body[data-difficulty="veryhard"] .sources {
  background: var(--haku-bg); padding: 12px; border-radius: 10px; border: 1px dashed var(--border);
}

/* ---------- article single page ---------- */
.article-page .card { cursor: default; }
.article-page .card:hover { transform: none; }
.article-back { display: inline-block; margin-bottom: 16px; font-size: 0.85rem; color: var(--accent); text-decoration: none; font-weight: 700; }
.article-back:hover { text-decoration: underline; }

@media (max-width: 480px) {
  .settings-panel { width: 88vw; }
  .diff-modal-grid { grid-template-columns: 1fr; }
  header { padding: 20px 56px 18px; }
  header .header-inner { justify-content: center; }
  header .header-avatar { width: 48px; height: 48px; }
  header h1 { font-size: 1.25rem; }
  header .header-text { text-align: center; }
  .container { padding: 18px 12px; }
  .card { padding: 18px; }
}
