:root {
    --primary: #1a1a1a;
    --secondary: #555;
    --accent: #6c5ce7;
    --accent-glow: rgba(108, 92, 231, 0.2);
    --wiki: #0984e3;
    --bg: #ffffff;
    --sidebar-bg: rgba(248, 249, 250, 0.8);
    --card-bg: rgba(255, 255, 255, 0.7);
    --border: rgba(225, 228, 232, 0.5);
    --radius: 12px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.05);
    --glass-border: rgba(255, 255, 255, 0.2);
    --btn-bg: #1a1a1a;
    --btn-text: #ffffff;
}

[data-theme="dark"] {
    --primary: #e0e0e0;
    --secondary: #999;
    --bg: #0f0f11;
    --sidebar-bg: rgba(20, 20, 22, 0.8);
    --card-bg: rgba(30, 30, 35, 0.6);
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --glass-border: rgba(255, 255, 255, 0.03);
    --btn-bg: #f5f5f5;
    --btn-text: #1a1a1a;
}

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--primary);
    background-color: var(--bg);
    line-height: 1.5;
    padding: 20px;
}

/* Utilities */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Header */
.header {
    margin-bottom: 40px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    padding: 40px 20px;
    background: linear-gradient(135deg, var(--bg), var(--sidebar-bg));
    border-radius: 0 0 30px 30px;
}

.header__inner {
    position: relative;
}

.header__logo {
    font-size: 2.5rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.header__logo span {
    color: var(--accent);
}

.header__tagline {
    color: var(--secondary);
    font-size: 0.9rem;
    margin-top: 5px;
}

.theme-toggle {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background: var(--primary);
    color: var(--bg);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 999;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.theme-toggle:hover {
    transform: translateY(-50%) scale(1.08);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

/* Container */
.container {
    max-width: 900px;
    margin: 0 auto;
}

/* Search */
.search {
    margin-bottom: 30px;
}

.search__box {
    display: flex;
    margin-bottom: 15px;
}

.search__box input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--radius) 0 0 var(--radius);
    font-size: 1rem;
    background: var(--card-bg);
    color: var(--primary);
}

.search__box button {
    padding: 10px 25px;
    background-color: var(--accent);
    color: white;
    border: 1px solid var(--accent);
    border-radius: 0;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
}

.search__box button:hover {
    background-color: #5a4ad1;
    box-shadow: 0 0 15px var(--accent-glow);
}

.search__box .btn-secondary {
    background-color: var(--sidebar-bg);
    color: var(--primary);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 1.2rem;
}

.search__box .btn-secondary:hover {
    background-color: var(--border);
}

/* Controls */
.search__controls {
    display: flex;
    gap: 15px;
    align-items: center;
    font-size: 0.9rem;
    flex-wrap: wrap;
}

.search__filter-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.search__filter-group select {
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--primary);
}

.search__reading-list-btn {
    margin-left: auto;
    padding: 6px 12px;
    background: none;
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: bold;
    color: var(--primary);
}

/* Status Messages */
.status-message {
    padding: 10px;
    margin-bottom: 20px;
    border-radius: var(--radius);
    text-align: center;
    font-size: 0.9rem;
}

.status-message.loading { background: transparent; padding: 2rem; }
.status-message.error { background: #fee; color: #a00; border: 1px solid #ecc; }
.status-message.info { background: #eef; color: #00a; border: 1px solid #cce; }

/* Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    margin: 0 auto 10px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spinner-text {
    font-weight: bold;
    color: var(--secondary);
}

.hidden { display: none !important; }

/* Grid & Cards */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.card {
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    gap: 20px;
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    box-shadow: var(--shadow);
}

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

.card--book { border-left: 5px solid var(--accent); }
.card--wiki { border-left: 5px solid var(--wiki); }

.card__cover {
    width: 60px;
    height: 90px;
    flex-shrink: 0;
    background: #f0f0f0;
}

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

.card__body {
    flex: 1;
}

.card__badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--secondary);
    margin-bottom: 5px;
}

.card__title {
    font-size: 1.2rem;
    margin-bottom: 5px;
}

.card__title a {
    color: var(--primary);
    text-decoration: none;
}

.card__title a:hover {
    text-decoration: underline;
}

.card__meta {
    font-size: 0.85rem;
    color: var(--secondary);
    margin-bottom: 8px;
}

.card__description {
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.card__actions {
    display: flex;
    gap: 10px;
}

.card__actions button, .card__actions a {
    padding: 6px 14px;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    color: var(--primary);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.card__actions button:hover, .card__actions a:hover {
    background: var(--border);
    transform: translateY(-1px);
}

.btn-save.saved {
    background-color: rgba(76, 175, 80, 0.15) !important;
    border-color: #4caf50 !important;
    color: #4caf50 !important;
}

.btn-read {
    background-color: var(--btn-bg) !important;
    color: var(--btn-text) !important;
    border-color: var(--btn-bg) !important;
}

.btn-copy.copied {
    background-color: #e3f2fd;
    border-color: var(--wiki);
    color: var(--wiki);
}

.btn-share {
    background-color: var(--sidebar-bg);
}

.btn-share:hover {
    background-color: var(--border);
}

/* Sidebar */
.reading-list {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--border);
    padding: 24px 20px 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
}

.reading-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.reading-list-header h2 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--primary);
}

.rl-controls {
    display: flex;
    gap: 4px;
}

.rl-controls button {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--secondary);
    transition: background 0.15s, color 0.15s;
}

.rl-controls button:hover {
    background: var(--border);
    color: var(--primary);
}

.reading-list__items {
    flex: 1;
    overflow-y: auto;
}

.rl-item {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.rl-item__info {
    flex: 1;
    min-width: 0;
}

.rl-item__title a {
    font-size: 0.875rem;
    color: var(--primary);
    text-decoration: none;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rl-item__title a:hover {
    text-decoration: underline;
}

.rl-item__type {
    font-size: 0.7rem;
    color: var(--secondary);
    margin-top: 2px;
    display: block;
}

.rl-item__remove {
    background: none;
    border: none;
    color: var(--secondary);
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
}

.rl-item__remove:hover {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.08);
}

.empty-list {
    text-align: center;
    color: var(--secondary);
    font-size: 0.875rem;
    padding: 2rem 0;
    line-height: 1.6;
}

.btn-clear-all {
    margin-top: 14px;
    padding: 9px;
    border: 1px solid rgba(231, 76, 60, 0.4);
    background: transparent;
    color: #e74c3c;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.15s;
}

.btn-clear-all:hover {
    background: rgba(231, 76, 60, 0.08);
}

/* Footer */
.footer {
    margin-top: 50px;
    text-align: center;
    font-size: 0.8rem;
    color: var(--secondary);
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--radius);
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow);
}

.modal-content h3 {
    margin-bottom: 1rem;
}

.modal-content p {
    margin-bottom: 1.5rem;
    color: var(--secondary);
}

.modal-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.modal-actions button {
    padding: 10px 20px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: bold;
    border: 1px solid var(--border);
}

.modal-actions .btn-confirm {
    background: #e74c3c;
    color: white;
    border-color: #e74c3c;
}

.modal-actions .btn-confirm:hover {
    background: #c0392b;
}

.modal-actions .btn-cancel:hover {
    background: #f0f0f0;
}

/* Responsive */
@media (max-width: 900px) {
    .container { padding: 0 15px; }
}

@media (max-width: 768px) {
    .results-grid { grid-template-columns: 1fr 1fr; }
    .header-inner { position: relative; }
    .theme-toggle { top: 10px; right: 10px; width: 32px; height: 32px; font-size: 1rem; }
}

@media (max-width: 600px) {
    body { padding: 10px; }
    .logo { font-size: 1.8rem; }
    .controls { flex-direction: column; align-items: stretch; }
    .reading-list-btn { margin-left: 0; }
    .card { flex-direction: column; }
    .card-cover { width: 100%; height: auto; aspect-ratio: 2/3; max-height: 150px; }
    .results-grid { grid-template-columns: 1fr; }
    .reading-list { width: 100%; }
}