/* Dark Theme Variables */
:root {
    --dark-bg-primary: #1a1d21; /* Body background */
    --dark-bg-secondary: #2a2f38; /* Container, modal background */
    --dark-bg-tertiary: #3c4250; /* Input, chatbox background */
    --dark-border-color: #30363d; /* Borders */
    --dark-text-primary: #e6edf3; /* Primary text */
    --dark-text-secondary: #8b949e; /* Secondary/muted text */
    --dark-link-color: #58a6ff; /* Link color */
    --dark-accent-blue: #2f81f7;
    --dark-accent-green: #238636;
    --dark-accent-red: #da3633;
    --dark-user-message-bg: #213454; /* User message bubble */
    --dark-ai-message-bg: #2a2f45;   /* AI message bubble */
    --dark-code-bg: #282c34;       /* Code block background */
    --dark-code-text: #abb2bf;      /* Code block text */
    --dark-bg-secondary-alpha: rgba(42, 47, 56, 0.92); /* --- 修改：增加不透明度，减少透明度 --- */
    --dark-accent-orange: #f9a03f; /* --- 新增：橙色变量 --- */
    --purple-button-bg: #9575cd; /* 定义紫色按钮背景 */
    --purple-button-hover-bg: #7e57c2; /* 定义紫色按钮悬停背景 */
}

html {
    height: 100%; /* Ensure HTML element covers full height */
}

body {
    font-family: sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--dark-bg-primary);
    color: var(--dark-text-primary); /* Default text color */
    min-height: 100%; /* Ensure body covers at least full height */
    display: flex; /* Use flexbox for body */
    flex-direction: column; /* Default to column direction */
}

/* Styles for the main chat page container */
body:not(.centered-form-page) .container {
    flex-grow: 1; /* Allow container to grow and fill vertical space */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent container itself from scrolling */
    /* Existing padding/margin rules apply */
    max-width: 800px; /* Keep max-width for desktop */
    margin: 20px auto; /* Center on desktop */
    padding: 20px;
    background-color: var(--dark-bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--dark-border-color);
}

/* Override container styles for mobile on non-centered pages */
@media (max-width: 768px) {
    body:not(.centered-form-page) .container {
        margin: 0; /* Remove margins on mobile */
        padding: 10px; /* Adjust padding for mobile */
        border-radius: 0; /* Remove border-radius on mobile */
        border: none; /* Remove border on mobile */
        max-width: none;
    }
}

/* --- Adjust Chatbox height within the flex container --- */
#chatbox {
    flex-grow: 1; /* Allow chatbox to take available vertical space */
    min-height: 100px; /* Optional: prevent it from becoming too small */
    border: 1px solid var(--dark-border-color);
    overflow-y: auto; /* Use auto instead of scroll to only show scrollbar when needed */
    margin-bottom: 15px;
    padding: 15px;
    background-color: transparent;
    background-image: none;
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    transition: background-image 0.5s ease-in-out;
    position: relative; /* Needed for pseudo-element overlay */
    z-index: 0;
    color: var(--dark-text-primary);
    /* Consider removing fixed height calculation if flexbox handles it well */
    /* height: calc(100vh - 250px); */
    /* max-height: 70vh; */
    /* Let flexbox determine the height based on container */
}

/* --- 叠加层样式 --- */
#chatbox::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.2); /* 默认较浅 */
    z-index: -1; /* Place it behind content */
    pointer-events: none;
    transition: background-color 0.3s ease;
     /* --- 添加：确保它不会滚动出界 (虽然 absolute 应该已经处理了) --- */
    /* overflow: hidden; */ /* 一般不需要对伪元素设置 */
}

/* --- 无角色激活时 (公告视图) 的叠加层样式 --- */
#chatbox.no-char-active::before {
    background-color: rgba(0, 0, 0, 0.6); /* 公告时较深 */
}

/* --- Ensure chat form doesn't shrink --- */
#chat-form {
    display: flex;
    gap: 10px;
    flex-shrink: 0; /* Prevent form from shrinking */
    /* Mobile stacking rules from media query still apply */
}

h1, h2 {
    color: var(--dark-text-primary);
    border-bottom: 1px solid var(--dark-border-color); /* Add subtle separator */
    padding-bottom: 10px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--dark-text-secondary);
}

input[type="text"],
input[type="url"],
input[type="password"],
textarea {
    width: 95%;
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid var(--dark-border-color);
    border-radius: 4px;
    background-color: var(--dark-bg-tertiary);
    color: var(--dark-text-primary);
}

textarea {
    resize: vertical;
}

/* General Button Styles */
button,
input[type="submit"] {
    background-color: var(--dark-accent-blue); /* Default to blue */
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 6px; /* Slightly more modern radius */
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.2s ease;
}

button:hover,
input[type="submit"]:hover {
    filter: brightness(1.2); /* Simple hover effect */
}

/* Specific button colors if needed */
#submit-feedback-button,
input[value="上传角色卡"] /* Assuming this is the submit button */
/* Add other potentially green buttons here */ {
    background-color: var(--dark-accent-green);
}

/* Delete buttons need different style */
.delete-message-btn,
.action-links a[onclick*='delete'] /* Target admin delete links */ {
    background-color: transparent; /* No background */
    color: var(--dark-accent-red); /* Red color */
    border: 1px solid var(--dark-accent-red);
    padding: 3px 6px;
    border-radius: 4px;
    text-decoration: none; /* Remove underline from links styled as buttons */
    margin-left: 8px;
    cursor: pointer;
    font-size: 0.9em;
    opacity: 0.7; /* Slightly visible */
    transition: opacity 0.2s, background-color 0.2s;
}
.delete-message-btn:hover,
.action-links a[onclick*='delete']:hover {
    background-color: rgba(218, 54, 51, 0.1); /* Subtle red background on hover */
    opacity: 1;
}

/* Adjust general links */
a {
    color: var(--dark-link-color);
    text-decoration: none; /* Remove underline by default */
}
a:hover {
    text-decoration: underline;
}

/* Admin Nav links need better visibility */
.admin-nav a {
    color: var(--dark-link-color);
    margin: 0 10px;
}

small {
    color: var(--dark-text-secondary);
    display: block;
    margin-top: -10px;
    margin-bottom: 10px;
}

#chatbox p {
    margin: 10px 0; /* Increased spacing */
    padding: 10px 15px; /* Increased padding */
    border-radius: 8px; /* More rounded bubbles */
    word-wrap: break-word;
    max-width: 85%; /* Limit bubble width */
    line-height: 1.5;
}

.user-message {
    background-color: var(--dark-bg-secondary-alpha); /* --- 修改：使用带透明度的背景 --- */
    /* text-align: right; */ /* Alignment handled by flexbox below */
    margin-left: auto; /* Push to the right */
    margin-right: 0;
    position: relative; /* Ensure message content is above chatbox overlay */
    z-index: 1;
}

.ai-message {
    background-color: var(--dark-bg-secondary-alpha); /* --- 修改：使用带透明度的背景 --- */
    /* text-align: left; */
    margin-right: auto; /* Push to the left */
    margin-left: 0;
    position: relative; /* Ensure message content is above chatbox overlay */
    z-index: 1;
    padding: 10px 15px; /* 确保内边距一致 */
    overflow: visible; /* 确保内容可见 */
}

/* 添加：确保消息内容能换行 */
.ai-message .message-content,
.user-message .message-content {
    white-space: normal; /* 允许自动换行 */
    word-wrap: break-word; /* 或 overflow-wrap: break-word; 允许长单词断开 */
    overflow-wrap: break-word;
    /* 确保没有其他样式（如 display: block; 或 width: 100%）阻止换行 */
}

/* 添加：强制 <pre> 标签内的内容换行 */
.ai-message .message-content pre,
.user-message .message-content pre {
    white-space: pre-wrap;  /* 保留空白符序列，但允许自动换行 */
    word-wrap: break-word;   /* 强制长单词断开 */
    overflow-wrap: break-word;
}

/* Remove button style adjustments were handled above */

#message {
    flex-grow: 1;
    margin-right: 0; /* Removed margin, using gap */
    margin-bottom: 0;
}

#chat-form input[type="submit"] {
    padding: 10px 15px; /* Consistent padding */
    flex-shrink: 0; /* Prevent button from shrinking */
}

/* Feedback Button - Keep simpler style */
/* Commenting out specific styles for #feedback-button to allow unified styles to apply */
/*
#feedback-button {
    padding: 8px 12px;
    margin-left: 10px;
    color: #ffffff !important;
    font-weight: bold !important;
}

#feedback-button:hover {
    background-color: var(--dark-border-color);
    color: var(--dark-text-primary);
}
*/

/* Modal Styles */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.7); /* Darker overlay */
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--dark-bg-secondary);
    color: var(--dark-text-primary);
    padding: 20px;
    border: 1px solid var(--dark-border-color);
    border-radius: 8px;
    width: 80%;
    max-width: 650px; /* Allow slightly wider modal for more columns */
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative;
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--dark-border-color);
    color: var(--dark-text-primary); /* Ensure heading is light */
}

.close-button {
    color: var(--dark-text-secondary);
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close-button:hover,
.close-button:focus {
    color: var(--dark-text-primary);
    text-decoration: none;
}

#feedback-textarea {
    /* Inherits dark style from general textarea rules */
    width: 100%; /* Ensure full width */
    box-sizing: border-box; /* Include padding/border in width */
}

/* Notification Badge - Keep visible */
.notification-badge {
    /* Styles seem okay, maybe adjust position slightly if needed */
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: var(--dark-accent-red);
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: bold;
    line-height: 1;
    min-width: 16px;
    text-align: center;
}

/* Character List Dark Theme - Increased Specificity & Refined Appearance */
#characterModal .character-list {
    list-style: none;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); /* Even smaller min width */
    gap: 12px; /* Slightly adjusted gap */
    max-height: 70vh;
    overflow-y: auto;
    margin-top: 10px;
}

#characterModal .character-list li {
    border: 1px solid var(--dark-border-color);
    background-color: var(--dark-bg-tertiary); /* Lighter card background */
    padding: 5px; /* Further reduced padding inside card */
    text-align: center;
    cursor: pointer;
    border-radius: 4px; /* Less rounded corners for cards */
    transition: all 0.2s ease-in-out;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* Align items to start */
    box-sizing: border-box;
    min-height: auto; /* Let content dictate height initially */
    color: var(--dark-text-primary);
}

#characterModal .character-list li:hover {
    background-color: var(--dark-border-color);
    box-shadow: none;
    transform: translateY(-2px);
}

#characterModal .character-list li img {
    max-width: 100%; /* Allow image to take full width */
    height: 100px; /* Fixed height for images */
    margin-bottom: 5px !important;
    border-radius: 2px; /* Sharper image corners */
    object-fit: cover;
    display: block; /* Ensure image behaves as block */
}

#characterModal .character-list li span {
    display: block;
    font-size: 0.8em !important; /* Even smaller text */
    line-height: 1.3;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
    margin-top: 5px; /* Small margin above text */
    padding: 0 2px; /* Small horizontal padding for text */
}

/* VIP Character Styles - Increased Specificity */
#characterModal .character-list li.vip-char {
    border: 2px solid gold !important;
}

/* VIP Badge Styles - Increased Specificity */
#characterModal .vip-badge {
    position: absolute;
    top: 2px; /* Adjusted position */
    right: 2px;
    background-color: gold;
    color: #333;
    font-size: 0.6em !important; /* Even smaller badge */
    font-weight: bold;
    padding: 1px 3px;
    border-radius: 2px;
    line-height: 1; /* Ensure badge text fits */
}

/* Admin Table Dark Theme */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    color: var(--dark-text-primary);
}

th, td {
    border: 1px solid var(--dark-border-color);
    padding: 10px; /* Slightly more padding */
    text-align: left;
}

th {
    background-color: var(--dark-bg-tertiary);
    color: var(--dark-text-secondary);
    font-weight: bold;
}

tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.03); /* Very subtle striping */
}

.char-image {
    max-width: 50px;
    max-height: 50px;
    vertical-align: middle;
    border-radius: 4px; /* Rounded images */
}

/* Login/Register Specific */
.login-choice-modal {
    /* Overlay color adjusted in .modal */
    /* Display is controlled by inline style in index.php */
}
.login-choice-content {
    background-color: var(--dark-bg-secondary) !important; /* Force dark background */
    color: var(--dark-text-primary) !important; /* Force light text */
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    max-width: 500px;
    width: 90%;
    text-align: center;
    border: 1px solid var(--dark-border-color);
}
.login-choice-content h2 {
    margin-top: 0;
    color: var(--dark-text-primary) !important; /* Ensure heading color */
    border-bottom: none; /* Remove border in this context */
}
.login-choice-content p {
    margin-bottom: 25px;
    color: var(--dark-text-secondary) !important; /* Ensure paragraph color */
}
.login-choice-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

/* --- Modification: Ensure all buttons/forms inside have 100% width --- */
.login-choice-buttons form,
.login-choice-buttons .login-choice-button {
    width: 100%; /* Make form and direct button take full width */
    margin: 0; /* Reset any potential margins */
}

.login-choice-buttons form button {
    width: 100%; /* Make button inside form take full width */
}
/* --- Modification End --- */

.login-choice-button {
    /* Inherits general button styles */
    /* Ensure consistent padding/font if needed */
    padding: 12px 20px; /* Example: slightly larger padding */
    font-size: 16px;
    box-sizing: border-box; /* Include padding in width calculation */
}
.auto-register-btn {
    background-color: var(--dark-accent-green);
}
.login-redirect-btn {
    background-color: var(--dark-accent-blue);
}
.login-note {
    font-size: 0.85em;
    color: var(--dark-text-secondary) !important; /* Ensure note color */
    margin-top: 20px;
    font-style: italic;
}

/* Alert Message */
.alert-message {
    padding: 10px 15px;
    margin-bottom: 15px;
    border-radius: 5px;
    /* Success (Green) */
    background-color: rgba(35, 134, 54, 0.2); /* Green accent with low opacity */
    color: #5dff82; /* Lighter green text */
    border: 1px solid var(--dark-accent-green);
    display: none; /* Initially hidden */
}

/* Code blocks in messages */
pre {
    background-color: var(--dark-code-bg);
    color: var(--dark-code-text);
    padding: 1em;
    border-radius: 5px;
    overflow-x: auto; /* Allow horizontal scroll */
    font-family: monospace;
    font-size: 0.9em;
    margin: 10px 0;
}

code:not(pre > code) {
    background-color: var(--dark-code-bg);
    color: var(--dark-code-text);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: monospace;
}


/* User Info Area - Refined Layout */
.user-info {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    justify-content: space-between; /* Space out groups */
    align-items: center; /* Vertically align items */
    gap: 10px 20px; /* Row gap, Column gap */
    margin-bottom: 15px;
    padding-bottom: 15px; /* Increased padding */
    border-bottom: 1px solid var(--dark-border-color);
    font-size: 0.9em;
    color: var(--dark-text-secondary);
}

.user-info > span, /* Direct span children like Welcome message */
.user-info > a    /* Direct link children like Logout */
{
    white-space: nowrap; /* Prevent wrapping within an item */
}

.user-info .welcome-user {
    /* Target the welcome message span specifically if needed */
    font-weight: bold;
    color: var(--dark-text-primary);
}

.user-info .user-links {
    /* Group the action links */
    display: flex;
    align-items: center;
    gap: 15px; /* Spacing between links */
    margin-left: auto; /* Push links to the right on wider screens if space allows */
}

.user-info a {
    color: var(--dark-link-color);
    text-decoration: none;
}
.user-info a:hover {
    text-decoration: underline;
}

.user-info .vip-status {
    color: gold;
    font-weight: bold;
    margin-left: 5px;
    border: 1px solid gold;
    padding: 3px 6px;
    border-radius: 4px;
    background-color: rgba(255, 215, 0, 0.15); /* Slightly more visible bg */
    white-space: nowrap;
}

.current-char-display {
    display: inline-flex; /* Use inline-flex */
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    border: 1px solid var(--dark-border-color);
    border-radius: 4px;
    background-color: var(--dark-bg-tertiary);
    white-space: nowrap;
}

.current-char-display img {
    width: 20px; /* Slightly smaller */
    height: 20px;
    border-radius: 50%;
    vertical-align: middle;
    margin: 0;
    border: none; /* Remove previous border */
}
#current-char-name {
    color: var(--dark-text-primary);
}

/* Character Selection Area - Refined Layout */
#character-selection {
    display: flex;
    flex-wrap: wrap; /* Allow buttons to wrap */
    gap: 10px; /* Consistent gap */
    margin-bottom: 20px;
    padding-bottom: 15px; /* Add padding below */
    border-bottom: 1px solid var(--dark-border-color); /* Add separator */
}

#character-selection button {
    /* Inherit general button styles */
    background-color: var(--dark-bg-tertiary);
    color: var(--dark-text-secondary);
    border: 1px solid var(--dark-border-color);
    padding: 8px 15px; /* Adjust padding */
    font-size: 0.95em;
    cursor: pointer; /* Ensure cursor changes */
    transition: background-color 0.2s, color 0.2s; /* Add transitions */
}

#character-selection button:hover {
    background-color: var(--dark-border-color);
    color: var(--dark-text-primary);
    filter: none;
}

/* --- Mobile adjustments for these areas --- */
@media (max-width: 768px) {
    /* Adjust user info alignment and spacing */
    .user-info {
        justify-content: center; /* Center items when they wrap */
        gap: 10px; /* Adjust gap for mobile */
        /* padding-bottom: 15px; Already set */
        /* user-links rules below handle link centering */
    }
    .user-info .user-links {
        margin-left: 0; /* Don't push links right on mobile */
        width: 100%; /* Make links take full width */
        justify-content: center; /* Center the links */
        margin-top: 10px; /* Add space above links when wrapped */
        order: 1; /* Ensure links appear below other info if wrapped */
    }

    /* Character Selection Buttons */
    #character-selection {
        justify-content: center; /* Center buttons on mobile */
        gap: 8px; /* Slightly reduce gap */
    }
    #character-selection button {
         flex-grow: 1; /* Allow buttons to grow slightly */
         padding: 10px 12px; /* Ensure good tap size */
         font-size: 0.9em; /* Adjust font size */
         flex-basis: 45%; /* Aim for roughly 2 buttons per row */
     }

     /* Further adjustments for very small screens */
     @media (max-width: 480px) {
         #character-selection button {
             flex-basis: 100%; /* Stack buttons vertically */
         }
         /* You might want to adjust .user-info further here if needed */
         .user-info {
             gap: 8px; /* Reduce gap further */
         }
     }

    /* ... other mobile rules from previous steps ... */
}

/* Modal Styles - Ensure dark theme applies */
#characterModal .modal-content { /* Increased Specificity */
    background-color: var(--dark-bg-secondary) !important; /* Force dark background */
    color: var(--dark-text-primary) !important; /* Force light text */
    padding: 20px;
    border: 1px solid var(--dark-border-color);
    border-radius: 8px;
    width: 80%;
    max-width: 650px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative;
}

#characterModal .modal-content h2 { /* Increased Specificity */
    margin-top: 0;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--dark-border-color);
    color: var(--dark-text-primary) !important; /* Ensure heading is light */
}

#characterModal .close-button { /* Increased Specificity */
    color: var(--dark-text-secondary) !important; /* Ensure button color */
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

#characterModal .close-button:hover,
#characterModal .close-button:focus { /* Increased Specificity */
    color: var(--dark-text-primary) !important;
    text-decoration: none;
}

/* Keep general modal class for other potential modals */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.7); /* Darker overlay */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Apply general dark theme to any modal-content that ISN'T #characterModal */
.modal-content:not(#characterModal .modal-content) {
    background-color: var(--dark-bg-secondary);
    color: var(--dark-text-primary);
    padding: 20px;
    border: 1px solid var(--dark-border-color);
    /* Add other necessary default styles */
}

/* Feedback Modal Specific Styles */
#feedback-modal .modal-content {
    /* Inherits general modal dark styles */
    max-width: 700px; /* Allow wider modal for feedback */
}

#feedback-submit-section,
#feedback-history-section {
    margin-bottom: 20px;
}

#feedback-history-section h3 {
    color: var(--dark-text-primary);
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--dark-border-color);
}

#feedback-history-content {
    max-height: 400px; /* Or some value to make it scrollable */
    overflow-y: scroll; /* Changed from auto to scroll to ensure it's always present */
    border: 1px solid var(--dark-border-color);
    padding: 15px;
    border-radius: 6px;
    background-color: var(--dark-bg-tertiary);
}

/* Custom Scrollbar for Feedback History */
#feedback-history-content::-webkit-scrollbar {
    width: 10px;
}

#feedback-history-content::-webkit-scrollbar-track {
    background: var(--dark-bg-secondary);
    border-radius: 6px;
}

#feedback-history-content::-webkit-scrollbar-thumb {
    background-color: var(--dark-text-secondary);
    border-radius: 6px;
    border: 2px solid var(--dark-bg-secondary);
}

#feedback-history-content::-webkit-scrollbar-thumb:hover {
    background-color: var(--dark-text-primary);
}


/* Style for individual feedback items (Assuming they are divs) */
#feedback-history-content .feedback-item { /* Use a specific class if possible, fallback to div */
    background-color: var(--dark-bg-secondary);
    padding: 15px;
    border: 1px solid var(--dark-border-color);
    border-radius: 4px;
    padding: 10px 15px;
    margin-bottom: 10px;
    color: var(--dark-text-primary); /* Ensure text is light */
    word-wrap: break-word; /* Allow long words to break */
}

/* Style for feedback metadata (like user, timestamp) if present */
#feedback-history-content .feedback-item .meta {
    font-size: 0.85em;
    color: var(--dark-text-secondary);
    margin-bottom: 5px;
    border-bottom: 1px dashed var(--dark-border-color); /* Separator */
    padding-bottom: 5px;
}

/* Remove margin from last item */
#feedback-history-content .feedback-item:last-child {
    margin-bottom: 0;
}


#feedback-textarea {
    /* Inherits dark style from general textarea rules */
    width: 100%;
    box-sizing: border-box;
}

#submit-feedback-button {
    /* Inherits general button styles (green) */
}

#feedback-status {
    margin-top: 10px;
    display: none;
    padding: 8px;
    border-radius: 4px;
    /* Dynamically set color/background in JS based on success/error */
}

#feedback-status.success {
    color: #5dff82;
    background-color: rgba(35, 134, 54, 0.2);
    border: 1px solid var(--dark-accent-green);
}

#feedback-status.error {
    color: #ff9999;
    background-color: rgba(218, 54, 51, 0.2);
    border: 1px solid var(--dark-accent-red);
}

#feedback-history-loading {
    color: var(--dark-text-secondary);
}

/* Style for the Purchase VIP Button */
.purchase-vip-button {
    display: inline-block; /* Make the link behave like a button */
    padding: 10px 20px; /* Adjust padding as needed */
    border-radius: 6px; /* Match other buttons */
    text-decoration: none;
    font-weight: bold;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;

    background-color: gold; /* VIP Gold color */
    color: #333; /* Dark text for contrast on gold */
    border: 1px solid #e6c300; /* Slightly darker gold border */
}

.purchase-vip-button:hover {
    background-color: #ffeb80; /* Lighter gold on hover */
    border-color: #ffd700;
    color: #000; /* Ensure contrast on lighter hover */
    text-decoration: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transform: translateY(-1px); /* Subtle lift effect */
}

/* =================================== */
/*          Mobile Responsiveness      */
/* =================================== */

@media (max-width: 768px) {
    body {
        font-size: 15px; /* Slightly adjust base font size for mobile */
    }

    /* --- Mobile styles for non-centered page containers --- */
    body:not(.centered-form-page) .container {
        margin: 0; /* Remove margins on mobile */
        padding: 10px; /* Adjust padding for mobile */
        border-radius: 0; /* Remove border-radius on mobile */
        border: none; /* Remove border on mobile */
        max-width: none;
    }

    /* --- Mobile styles FOR CENTERED page containers --- */
    body.centered-form-page .container {
        width: 90%; /* Use most of the screen width */
        max-width: 500px; /* Optional: Still provide a max-width, smaller than desktop */
        padding: 20px; /* Keep reasonable padding for forms */
        /* margin: 0; is already handled by the flex centering */
        box-sizing: border-box;
    }

    h1 {
        font-size: 1.8em; /* Adjust heading size */
    }
    h2 {
        font-size: 1.4em; /* Adjust subheading size */
    }

    /* Adjust user info alignment and spacing */
    .user-info {
        justify-content: center; /* Center items when they wrap */
        gap: 10px;
        padding-bottom: 15px;
    }

    /* Chatbox adjustments */
    #chatbox {
        height: 60vh; /* Adjust height relative to viewport */
        padding: 10px;
    }
    #chatbox p {
        padding: 8px 12px;
        max-width: 90%; /* Allow bubbles to be slightly wider */
    }

    /* Chat form adjustments - Stack input and button */
    #chat-form {
        flex-direction: column; /* Stack vertically */
        gap: 8px;
    }
    #message {
        width: 100%; /* Full width input */
        box-sizing: border-box; /* Include padding in width */
        margin-right: 0;
    }
    #chat-form input[type="submit"] {
        width: 100%; /* Full width button */
        padding: 12px; /* Ensure good tap target size */
    }

    /* Character Selection Buttons */
    #character-selection {
        justify-content: center; /* Center buttons */
    }

    /* Modal adjustments */
    .modal-content {
        width: 90%; /* Use more screen width */
        max-width: 90%;
        padding: 15px;
    }
    #characterModal .character-list {
        grid-template-columns: repeat(auto-fill, minmax(95px, 1fr)); /* Allow slightly smaller cards for potentially 3 columns on wider mobile */
        gap: 8px;
        max-height: 65vh; /* Adjust height */
    }
    #characterModal .character-list li {
        min-height: auto; /* Adjust height as needed */
        padding: 6px;
    }
    #characterModal .character-list li img {
         max-width: 60px;
         max-height: 80px; /* Adjust if needed */
         height: 80px;
    }
     #characterModal .character-list li span {
         font-size: 0.75em !important;
     }
      #characterModal .vip-badge {
         font-size: 0.6em !important;
         padding: 1px 3px;
         top: 2px;
         right: 2px;
     }

    /* Admin table adjustments (if viewed on mobile) */
    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block; /* Stack table cells */
    }
    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
         border: none;
    }
    tr {
        border: 1px solid var(--dark-border-color);
        margin-bottom: 10px;
        border-radius: 4px;
    }
    td {
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        position: relative;
        padding-left: 50%; /* Make space for label */
        text-align: right; /* Align content to the right */
        white-space: normal; /* Allow wrapping */
    }
    td:before {
        /* Use data-label for headers */
        position: absolute;
        top: 6px;
        left: 6px;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        content: attr(data-label);
        font-weight: bold;
        text-align: left; /* Align label to the left */
        color: var(--dark-text-secondary);
    }
     td:last-child {
         border-bottom: 0;
     }
     .char-image {
         max-width: 40px !important;
         max-height: 40px !important;
         float: right; /* Align image right */
     }
      /* Add data-label attributes to your table cells in PHP if using this approach */
      /* Example: <td data-label="图片">...</td> <td data-label="名称">...</td> */

    /* Login/Register form adjustments */
    .login-choice-content {
        width: 85%;
    }

}

/* Optional: Further adjustments for very small screens */
@media (max-width: 480px) {
    body {
        font-size: 14px;
    }
    h1 { font-size: 1.6em; }
    h2 { font-size: 1.3em; }

    #characterModal .character-list {
         grid-template-columns: repeat(auto-fill, minmax(85px, 1fr)); /* Allow smaller cards, maybe 2 columns */
    }

    /* Further reduce padding/margins if needed */
    .container { padding: 10px; }
    #chatbox { padding: 8px; }
}

/* =================================== */
/*       Page Centering Utilities      */
/* =================================== */

body.centered-form-page {
    /* display: flex; */ /* Already set on body */
    align-items: center; /* Vertical center */
    justify-content: center; /* Horizontal center */
    min-height: 100vh; /* Ensure body takes full viewport height */
    padding: 20px;
    box-sizing: border-box;
}
body.centered-form-page .container {
    margin: 0;
    flex-grow: 0; /* Don't allow centered container to grow */
    overflow: visible; /* Allow potential shadows/overflow */
    /* Other container styles apply */
}

/* Make images within chat messages responsive */
#chatbox .message-content img {
    max-width: 100%; /* Ensure image never exceeds container width */
    height: auto;    /* Maintain aspect ratio */
    display: block;  /* Prevent extra space below image */
    margin-top: 8px; /* Add some space above image */
    margin-bottom: 8px; /* Add some space below image */
    border-radius: 6px; /* Optional: round corners slightly */
}

/* =================================== */
/*          Admin Page Overrides       */
/* =================================== */

body.admin-page {
    display: block; /* Override body flexbox for admin pages */
    min-height: 100%; /* Still ensure it tries to take full height */
    /* Let the browser handle overflow/scrolling naturally */
    /* Remove centering properties from centered-form-page if they were inherited */
    align-items: initial;
    justify-content: initial;
}

/* Container on admin pages should revert to standard margin: auto for centering */
body.admin-page .container {
    margin: 20px auto; /* Restore auto horizontal margins */
    flex-grow: 0; /* Ensure it doesn't try to grow vertically */
    max-width: 1200px; /* Allow admin containers to be wider */
    /* Keep other .container styles like padding, background, border */
}

/* Ensure mobile rules for admin container don't conflict */
@media (max-width: 768px) {
    body.admin-page .container {
        margin: 10px; /* Consistent mobile margin */
        max-width: none; /* Remove max-width on mobile */
        width: auto;
        padding: 15px; /* Consistent mobile padding */
    }
}

/* =================================== */
/*             New Top Bar             */
/* =================================== */

#top-bar {
    display: flex;
    justify-content: space-between; /* Space out items */
    align-items: center; /* Vertically align items */
    padding: 10px 15px; /* Adjust padding as needed */
    border-bottom: 1px solid var(--dark-border-color);
    background-color: var(--dark-bg-secondary); /* Match container background */
    margin-bottom: 15px;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    gap: 10px; /* Add gap between wrapped items */
}

.user-greeting-info {
    display: flex;
    align-items: center;
    gap: 15px; /* Space between user info items */
    overflow: hidden; /* Add overflow hidden to the container */
    min-width: 0; /* Allow shrinking below content size */
}

.user-greeting-info span:not(.vip-info):not(.current-char-info) { /* Target only direct text spans */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block; /* Needed for ellipsis */
    flex-shrink: 1; /* Allow welcome message to shrink */
    min-width: 0;
}

.vip-info { /* Already styled, ensure no shrink */
    background-color: #e6a23c;
    color: #fff;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
    white-space: nowrap; /* Keep VIP text on one line */
    flex-shrink: 0; /* Prevent VIP badge from shrinking */
}

.current-char-info {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--dark-text-secondary);
    flex-shrink: 1; /* Allow this whole group to shrink */
    min-width: 0; /* Critical for shrinking */
    overflow: hidden; /* Hide overflow within this group */
}

.char-avatar-small { /* Already styled, ensure no shrink */
    width: 24px;
    height: 24px;
    border-radius: 50%;
    vertical-align: middle;
    flex-shrink: 0; /* Prevent avatar from shrinking */
}

/* Target text spans within current-char-info */
.current-char-info > #current-char-name,
.current-char-info > #current-char-id {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block; /* Or inline */
    flex-shrink: 1; /* Allow name and ID to shrink */
    min-width: 0;
}

/* --- User Actions Container (Right side of top bar) --- */
.user-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    /* justify-content: flex-end; */ /* Changed */
    justify-content: space-between; /* ++ Use space-between for alignment ++ */
    overflow: hidden;
    min-width: 0;
    flex-grow: 1; /* ++ Allow container to grow and fill space ++ */
    /* flex-wrap: wrap; */ /* No wrap */
}

/* --- Buttons within User Actions --- */
/* ++ Apply unified style to BOTH .top-bar-button and .top-bar-link ++ */
.user-actions > .top-bar-button,
.user-actions > .top-bar-link {
    display: inline-block;
    padding: 10px 15px; /* ++ Increased default padding (approx 20%) ++ */
    font-size: 16px;   /* ++ Increased default font size (approx 14%) ++ */
    margin: 0;
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, padding 0.2s ease, font-size 0.2s ease;
    white-space: nowrap;
    flex-shrink: 1;
    text-align: center;
    color: var(--dark-text-primary);
    background-color: var(--dark-bg-tertiary);
    border: 1px solid var(--dark-border-color);
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Unified Hover effect --- */
.user-actions > .top-bar-button:hover,
.user-actions > .top-bar-link:hover {
    background-color: var(--dark-accent-blue);
    border-color: var(--dark-accent-blue);
    color: white;
}

/* --- Responsive Adjustments for Top Bar (Apply to both classes) --- */
@media (max-width: 768px) {
    /* ... (#top-bar, .user-greeting-info styles) ... */
    .user-actions {
        /* justify-content: flex-end; */ /* Keep space-between */
        gap: 6px;
    }
    /* Smaller buttons on medium screens */
    .user-actions > .top-bar-button,
    .user-actions > .top-bar-link {
        padding: 8px 10px;  /* ++ Adjusted smaller padding ++ */
        font-size: 14px;    /* ++ Adjusted smaller font size ++ */
    }
}

@media (max-width: 480px) {
    /* ... (#top-bar styles) ... */
    .user-actions {
        gap: 4px;
        /* justify-content: space-around; */ /* Keep space-between */
    }
    /* Smallest buttons */
    .user-actions > .top-bar-button,
    .user-actions > .top-bar-link {
        padding: 6px 6px; /* ++ Adjusted smallest padding ++ */
        font-size: 12px;  /* ++ Adjusted smallest font size ++ */
    }
}

/* =================================== */
/*   Character Selection Button Bar    */
/* =================================== */

/* Commenting out old styles, as they are replaced by #top-bar */
/*
#character-selection.character-selection-area {
    ...
}
#character-selection.character-selection-area > .char-control-btn {
   ...
}
#character-selection.character-selection-area > .char-control-btn:hover {
   ...
}
*/

/* ... Rest of the CSS ... */

/* Style for delete buttons on messages (Corrected Selector) */
.user-message .delete-message-btn,
.ai-message .delete-message-btn {
    opacity: 0.6;
    font-size: 0.7em;
    padding: 2px 5px;
    margin-left: 8px;
    cursor: pointer;
    background-color: transparent;
    color: var(--dark-accent-red);
    border: 1px solid var(--dark-accent-red);
    border-radius: 3px;
    vertical-align: middle;
    transition: opacity 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

/* Corrected hover selector as well */
.user-message .delete-message-btn:hover,
.ai-message .delete-message-btn:hover {
    opacity: 1;
    background-color: var(--dark-accent-red);
    color: white;
}

/* ++ 新增：复制按钮的样式 ++ */
.user-message .copy-message-btn,
.ai-message .copy-message-btn {
    opacity: 0.6;
    font-size: 0.7em;
    padding: 2px 5px;
    margin-left: 4px; /* 比删除按钮小一点的左边距 */
    cursor: pointer;
    background-color: transparent;
    color: var(--dark-accent-blue, #6ca7d9); /* 使用蓝色调，并提供备用颜色 */
    border: 1px solid var(--dark-accent-blue, #6ca7d9);
    border-radius: 3px;
    vertical-align: middle;
    transition: opacity 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.user-message .copy-message-btn:hover,
.ai-message .copy-message-btn:hover {
    opacity: 1;
    background-color: var(--dark-accent-blue, #6ca7d9);
    color: white;
}
/* ++ 样式结束 ++ */

/* 新增：让按钮看起来像链接 */
.link-style-button {
    background: none;
    border: none;
    color: #337ab7; /* 或者你的链接颜色变量 */
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    font-size: inherit; /* 继承表格字体大小 */
    display: inline; /* 确保和其他链接在同一行 */
    vertical-align: baseline;
}

.link-style-button:hover {
    color: #23527c; /* 链接悬停颜色 */
    text-decoration: underline;
}

/* 修复开场白不显示问题 - 确保ai-message内的所有内容无论位置都能显示 */
.ai-message > p {
    display: block !important;
    visibility: visible !important;
    margin: 0.5em 0 !important;
    color: inherit !important;
}

/* 确保初始问候语无论DOM结构如何都能完整显示 */
#initial-greeting > p,
#initial-greeting > span:not(.message-content),
#initial-greeting > div:not(.message-content) {
    display: block !important;
    visibility: visible !important;
    margin: 0.5em 0 !important;
    color: inherit !important;
}

/* 直接修复截图中显示的DOM结构问题 */
.ai-message:after {
    content: "";
    display: block;
    clear: both;
    visibility: hidden;
    height: 0;
}

/* 应用额外样式确保所有子元素可见 */
.ai-message *,
#initial-greeting * {
    opacity: 1 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
}

/* 优化消息内容显示 */
.message-content {
    display: block !important;
    min-height: 1em;
    white-space: normal;
    word-wrap: break-word;
}

/* Keep existing styles below... */
/* Basic Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* --- 新增：专门针对紫色按钮的样式 --- */
.horizontal-button-container {
    margin: 0 auto 5px auto; /* 修改：进一步压缩垂直边距 */
}

.btn-purple-specific {
    display: block;
    width: 100%;
    max-width: 600px;
    margin: 0 auto; /* 修改：移除垂直外边距 */
    padding: 2px 15px; /* 修改：进一步压缩垂直内边距 */
    background-color: #9575CD; /* Material Design a purple color */
    color: white;
    text-align: center;
    border-radius: 8px;
    text-decoration: none;
    font-size: 14px; /* 修改：缩小字体 */
    font-weight: normal; /* 修改：去除加粗 */
    line-height: 1.5;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: background-color 0.3s, box-shadow 0.3s;
}

.btn-purple-specific:hover {
    background-color: var(--purple-button-hover-bg);
    filter: none; /* Remove default brightness filter if applied */
    text-decoration: none; /* Ensure no underline on hover */
}
/* --- 结束新增 --- */

/* --- Admin User Manager UI Improvements --- */
.filter-sort-form .search-group {
    flex-grow: 1;
    min-width: 200px;
}

table th {
    white-space: nowrap;
}

table th, table td {
    padding: 10px 12px; /* 增加垂直和水平内边距 */
    vertical-align: middle; /* 垂直居中对齐单元格内容 */
}

.action-buttons {
    display: flex;
    gap: 5px; /* 按钮之间的间距 */
    align-items: center; /* 确保按钮垂直对齐 */
    flex-wrap: wrap; /* 在小屏幕上换行 */
}

/* 确保按钮和链接在 flex 容器中表现一致 */
.action-buttons .btn {
    margin: 2px 0; /* 为换行情况添加微小的垂直边距 */
}

.password-cell {
    cursor: pointer;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Responsive table wrapper for horizontal scrolling --- */
.table-responsive-wrapper {
    overflow-x: auto;
    width: 100%;
    margin-bottom: 1rem; /* 与下方按钮保持一些间距 */
}

/* --- Full-width container for admin pages --- */
.container-full-width {
    width: 100%;
    max-width: 92%; /* 减小最大宽度以增加左右边距 */
    margin: 2rem auto; /* 增加上下外边距，并保持左右居中 */
    padding: 20px;
    background-color: var(--background-color);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    box-sizing: border-box; /* 确保 padding 不会增加总宽度 */
}
