/* =========================================================
   がくしゅうブログ — シェルのスタイル
   方針: 子ども向けにカラフル。教科は色＋アイコン＋文字で三重に区別。
   ========================================================= */

:root {
  --bg:        #f4f7fb;
  --card:      #ffffff;
  --ink:       #22313f;
  --ink-soft:  #5d7184;
  --line:      rgba(34, 49, 63, .10);
  --shadow:    0 8px 24px rgba(34, 49, 63, .09);
  --shadow-lg: 0 16px 40px rgba(34, 49, 63, .14);
  --radius:    22px;

  /* 教科カラー（仕様書 §10.2） */
  --c-kokugo:   #E8544B;
  --c-sansu:    #3B82D6;
  --c-rika:     #2FAE6B;
  --c-shakai:   #E89A2B;
  --c-eigo:     #8B5CF6;
  --c-seikatsu: #F2A0C0;
  --c-sonota:   #6B7280;

  --fs-base: 18px;
}

/* 文字サイズ設定（シェル側） */
html[data-fs="S"] { --fs-base: 16px; }
html[data-fs="M"] { --fs-base: 18px; }
html[data-fs="L"] { --fs-base: 22px; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Meiryo", sans-serif;
  font-size: var(--fs-base);
  line-height: 1.8;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; }

/* ---------------- ヘッダー ---------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #ffd97d, #ffb3c7 45%, #a5d8ff);
  box-shadow: 0 4px 18px rgba(34, 49, 63, .12);
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, .82);
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 800;
  color: #2a3b4d;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
  min-height: 44px;
}
.logo-mark { font-size: 1.3em; }
.header-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, .82);
  font-size: 1.25rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

/* ---------------- レイアウト ---------------- */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 28px 0 14px;
  font-size: 1.25rem;
  font-weight: 800;
}
.section-title:first-child { margin-top: 8px; }

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  font-size: .9rem;
  color: var(--ink-soft);
}
.crumbs button {
  border: none;
  background: rgba(255, 255, 255, .9);
  border-radius: 999px;
  padding: 6px 14px;
  color: #2a3b4d;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
  min-height: 36px;
}

/* ---------------- 検索 ---------------- */
.search-wrap { position: relative; margin: 6px 0 4px; }

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 3px solid #ffd97d;
  border-radius: 999px;
  padding: 6px 10px 6px 18px;
  box-shadow: var(--shadow);
}
.search-box .ico { font-size: 1.3rem; }
.search-box input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 1.05rem;
  font-family: inherit;
  padding: 12px 0;
  background: transparent;
  min-width: 0;
}
.search-box .clear {
  border: none;
  background: #eef2f7;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  color: var(--ink-soft);
}

.suggest {
  position: absolute;
  z-index: 40;
  left: 0; right: 0;
  top: calc(100% + 6px);
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.suggest button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  min-height: 48px;
}
.suggest button:last-child { border-bottom: none; }
.suggest button:hover, .suggest button:focus { background: #f2f7ff; }
.suggest .s-kind {
  font-size: .75rem;
  font-weight: 800;
  color: #fff;
  background: var(--ink-soft);
  border-radius: 999px;
  padding: 2px 10px;
  flex: none;
}

/* ---------------- タイル（学年・教科） ---------------- */
.tiles {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .tiles { grid-template-columns: repeat(6, 1fr); } }

.tile {
  border: none;
  border-radius: var(--radius);
  padding: 20px 12px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #fff;
  font-weight: 800;
  font-size: 1.15rem;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.tile:active { transform: translateY(0); }
.tile .tile-ico { font-size: 2rem; line-height: 1; }
.tile .tile-sub { font-size: .82rem; font-weight: 700; opacity: .92; }

.tile.g1 { background: linear-gradient(135deg, #ff9a8b, #ff6a88); }
.tile.g2 { background: linear-gradient(135deg, #ffb86c, #ff8c42); }
.tile.g3 { background: linear-gradient(135deg, #ffd76e, #f7b733); }
.tile.g4 { background: linear-gradient(135deg, #7ee8a2, #2fae6b); }
.tile.g5 { background: linear-gradient(135deg, #7fc7ff, #3b82d6); }
.tile.g6 { background: linear-gradient(135deg, #b39dfb, #7c5cf5); }

.tile.subject { min-height: 110px; }
.tile.subject[data-subject="国語"]   { background: linear-gradient(135deg, #ff8c85, var(--c-kokugo)); }
.tile.subject[data-subject="算数"]   { background: linear-gradient(135deg, #7fb4f0, var(--c-sansu)); }
.tile.subject[data-subject="理科"]   { background: linear-gradient(135deg, #6fd8a3, var(--c-rika)); }
.tile.subject[data-subject="社会"]   { background: linear-gradient(135deg, #f6c46a, var(--c-shakai)); }
.tile.subject[data-subject="英語"]   { background: linear-gradient(135deg, #b39dfb, var(--c-eigo)); }
.tile.subject[data-subject="生活"]   { background: linear-gradient(135deg, #f8c4d8, var(--c-seikatsu)); }
.tile.subject[data-subject="その他"] { background: linear-gradient(135deg, #9aa4b2, var(--c-sonota)); }

/* ---------------- 単元リスト ---------------- */
.unit-list { display: grid; gap: 10px; }
.unit-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: none;
  background: var(--card);
  border-radius: 16px;
  padding: 14px 18px;
  text-align: left;
  box-shadow: var(--shadow);
  min-height: 56px;
}
.unit-row:hover { background: #f7fbff; }
.unit-row .u-name { flex: 1; font-weight: 700; }
.unit-row .u-count {
  font-size: .85rem;
  color: var(--ink-soft);
  background: #eef2f7;
  border-radius: 999px;
  padding: 3px 12px;
}
.unit-row .u-arrow { color: var(--ink-soft); }

/* ---------------- 記事カード ---------------- */
.cards {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}
@media (min-width: 600px)  { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .cards { grid-template-columns: repeat(3, 1fr); } }

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: none;
  border-top: 6px solid var(--c-sonota);
  border-radius: 18px;
  background: var(--card);
  padding: 16px 16px 14px;
  text-align: left;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
  min-height: 44px;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.card[data-subject="国語"]   { border-top-color: var(--c-kokugo); }
.card[data-subject="算数"]   { border-top-color: var(--c-sansu); }
.card[data-subject="理科"]   { border-top-color: var(--c-rika); }
.card[data-subject="社会"]   { border-top-color: var(--c-shakai); }
.card[data-subject="英語"]   { border-top-color: var(--c-eigo); }
.card[data-subject="生活"]   { border-top-color: var(--c-seikatsu); }

.card-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  font-size: .78rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 3px 10px;
  background: #eef2f7;
  color: #445;
}
.badge.subject { color: #fff; background: var(--c-sonota); }
.badge.subject[data-subject="国語"]   { background: var(--c-kokugo); }
.badge.subject[data-subject="算数"]   { background: var(--c-sansu); }
.badge.subject[data-subject="理科"]   { background: var(--c-rika); }
.badge.subject[data-subject="社会"]   { background: var(--c-shakai); }
.badge.subject[data-subject="英語"]   { background: var(--c-eigo); }
.badge.subject[data-subject="生活"]   { background: var(--c-seikatsu); }
.badge.interactive { background: #fff3cd; color: #8a6100; }
.badge.read { background: #d8f5e3; color: #1c6b3f; }

.card-title { font-weight: 800; font-size: 1.05rem; line-height: 1.5; }
.card-summary { font-size: .92rem; color: var(--ink-soft); line-height: 1.7; }
.card-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .85rem;
  color: var(--ink-soft);
  margin-top: auto;
  padding-top: 6px;
}
.card-foot .fav-on { color: #f0a500; }

/* ---------------- 空状態・メッセージ ---------------- */
.empty {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.empty .big { font-size: 2.6rem; }
.empty p { color: var(--ink-soft); }

.didyoumean {
  background: #fff8e1;
  border: 2px dashed #f0c419;
  border-radius: 16px;
  padding: 14px 18px;
  margin-bottom: 14px;
}
.didyoumean button {
  border: none;
  background: #f0c419;
  color: #4a3b00;
  font-weight: 800;
  border-radius: 999px;
  padding: 6px 16px;
  margin-left: 8px;
  min-height: 36px;
}

/* ---------------- マイページ ---------------- */
.stat-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 8px;
}
@media (min-width: 700px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--card);
  border-radius: 18px;
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat .n { font-size: 1.9rem; font-weight: 800; color: var(--c-sansu); }
.stat .l { font-size: .85rem; color: var(--ink-soft); }

.badge-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.badge-card {
  background: var(--card);
  border-radius: 18px;
  padding: 16px 12px;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: .38;
  filter: grayscale(1);
}
.badge-card.got { opacity: 1; filter: none; }
.badge-card .b-ico { font-size: 2.1rem; }
.badge-card .b-name { font-weight: 800; font-size: .95rem; }
.badge-card .b-cond { font-size: .78rem; color: var(--ink-soft); }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.seg { display: flex; gap: 6px; }
.seg button {
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 700;
  min-height: 44px;
}
.seg button.on { background: var(--c-sansu); color: #fff; border-color: var(--c-sansu); }

.btn-danger {
  border: 2px solid #f3c2c2;
  background: #fff;
  color: #c0392b;
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 700;
  min-height: 44px;
}

/* ---------------- 記事ビュー ---------------- */
.reader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.reader[hidden] { display: none; }

.reader-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(34, 49, 63, .08);
  flex-wrap: wrap;
}
.reader-back {
  border: none;
  background: #eef2f7;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 800;
  min-height: 44px;
  flex: none;
}
.reader-title {
  flex: 1;
  font-weight: 800;
  font-size: .98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 80px;
}
.reader-tools { display: flex; gap: 6px; flex: none; flex-wrap: wrap; }

.tool-btn {
  position: relative;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tool-btn .cnt { font-size: .8rem; font-weight: 800; color: var(--ink-soft); }
.tool-btn.on { background: #fff3cd; border-color: #f0c419; }
.tool-btn.on .cnt { color: #8a6100; }
.tool-btn.pop { animation: pop .32s ease; }
@keyframes pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.28); }
  100% { transform: scale(1); }
}

.reader-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

@media (max-width: 599px) {
  .reader-title { order: 3; width: 100%; flex-basis: 100%; }
}

/* ---------------- モーダル / トースト ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(20, 30, 40, .45);
}
.modal[hidden] { display: none; }
.modal-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  width: min(460px, 100%);
  box-shadow: var(--shadow-lg);
}
.modal-card h3 { margin: 0 0 6px; }
.modal-sub { margin: 0 0 16px; color: var(--ink-soft); font-size: .92rem; }
.share-label { font-size: .82rem; font-weight: 800; color: var(--ink-soft); }
.share-url {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-family: inherit;
  font-size: .88rem;
  margin: 6px 0 16px;
  background: #f8fafc;
}
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-primary {
  flex: 1;
  border: none;
  background: var(--c-sansu);
  color: #fff;
  font-weight: 800;
  border-radius: 999px;
  padding: 12px 20px;
  min-height: 48px;
}
.btn-ghost {
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 12px 20px;
  font-weight: 700;
  min-height: 48px;
}
.share-hint { font-size: .82rem; color: var(--ink-soft); margin: 12px 0 0; min-height: 1.2em; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 300;
  background: #22313f;
  color: #fff;
  font-weight: 700;
  border-radius: 999px;
  padding: 12px 24px;
  box-shadow: var(--shadow-lg);
  animation: rise .25s ease;
}
.toast[hidden] { display: none; }
@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* 横スクロール防止 */
img, table, pre { max-width: 100%; }
