:root {
    --bg-main: #ffffff;
    --bg-sidebar: #f7f7f5;
    --bg-hover: #efefed;
    --text-main: #37352f;
    --text-muted: #9b9a97;
    --border-color: #e9e9e7;
    --primary-color: #2383e2;
    --tag-bg: #e8f0fe;
    --tag-text: #1967d2;
    --link-color: #e28743;
    
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05);
    --shadow-hover: 0 8px 15px rgba(0,0,0,0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px 12px;
}

.sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    padding: 0 12px;
    margin-bottom: 24px;
    color: var(--text-main);
}

.nav-links {
    list-style: none;
}

.nav-links li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    color: var(--text-main);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: background 0.2s ease;
    cursor: pointer;
}

.nav-links li a:hover {
    background-color: var(--bg-hover);
}

.nav-links li a.active {
    background-color: var(--bg-hover);
    font-weight: 500;
}

.nav-links i {
    font-size: 18px;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    position: relative;
    background-color: var(--bg-main);
}

.view {
    display: none;
    padding: 48px;
    max-width: 900px;
    margin: 0 auto;
    animation: fadeIn 0.3s ease-out;
}

.view.active {
    display: block;
}

.view-header {
    margin-bottom: 32px;
}

.view-header h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* UI Elements */
input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    outline: none;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    font-family: inherit;
}

input[type="text"]:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(35, 131, 226, 0.2);
}

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

/* Search Box */
.search-container {
    margin-bottom: 32px;
}

.search-box {
    display: flex;
    gap: 8px;
    position: relative;
}

.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 20px;
}

.search-box input {
    padding-left: 44px;
}

#search-btn {
    padding: 0 24px;
    background-color: var(--text-main);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: opacity 0.2s;
}

#search-btn:hover {
    opacity: 0.9;
}

/* Grids & Cards */
.books-grid, .search-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 24px;
}

.book-card {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.book-cover {
    width: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    background-color: var(--bg-hover);
    border-bottom: 1px solid var(--border-color);
}

.book-info {
    padding: 16px;
}

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

.book-author {
    font-size: 12px;
    color: var(--text-muted);
}

.add-btn {
    margin-top: 12px;
    width: 100%;
    padding: 8px;
    border: 1px solid var(--text-main);
    background: transparent;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}

.add-btn:hover {
    background: var(--text-main);
    color: white;
}

/* Editor View */
.editor-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.danger-btn {
    color: #e53e3e;
}

.danger-btn:hover {
    background: #fff5f5 !important;
    color: #c53030 !important;
}

.icon-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.book-meta {
    display: flex;
    gap: 32px;
    margin-bottom: 48px;
    align-items: flex-end;
}

.editor-cover {
    width: 120px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}

.editor-title {
    font-size: 40px;
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.editor-author {
    font-size: 16px;
    color: var(--text-muted);
}

.editor-properties {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
    width: 100%;
}

.property-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.property-label {
    width: 70px;
    color: var(--text-muted);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.property-value {
    flex: 1;
}

.property-value input[type="text"],
.property-value input[type="number"] {
    background: transparent;
    border: none;
    padding: 6px 8px;
    font-size: 14px;
    border-radius: var(--radius-sm);
    width: 100%;
    transition: background 0.2s;
}

.property-value input:hover {
    background: var(--bg-hover);
}

.property-value input:focus {
    background: var(--bg-hover);
    outline: none;
    box-shadow: none;
    border-color: transparent;
}

.progress-value {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-main);
}

.progress-value input[type="number"]::-webkit-inner-spin-button,
.progress-value input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

.progress-value input[type="number"] {
    width: 60px;
    text-align: right;
    -moz-appearance: textfield;
    appearance: none;
}

.editor-workspace {
    position: relative;
}

.editor-placeholder {
    color: #e0e0e0;
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    font-size: 16px;
    display: none;
}

.editor-content {
    min-height: 300px;
    font-size: 16px;
    line-height: 1.7;
    outline: none;
}

.editor-content:empty:before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    pointer-events: none;
}

/* Obsidian-like syntax highlighting */
.tag-highlight {
    background-color: var(--tag-bg);
    color: var(--tag-text);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}

.link-highlight {
    color: var(--link-color);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    cursor: pointer;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    #app {
        flex-direction: column-reverse;
    }

    .sidebar {
        width: 100%;
        height: 60px;
        flex-direction: row;
        padding: 0;
        border-right: none;
        border-top: 1px solid var(--border-color);
        justify-content: space-around;
        align-items: center;
    }

    .sidebar-header {
        display: none;
    }

    .nav-links {
        display: flex;
        width: 100%;
        justify-content: space-around;
    }

    .nav-links li a {
        flex-direction: column;
        gap: 4px;
        font-size: 10px;
        padding: 8px;
    }

    .nav-links i {
        font-size: 24px;
    }

    .view {
        padding: 24px 16px;
    }

    .book-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    /* iPhone用UI調整 */
    .pc-only {
        display: none !important;
    }

    .sidebar {
        width: 100%;
        height: calc(65px + env(safe-area-inset-bottom));
        flex-direction: row;
        padding: 0;
        padding-bottom: env(safe-area-inset-bottom);
        border-right: none;
        border-top: 1px solid var(--border-color);
        justify-content: space-around;
        align-items: center;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        z-index: 1000;
    }

    .nav-links {
        display: grid;
        grid-template-columns: 1fr 1fr; /* 2段組み（2列）にして大きく表示 */
        width: 100%;
        height: 100%;
        margin: 0;
    }

    .nav-links li {
        width: 100%;
        height: 100%;
    }

    .nav-links li a {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 4px;
        font-size: 11px;
        height: 100%;
        border-radius: 0;
        padding: 0;
    }

    .nav-links i {
        font-size: 22px;
    }

    .view {
        padding: 24px 16px 100px 16px; /* 下部ナビに隠れないよう余白を追加 */
    }

/* iPhone用：1列だと画像が荒くなるため、強制的に2列表示にする（復元） */
    .books-grid, .search-results {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
}

/* ==========================================
   ライブラリ コントロールバー
   ========================================== */

.library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.library-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sort-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 7px 32px 7px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-main) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%239b9a97' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") no-repeat right 10px center;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-main);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    min-width: 140px;
}

.sort-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(35, 131, 226, 0.2);
}

.settings-icon-btn {
    padding: 7px 10px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.settings-icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

/* ==========================================
   タグフィルターバー
   ========================================== */

.tag-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
}

.tag-filter-btn {
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--bg-main);
    font-size: 13px;
    font-family: inherit;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.tag-filter-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
    border-color: #ccc;
}

.tag-filter-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    font-weight: 500;
}

/* ==========================================
   設定モーダル
   ========================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-main);
}

.setting-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
    line-height: 1.6;
}

.setting-desc a {
    color: var(--primary-color);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 24px;
}

.primary-btn {
    padding: 10px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s;
}

.primary-btn:hover {
    opacity: 0.85;
}

@media (max-width: 768px) {
    .library-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .library-controls {
        width: 100%;
    }

    .sort-select {
        flex: 1;
    }
}

/* ==========================================
   検索カード追加スタイル
   ========================================== */

.search-card-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    margin-bottom: 0;
    flex-wrap: wrap;
}

.search-card-meta span {
    font-size: 11px;
    color: var(--text-muted);
}

/* ソースバッジ */
.source-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.source-badge.google {
    background: #e8f0fe;
    color: #1967d2;
}

.source-badge.ndl {
    background: #fce8e6;
    color: #c5221f;
}

.source-badge.rakuten {
    background: #fde8e8;
    color: #db3b3b;
}

/* 検索中ローディング */
.search-loading {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    padding: 24px 0;
    font-size: 14px;
}

/* ==========================================
   満足度スターUI
   ========================================== */

.rating-stars {
    display: flex;
    gap: 2px;
    align-items: center;
    padding: 4px 0;
}

.star-btn {
    background: none;
    border: none;
    font-size: 22px;
    line-height: 1;
    color: #e0e0e0;
    cursor: pointer;
    padding: 2px 3px;
    transition: color 0.1s ease, transform 0.1s ease;
}

.star-btn:hover,
.star-btn.hovered {
    color: #f5a623;
    transform: scale(1.15);
}

.star-btn.active {
    color: #f5a623;
}

/* ==========================================
   感想プロンプトカード
   ========================================== */

.impression-prompt {
    background: linear-gradient(135deg, #fefdf8 0%, #fff8ec 100%);
    border: 1px solid #f0e0c0;
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 24px;
    transition: box-shadow 0.3s ease;
}

.impression-prompt.flash {
    animation: impressionFlash 1.2s ease;
}

@keyframes impressionFlash {
    0%   { box-shadow: 0 0 0 0 rgba(245, 166, 35, 0); border-color: #f0e0c0; }
    20%  { box-shadow: 0 0 0 6px rgba(245, 166, 35, 0.25); border-color: #f5a623; }
    60%  { box-shadow: 0 0 0 10px rgba(245, 166, 35, 0.1); border-color: #f5a623; }
    100% { box-shadow: 0 0 0 0 rgba(245, 166, 35, 0); border-color: #f0e0c0; }
}

.impression-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}

.impression-icon {
    font-size: 20px;
    flex-shrink: 0;
    margin-top: 1px;
}

.impression-message {
    font-size: 14px;
    line-height: 1.6;
    color: #7a5c2e;
    font-weight: 500;
}

.impression-textarea {
    width: 100%;
    min-height: 90px;
    padding: 12px 14px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.7;
    border: 1px solid #e8d5aa;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-main);
    resize: vertical;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.impression-textarea:focus {
    border-color: #f5a623;
    box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.15);
}

/* 感想プロンプト内アクション */
.impression-actions {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
}

#add-impression-btn {
    min-height: 44px;
    padding: 0 24px;
    font-weight: 600;
    border-radius: var(--radius-md);
    background: #f5a623;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, transform 0.1s;
}

#add-impression-btn:hover {
    background: #e69516;
}

#add-impression-btn:active {
    transform: scale(0.98);
}

/* 感想ログカード一覧 */
.impression-logs-list {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.impression-log-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.log-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.log-date {
    font-weight: 600;
}

.log-page {
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 10px;
}

.log-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.log-edit-btn, .log-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    font-size: 16px;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.log-edit-btn:hover { color: var(--primary-color); }
.log-delete-btn:hover { color: var(--danger-color); }

.log-content {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-main);
    word-break: break-all;
}

/* モバイル対応：iPhone等の小さい画面でボタンを大きく */
@media (max-width: 600px) {
    #add-impression-btn {
        width: 100%;
        min-height: 52px; /* 押しやすいサイズ */
        justify-content: center;
        font-size: 16px;
    }
}

/* ==========================================
   ダミー表紙 (画像URLが取得できなかった場合)
   ========================================== */

.dummy-cover {
    /* book-cover と同じレイアウト */
    width: 100%;
    aspect-ratio: 2 / 3;
    border-bottom: 1px solid var(--border-color);

    /* タイトルのハッシュ値（--dummy-hue）から個性的なグラデーションを生成 */
    background:
        linear-gradient(
            145deg,
            hsl(var(--dummy-hue, 200), 45%, 88%) 0%,
            hsl(calc(var(--dummy-hue, 200) + 30), 55%, 72%) 100%
        );

    /* 中央にタイトルテキストを配置 */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;

    /* 本らしい背表紙風の左帯 */
    border-left: 4px solid hsl(var(--dummy-hue, 200), 55%, 55%);
}

/* 装飾用のサブレイヤー */
.dummy-cover::before {
    content: '';
    position: absolute;
    inset: 8px;
    border: 1px solid hsl(var(--dummy-hue, 200), 30%, 75%);
    border-radius: 2px;
    opacity: 0.6;
    pointer-events: none;
}

.dummy-title {
    position: relative;
    z-index: 1;
    color: hsl(var(--dummy-hue, 200), 40%, 28%);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    text-align: center;
    padding: 8px;
    word-break: break-all;

    /* 最大4行まで表示してあふれたら省略 */
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    line-clamp: 5;
    overflow: hidden;
    max-height: 80%;
}

/* エディタ画面用：縦長サイズ対応 */
.dummy-cover.editor-cover {
    width: 120px;
    aspect-ratio: 2 / 3;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
}

.dummy-cover.editor-cover .dummy-title {
    font-size: 11px;
    -webkit-line-clamp: 6;
    line-clamp: 6;
}
