/* --- System Reset & Base --- */
:root {
    --bg-color: #FBFBFD;
    /* Apple "grouped" background */
    --sidebar-bg: #1e1e1e;
    /* Dark sidebar */
    --accent-color: #007aff;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    --card-hover-shadow: 0 16px 32px rgba(0, 0, 0, 0.12);
}

body {
    background-color: var(--bg-color);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    margin: 0;
    display: flex;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* --- Sidebar --- */
.sidebar {
    width: 300px;
    background-color: var(--sidebar-bg);
    color: #f5f5f7;
    padding: 2rem 1.5rem;
    /* Reduced padding */
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    /* Reduced gap */
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.1);
    z-index: 10;
    box-sizing: border-box;
    /* Ensure padding doesn't push height off screen */
}

.sidebar h2 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #86868b;
    margin: 0 0 1rem 0;
    font-weight: 600;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar label {
    font-size: 0.9rem;
    font-weight: 500;
}

/* --- Search Container --- */
.search-container {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 6px;
    transition: all 0.2s;
}

.search-container:focus-within {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--accent-color);
}

.search-container input {
    background: transparent;
    border: none;
    color: white;
    font-size: 1rem;
    padding: 8px;
    width: 100%;
    outline: none;
    font-family: inherit;
}

.search-container input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.random-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s;
}

.random-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.icon-btn {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    width: 44px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Active Logic Visuals */
.active-logic-section {
    margin-top: auto;
    font-size: 0.85rem;
}

.active-logic-section label {
    display: block;
    margin-bottom: 12px;
    color: #e0e0e0;
    /* Brighter label */
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.logic-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.logic-card {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    /* Slightly smaller radius */
    padding: 8px 12px;
    /* Reduced padding */
    position: relative;
    transition: all 0.2s;
    z-index: 1;
}

.logic-card:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
    z-index: 1000;
}

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

.logic-name {
    font-weight: 700;
    color: #fff;
    /* Pure white */
    font-size: 0.95rem;
}

.logic-pct {
    color: #4da6ff;
    /* Brighter accent */
    font-weight: 700;
    font-size: 0.95rem;
}

.logic-desc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.logic-desc {
    font-size: 0.8rem;
    color: #d1d1d6;
    /* Brighter gray */
    margin-bottom: 6px;
}

/* Info Tooltip */
.info-btn {
    color: #86868b;
    cursor: pointer;
    font-size: 0.9rem;
    position: relative;
    transition: color 0.2s;
    margin-left: 8px;
}

.info-btn:hover {
    color: var(--accent-color);
}

.info-tooltip {
    visibility: hidden;
    width: 200px;
    background-color: #333;
    color: #fff;
    text-align: left;
    border-radius: 6px;
    padding: 8px 10px;
    position: absolute;
    z-index: 100;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.75rem;
    font-weight: 400;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    line-height: 1.4;
}

.info-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

.info-btn:hover .info-tooltip {
    visibility: visible;
    opacity: 1;
}

.w-bar-bg {
    height: 5px;
    background: rgba(255, 255, 255, 0.2);
    /* Brighter track */
    border-radius: 3px;
    overflow: hidden;
}

.w-bar-fill {
    height: 100%;
    background: #4da6ff;
    /* Brighter fill */
    border-radius: 3px;
}

/* --- Strategy Cards --- */
.strategy-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.strategy-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 10px 12px;
    /* Reduced padding */
    border-radius: 8px;
    /* Slightly smaller radius */
    cursor: pointer;
    transition: all 0.2s ease;
}

.strategy-card:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(2px);
}

.strategy-card.selected {
    background: rgba(0, 122, 255, 0.15);
    border-color: var(--accent-color);
}

.strat-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.strat-name {
    font-size: 0.95rem;
    font-weight: 500;
    color: #fff;
}

.strat-desc {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
}

.check-icon {
    color: var(--accent-color);
    font-weight: bold;
    font-size: 1.1rem;
}

.primary-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    width: 100%;
    transition: transform 0.1s, opacity 0.2s;
    margin-top: 1rem;
}

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

.primary-btn:active {
    transform: scale(0.98);
}

/* --- Main Content --- */
.main-content {
    margin-left: 300px;
    /* Sidebar width */
    padding: 2rem 4rem;
    /* Reduced padding */
    flex: 1;
    max-width: 100%;
    /* Better responsiveness */
    overflow-x: hidden;
    box-sizing: border-box;
    /* Proper box model */
}

/* Header Animation */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

header {
    margin-bottom: 0;
    animation: fadeInDown 0.6s ease-out;
}

h1 {
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 0;
}

.subtitle {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    margin-bottom: 0;
    font-weight: 400;
}

/* --- Shelves --- */
section {
    margin-bottom: 0;
}

h3 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.shelf {
    display: flex;
    gap: 30px;
    overflow-x: auto;
    padding: 30px 10px;
    /* Space for hover growth */
    margin: 0 -10px;
    /* Counteract padding layout offset */
    scrollbar-width: none;
    /* Hide scrollbar Firefox */
    -ms-overflow-style: none;
    scroll-behavior: smooth;
}

.shelf::-webkit-scrollbar {
    display: none;
}

.book-card {
    position: relative;
    background: white;
    width: 155px;
    /* Back to original size */
    height: 280px;
    /* Proportional */
    flex: 0 0 auto;
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    border: 1px solid rgba(0, 0, 0, 0.08);
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    cursor: pointer;
}

.animate-card {
    opacity: 0;
    animation: fadeInUp 0.6s ease-out forwards;
}

.book-img {
    width: 100%;
    height: 180px;
    /* original height */
    object-fit: cover;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.book-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: left;
    flex: 1;
}

.book-title {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: 4px;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

/* Badge */
.match-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 122, 255, 0.95);
    backdrop-filter: blur(8px);
    color: white;
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 20px;
    /* Pill shape */
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
    z-index: 2;
}


/* --- Modal (Glassmorphism) --- */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    /* Dimmer background */
    backdrop-filter: blur(8px);
    /* Blur the content behind */
    z-index: 2000;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: rgba(255, 255, 255, 0.95);
    /* Slightly transparent white */
    width: 750px;
    max-width: 90%;
    max-height: 85vh;
    border-radius: 24px;
    /* Very round */
    padding: 3rem;
    position: relative;
    overflow-y: auto;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    animation: scaleUp 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
}

@keyframes scaleUp {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.close-btn {
    position: absolute;
    top: 24px;
    right: 32px;
    font-size: 2rem;
    font-weight: 200;
    cursor: pointer;
    color: #aeaeae;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #111;
}

.modal-header-section {
    display: flex;
    gap: 40px;
    margin-bottom: 2rem;
}

.modal-cover {
    width: 200px;
    height: 300px;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.modal-details {
    flex: 1;
}

.modal-details h2 {
    margin-top: 0;
    font-size: 2rem;
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.modal-meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px 30px;
    margin-top: 30px;
    font-size: 0.9rem;
}

.meta-item label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 4px;
}

.meta-item span {
    color: var(--text-primary);
    font-weight: 500;
}

.clean-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
}

.clean-table td {
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}

/* Driven By Section (Modal) */
.driven-badge {
    display: inline-block;
    background: rgba(0, 122, 255, 0.1);
    color: #007aff;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 20px;
    margin-bottom: 6px;
}

.driven-desc {
    font-size: 0.85rem;
    color: #666;
    margin: 0;
    line-height: 1.4;
    font-style: italic;
}

.sidebar-divider {
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 20px 0;
}

.main-divider {
    border: 0;
    border-top: 1px solid #e0e0e0;
    margin: 30px 0;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}