/* ========================================
   リセット & ベース
   ======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* ========================================
   ヘッダー
   ======================================== */
.app-header {
  background: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
}

.app-title {
  text-align: center;
  font-size: 32px;
  color: #2c3e50;
  margin-bottom: 30px;
  font-weight: 700;
}

/* 閲覧・カテゴリ専用（検索窓なし） */
.app-header-simple {
  background: white;
  padding: 16px 12px 24px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
  /* ★ ここを一旦コメントアウト or 削除 ★ */
  /* max-width: 528px; */
  margin-left: auto;
  margin-right: auto;
}

.app-title-simple {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  color: #2c3e50;
}

/* ========================================
   検索エリア
   ======================================== */
.search-wrapper {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
}

.search-box {
  display: flex;
  gap: 10px;
}

#searchInput {
  flex: 1;
  padding: 14px 18px;
  font-size: 16px;
  border: 2px solid #ddd;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.3s;
}

#searchInput:focus {
  border-color: #3498db;
}

#searchBtn {
  width: 48px;
  height: 48px;
  padding: 0;
  background: #3498db;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#searchBtn .material-symbols-outlined {
  font-size: 24px;
  color: white;
}

#searchBtn:hover {
  background: #2980b9;
}

#searchBtn:active {
  transform: scale(0.98);
}

/* ========================================
   検索ドロップダウン
   ======================================== */
.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  max-height: 320px;
  overflow-y: auto;
  z-index: 1000;
}

.search-dropdown.hidden {
  display: none;
}

#dropdownResults {
  max-height: inherit;
  overflow-y: auto;
}

.search-dropdown::-webkit-scrollbar {
  width: 8px;
}

.search-dropdown::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.search-dropdown::-webkit-scrollbar-thumb {
  background: #3498db;
  border-radius: 4px;
}

.dropdown-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.2s;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background: #f8f9fa;
}

.dropdown-item-img {
  width: 50px;
  height: 75px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.dropdown-item-info {
  flex: 1;
  min-width: 0;
}

.dropdown-item-title {
  font-size: 14px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-item-author {
  font-size: 12px;
  color: #7f8c8d;
}

.dropdown-loading,
.dropdown-empty,
.dropdown-error {
  padding: 20px;
  text-align: center;
  color: #7f8c8d;
}

.dropdown-error {
  color: #e74c3c;
}

/* ========================================
   メインエリア
   ======================================== */
.app-main {
  background: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.grid-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.grid-title {
  font-size: 22px;
  font-weight: 600;
  color: #2c3e50;
}

.selected-count {
  font-size: 18px;
  font-weight: 600;
  color: #3498db;
}

/* ========================================
   9グリッド
   ======================================== */
.selected-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  margin-bottom: 30px;
}

.grid-slot {
  aspect-ratio: 1;
  background: #f8f9fa;
  border: 2px solid #ddd;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: #bbb;
  position: relative;
  transition: border-color 0.3s;
  font-weight: 600;
}

.grid-slot.empty {
  cursor: default;
}

.grid-slot.filled {
  border: 2px solid #3498db;
  background: white;
  cursor: grab;
}

.grid-slot.drag-over {
  border-color: #2196f3;
  border-width: 3px;
}

.grid-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: left top;
  border-radius: 6px;
}

.remove-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  background: rgba(149, 165, 166, 0.85);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  font-weight: bold;
  line-height: 1;
}

.remove-btn:hover {
  background: rgba(127, 140, 141, 1);
  transform: scale(1.1);
}

/* ========================================
   シェアエリア
   ======================================== */
.share-area {
  padding: 20px;
  border-top: 1px solid #ecf0f1;
  opacity: 0;
  transform: translateY(-10px);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
}

.share-area.hidden {
  display: none;
}

.share-area.fade-in {
  opacity: 1;
  transform: translateY(0);
}

.share-label {
  font-size: 14px;
  font-weight: 600;
  color: #7f8c8d;
  margin-bottom: 8px;
}

.share-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

#shareUrl {
  flex: 1;
  padding: 12px 16px;
  font-size: 14px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: #f8f9fa;
  color: #2c3e50;
  outline: none;
}

.copy-btn {
  width: 48px;
  height: 48px;
  padding: 0;
  background: #3498db;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.copy-btn .material-symbols-outlined {
  font-size: 24px;
  color: white;
}

.copy-btn:hover {
  background: #2980b9;
}

.copy-btn:active {
  transform: scale(0.98);
}

.share-btn-secondary {
  width: 100%;
  padding: 12px;
  font-size: 14px;
  background: #27ae60;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s;
}

.share-btn-secondary:hover {
  background: #229954;
}

.share-btn-secondary:active {
  transform: scale(0.98);
}

/* ========================================
   モーダル
   ======================================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  max-width: 400px;
  width: 90%;
}

.modal-content h3 {
  font-size: 20px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 20px;
  text-align: center;
}

.modal-share-btn {
  width: 100%;
  padding: 14px;
  margin-bottom: 10px;
  font-size: 14px;
  background: #3498db;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s;
}

.modal-share-btn:hover {
  background: #2980b9;
}

.modal-share-btn:active {
  transform: scale(0.98);
}

.modal-close-btn {
  width: 100%;
  padding: 14px;
  font-size: 14px;
  background: #95a5a6;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s;
}

.modal-close-btn:hover {
  background: #7f8c8d;
}

.modal-close-btn:active {
  transform: scale(0.98);
}

/* ========================================
   エラーバナー
   ======================================== */
.error-banner {
  padding: 14px 24px;
  background: rgba(149, 165, 166, 0.95);
  color: white;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  margin-top: 20px;
}

.error-banner.hidden {
  display: none;
}

/* ========================================
   エラートースト
   ======================================== */
.error-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(149, 165, 166, 0.95);
  color: white;
  padding: 14px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 10000;
}

.error-toast.show {
  opacity: 1;
}

/* ========================================
   スマホ
   ======================================== */
@media (max-width: 768px) {
  .container {
    padding: 15px;
  }

  .app-header {
    padding: 20px;
  }

  .app-title {
    font-size: 24px;
    margin-bottom: 20px;
  }

  #searchInput {
    font-size: 14px;
  }

  .app-main {
    padding: 20px;
  }

  .selected-grid {
    gap: 10px;
  }

  .grid-slot {
    font-size: 20px;
  }

  .share-area {
    padding: 15px;
  }

  .modal-content {
    padding: 20px;
  }
}

/* ========================================
   タブレット以上（768px〜）
   ======================================== */
@media (min-width: 768px) {
  .app-main {
    max-width: 528px;
    margin-left: auto;
    margin-right: auto;
  }

  .selected-grid {
    max-width: 488px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* ========================================
   PC（1024px〜）
   ======================================== */
@media (min-width: 1024px) {
  .app-main {
    max-width: 528px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* ========================================
   閲覧モード用
   ======================================= */
.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #666;
  text-decoration: none;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  transition: all 0.2s;
}

.back-btn:hover {
  background: #f8f9fa;
  border-color: #3498db;
  color: #3498db;
}

.grid-slot.view-mode {
  cursor: default !important;
}

.grid-slot.view-mode.filled {
  position: relative;
}

.book-title {
  position: absolute;
  bottom: 4px;
  left: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 11px;
  padding: 2px 4px;
  text-align: center;

  /* 標準プロパティ */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;

  /* 標準互換性 */
  display: box;
  line-clamp: 2;
  box-orient: vertical;

  /* フォールバック */
  max-height: 2.2em;
}

/* ========================================
   縦リスト用CSS（既存style.cssに追加）
   ======================================== */

/* 縦リストコンテナ */
.book-list {
  margin-top: 30px;
  width: 100%;
}

/* 縦リストアイテム */
.book-list-item {
  display: flex;
  align-items: center;
  padding: 12px;
  margin-bottom: 10px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.2s;
}

.book-list-item:hover {
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* ナンバリング */
.book-list-number {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #3498db;
  color: white;
  font-weight: bold;
  font-size: 16px;
  border-radius: 50%;
  margin-right: 12px;
}

/* 書籍画像 */
.book-list-image {
  flex-shrink: 0;
  width: 60px;
  height: 90px;
  object-fit: cover;
  border-radius: 4px;
  margin-right: 12px;
}

/* 書籍情報 */
.book-list-info {
  flex: 1;
  min-width: 0;
}

.book-list-title {
  font-size: 14px;
  font-weight: 600;
  color: #2c3e50;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
}

.book-list-author {
  font-size: 12px;
  color: #7f8c8d;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 閲覧モード専用スタイル（既存のview-mode関連を拡張） */
.view-mode .selected-grid {
  pointer-events: none;
}

.view-mode .grid-slot {
  border: none;
}

.view-mode .grid-slot.filled {
  border: none;
  background: white;
}

/* スマホ対応 */
@media (max-width: 768px) {
  .book-list-image {
    width: 50px;
    height: 75px;
  }

  .book-list-number {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }

  .book-list-title {
    font-size: 13px;
  }

  .book-list-author {
    font-size: 11px;
  }
}

/* タブレット以上（768px〜）で縦リストも中央配置 */
@media (min-width: 768px) {
  .book-list {
    max-width: 488px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* ========================================
   自分のグリッド作成ボタン
   ======================================== */

.create-button-wrapper {
  margin-top: 20px;
}

.create-button {
  display: block;
  width: 100%;
  max-width: 528px;
  margin-left: auto;
  margin-right: auto;

  padding: 14px 20px;
  background: #f97316; /* オレンジ */
  color: white;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  border-radius: 8px;
  text-decoration: none;
  transition:
    background 0.3s,
    transform 0.1s;
}

.create-button:hover {
  background: #ea6a10;
}

.create-button:active {
  transform: scale(0.98);
}

#dates {
  font-size: 11px;
  color: #6b7280;

  display: grid;
  grid-template-columns: 70px 1fr; /* 左：ラベル / 右：日付 */
  row-gap: 2px;

  margin-top: 12px;
  margin-bottom: 12px;

  width: 100%;
  padding-left: 12px;
}

/* 1行＝1レコードとして扱う */
#dates > div {
  display: contents; /* 中の span をそのままグリッドに乗せる */
}

/* ラベル側 */
#dates span[id^="label-"] {
  font-family: 'Courier New', Consolas, monospace;
}

/* 日付側（特に指定不要だが、必要ならここで調整） */
#dates #date-updated,
#dates #date-created {
  font-family: inherit;
}



/* ========================================
   フッター
   ======================================== */

.site-footer {
  padding: 32px 0 16px;
  border-top: 1px solid #e5e7eb;
  margin-top: 20px;
}

.site-footer-inner {
  text-align: center;
  font-size: 11px;
  color: #6b7280;
}

.site-footer-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.site-footer-nav a {
  padding: 4px 8px;
  color: #6b7280;
  text-decoration: none;
  transition: color 0.2s ease;
}

.site-footer-nav a:hover {
  color: #3b82f6;
}
