.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(222px, 1fr));
    gap: 10px;
    justify-items: center;
    padding: 10px;
}

.book-card {
    width: 222px;
    min-height: 202px;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.book-card img.card-img-top {
    width: 222px;
    height: 160px;
    object-fit: cover;
}

.card-body {
    padding: 8px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.card-title {
    font-size: 1rem;
    font-weight: bold;
    height: 32px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 4px;
}

.card-text {
    flex-grow: 1;
    /* height: 100px; */
    overflow: hidden;
    font-size: 0.9rem;
}

.card-footer {
    padding: 8px;
    background-color: hwb(46 0% 21%);
    border-top: 1px solid #eee;
    font-size: 0.95rem;
    text-align: center;
    min-height: 36px;
}

/* Speech-to-Text Controls */
.speech-controls {
    margin-top: 10px;
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background-color: #f8f9fa;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap !important;
    flex-direction: row !important;
    overflow-x: auto;
}

.speech-language-select {
    padding: 4px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background-color: #fff;
    color: #495057;
    font-size: 12px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    width: 100px;
    flex-shrink: 0;
}

.speech-language-select:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.speech-mic-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border: 1px solid #007bff;
    border-radius: 50%;
    background-color: #fff;
    color: #007bff;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.speech-mic-btn:hover {
    background-color: #007bff;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
}

.speech-mic-btn:focus {
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

.speech-mic-btn.listening {
    background-color: #dc3545;
    border-color: #dc3545;
    color: #fff;
    animation: pulse 1.5s infinite;
}

.speech-mic-btn.listening:hover {
    background-color: #c82333;
    border-color: #c82333;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

.speech-mic-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.speech-clear-btn {
    padding: 4px 8px;
    border: 1px solid #6c757d;
    border-radius: 4px;
    background-color: #fff;
    color: #6c757d;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.speech-clear-btn:hover {
    background-color: #6c757d;
    color: #fff;
}

.speech-status {
    flex: 1;
    min-width: 150px;
    font-size: 11px;
    color: #495057;
    font-style: italic;
    padding: 2px 4px;
}

.speech-status.error {
    color: #dc3545;
    font-weight: 500;
}

/* Responsive adjustments - Keep one row layout on all screen sizes */
@media (max-width: 576px) {
    .speech-language-select {
        min-width: 80px;
        font-size: 11px;
    }

    .speech-status {
        min-width: 100px;
        font-size: 10px;
    }
}

/* Integration with existing form styles */
textarea[data-speech-input] {
    margin-bottom: 0;
}

.speech-controls + .form-group,
.speech-controls + .field {
    margin-top: 16px;
}

/* Chain Story Mode - Login Link Styling */
/* Make login link highly visible on orange alert background */
.alert.alert-warning .chain-story-login-link,
.alert-warning .chain-story-login-link {
    display: inline-block !important;
    padding: 6px 12px !important;
    margin: 0 !important;
    background-color: #007bff !important;
    color: #ffffff !important;
    font-weight: normal !important;
    font-size: 14px !important;
    line-height: 1.42857143 !important;
    text-decoration: none !important;
    border: 1px solid transparent !important;
    border-radius: 4px !important;
    transition: all 0.2s ease !important;
    box-shadow: none !important;
    text-align: center !important;
    white-space: nowrap !important;
    vertical-align: middle !important;
    cursor: pointer !important;
}

.alert.alert-warning .chain-story-login-link:hover,
.alert-warning .chain-story-login-link:hover {
    background-color: #0056b3 !important;
    color: #ffffff !important;
    text-decoration: none !important;
    border-color: transparent !important;
}

.alert.alert-warning .chain-story-login-link:active,
.alert-warning .chain-story-login-link:active {
    background-color: #004085 !important;
    border-color: transparent !important;
    box-shadow: inset 0 3px 5px rgba(0,0,0,.125) !important;
}

.alert.alert-warning .chain-story-login-link:focus,
.alert-warning .chain-story-login-link:focus {
    outline: thin dotted !important;
    outline: 5px auto -webkit-focus-ring-color !important;
    outline-offset: -2px !important;
}

/* Story Order Toggle Button */
#toggle-order-btn {
    font-size: 16px;
    padding: 2px 8px;
    vertical-align: middle;
    line-height: 1;
}

#toggle-order-btn:hover {
    background-color: #6c757d;
    color: white;
    border-color: #6c757d;
}

.comments-section h2 {
    display: inline-flex;
    align-items: center;
}

/* Header User Login/Logout Info */
.navigation__user-info {
    display: flex;
    align-items: center;
    margin-left: 20px;
    font-size: 14px;
}

/* User dropdown */
.user-dropdown {
    position: relative;
}

.user-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: none;
    border: none;
    color: #333;
    font-size: 14px;
    font-weight: normal;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.user-dropdown-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.user-dropdown-toggle svg {
    width: 12px;
    height: 8px;
    transition: transform 0.2s ease;
}

.user-dropdown:hover .user-dropdown-toggle svg,
.user-dropdown-toggle:focus svg {
    transform: rotate(180deg);
}

.user-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background-color: #ffffff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    min-width: 150px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    z-index: 1000;
}

.user-dropdown:hover .user-dropdown-menu,
.user-dropdown-toggle:focus + .user-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown-item {
    display: block;
    padding: 10px 16px;
    color: #000;
    text-decoration: none;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

.user-dropdown-item:hover {
    background-color: #f5f5f5;
    text-decoration: none;
    color: #000;
}

/* Login link (when not authenticated) */
.user-login-link {
    color: #000;
    text-decoration: none;
    font-weight: normal;
    padding: 6px 12px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.user-login-link:hover {
    background-color: rgba(0, 0, 0, 0.05);
    text-decoration: none;
}

.user-login-link:focus {
    outline: 2px solid #000;
    outline-offset: 2px;
}

/* ============================================
   Chain Story Layout - Collapsible Sidebar
   ============================================ */

/* Two-column layout container */
.chain-story-layout {
    display: flex;
    gap: 20px;
    margin: 2rem 0;
    align-items: flex-start;
}

/* Sidebar */
.chain-story-sidebar {
    position: relative;
    width: 280px;
    min-width: 280px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    overflow: hidden;
    transition: width 0.3s ease, min-width 0.3s ease;
}

/* Collapsed sidebar */
.chain-story-sidebar.collapsed {
    width: 40px;
    min-width: 40px;
}

/* Toggle button */
.sidebar-toggle-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    width: 30px;
    height: 30px;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background-color 0.2s ease, transform 0.3s ease;
}

.sidebar-toggle-btn:hover {
    background-color: #0056b3;
}

.chain-story-sidebar.collapsed .sidebar-toggle-btn {
    right: 5px;
    transform: rotate(180deg);
}

/* Sidebar content */
.sidebar-content {
    padding: 15px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.chain-story-sidebar.collapsed .sidebar-content {
    opacity: 0;
    pointer-events: none;
}

/* Collapsed title - hidden by default, shown when collapsed */
.sidebar-collapsed-title {
    display: none;
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 14px;
    font-weight: bold;
    color: #333;
    writing-mode: vertical-rl;
    text-orientation: upright;
}

.chain-story-sidebar.collapsed .sidebar-collapsed-title {
    display: block;
}

/* Sidebar header */
.sidebar-header {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #dee2e6;
}

.sidebar-header h5 {
    margin: 0;
    font-size: 16px;
    font-weight: bold;
    color: #333;
}

/* Sidebar sections */
.sidebar-section {
    margin-bottom: 10px;
}

/* Sidebar cards (compact) */
.sidebar-card {
    background-color: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
}

.sidebar-card-title {
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 8px;
    color: #495057;
}

/* Collapsible cards */
.collapsible-card {
    overflow: hidden;
}

.collapsible-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s ease;
    padding: 4px;
    margin: -4px;
    border-radius: 4px;
}

.collapsible-header:hover {
    background-color: #f0f0f0;
}

.collapse-icon {
    font-size: 10px;
    transition: transform 0.2s ease;
    margin-left: 8px;
}

.collapsible-content {
    margin-top: 8px;
    transition: max-height 0.3s ease;
}

/* Sidebar alert */
.sidebar-alert {
    background-color: #d1ecf1;
    border: 1px solid #bee5eb;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
}

/* Queue list */
.queue-list {
    margin: 0;
    padding-left: 20px;
    font-size: 13px;
}

.queue-list li {
    padding: 3px 0;
}

.queue-list .current-user {
    background-color: #fff3cd;
    padding: 3px 6px;
    border-radius: 3px;
    font-weight: bold;
}

/* Participants list */
.participants-list {
    max-height: 150px;
    overflow-y: auto;
}

.participant-item {
    padding: 4px 0;
    border-bottom: 1px solid #f0f0f0;
}

.participant-item:last-child {
    border-bottom: none;
}

/* Sidebar actions (buttons) */
.sidebar-actions {
    margin-bottom: 10px;
}

.sidebar-actions .btn {
    margin-bottom: 6px;
}

/* Comment form in sidebar */
.sidebar-comment-form {
    border: 2px solid #28a745;
    box-shadow: 0 0 8px rgba(40, 167, 69, 0.3);
}

.sidebar-comment-form .form-control-sm {
    font-size: 13px;
}

/* Right side content area - vertical stack */
.chain-story-content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 0;
}

/* Comment form in main area - ensure full width */
.chain-story-content-area #comment-form-section {
    width: 100%;
    flex-shrink: 0;
}

/* Main content area */
.chain-story-main {
    flex: 1;
    min-width: 0;
    width: 100%;
    transition: margin-left 0.3s ease;
}

/* Responsive design */
@media (max-width: 768px) {
    .chain-story-layout {
        flex-direction: column;
    }

    .chain-story-sidebar {
        width: 100%;
        min-width: 100%;
    }

    .chain-story-sidebar.collapsed {
        width: 100%;
        min-width: 100%;
        height: 50px;
    }

    .sidebar-toggle-btn {
        top: 10px;
        right: 10px;
    }

    /* Mobile: show collapsed title horizontally */
    .chain-story-sidebar.collapsed .sidebar-collapsed-title {
        top: 15px;
        left: 10px;
        transform: none;
        writing-mode: horizontal-tb;
        text-orientation: mixed;
        font-size: 16px;
    }
}
