*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #F7F8FA;
  --surface:   #FFFFFF;
  --green:     #3D7A5F;
  --green-light: #EAF3EE;
  --text:      #1A2433;
  --muted:     #4A5568;
  --border:    #E2E6EC;
  --danger:    #c0392b;
  --danger-light: #fdf0f0;
  --serif:     'Noto Serif JP', serif;
  --sans:      'Noto Sans JP', sans-serif;
}

/* ダークモード */
[data-theme="dark"] {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --green:       #4eab7d;
  --green-light: #1a2e25;
  --text:        #e8eaf0;
  --muted:       #8b95a8;
  --border:      #2a2d3a;
  --danger:      #e57373;
  --danger-light: #3a1f1f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0f1117;
    --surface:     #1a1d27;
    --green:       #4eab7d;
    --green-light: #1a2e25;
    --text:        #e8eaf0;
    --muted:       #8b95a8;
    --border:      #2a2d3a;
    --danger:      #e57373;
    --danger-light: #3a1f1f;
  }
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr 300px;
  grid-template-rows: auto;
  max-width: 1200px;
  margin: 0 auto;
}
    
/* ── ヘッダー ── */
header {
  display: none;
}

.logo {
  display: block;
  text-decoration: none;
}

    .header-actions {
      display: flex;
      gap: 0.75rem;
      align-items: center;
    }

    .btn {
      font-family: var(--sans);
      font-size: 0.85rem;
      padding: 0.4rem 1rem;
      border-radius: 4px;
      cursor: pointer;
      transition: background 0.15s, color 0.15s;
      border: none;
    }

    .btn-ghost {
      background: transparent;
      color: var(--muted);
    }
    .btn-ghost:hover { color: var(--text); }

    .btn-primary {
      background: var(--green);
      color: #fff;
    }
    .btn-primary:hover { background: #2f6149; }

    /* ── メインレイアウト ── */
    .container {
      padding: 1.5rem 1rem;
      border-left: 1px solid var(--border);
      border-right: 1px solid var(--border);
      min-height: 100vh;
    }

    /* ── キャッチ ── */
    .catch {
      margin-bottom: 1rem;
    }

    .catch h1 {
      font-family: var(--serif);
      font-size: 1.45rem;
      font-weight: 600;
      line-height: 1.5;
      margin-bottom: 0.5rem;
    }

    .catch p {
      color: var(--muted);
      font-size: 0.9rem;
    }

    /* ── 気分タグ ── */
    .mood-bar {
      display: flex;
      gap: 0.5rem;
      flex-wrap: wrap;
      margin-bottom: 2rem;
    }

    .mood-tag {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 999px;
      padding: 0.3rem 0.9rem;
      font-size: 0.82rem;
      color: var(--muted);
      cursor: pointer;
      transition: all 0.15s;
    }
    .mood-tag:hover, .mood-tag.active {
      background: var(--green-light);
      border-color: var(--green);
      color: var(--green);
    }

    /* ── 投稿一覧 ── */
    .section-label {
      font-size: 0.78rem;
      color: var(--muted);
      letter-spacing: 0.06em;
      margin-bottom: 1rem;
      padding-bottom: 0.5rem;
      border-bottom: 1px solid var(--border);
    }

    .post-list {
      display: flex;
      flex-direction: column;
      gap: 0;
    }

    .post-item {
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      border-radius: 0;
      padding: 1.25rem 1.5rem;
      cursor: pointer;
      transition: background 0.15s ease, transform 0.1s ease;
    }
    .post-item:first-child { border-top: 1px solid var(--border); }
    .post-item:hover { background: var(--green-light); }

    .post-comment {
      font-family: var(--serif);
      font-size: 0.98rem;
      color: var(--text);
      margin-bottom: 0.75rem;
      line-height: 1.65;
    }

    .post-comment::before {
      content: '「';
      color: var(--green);
      font-size: 1.1em;
    }
    .post-comment::after {
      content: '」';
      color: var(--green);
      font-size: 1.1em;
    }

    .post-meta {
      display: flex;
      align-items: center;
      gap: 1rem;
    }

    .book-info {
      display: flex;
      align-items: center;
      gap: 0.6rem;
      flex: 1;
      min-width: 0;
    }

    .book-cover {
      width: 36px;
      height: 50px;
      background: var(--green-light);
      border-radius: 2px;
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 1.2rem;
      border: 1px solid var(--border);
      overflow: hidden;
    }

    .book-cover img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .book-detail { min-width: 0; }

    .book-title {
      font-size: 0.88rem;
      font-weight: 500;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .book-author {
      font-size: 0.78rem;
      color: var(--muted);
    }

    .post-tags {
      display: flex;
      gap: 0.4rem;
      flex-shrink: 0;
    }

    .genre-tag {
      background: var(--green-light);
      color: var(--green);
      font-size: 0.72rem;
      padding: 0.15rem 0.55rem;
      border-radius: 3px;
    }

    /* ── 投稿ボタン（固定） ── */
    .fab {
      position: fixed;
      bottom: 2rem;
      right: 2rem;
      background: var(--green);
      color: #fff;
      border: none;
      border-radius: 999px;
      padding: 0.75rem 1.5rem;
      font-family: var(--sans);
      font-size: 0.9rem;
      font-weight: 500;
      cursor: pointer;
      box-shadow: 0 4px 16px rgba(61,122,95,0.35);
      transition: background 0.15s, transform 0.1s;
      z-index: 200;
    }
    .fab:hover { background: #2f6149; transform: translateY(-2px); }

    /* ── モーダル ── */
    .modal-overlay {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(26,36,51,0.45);
      z-index: 300;
      align-items: center;
      justify-content: center;
      padding: 1rem;
    }
    .modal-overlay.open { display: flex; }
    
    html.modal-open {
      overflow: hidden;
    }

    .modal {
      background: var(--surface);
      border-radius: 10px;
      padding: 2rem;
      width: 100%;
      max-width: 480px;
      max-height: 90vh;
      overflow-y: auto;
    }

    .modal.modal-detail {
      max-width: 680px;
    }

    .modal h2 {
      font-family: var(--serif);
      font-size: 1.1rem;
      margin-bottom: 1.25rem;
    }

    .field { margin-bottom: 1rem; }

    .field label {
      display: block;
      font-size: 0.8rem;
      color: var(--muted);
      margin-bottom: 0.35rem;
    }

    .field input, .field textarea, .field select {
      width: 100%;
      border: 1px solid var(--border);
      border-radius: 5px;
      padding: 0.6rem 0.75rem;
      font-family: var(--sans);
      font-size: 0.9rem;
      color: var(--text);
      background: var(--bg);
      outline: none;
      transition: border-color 0.15s;
    }
    .field input:focus, .field textarea:focus, .field select:focus {
      border-color: var(--green);
    }

    .field textarea { height: 80px; resize: vertical; }

    .char-count {
      font-size: 0.75rem;
      color: var(--muted);
      text-align: right;
      margin-top: 0.25rem;
    }
    .char-count.over { color: var(--danger); }

    .modal-actions {
      display: flex;
      gap: 0.5rem;
      justify-content: flex-end;
      margin-top: 1.5rem;
      flex-wrap: wrap;
    }

    /* ── 詳細モーダル ── */
    .detail-title {
      font-family: var(--serif);
      font-size: 1.2rem;
      font-weight: 600;
      margin-bottom: 0.25rem;
    }

    .detail-author {
      color: var(--muted);
      font-size: 0.85rem;
      margin-bottom: 1.25rem;
    }

    .detail-comment {
      font-family: var(--serif);
      font-size: 1rem;
      background: var(--green-light);
      border-left: 3px solid var(--green);
      padding: 0.75rem 1rem;
      border-radius: 0 5px 5px 0;
      margin-bottom: 1.5rem;
      line-height: 1.7;
    }

    .obtain-label {
      font-size: 0.78rem;
      color: var(--muted);
      margin-bottom: 0.6rem;
    }

    .obtain-buttons {
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
    }

    .obtain-btn {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 0.7rem 1rem;
      cursor: pointer;
      background: var(--surface);
      font-family: var(--sans);
      font-size: 0.88rem;
      color: var(--text);
      text-decoration: none;
      transition: background 0.12s, border-color 0.12s;
    }
    .obtain-btn:hover { background: var(--green-light); border-color: var(--green); }

    .obtain-icon { font-size: 1.1rem; }

    .obtain-sub {
      font-size: 0.75rem;
      color: var(--muted);
      margin-left: auto;
    }

    /* ── 空状態 ── */
    .empty {
      text-align: center;
      padding: 3rem 0;
      color: var(--muted);
      font-size: 0.9rem;
    }

    /* --書籍検索結果　*/
    .search-result-item {
      display: flex;
      align-items: center;
      gap: 0.75rem;
      padding: 0.6rem 0.75rem;
      border: 1px solid var(--border);
      border-radius: 5px;
      margin-top: 0.4rem;
      cursor: pointer;
      transition: background 0.12s;
    }
    .search-result-item:hover { background: var(--green-light);}

    .search-result-item img {
      width: 36px;
      height: 50px;
      object-fit: cover;
      border-radius: 2px;
      flex-shrink: 0;
    }

    .sr-title {
      font-size: 0.88rem;
      font-weight: 500;
    }

    .sr-author{
      font-size: 0.78rem;
      color: var(--muted);
    }

    .sr-selected{
      font-size: 0.85rem;
      color: var(--green);
      padding: 0.5rem 0.75rem;
      background: var(--green-light);
      border-radius: 5px;
      margin-top: 0.4rem;
    }

    .filter-group {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      flex-wrap: wrap;
      width: 100%;
      padding: 0.25rem 0;
    }

    .filter-label {
      font-size: 0.75rem;
      color: var(--muted);
      width: 80px;
      flex-shrink: 0;
    }

    /* ── 3カラムレイアウト ── */
    .left-col {
      position: sticky;
      top: 0;
      height: 100vh;
      padding: 1.5rem 1rem;
      display: flex;
      flex-direction: column;
      gap: 1.5rem;
      border-right: 1px solid var(--border);
      overflow-y: auto;
    }

    .nav-links {
      display: flex;
      flex-direction: column;
      gap: 0.25rem;
    }

    .nav-item {
      display: block;
      padding: 0.5rem 1rem;
      border-radius: 999px;
      font-size: 0.9rem;
      color: var(--text);
      text-decoration: none;
      transition: background 0.12s;
    } 
    .nav-item:hover { background: var(--green-light); }
    .nav-item.active { font-weight: 500; color: var(--green); }

    .right-col {
      position: sticky;
      top: 0;
      height: 100vh;
      padding: 1.5rem 1rem;
      border-left: 1px solid var(--border);
      overflow-y: auto;
    }

    .right-section {
      margin-bottom: 1.5rem;
    }

    .recommend-count {
      background: transparent;
      color: var(--green);
      border: 1px solid var(--green);
      font-weight: 500;
      border-radius: 999px;
      padding: 0.15rem 0.75rem;
      font-size: 0.68rem;
    }

    .like-btn {
      background: transparent;
      border: 1px solid var(--border);
      border-radius: 999px;
      padding: 0.15rem 0.75rem;
      font-size: 0.72rem;
      color: var(--muted);
      cursor: pointer;
      transition: all 0.15s;
    }
    .like-btn:hover { border-color: #e74c3c; color: #e74c3c; }
    .like-btn.liked { border-color: #e74c3c; color: #e74c3c; background: var(--danger-light); }

    /* ── グリッドレイアウト（ホーム） ── */
    .post-grid {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 0.75rem;
    }

    .grid-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 8px;
      overflow: hidden;
      cursor: pointer;
      transition: transform 0.15s, box-shadow 0.15s;
      aspect-ratio: 2 / 3;
      display: flex;
      flex-direction: column;
    }
    .grid-card:hover {
      transform: translateY(-3px);
      box-shadow: 0 6px 20px rgba(0,0,0,0.1);
    }

    .grid-card-cover {
      flex: 1;
      background: var(--green-light);
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      font-size: 3rem;
    }

    .grid-card-cover img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .grid-card-info {
      padding: 0.6rem 0.75rem;
      border-top: 1px solid var(--border);
      background: var(--surface);
    }

    .grid-card-title {
      font-size: 0.78rem;
      font-weight: 500;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-bottom: 0.2rem;
    }

    .grid-card-comment {
      font-size: 0.72rem;
      color: var(--muted);
      display: -webkit-box;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
      line-height: 1.4;
    }

.modal-close-row {
  height: 0;
  display: flex;
  justify-content: flex-end;
  position: sticky;
  top: 0;
  z-index: 2;
}
.modal-close {
  width: 32px;
  height: 32px;
  margin: -0.5rem -0.5rem 0 0;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

#tlList {
  display: flex;
  flex-direction: column;
  gap: 0;
}

html {
  overflow-y: scroll;
}

@keyframes slideIn {
  from { transform: translateX(100px); opacity: 0; }
  to   { transform: translateX(0);     opacity: 1; }
}

/* ── レスポンシブ ── */

/* タブレット：右カラムを隠して2カラム */
@media (max-width: 1024px) {
  body {
    grid-template-columns: 200px 1fr;
  }
  .right-col {
    display: none;
  }
}

/* ── スマホ用タブバー：PCでは非表示 ── */
.mobile-tabbar { display: none; }

/* ── タブレット ── */
@media (max-width: 1024px) {
  body { grid-template-columns: 200px 1fr; }
  .right-col { display: none; }
}

/* ── スマホ ── */
@media (max-width: 768px) {
  body {
    grid-template-columns: minmax(0, 1fr);
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
    font-size: 14px;
  }

  .container {
    border-left: none;
    border-right: none;
    min-height: auto;
    min-width: 0;
    padding: 1.25rem 1rem;
  }

  /* 左カラム：下からせり上がるメニューパネルにする */
  .left-col {
    position: fixed;
    left: 0; right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom));
    top: auto;
    height: auto;
    max-height: 70vh;
    background: var(--surface);
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
    z-index: 240;
    transform: translateY(110%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0.25s;
  }
  .left-col.open {
    transform: translateY(0);
    visibility: visible;
  }
  .left-col .logo { display: none; }

  /* 下部タブバー */
  .mobile-tabbar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 250;
  }
  .tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    font-size: 1.2rem;
    text-decoration: none;
    color: var(--muted);
  }
  .tab-item span { font-size: 0.65rem; margin-top: 2px; }
  .tab-item.active { color: var(--green); }

  /* 投稿ボタンをタブバーの上に */
  .fab {
    bottom: calc(76px + env(safe-area-inset-bottom));
    right: 1rem;
    padding: 0.65rem 1.1rem;
    font-size: 0.85rem;
  }

  /* 入力欄：iOSの自動ズーム防止 */
  input, textarea, select { font-size: 16px !important; }

  /* モーダル */
  .modal { padding: 1.25rem; position: relative; }
  .modal-overlay { padding: 0.5rem; }

  /* 投稿一覧 */
  .post-item { padding: 1rem; overflow-wrap: anywhere; }
  .post-meta { flex-direction: column; align-items: flex-start; gap: 0.5rem;}
  .book-info { width: 100%; flex: none; }
  .book-title {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .post-tags { flex-wrap: wrap; }

  /* 本のグリッドは2列 */
  .post-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* フィルターのラベル幅を縮める */
  .filter-label { width: 100%; }

  .catch h1 { font-size: 1.25rem; }
  .catch p { font-size: 0.85rem; }
  .post-comment { font-size: 0.92rem; }

  #searchPageInput { min-width: 0; }
  #postList .grid-card:nth-child(n+5) { display: none; }
}

.featured-main-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 2rem;
  align-items: start;
}
.featured-main-cover {
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 2/3;
  background: var(--green-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
}

@media (max-width: 768px) {
  .featured-main-layout {
    grid-template-columns: 1fr;
  }
  .featured-main-cover {
    max-width: 160px;
    margin: 0 auto;
  }
}

.featured-books-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .featured-books-grid {
    grid-template-columns: 1fr;
  }
}

.featured-book-card {
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--surface);
}
.featured-book-cover {
  aspect-ratio: 2/3;
  background: var(--green-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  overflow: hidden;
}

.devtools-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}
.devtools-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}
.devtools-stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--green);
}
.devtools-stat-label {
  font-size: 0.78rem;
  color: var(--muted);
}

@media (max-width: 768px) {
  .devtools-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}