/* =========================================
   1. CSS変数定義
   ========================================= */
:root {
    --bg-color: #f8fafc; /* 少し明るい背景に変更してタイルを際立たせる */
    --text-main: #111111;
    --text-meta: #707070;
    --danger-color: #d32f2f;
    --alert-high: #d32f2f;
    --primary-deep: #0e7490;
    --card-bg: #ffffff;
    --border-radius: 16px;
    --font-mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

/* =========================================
   2. ベースレイアウト
   ========================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI",
                 "Hiragino Kaku Gothic ProN", sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    padding-bottom: 90px;
    -webkit-tap-highlight-color: transparent;
}

header {
    background-color: var(--primary-deep);
    color: white;
    padding: 16px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 50;
    transition: padding 0.3s ease, box-shadow 0.3s ease;
    will-change: padding;
}

header.scrolled {
    padding: 8px 16px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.15);
}

header h1 {
    font-family: 'Zen Kaku Gothic New', sans-serif;
    font-weight: 900;
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 4px;
    transition: font-size 0.3s ease, margin-bottom 0.3s ease;
}

header.scrolled h1 {
    font-size: 1.3rem;
    margin-bottom: 0;
}

.logo-text {
    background: linear-gradient(135deg, #ffffff 0%, #a5f3fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.title-divider { font-weight: 300; font-size: 1.2rem; opacity: 0.5; transition: font-size 0.3s ease; }
header.scrolled .title-divider { font-size: 0.9rem; }
header h1 small { font-size: 0.9rem; font-weight: 400; color: rgba(255,255,255,0.9); transition: font-size 0.3s ease, opacity 0.2s ease; }
header.scrolled h1 small { font-size: 0; overflow: hidden; opacity: 0; }
.subtitle { font-size: 0.8rem; opacity: 0.8; max-height: 2em; overflow: hidden; transition: max-height 0.3s ease, opacity 0.25s ease; }
header.scrolled .subtitle { max-height: 0; opacity: 0; pointer-events: none; }

/* =========================================
   3. コンテナ・検索バー
   ========================================= */
.container {
    padding: 16px;
    max-width: 800px;
    margin: 0 auto;
}

.search-wrapper {
    position: relative;
    margin-bottom: 24px;
}

.search-bar {
    width: 100%;
    padding: 14px 40px 14px 20px;
    font-size: 1rem;
    border: 2px solid transparent;
    border-radius: 12px;
    background-color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    -webkit-appearance: none;
    transition: all 0.2s;
}
.search-bar:focus {
    outline: none;
    border-color: var(--primary-deep);
    box-shadow: 0 4px 12px rgba(14, 116, 144, 0.1);
}

.search-clear-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: #f1f5f9;
    color: #64748b;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s;
}
.search-clear-btn.visible { opacity: 1; pointer-events: auto; }

/* =========================================
   4. タイルグリッド & スケルトン
   ========================================= */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

/* スケルトンローディングのアニメーション */
.skeleton-card {
    aspect-ratio: 1 / 1;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--border-radius);
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.bio-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: 0 4px 10px rgba(0,0,0,0.04);
    border: 1px solid #f1f5f9;
    aspect-ratio: 1 / 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    user-select: none;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}

.bio-card:active {
    transform: scale(0.95);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.bio-card.danger { border: 2px solid #fca5a5; background-color: #fffcfc; }
.bio-card.protect-border { border: 2px solid #6ee7b7; background-color: #f0fdf4; }

.tile-badge {
    position: absolute; top: 8px; left: 8px; font-size: 14px;
    background: #fff; border-radius: 50%; width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); z-index: 10;
}

.tile-image-wrapper {
    width: 55%; height: 55%; border-radius: 50%; overflow: hidden;
    margin-bottom: 8px; background-color: #f1f5f9; box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}
.tile-image-wrapper img { width: 100%; height: 100%; object-fit: cover; }

.tile-name {
    font-size: 0.9rem; font-weight: 700; color: var(--text-main);
    text-align: center; width: 90%; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.tile-category { font-size: 0.65rem; color: var(--text-meta); margin-top: 2px; }

/* =========================================
   5. Empty State
   ========================================= */
.empty-state {
    display: none; flex-direction: column; align-items: center; justify-content: center;
    padding: 40px 20px; text-align: center; color: var(--text-meta);
}
.empty-icon { width: 64px; height: 64px; opacity: 0.5; margin-bottom: 16px; }
.empty-reset-btn {
    margin-top: 16px; padding: 10px 20px; background: var(--primary-deep); color: #fff;
    border: none; border-radius: 20px; font-weight: bold; cursor: pointer; transition: background 0.2s;
}
.empty-reset-btn:active { background: #0891b2; }

/* =========================================
   6. モーダル
   ========================================= */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px);
    z-index: 2000; display: flex; align-items: flex-end;
    justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-content {
    background: #fff; width: 100%; max-width: 600px; height: 90vh;
    border-radius: 24px 24px 0 0; position: relative;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex; flex-direction: column;
    box-shadow: 0 -10px 25px rgba(0,0,0,0.1);
}
.modal-content.dragging { transition: none !important; }
.modal-overlay.active .modal-content { transform: translateY(0); }

.modal-handle {
    width: 40px; height: 5px; background: #cbd5e1; border-radius: 3px;
    margin: 12px auto; cursor: grab;
}
.modal-close-btn {
    position: absolute; top: 12px; right: 16px; width: 32px; height: 32px;
    background: rgba(0,0,0,0.05); border: none; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 16px;
    color: #666; cursor: pointer; z-index: 10; transition: background 0.2s;
}

.modal-body { padding: 0 24px 24px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }

.modal-header-img { width: 100%; height: 200px; border-radius: 12px; object-fit: cover; background-color: #f1f5f9; margin-bottom: 8px; }

/* クレジット表記全体のスタイル */
.image-credit { font-size: 0.65rem; color: #888; text-align: right; margin-bottom: 16px; }
.image-credit a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.image-credit a:hover { color: var(--primary-deep); }

/* --- ここからCCアイコンの追加スタイル --- */
.image-credit i.fa-brands {
    font-size: 1.2em; /* テキストより少し大きく */
    margin-left: 4px; /* 著作者名とアイコン間の余白 */
    vertical-align: middle; /* テキストのベースラインに合わせる */
    color: #888; 
}
.image-credit i.fa-brands + i.fa-brands {
    margin-left: 2px; /* 複数のアイコンが並ぶ場合の間隔 */
}
/* --- ここまで追加スタイル --- */

.modal-title { font-size: 1.5rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.modal-meta { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; padding-bottom: 16px; border-bottom: 1px solid #f1f5f9; }
.modal-meta dd { margin: 0; }
.modal-meta .scientific-name { font-family: var(--font-mono); font-size: 0.8rem; color: #64748b; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

span.danger-badge { color: #ffffff; font-size: 11px; font-weight: 600; padding: 4px 8px; border-radius: 4px; display: inline-block; }
span.danger-badge.contact { background: var(--alert-high); }
span.danger-badge.eat { background: #f59e0b; }
span.danger-badge.protect { background: #10b981; }

h3.section-label { font-family: var(--font-mono); background: #f1f5f9; color: var(--primary-deep); padding: 4px 8px; border-radius: 4px; font-size: 11px; font-weight: 700; display: inline-block; margin: 20px 0 12px; }
h3.section-label.alert { background: #fef2f2; color: var(--alert-high); }

.styled-list { padding-left: 20px; margin-bottom: 16px; font-size: 0.95rem; }
.alert-box { background-color: #fef2f2; border: 1px solid #fecaca; padding: 12px 16px; border-radius: 8px; margin-top: 16px; font-size: 0.95rem; color: #7f1d1d; }

details { margin-top: 24px; font-size: 0.85rem; color: #64748b; background: #f8fafc; padding: 12px; border-radius: 8px; }
summary { font-weight: bold; cursor: pointer; }

/* シェアボタン */
.share-btn {
    width: 100%; padding: 14px; margin-top: 24px; border: none; border-radius: 12px;
    background: #f1f5f9; color: var(--primary-deep); font-weight: bold; font-size: 1rem;
    display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; transition: background 0.2s;
}
.share-btn:active { background: #e2e8f0; }

/* =========================================
   7. ボトムナビゲーション
   ========================================= */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; width: 100%;
    background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(8px);
    display: flex; justify-content: flex-start; overflow-x: auto; white-space: nowrap;
    -webkit-overflow-scrolling: touch; padding: 12px 16px; gap: 8px;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05); border-top: 1px solid #f1f5f9; z-index: 1000;
}
.bottom-nav::-webkit-scrollbar { display: none; }

.nav-item {
    font-size: 0.85rem; font-weight: bold; color: var(--text-main); text-decoration: none;
    padding: 8px 16px; background-color: var(--card-bg); border-radius: 20px;
    flex-shrink: 0; transition: all 0.2s;
}
.nav-item.active { background-color: var(--primary-deep); color: #ffffff; box-shadow: 0 2px 6px rgba(14, 116, 144, 0.3); }

/* =========================================
   8. その他 (シンボル、フッター、トースト)
   ========================================= */
.symbol-icon { font-size: 0.85em; margin-left: 6px; color: var(--primary-deep); opacity: 0.75; vertical-align: middle; }
.symbol-svg { vertical-align: -0.15em; margin-right: 4px; }
.symbol-label { font-size: 0.75em; letter-spacing: 0.05em; vertical-align: middle; }
.category-tag { background-color: rgba(14, 116, 144, 0.1); color: var(--primary-deep); font-size: 0.75rem; font-weight: 600; padding: 4px 10px; border-radius: 20px; }

.footer { text-align: center; padding: 24px 16px 40px; font-size: 11px; color: #94a3b8; }
.footer a { color: inherit; } /* リンクを周りの文字色に合わせる */
.footer a.lifesaving-link { color: var(--danger-color); } /* 特定のリンクのみ赤系に */
.footer-disclaimer { background: var(--bg-color); padding: 12px; border-radius: 8px; text-align: left; margin: 16px 0; } /* 背景色を全体に揃える */
.footer-copyright {
    margin-top: 20px;
}
/* トースト通知 */
#toast {
    visibility: hidden; min-width: 200px; background-color: var(--primary-deep); color: #fff;
    text-align: center; border-radius: 30px; padding: 12px 24px;
    position: fixed; z-index: 3000; left: 50%; bottom: 80px; transform: translateX(-50%);
    font-size: 13px; font-weight: 600; box-shadow: 0 4px 12px rgba(14, 116, 144, 0.3);
    opacity: 0; transition: visibility 0s, opacity 0.3s, bottom 0.3s;
}
#toast.show { visibility: visible; opacity: 1; bottom: 90px; }

.references-details {
    margin-top: 16px;
    border-top: 1px solid #e2e8f0;
    padding-top: 12px;
}
.references-details summary {
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--primary-deep);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.references-details summary::-webkit-details-marker { display: none; }
.references-details summary::before {
    content: '▶';
    font-size: 0.7rem;
    transition: transform 0.2s;
}
.references-details[open] summary::before { transform: rotate(90deg); }
.references-list {
    margin: 10px 0 0 0;
    padding-left: 16px;
    font-size: 0.8rem;
    color: #475569;
    line-height: 1.7;
}
.references-list a {
    color: var(--primary-deep);
    text-decoration: underline;
    word-break: break-all;
}
.ref-meta { color: #94a3b8; font-size: 0.75rem; }
