/* ===== モノシリおじいちゃん PWA（スマホ向け全画面） ===== */
/* ロゴ用フォント（ヒカリ角ゴ Heavy・ロゴ文字のみサブセット） */
@font-face {
  font-family: 'GlowSansJP';
  src: url('glow-sans-title.woff2') format('woff2');
  font-weight: 900;
  font-display: swap;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #FFFDF7;
  --bg-warm: #FDF6EC;
  --bg-warmer: #F5E6C8;
  --border: #D4B896;
  --border-light: #E8D8C4;
  --accent: #8B6D48;
  --accent-dark: #A07840;
  --text: #1A1A1A;
  --text-soft: #5A3A1A;
  --text-muted: #7A5A3A;
  --text-light: #9A7A5A;
}

html, body {
  height: 100%;
  background: var(--bg);
  font-family: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Meiryo', sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

/* ===== ヘッダー ===== */
.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 10px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg-warm);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.app-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.app-title {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.app-name {
  font-family: 'GlowSansJP', 'Hiragino Maru Gothic ProN', 'Meiryo', sans-serif;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: #5A3A1A;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-word {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  line-height: 0;
  flex-shrink: 0;
  color: var(--text-soft);
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: #EDD8C0; }
.icon-btn svg { display: block; }

/* ロゴと最初のアイコンの間隔を広げる */
#history-btn { margin-left: 6px; }

/* アイコン間の区切り線（履歴 | お気に入り | アバウト）。
   ヘッダーの gap(8px) のちょうど中央に線を置く（gap の半分 = 4px 左） */
#favorites-btn::before, #about-btn::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 15px;
  background: var(--border);
}

/* ===== レベル選択 ===== */
.level-area {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-warm);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.level-btn {
  flex: 1;
  padding: 10px 8px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 700;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.level-btn:active { background: #EDD8C0; }
.level-btn.active {
  background: var(--accent);
  color: #FFFDF7;
  border-color: var(--accent);
}

/* ===== 検索ボックス ===== */
.search-area {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-warm);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-light); }

#search-btn {
  padding: 11px 20px;
  background: var(--accent);
  color: #FFFDF7;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.15s;
}
#search-btn:active { background: var(--accent-dark); }

/* ===== ホーム画面に追加バー ===== */
.install-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-warmer);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.install-bar[hidden] { display: none; }
.install-text {
  flex: 1;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-soft);
  line-height: 1.4;
}
.install-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--accent);
  color: #FFFDF7;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}
.install-btn:active { background: var(--accent-dark); }
.install-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px 6px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
}
.install-close svg { display: block; }
body.dark .install-btn { color: #FFFDF7; }

/* ===== 本文 ===== */
.app-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

/* 各画面の見出し（一覧件数・解説タイトル・このアプリについて） */
.screen-title {
  font-size: 17px;
  font-weight: 800;
  color: #8B6D48;
  margin: 0 0 18px;
}
.list-header .screen-title { margin: 0; }

.welcome {
  text-align: center;
  padding: 48px 16px 24px;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.9;
}

/* トップ画面の提案ワード */
.suggest {
  margin-top: 8px;
  padding-top: 22px;
  border-top: 1px solid var(--border-light);
}
.suggest-title {
  text-align: center;
  font-size: 14px;
  font-weight: 800;
  color: #5A3A1A;
  margin-bottom: 16px;
}
.suggest-words {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
}

/* ===== ローディング ===== */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  gap: 14px;
}

@keyframes thinking-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25%      { transform: translateY(-6px) rotate(-4deg); }
  75%      { transform: translateY(-6px) rotate(4deg); }
}
@keyframes progress-run {
  from { width: 0%; }
  to   { width: 85%; }
}

.thinking-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  animation: thinking-bob 1.8s ease-in-out infinite;
}
.loading-msg {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  margin: 0;
}
.progress-bar {
  width: 80%;
  max-width: 280px;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #C49A6A, #A07840);
  border-radius: 3px;
  animation: progress-run 14s ease-out forwards;
}

/* ===== 解説本文 ===== */
.action-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 32px;
  margin-bottom: 48px;
}
.fav-btn, .copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-warm);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 700;
  transition: background 0.15s, color 0.15s;
}
.fav-btn svg, .copy-btn svg { display: block; flex-shrink: 0; }
.fav-btn.active {
  background: var(--accent);
  color: #FFFDF7;
  border-color: var(--accent);
}
.copy-btn.copied {
  background: var(--accent);
  color: #FFFDF7;
  border-color: var(--accent);
}

.explanation-text {
  font-size: 16px;
  line-height: 1.8;
  color: var(--text);
}
.explanation-text p {
  margin: 0 0 34px; /* ② 段落どうしの間隔（統一・広め） */
}
.explanation-text p:last-child { margin-bottom: 0; }

/* 締めの一文・文字数表示 */
.explanation-text .exp-closing {
  margin: 46px 0 0; /* 本文 → 締めの一文 */
}
.explanation-text .exp-count {
  margin: 28px 0 0; /* 締めの一文からさらに一行分 */
  color: var(--text-light);
}

/* ③ ■見出し（茶色・太字） */
.explanation-text .exp-section {
  font-size: 16px;
  font-weight: 800;
  color: #8B6D48;
  margin: 46px 0 12px; /* B 上=段落→小見出し / C 下=小見出し→本文 */
}
.explanation-text .exp-section:first-child { margin-top: 0; }

/* ===== 関連語 ===== */
.related {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}
.related-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 800;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.related-title svg { display: block; }
.related-words {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.related-word {
  padding: 8px 14px;
  background: var(--bg-warm);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 700;
  transition: background 0.15s;
}
.related-word:active { background: #EDD8C0; }

/* ===== エラー ===== */
.error {
  color: var(--text-muted);
  text-align: center;
  padding: 24px 12px;
}
.error p { margin: 6px 0; }
.error-detail {
  font-size: 12px;
  color: #B07A5A;
  word-break: break-all;
}

/* ===== 履歴・お気に入り一覧 ===== */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  background: var(--bg-warm);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.list-item:active { background: #EDD8C0; }
.list-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  pointer-events: none;
  min-width: 0;
}
.list-word {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-soft);
}
.list-meta {
  font-size: 12px;
  color: var(--text-light);
}
.list-remove {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 15px;
  color: var(--text-light);
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.list-remove:active {
  background: var(--accent);
  color: #FFFDF7;
}
/* 削除確認中（1タップ目で「削除」表示・赤、2タップ目で実行） */
.list-remove.confirm {
  width: auto;
  padding: 0 14px;
  height: 38px;
  border-radius: 19px;
  background: #C0392B;
  border-color: #C0392B;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 36px;
  margin-bottom: 16px;
  gap: 8px;
}
.clear-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-light);
  cursor: pointer;
  font-family: inherit;
}
.clear-btn svg { display: block; }
.clear-btn:active { background: var(--accent); color: #FFFDF7; }

.clear-confirm-text { font-size: 13px; color: #C0392B; font-weight: 700; }
.clear-yes, .clear-no {
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--border);
}
.clear-yes { background: var(--accent); color: #FFFDF7; border-color: var(--accent); }
.clear-no { background: var(--bg); color: var(--text-muted); }

/* ===== このアプリについて ===== */
.about-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #5A3A1A;
  margin: 20px 0 52px;
}
.about-title::before, .about-title::after {
  content: "";
  width: 16px;
  height: 1px;
  background: #5A3A1A;
}

.about {
  font-size: 15px;
  line-height: 1.85;
  color: var(--text);
}
.about-section {
  margin-bottom: 64px;
}
.about-section:last-child { margin-bottom: 0; }
.about-h {
  font-size: 16px;
  font-weight: 800;
  color: #5A3A1A;
  margin-bottom: 12px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border-light);
}
.about-section p {
  margin: 0 0 10px;
  color: var(--text-soft);
}
.about-section p:last-child { margin-bottom: 0; }
.about-steps {
  margin: 0;
  padding-left: 22px;
  color: var(--text-soft);
}
.about-steps li { margin-bottom: 14px; }
.about-steps li:last-child { margin-bottom: 0; }
.about-faq .about-q {
  font-weight: 800;
  color: var(--text-soft);
  margin: 28px 0 4px;
}
.about-faq .about-q:first-child { margin-top: 0; }
.about-faq .about-a {
  color: var(--text-soft);
  margin: 0;
}
.about-footer {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}
.about-footer .site { color: var(--accent-dark); font-weight: 700; }
.about-footer .copy { color: var(--accent-dark); font-weight: 700; }

/* ===== ダークモード ===== */
body.dark {
  --bg: #1F1A14;
  --bg-warm: #2A2218;
  --bg-warmer: #3A2A1A;
  --border: #5A4A3A;
  --border-light: #4A3A2A;
  --accent: #8A6A4A;
  --accent-dark: #A07840;
  --text: #F0E6D5;
  --text-soft: #F5E6C8;
  --text-muted: #C4A882;
  --text-light: #8A7A5A;
}
body.dark #search-btn,
body.dark .level-btn.active,
body.dark .fav-btn.active,
body.dark .copy-btn.copied {
  color: #FFFDF7;
}
body.dark .progress-fill {
  background: linear-gradient(90deg, #8A6A4A, #C49A6A);
}
