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

:root {
    --bg: #fafaf7;
    --card-bg: #fff;
    --text: #2d2d2d;
    --text-muted: #777;
    --accent: #4a7c59;
    --accent-light: #e8f0eb;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    overflow-x: hidden;
}

header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--accent);
    color: #fff;
    padding: 16px;
    text-align: center;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    position: relative;
}

header h1 {
    font-size: 1.3rem;
    font-weight: 600;
}

.favs-btn {
    position: absolute;
    right: 0;
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
}

.favs-btn.fav-active {
    color: #ff6b6b;
}

.search-box {
    max-width: 500px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-input-wrap {
    flex: 1;
    min-width: 0;
    position: relative;
}

.search-input-wrap input[type="search"] {
    width: 100%;
    padding: 10px 36px 10px 16px;
    border: none;
    border-radius: 24px;
    font-size: 1rem;
    outline: none;
    background: rgba(255,255,255,0.95);
    color: var(--text);
}

.search-input-wrap input[type="search"]::-webkit-search-cancel-button {
    display: none;
}

.search-input-wrap input[type="search"]::placeholder {
    color: var(--text-muted);
}

.search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    display: flex;
    align-items: center;
}

.search-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    white-space: nowrap;
}

main {
    padding: 12px;
    max-width: 1200px;
    margin: 0 auto;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (min-width: 500px) {
    .book-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    main { padding: 16px; }
}

.book-grid[hidden] {
    display: none;
}

.book-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    text-decoration: none;
    color: inherit;
    display: block;
}

.book-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.book-card img {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    display: block;
    background: var(--accent-light);
}

.book-card .book-info {
    padding: 10px;
}

.book-card .book-info h3 {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-card .book-info p {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.search-result {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px;
    margin-bottom: 10px;
    cursor: pointer;
    display: flex;
    gap: 10px;
    align-items: center;
}

.search-result:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.result-thumb {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.result-thumb.no-thumb {
    background: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--accent);
}

.result-text {
    flex: 1;
    min-width: 0;
}

.search-result .result-book {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.search-result .result-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.search-result .result-snippet {
    font-size: 0.85rem;
    line-height: 1.5;
    color: #444;
}

.search-result .result-snippet mark {
    background: #fef08a;
    padding: 0 2px;
    border-radius: 2px;
}

.no-cover {
    width: 100%;
    aspect-ratio: 2/3;
    background: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.favorites h2 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text-muted);
}

.favorites p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.favorites .recipe-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

@media (min-width: 500px) {
    .favorites .recipe-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

.favorites .recipe-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.favorites .recipe-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
    background: var(--accent-light);
}

.favorites .no-thumb {
    width: 100%;
    aspect-ratio: 1;
    background: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--accent);
}

.favorites .recipe-footer {
    display: flex;
    align-items: start;
    padding: 6px 8px 2px;
}

.favorites .recipe-title {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.3;
    color: inherit;
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.favorites .recipe-book {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0 8px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.favorites .fav-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 0 0 4px;
    flex-shrink: 0;
    color: #ccc;
}

.favorites .fav-btn.fav-active {
    color: #ff6b6b;
}
