:root {
    /* Light Theme */
    --bg-color: #fff;
    --text-color: #000;
    --border-color: #000;
    --dashed-border: #000;
    --hover-bg: #f5f5f5;
    --secondary-text: #666;
    --link-color: #0000ff;
    --modal-bg: #fff;
    --details-overlay: rgba(255, 255, 255, 0.9);
    --modal-shadow: rgba(0, 0, 0, 0.1);
    --input-bg: #fff;
    --input-border: #ccc;
    --btn-hover: #eee;
}

body.dark-theme {
    /* Dark Theme */
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --border-color: #555;
    --dashed-border: #555;
    --hover-bg: #2a2a2a;
    --secondary-text: #999;
    --link-color: #f8d66d;
    --modal-bg: #252525;
    --details-overlay: rgba(0, 0, 0, 0.8);
    --modal-shadow: rgba(0, 0, 0, 0.5);
    --input-bg: #333;
    --input-border: #555;
    --btn-hover: #333;
}

body {
    font-family: monospace;
    color: var(--text-color);
    background-color: var(--bg-color);
    margin: 2rem;
    font-size: 13px;
    line-height: 1.4;
}

h1 {
    font-size: 15px;
    font-weight: bold;
    margin: 0;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.controls {
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

input[type="text"] {
    font-family: monospace;
    border: 1px solid var(--input-border);
    background-color: var(--input-bg);
    color: var(--text-color);
    padding: 2px 5px;
    width: 300px;
    max-width: 100%;
    box-sizing: border-box;
}

button.theme-btn {
    background: none;
    border: 1px solid var(--input-border);
    color: var(--text-color);
    font-family: monospace;
    cursor: pointer;
    padding: 2px 8px;
    background-color: var(--input-bg);
    white-space: nowrap;
}

button.theme-btn:hover {
    background-color: var(--btn-hover);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    border-bottom: 1px dashed var(--dashed-border);
    padding: 4px 8px 4px 0;
    font-weight: bold;
}

td {
    padding: 2px;
    vertical-align: top;
}

tr {
    cursor: pointer;
}

tr:hover td {
    background-color: var(--hover-bg);
}

.col-title {
    width: 28%;
}

.col-written-by {
    width: 18%;
}

.col-genre {
    width: 12%;
}

.col-lang {
    width: 8%;
}

.col-publisher {
    width: 18%;
}

.col-edition {
    width: 8%;
}

.col-isbn {
    width: 8%;
}

.footer {
    margin-top: 40px;
    font-size: 11px;
    color: var(--secondary-text);
    border-top: 1px solid var(--input-border);
    padding-top: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
}

#book-count {
    white-space: nowrap;
}

.source-link {
    font-size: 11px;
    color: var(--secondary-text);
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-left: auto;
    align-items: flex-end;
    text-align: right;
}

.source-link a {
    color: var(--link-color);
    text-decoration: none;
}

.book-link,
.book-link:visited {
    display: block;
    padding: 2px;
    color: inherit;
    text-decoration: none;
}

.details-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--details-overlay);
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 10px;
    box-sizing: border-box;
}

.modal-content {
    background: var(--modal-bg);
    border: 1px solid var(--border-color);
    width: 600px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
    box-shadow: 8px 8px 0 var(--modal-shadow);
    position: relative;
    color: var(--text-color);
    box-sizing: border-box;
}

.modal-header {
    border-bottom: 1px dashed var(--dashed-border);
    padding-bottom: 10px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: start;
}

.close-btn {
    cursor: pointer;
    color: var(--link-color);
    text-decoration: underline;
    user-select: none;
}

.detail-row {
    display: flex;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.detail-label {
    width: 120px;
    font-weight: bold;
    flex-shrink: 0;
    color: var(--secondary-text);
}

.detail-value {
    flex-grow: 1;
}

.detail-summary {
    margin-top: 20px;
    padding-top: 10px;
    border-top: 1px dashed var(--input-border);
    white-space: pre-wrap;
}

/* Responsive Styles */
@media (max-width: 768px) {
    body {
        margin: 0.5rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    input[type="text"] {
        width: 100%;
    }

    table {
        table-layout: fixed;
    }

    th,
    td {
        white-space: normal;
        word-wrap: break-word;
        word-break: break-word;
        font-size: 11px;
    }

    .col-title {
        width: 26%;
    }

    .col-written-by {
        width: 20%;
    }

    .col-genre {
        width: 18%;
    }

    .col-lang {
        width: 10%;
    }

    .col-isbn {
        width: 26%;
    }

    .col-publisher,
    .col-edition {
        display: none;
    }

    .modal-content {
        box-shadow: 4px 4px 0 var(--modal-shadow);
    }
}