body {
    font-family: Arial, sans-serif;
    background: #f4f4f4;
    margin: 0;
    padding: 0; /* Remove body padding, apply to page-wrapper if needed */
    display: flex; /* Make body a flex container for page-wrapper */
    min-height: 100vh;
    height: auto;
}
.page-wrapper {
    display: flex;
    width: 100%;
    height: 100vh; /* Make page-wrapper take full viewport height */
    padding: 2vh 1vw; /* Add some padding around the page */
    box-sizing: border-box;
}
.sidebar {
    width: 240px; /* Increased width for sidebar */
    flex-shrink: 0; /* Prevent sidebar from shrinking */
    background: #e9e9e9;
    padding: 1rem;
    border-radius: 0.5rem;
    margin-right: 1rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    height: calc(
        100% - 4vh
    ); /* Adjust height considering page-wrapper padding */
    display: flex; /* Use flexbox to position button at bottom */
    flex-direction: column; /* Stack items vertically */
}
.sidebar-content-scrollable {
    flex-grow: 1; /* Allow this section to take available space */
    overflow-y: auto; /* Enable scrolling for language list */
    margin-bottom: 1rem; /* Space before the sticky button */
}
.sidebar-stats {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #ccc;
    font-size: 0.9em;
    color: #333;
}
.sidebar-stats div {
    margin-bottom: 0.25rem;
}
.sidebar-quest {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background-color: #fff;
    border-radius: 0.5rem;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
    color: #333;
}
.sidebar-quest.complete {
    border: 1px solid #4caf50;
    box-shadow: inset 0 0 0 1px rgba(76, 175, 80, 0.3);
}
.sidebar h3 {
    margin-top: 0;
    color: #333;
    border-bottom: 1px solid #ccc;
    padding-bottom: 0.5rem;
}
.sidebar-quest h3 {
    margin: 0 0 0.25rem;
    border: 0;
    padding-bottom: 0;
    font-size: 1.05em;
}
.quest-status {
    font-weight: 600;
    font-size: 0.9em;
}
.quest-progress {
    width: 100%;
    height: 0.5rem;
    border-radius: 9999px;
    background: rgba(0, 0, 0, 0.08);
    overflow: hidden;
    margin: 0.5rem 0;
}
.quest-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ff9800, #ffc107);
    transition: width 0.3s ease;
}
.sidebar-quest.complete .quest-progress-fill {
    background: linear-gradient(90deg, #4caf50, #81c784);
}
.quest-message {
    font-size: 0.85em;
    color: #555;
    margin: 0;
}
.sidebar-quest.complete .quest-message {
    color: #2e7d32;
    font-weight: 600;
}
.sidebar label {
    display: flex; /* Align checkbox and text nicely */
    align-items: center; /* Vertically center checkbox with text */
    margin-bottom: 0.75rem; /* Increased spacing */
    font-size: 0.9em;
    color: #555;
    cursor: pointer; /* Indicate label is clickable */
}
.sidebar input[type="checkbox"] {
    margin-right: 0.75rem; /* Increased spacing */
    /* Consider adding a slight scale or size increase if checkboxes are too small */
    /* transform: scale(1.1); */
}
label.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem 0 0.75rem;
    font-size: 0.95em;
    color: #333;
    font-weight: 600;
}
label.theme-toggle input[type="checkbox"] {
    margin: 0;
    margin-right: 0.6rem;
    width: 1.1rem;
    height: 1.1rem;
}
.container {
    background: white;
    flex-grow: 1; /* Allow container to take remaining space */
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    max-height: calc(
        100% - 4vh
    ); /* Adjust height considering page-wrapper padding */
    overflow-y: auto; /* Enable vertical scrollbar for container */
}
.article {
    margin-bottom: 1.5rem;
}
#content {
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 1.1em; /* Slightly increased text size */
    line-height: 1.7; /* Increased line spacing */
}
#content p::first-letter,
#content div::first-letter,
#content::first-letter {
    /* Target p, div, or direct text for dropcap */
    font-size: 3.5em; /* Increased dropcap size */
    font-weight: bold;
    float: left;
    margin-right: 0.1em;
    line-height: 0.8;
    padding-top: 0.1em; /* Fine-tune vertical alignment */
}
.stars {
    display: flex;
    gap: 0.5rem;
}
.star {
    font-size: 2rem;
    cursor: pointer;
    color: #ddd;
}
.star.selected {
    color: gold;
}
.highlight {
    background-color: #fff59d; /* A nice yellow highlight color */
    padding: 0.1em 0;
    border-radius: 3px;
}

.highlight:hover {
    background-color: #ffcb9d; /* A nice yellow highlight color */
    padding: 0.1em 0;
    border-radius: 3px;
}

#topicsTable {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}
#topicsTable th,
#topicsTable td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: center;
    vertical-align: middle;
}
#topicsTable th {
    background-color: #f2f2f2;
}
.topic-name {
    cursor: help;
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}
.topic-tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    font-size: 0.75rem;
    line-height: 1;
    border-radius: 50%;
    border: 1px solid #888;
    color: #888;
    font-weight: 700;
}
.topic-tooltip {
    visibility: hidden;
    width: 250px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;
    position: absolute;
    z-index: 10000; /* Increased z-index to make tooltip appear above other elements */
    bottom: 125%;
    left: 50%;
    margin-left: -125px;
    opacity: 0;
    transition: opacity 0.3s;
}

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

.topic-name:hover .topic-tooltip {
    visibility: visible;
    opacity: 1;
}

.topic-note-input {
    width: 100%;
    min-height: 2.5rem;
    resize: vertical;
    padding: 0.4rem;
    font-size: 0.9rem;
    font-family: inherit;
    box-sizing: border-box;
    text-align: left;
}

#submitBtn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.5rem;
    background-color: #007bff;
    color: white;
    cursor: pointer;
    position: relative; /* For the fill effect */
    overflow: hidden; /* To contain the fill */
    transition: background-color 0.3s ease; /* Smooth hover effect */
}
#submitBtn:hover {
    background-color: #0056b3;
}
#submitBtn .fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%; /* Starts at 0, fills to 100% */
    background-color: #0056b3; /* Darker shade for fill */
    opacity: 0.5;
    transition: width 1s linear; /* Animation for 1 second */
    z-index: 0;
}
#submitBtn span {
    position: relative; /* To ensure text is above the fill */
    z-index: 1;
}
#submitBtn.loading .fill {
    width: 100%;
}
#submitBtn.loading {
    background-color: #007bff; /* Keep original color during load */
}

.rating {
    position: relative; /* For tooltip positioning */
}
#submitTooltip {
    display: none;
    position: absolute;
    bottom: 100%; /* Position above the button */
    left: 50%;
    transform: translateX(-50%) translateY(-10px); /* Center and add some space */
    background-color: #333; /* Dark background for tooltip */
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    z-index: 1000;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); /* Subtle shadow for depth */
}

@keyframes rumble {
    0% {
        transform: translate(0, 0) rotate(0deg);
    }
    25% {
        transform: translate(-1px, 1px) rotate(-0.5deg);
    }
    50% {
        transform: translate(1px, -1px) rotate(0.5deg);
    }
    75% {
        transform: translate(-1px, -1px) rotate(-0.5deg);
    }
    100% {
        transform: translate(1px, 1px) rotate(0.5deg);
    }
}

#submitBtn.rumbling {
    animation: rumble 0.15s infinite linear; /* Faster rumble */
}

@keyframes pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15) rotate(-5deg);
    }
    75% {
        transform: scale(1.05) rotate(3deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

#submitBtn.popping {
    animation: pop 0.35s ease-out;
}

#refreshArticleBtn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.5rem;
    background-color: #28a745; /* Green color for refresh */
    color: white;
    cursor: pointer;
    transition: background-color 0.3s ease;
    width: 100%; /* Make button full width of sidebar */
    margin-top: auto; /* Pushes button to the bottom in a flex column */
    flex-shrink: 0; /* Prevent button from shrinking */
}
#refreshArticleBtn:hover {
    background-color: #218838; /* Darker green on hover */
}

/* Modal Styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 2000; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0, 0, 0); /* Fallback color */
    background-color: rgba(0, 0, 0, 0.4); /* Black w/ opacity */
    padding-top: 60px;
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto; /* 5% from the top and centered */
    padding: 20px;
    border: 1px solid #888;
    width: 80%; /* Could be more or less, depending on screen size */
    max-width: 500px;
    border-radius: 0.5rem;
    box-shadow:
        0 4px 8px 0 rgba(0, 0, 0, 0.2),
        0 6px 20px 0 rgba(0, 0, 0, 0.19);
    position: relative;
}

.close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close-btn:hover,
.close-btn:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

#infoBtn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.5rem;
    background-color: #17a2b8; /* Info color (teal) */
    color: white;
    cursor: pointer;
    transition: background-color 0.3s ease;
    width: 100%;
    margin-bottom: 0.5rem; /* Space before refresh button */
    flex-shrink: 0;
}
#infoBtn:hover {
    background-color: #138496; /* Darker teal on hover */
}

#keywordBtn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.5rem;
    background-color: #ff9800;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s ease;
    width: 100%;
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}
#keywordBtn:hover {
    background-color: #e68900;
}

#rsvpBtn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.5rem;
    background-color: #6f42c1; /* Purple color for RSVP */
    color: white;
    cursor: pointer;
    transition: background-color 0.3s ease;
    width: 100%;
    margin-bottom: 0.5rem; /* Space before refresh button */
    flex-shrink: 0;
}
#rsvpBtn:hover {
    background-color: #5a32a3; /* Darker purple on hover */
}

#feedbackModalBtn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.5rem;
    background-color: #607d8b;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s ease;
    width: 100%;
    margin-bottom: 0.5rem; /* Space before refresh button */
    flex-shrink: 0;
}
#feedbackModalBtn:hover {
    background-color: #4b646f;
}

/* RSVP Modal Styles */
.rsvp-modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 30px;
    border: 1px solid #888;
    width: 90%;
    max-width: 600px;
    border-radius: 0.5rem;
    box-shadow:
        0 4px 8px 0 rgba(0, 0, 0, 0.2),
        0 6px 20px 0 rgba(0, 0, 0, 0.19);
    position: relative;
    text-align: center;
}

.rsvp-word-display {
    font-size: 3rem;
    font-weight: bold;
    font-family: "Arial", sans-serif;
    color: #333;
    min-height: 4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 2rem 0;
    padding: 1rem;
    border: 2px solid #e0e0e0;
    border-radius: 0.5rem;
    background-color: #f9f9f9;
}

.rsvp-word-display.highlighted {
    background-color: #fff59d; /* Same yellow as article highlights */
    border-color: #ffeb3b;
    color: #333;
}

.rsvp-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    align-items: center;
    margin: 1.5rem 0;
    flex-wrap: wrap;
}

.rsvp-controls button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.3s ease;
}

.rsvp-play-btn {
    background-color: #28a745;
    color: white;
}
.rsvp-play-btn:hover {
    background-color: #218838;
}

.rsvp-pause-btn {
    background-color: #ffc107;
    color: #212529;
}
.rsvp-pause-btn:hover {
    background-color: #e0a800;
}

.rsvp-stop-btn {
    background-color: #dc3545;
    color: white;
}
.rsvp-stop-btn:hover {
    background-color: #c82333;
}

#keywordForm {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

#keywordForm input[type="text"] {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 0.25rem;
}

#keywordForm button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.25rem;
    background-color: #007bff;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#keywordForm button:hover {
    background-color: #0056b3;
}

.keyword-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    min-height: 2rem;
}

.keyword-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.6rem;
    background-color: #f1f3f5;
    border-radius: 999px;
    font-size: 0.9rem;
    border: 1px solid #d0d4d9;
}

.keyword-chip button {
    border: none;
    background: none;
    color: #c0392b;
    cursor: pointer;
    font-size: 0.85rem;
}

.keyword-chip button:hover {
    color: #922b21;
}

#clearKeywordsBtn {
    margin-top: 1rem;
    padding: 0.4rem 0.8rem;
    border: 1px solid #ccc;
    border-radius: 0.25rem;
    background-color: #f8f9fa;
    cursor: pointer;
}

#clearKeywordsBtn:hover {
    background-color: #e2e6ea;
}

.keyword-highlight {
    background-color: #ffcc80;
    border-bottom: 2px solid #fb8c00;
}

.keyword-empty-state {
    color: #6c757d;
    font-style: italic;
}

.rsvp-wpm-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.rsvp-wpm-control label {
    font-weight: bold;
    color: #333;
}

.rsvp-wpm-control input {
    width: 80px;
    padding: 0.25rem;
    border: 1px solid #ccc;
    border-radius: 0.25rem;
    text-align: center;
}

.rsvp-progress {
    margin: 1rem 0;
    color: #666;
    font-size: 0.9rem;
}

.rsvp-progress-bar {
    width: 100%;
    height: 8px;
    background-color: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    margin: 0.5rem 0;
}

.rsvp-progress-fill {
    height: 100%;
    background-color: #6f42c1;
    transition: width 0.1s ease;
}
.feedback-modal-content {
    max-width: 720px;
}
.feedback-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
}
.feedback-table th,
.feedback-table td {
    border: 1px solid #e5e7eb;
    padding: 0.5rem;
    text-align: center;
}
.feedback-table th {
    background: #f1f5f9;
    color: #111827;
}
.feedback-diff-positive {
    color: #16a34a;
    font-weight: 700;
}
.feedback-diff-negative {
    color: #dc2626;
    font-weight: 700;
}
.feedback-empty {
    font-style: italic;
    color: #6b7280;
    margin-top: 0.25rem;
}
.feedback-subtitle {
    color: #4b5563;
    font-size: 0.95rem;
    margin-top: 0.15rem;
}
.feedback-loading,
.feedback-error {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.95rem;
}
.feedback-loading {
    color: #2563eb;
}
.feedback-error {
    color: #b91c1c;
}
.feedback-spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid #bfdbfe;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: feedback-spin 0.8s linear infinite;
}
.feedback-loading-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    justify-content: center;
    color: #2563eb;
}
.feedback-loading-inline .feedback-spinner {
    width: 0.85rem;
    height: 0.85rem;
}
@keyframes feedback-spin {
    to {
        transform: rotate(360deg);
    }
}
.feedback-toggle {
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: #333;
}

/* Mobile Responsive Styles */
@media screen and (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .page-wrapper {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        padding: 1vh 2vw;
    }

    .sidebar {
        width: 100%;
        margin-right: 0;
        margin-top: 1rem;
        order: 2; /* Move sidebar after container */
        height: auto;
        max-height: 40vh; /* Limit sidebar height on mobile */
    }

    .container {
        order: 1; /* Keep container first */
        max-height: none;
        margin-bottom: 1rem;
    }

    .sidebar-content-scrollable {
        max-height: 25vh; /* Limit scrollable content height */
    }

    /* Make buttons stack vertically on very small screens */
    @media screen and (max-width: 480px) {
        .sidebar {
            padding: 0.75rem;
        }

        #infoBtn,
        #keywordBtn,
        #rsvpBtn,
        #refreshArticleBtn {
            margin-bottom: 0.5rem;
            font-size: 0.9rem;
            padding: 0.4rem 0.8rem;
        }

        .container {
            padding: 1rem;
        }

        #content {
            font-size: 1rem;
            line-height: 1.6;
        }

        .stars {
            gap: 0.3rem;
        }

        .star {
            font-size: 1.5rem;
        }

        #topicsTable th,
        #topicsTable td {
            padding: 6px;
            font-size: 0.9rem;
        }
    }
}
