:root {
    --bg: #f7f7f5;
    --surface: #ffffff;
    --text: #1a1a1a;
    --text-muted: #777;
    --accent: #2c5282;
    --border: #e4e4e4;
    --radius: 8px;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

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

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Header */

header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    height: 56px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.site-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
    letter-spacing: -0.01em;
}

.header-nav {
    margin-left: auto;
    display: flex;
    gap: 1rem;
}

.header-nav-link {
    font-size: 0.88rem;
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.25rem 0;
}

.header-nav-link:hover {
    color: var(--accent);
}

/* Main content */

main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 2rem;
}

.page-header {
    margin-bottom: 1.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.page-header h1 {
    font-size: 1.4rem;
    font-weight: 600;
    flex: 1;
}

.count {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 0.4rem;
}

/* Book grid */

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1.5rem;
}

.book-card {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: transform 0.15s ease;
}

.book-card:hover {
    transform: translateY(-3px);
}

/* Cover */

.cover {
    aspect-ratio: 2 / 3;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--border);
    box-shadow: var(--shadow);
}

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

.cover-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #3b6cb7, #1a3560);
    color: #fff;
    font-size: 2.5rem;
    font-weight: 700;
    user-select: none;
}

/* Book metadata below cover */

.book-meta {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.book-title {
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author {
    font-size: 0.76rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rating {
    font-size: 0.72rem;
    color: #b8880e;
    letter-spacing: 1px;
    margin-top: 0.1rem;
}

/* ── Breadcrumb ── */

.breadcrumb {
    margin-bottom: 1.5rem;
}

.breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}

.breadcrumb a:hover {
    color: var(--accent);
}

/* ── Detail layout ── */

.detail-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 2.5rem;
    align-items: start;
}

.detail-cover img,
.detail-cover .cover-placeholder.large {
    width: 200px;
    aspect-ratio: 2 / 3;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    object-fit: cover;
    display: block;
    position: sticky;
    top: 72px;
}

.cover-placeholder.large {
    font-size: 4rem;
    background: linear-gradient(145deg, #3b6cb7, #1a3560);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.detail-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* ── Book metadata ── */

.detail-meta h1 {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.25rem;
}

.detail-author {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.detail-badges {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.detail-badges .rating {
    font-size: 1rem;
    letter-spacing: 2px;
}

.badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-finished  { background: #d1fae5; color: #065f46; }
.badge-reading   { background: #dbeafe; color: #1e40af; }
.badge-to_read   { background: #f3f4f6; color: #374151; }
.badge-abandoned { background: #fee2e2; color: #991b1b; }

.detail-info-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.synopsis {
    font-size: 0.9rem;
    line-height: 1.7;
    color: #444;
    border-left: 3px solid var(--border);
    padding-left: 1rem;
    margin-top: 0.5rem;
}

.synopsis-search-link {
    display: inline-block;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
}

.synopsis-search-link:hover { color: var(--accent); }

.synopsis-candidates {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.synopsis-candidate {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
}

.synopsis-candidate-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.6rem;
}

.synopsis-candidate-text {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text);
    margin: 0;
    border-left: 3px solid var(--border);
    padding-left: 1rem;
}

.btn-sm {
    padding: 0.3rem 0.75rem;
    font-size: 0.82rem;
}

/* ── Sections ── */

.detail-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.detail-section h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text);
}

/* ── Form ── */

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-row label,
.label-block {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-row label input,
.form-row label select {
    font-size: 0.9rem;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    min-width: 140px;
}

.label-block {
    width: 100%;
    margin-bottom: 1rem;
}

.label-block textarea {
    font-size: 0.9rem;
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    resize: vertical;
    font-family: inherit;
    line-height: 1.6;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

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

/* ── Clippings ── */

.clipping-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.clipping-meta {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.3rem;
    font-size: 0.78rem;
}

.clipping-delete-form {
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.15s;
}

.clipping:hover .clipping-delete-form {
    opacity: 1;
}

.clipping-delete {
    background: none;
    border: none;
    cursor: pointer;
    color: #aaa;
    font-size: 0.85rem;
    padding: 0 0.2rem;
    line-height: 1;
}

.clipping-delete:hover {
    color: #e53e3e;
}

.clipping-type {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.68rem;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.clipping-type-highlight { background: #fef9c3; color: #854d0e; }
.clipping-type-note      { background: #dbeafe; color: #1e40af; }
.clipping-type-bookmark  { background: #f3f4f6; color: #374151; }
.clipping-type-unknown   { background: #f3f4f6; color: #374151; }

.clipping blockquote {
    margin: 0;
    padding: 0.5rem 0 0.5rem 1rem;
    border-left: 3px solid #e9c46a;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #333;
}

.muted {
    color: var(--text-muted);
}

/* ── Add book page ── */

h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.search-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.search-form .form-row {
    margin-bottom: 1rem;
}

.search-form .form-row label input {
    width: 280px;
}

.search-results {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.search-results h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.result-cover {
    flex-shrink: 0;
    width: 60px;
}

.result-cover img {
    width: 60px;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    border-radius: 4px;
    display: block;
}

.result-cover .cover-placeholder {
    width: 60px;
    aspect-ratio: 2 / 3;
    font-size: 1.2rem;
}

.result-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.9rem;
}

.result-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.result-synopsis {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.btn-sm {
    padding: 0.35rem 0.85rem;
    font-size: 0.82rem;
    align-self: center;
    white-space: nowrap;
}

/* ── Filter bar ── */

.filter-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
}

.status-tabs {
    display: flex;
    gap: 0.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.25rem;
}

.status-tab {
    appearance: none;
    -webkit-appearance: none;
    border: none;
    background: transparent;
    padding: 0.35rem 0.9rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    line-height: 1.4;
}

.status-tab:hover {
    color: var(--text);
    background: var(--bg);
}

.status-tab.active {
    background: var(--accent);
    color: #fff;
}

.status-tab-reading.active  { background: #1e40af; }
.status-tab-finished.active { background: #065f46; }
.status-tab-abandoned.active { background: #991b1b; }
.status-tab-to_read.active  { background: #374151; }

.search-bar {
    margin-bottom: 0.75rem;
}

.search-input {
    width: 100%;
    padding: 0.55rem 1rem 0.55rem 2.4rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text);
    background-color: var(--surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%23aaa' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.75rem center;
    transition: border-color 0.15s, box-shadow 0.15s;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: var(--shadow);
}

.search-input::placeholder {
    color: #bbb;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(44, 82, 130, 0.1);
}

.search-input.active {
    border-color: var(--accent);
}

.filter-extras {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: auto;
    flex-wrap: nowrap;
}

.filter-select {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%23999' d='M5 7L0 2h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    padding: 0.35rem 1.9rem 0.35rem 0.8rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.filter-select:hover {
    border-color: #aaa;
    color: var(--text);
}

.filter-select:focus {
    outline: none;
    border-color: var(--accent);
}

.filter-select.active {
    border-color: var(--accent);
    color: var(--accent);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%232c5282' d='M5 7L0 2h10z'/%3E%3C/svg%3E");
}

.controls-divider {
    width: 1px;
    height: 1.25rem;
    background: var(--border);
    margin: 0 0.1rem;
    flex-shrink: 0;
}

.btn-clear {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.35rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: 999px;
    white-space: nowrap;
    font-weight: 500;
    transition: border-color 0.15s, color 0.15s;
}

.btn-clear:hover {
    color: var(--text);
    border-color: #aaa;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    font-weight: 500;
    background: #ebf2ff;
    color: var(--accent);
    border: 1.5px solid #bfd3f5;
    padding: 0.32rem 0.7rem;
    border-radius: 999px;
}

.chip-remove {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.9rem;
    line-height: 1;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.chip-remove:hover {
    opacity: 1;
}

.book-author-link {
    font-size: 0.76rem;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.book-author-link:hover {
    color: var(--accent);
    text-decoration: underline;
}

.detail-author-link {
    text-decoration: none;
    display: block;
}

.detail-author-link:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* ── Group sections ── */

.group-section {
    margin-bottom: 2.5rem;
}

.group-heading {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.8rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* ── Cover hover overlay ── */

.cover-wrap {
    position: relative;
    width: 200px;
    aspect-ratio: 2 / 3;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: pointer;
}

.cover-wrap img,
.cover-wrap .cover-placeholder.large {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 0;
    box-shadow: none;
    position: static;
}

.cover-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    padding: 1rem;
}

.cover-wrap:hover .cover-overlay {
    opacity: 1;
}

.cover-overlay-title {
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.cover-overlay-btn {
    display: block;
    width: 100%;
    text-align: center;
    font-size: 0.78rem;
    font-weight: 500;
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    border: 1.5px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
    font-family: inherit;
}

.cover-overlay-btn:hover {
    background: rgba(255, 255, 255, 0.28);
}

.cover-overlay-btn input[type="file"] {
    display: none;
}

/* ── Cover picker page ── */

.covers-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.covers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 1.25rem;
}

.cover-option {
    display: contents;
}

.cover-option-btn {
    background: none;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: border-color 0.15s, transform 0.15s;
}

.cover-option-btn:hover {
    border-color: var(--accent);
    transform: translateY(-3px);
}

.cover-option-btn img {
    width: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    display: block;
}

.cover-source {
    font-size: 0.68rem;
    color: var(--text-muted);
    padding: 0.25rem 0.4rem;
    text-align: center;
    background: var(--bg);
}

/* ── Danger zone ── */

.danger-zone {
    border-color: #fecaca;
}

.danger-zone h2 {
    color: #991b1b;
}

.danger-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.btn-danger {
    background: #dc2626;
    color: #fff;
    border: none;
    padding: 0.5rem 1.25rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-danger:hover {
    background: #b91c1c;
}

/* Kindle import page */

.import-form-wrap,
.import-result,
.import-error {
    max-width: 640px;
    margin: 2rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
}

.import-detected {
    background: #f0fdf4;
    border: 1px solid #86efac;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.95rem;
}

.import-no-detect {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.95rem;
}

.import-form .form-row {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}

.import-form label {
    font-weight: 600;
    font-size: 0.9rem;
}

.input-drive {
    width: 100px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    text-transform: uppercase;
}

.form-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.import-info {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.88rem;
    color: var(--text-muted);
}

.import-info h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.75rem;
}

.import-info ul,
.import-info ol {
    padding-left: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.import-info p {
    margin-top: 0.75rem;
}

.import-info code {
    background: #f1f5f9;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
}

.result-ok {
    border-left: 4px solid #22c55e;
}

.result-neutral {
    border-left: 4px solid var(--border);
}

.import-result h2 {
    font-size: 1.15rem;
    margin-bottom: 1.25rem;
}

.import-warning {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    font-size: 0.88rem;
    margin-bottom: 1rem;
}

.import-collections {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.import-stats {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
}

.import-stats th,
.import-stats td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.import-stats th {
    text-align: left;
    font-weight: 500;
    color: var(--text-muted);
    width: 65%;
}

.import-stats td {
    font-weight: 700;
    font-size: 1.05rem;
    text-align: right;
}

.import-next {
    background: #f8fafc;
    border-radius: 6px;
    padding: 1rem 1.25rem;
    font-size: 0.88rem;
    margin-bottom: 1.5rem;
}

.import-next p {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.import-next ol {
    padding-left: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.import-next code {
    background: #e2e8f0;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
}

.import-actions {
    display: flex;
    gap: 0.75rem;
}

.import-error {
    border-left: 4px solid #dc2626;
}

.import-error p {
    margin-bottom: 1rem;
}
