/* ========================================
   リセット・基本設定
   ======================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* カラーパレット（変数として定義）
   色を変えたいときはここだけ修正すればOK */
:root {
  --color-bg:           #fdf8f4;  /* ページ背景：温かいオフホワイト */
  --color-header-bg:    #fff4e8;  /* ヘッダー背景：薄いオレンジがかったベージュ */
  --color-accent:       #e0894a;  /* アクセント：温かいオレンジ */
  --color-accent-dark:  #c07238;  /* アクセント濃いめ */
  --color-accent-light: #fde8cc;  /* アクセント薄め */
  --color-white:        #ffffff;
  --color-gray-100:     #f5f2ee;
  --color-gray-200:     #e5e0d8;
  --color-gray-400:     #b0a898;
  --color-gray-600:     #7a7068;
  --color-text:         #3a3028;  /* メインテキスト */
  --color-text-sub:     #8a7a6a;  /* サブテキスト */
  --color-favorite:     #e05c7a;  /* お気に入り（ピンク） */

  /* ビューア配色（暗め） */
  --viewer-bg:          #28211c;
  --viewer-ctrl-bg:     rgba(32, 26, 20, 0.96);
  --viewer-text:        #f0e6da;
  --viewer-text-sub:    #b09880;
  --viewer-btn-hover:   rgba(255, 255, 255, 0.12);
  --viewer-border:      rgba(255, 255, 255, 0.08);

  /* サイズ */
  --header-h:    52px;
  --footer-h:    60px;
  --radius:      8px;
  --radius-lg:   16px;
}

html {
  height: 100%;
}

body {
  min-height: 100%;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: 'Hiragino Sans', 'Meiryo', 'Yu Gothic', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ユーティリティ：非表示 */
.hidden {
  display: none !important;
}


/* ========================================
   トップページ
   ======================================== */

#top-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* サイトヘッダー */
.top-header {
  background-color: var(--color-header-bg);
  border-bottom: 2px solid var(--color-accent-light);
  flex-shrink: 0;
  padding: 0;
}

/* ヘッダーの中身を中央寄せ＆最大幅固定する箱 */
.header-inner {
  max-width: 1000px;   /* ← ここでヘッダーの横幅を制御 */
  margin: 0 auto;      /* ← 画面中央に寄せる */
  padding: 0 20px;     /* ← 画面が狭い時の余白 */
}

/* ヘッダー画像 */
.header-image {
  width: 100%;
  height: auto;
  display: block;
}

/* タイトル */
.site-title {
  font-size: 20px;
  font-weight: bold;
  color: var(--color-accent-dark);
  letter-spacing: 0.06em;

  margin: 0;
  padding: 18px 0;  /* ← 左右は header-inner の padding が担当 */
}

.site-title::before {
  content: '📖 ';
}

/* スマホ対応 */
@media (max-width: 600px) {
  .site-title {
    font-size: 20px;
    left: 15px;
    bottom: 15px;
    padding: 8px 12px;
  }
}

/* メインコンテンツ */
.top-main {
  flex: 1;
  padding: 24px 16px 40px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

/* 作品カードグリッド */
.work-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 20px;
}

/* 作品カード */
.work-card {
  background: var(--color-white);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(60, 40, 20, 0.07);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.work-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(60, 40, 20, 0.13);
}

/* カバー画像エリア */
.work-cover-area {
  width: 100%;
  aspect-ratio: 4 / 3;
  background-color: var(--color-gray-100);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.work-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 表紙がないときのプレースホルダー */
.work-cover-placeholder {
  font-size: 48px;
  opacity: 0.4;
  user-select: none;
}

/* カードのタイトル・ボタンエリア */
.work-card-info {
  padding: 12px;
  background: var(--color-header-bg);
  border-top: 1px solid var(--color-accent-light);
}

.work-card-title {
  font-size: 13px;
  font-weight: bold;
  color: var(--color-text);
  line-height: 1.4;
  margin-bottom: 10px;
  /* 長すぎるタイトルは2行で切る */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ボタングループ */
.work-card-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* 最初から読むボタン */
.btn-read-start {
  background-color: var(--color-accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  width: 100%;
  transition: background-color 0.15s;
  letter-spacing: 0.02em;
}

.btn-read-start:hover {
  background-color: var(--color-accent-dark);
}

/* 続きから読むボタン */
.btn-continue {
  background-color: var(--color-white);
  color: var(--color-accent-dark);
  border: 1.5px solid var(--color-accent);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  width: 100%;
  transition: background-color 0.15s;
}

.btn-continue:hover {
  background-color: var(--color-accent-light);
}

/* 作品なしメッセージ */
.no-works-msg {
  text-align: center;
  color: var(--color-text-sub);
  padding: 60px 20px;
  line-height: 2.4;
}

.no-works-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 12px;
}

.no-works-msg code {
  background: var(--color-gray-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 13px;
  color: var(--color-accent-dark);
}


/* ========================================
   閲覧ページ（ビューア）全体
   ======================================== */

#viewer-page {
  position: fixed;
  inset: 0; /* top/right/bottom/left: 0 の省略形 */
  display: flex;
  flex-direction: column;
  background-color: var(--viewer-bg);
  z-index: 100;
}


/* --- ヘッダー --- */

.viewer-header {
  height: var(--header-h);
  background-color: var(--viewer-ctrl-bg);
  border-bottom: 1px solid var(--viewer-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
  z-index: 10;
}

.btn-back {
  background: rgba(255, 255, 255, 0.1);
  color: var(--viewer-text);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  padding: 7px 13px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
}

.btn-back:hover {
  background: rgba(255, 255, 255, 0.2);
}

.viewer-title {
  flex: 1;
  text-align: center;
  font-size: 13px;
  font-weight: bold;
  color: var(--viewer-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-counter {
  font-size: 12px;
  color: var(--viewer-text-sub);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}


/* --- メイン（漫画ページ表示）--- */

.viewer-main {
  flex: 1;
  min-height: 0; /* flexboxでの縮小を許可するため必要 */
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

/* 画像コンテナ */
.image-area {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* 漫画画像本体 */
.manga-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  /* 画像の表示が崩れないよう縦横比を維持 */
}

/* 画像エラー表示 */
.img-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #1e1814;
}

.img-error-inner {
  text-align: center;
  color: var(--viewer-text-sub);
  padding: 20px;
}

.img-error-icon {
  font-size: 52px;
  display: block;
  margin-bottom: 16px;
}

.img-error-hint {
  font-size: 12px;
  margin-top: 6px;
  color: #70605a;
}

.img-error-path {
  font-size: 11px;
  font-family: monospace;
  color: #60504a;
  margin-top: 8px;
  word-break: break-all;
  max-width: 280px;
  background: rgba(255,255,255,0.04);
  padding: 6px 10px;
  border-radius: 4px;
}


/* --- ナビゲーションボタン（左右）--- */

.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  width: 52px;
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  gap: 1px;
}

.nav-btn:hover:not(:disabled) {
  background: rgba(224, 137, 74, 0.45);
  color: white;
  border-color: rgba(224, 137, 74, 0.6);
}

.nav-btn:disabled {
  opacity: 0.15;
  cursor: default;
}

.nav-btn-arrow {
  font-size: 16px;
  line-height: 1;
}

.nav-btn-label {
  font-size: 10px;
  line-height: 1;
}

/* 前へ：右側に配置（日本語漫画の向きに合わせて） */
.nav-btn-prev {
  right: 12px;
}

/* 次へ：左側に配置（日本語漫画の向きに合わせて） */
.nav-btn-next {
  left: 12px;
}


/* --- フッター --- */

.viewer-footer {
  height: var(--footer-h);
  background-color: var(--viewer-ctrl-bg);
  border-top: 1px solid var(--viewer-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 6px;
  flex-shrink: 0;
  z-index: 10;
}

.footer-btn {
  background: transparent;
  color: var(--viewer-text-sub);
  border: none;
  border-radius: var(--radius);
  min-width: 52px;
  height: 44px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  transition: color 0.15s, background 0.15s;
  letter-spacing: 0.02em;
}

.footer-btn:hover:not(:disabled) {
  color: var(--viewer-text);
  background: var(--viewer-btn-hover);
}

.footer-btn:disabled {
  opacity: 0.2;
  cursor: default;
}

/* お気に入りボタン：文字を少し大きく */
.footer-btn-fav {
  font-size: 20px;
}

/* お気に入り登録済みのページ */
.footer-btn.is-favorite {
  color: var(--color-favorite);
}

/* サムネイルが開いているとき */
.footer-btn.is-active {
  color: var(--color-accent);
  background: rgba(224, 137, 74, 0.15);
}


/* ========================================
   サムネイルパネル
   ======================================== */

/* 背景オーバーレイ（クリックで閉じる） */
.thumbnail-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 20;
}

/* パネル本体 */
.thumbnail-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  background: #1e1814;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 62vh;
  display: flex;
  flex-direction: column;
  /* 初期状態：画面下に隠れている */
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

/* 開いた状態 */
.thumbnail-panel.panel-open {
  transform: translateY(0);
}

/* パネルヘッダー */
.thumbnail-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.thumbnail-panel-title {
  color: var(--viewer-text);
  font-size: 14px;
  font-weight: bold;
}

.btn-close-panel {
  background: rgba(255, 255, 255, 0.08);
  color: var(--viewer-text-sub);
  border: none;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-close-panel:hover {
  background: rgba(255, 255, 255, 0.16);
  color: var(--viewer-text);
}

/* サムネイルグリッド（スクロール可能エリア） */
.thumbnail-grid {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
  gap: 8px;
  align-content: start;
  /* スマホでのスクロールを滑らかに */
  -webkit-overflow-scrolling: touch;
}

/* 個別サムネイル */
.thumb-item {
  cursor: pointer;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  background: #2a2218;
  transition: border-color 0.15s, transform 0.1s;
  position: relative;
}

.thumb-item:hover {
  border-color: var(--color-accent);
  transform: scale(1.05);
}

/* 現在表示中のページ */
.thumb-item.current-thumb {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 1px var(--color-accent);
}

/* お気に入り登録されているページのマーク */
.thumb-item.favorite-thumb::after {
  content: '♥';
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 11px;
  color: var(--color-favorite);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  line-height: 1;
}

.thumb-img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  background: #2a2218;
}

.thumb-num {
  text-align: center;
  font-size: 10px;
  color: #7a6a5a;
  padding: 3px 0;
  line-height: 1;
}


/* ========================================
   汎用ボタン共通スタイル
   ======================================== */

.btn {
  cursor: pointer;
  user-select: none;
  /* スマホでタップしたときの青いハイライトを消す */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:active {
  opacity: 0.7;
}


/* ========================================
   レスポンシブ対応
   ======================================== */

/* スマートフォン（480px以下） */
@media (max-width: 480px) {
  .work-list {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 14px;
  }

  .viewer-title {
    font-size: 11px;
  }

  .page-counter {
    font-size: 11px;
  }

  .nav-btn {
    width: 44px;
    height: 44px;
  }

  .nav-btn-arrow {
    font-size: 14px;
  }

  .footer-btn {
    font-size: 12px;
    min-width: 44px;
  }

  .thumbnail-grid {
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  }
}

/* タブレット以上（768px以上） */
@media (min-width: 768px) {
  .work-list {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  }

  .nav-btn {
    width: 58px;
    height: 58px;
  }

  .nav-btn-arrow {
    font-size: 20px;
  }

  .nav-btn-label {
    font-size: 11px;
  }
}

/* デスクトップ（1024px以上） */
@media (min-width: 1024px) {
  .top-main {
    padding: 32px 24px 60px;
  }
}

.site-header {
    text-align: center;
    padding: 20px 20px 10px;
}

.header-image {
    width: min(100%, 900px);
    border-radius: 16px;
    display: block;
    margin: 0 auto 20px;
}

.header-text h1 {
    font-size: 2rem;
    color: #d47a2c;
    margin-bottom: 8px;
}

.header-text p {
    color: #8a6b52;
    font-size: 1rem;
}