:root {
    --bg-color: #000000;
    /* Apple Dark Mode Secondary System Background */
    --card-bg: #1C1C1E; 
    --text-primary: #ffffff;
    --text-secondary: #8e8e93; /* Apple System Gray */
    --accent-red: #ff3b30; /* Apple System Red */
    --accent-blue: #0a84ff; /* Apple System Blue */
    --accent-green: #30d158; /* Apple System Green */
    --primary-color: #0a84ff; /* Use Apple Blue as primary */
    --nav-height: 60px;
    --header-height: 44px;
    --border-radius: 12px;
}

/* 全局隐藏滚动条 */
::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

html, body {
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden; /* Prevent body scroll, handle in main */
    height: 100vh;
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1024px; /* iPad Pro 12.9 width */
    margin: 0 auto;
    
    /* Transparent container */
    background: transparent;
    
    position: relative;
    /* No shadow */
}

/* Header */
.app-header {
    height: var(--header-height);
    display: none; /* Default hidden to prevent flash on Home Page */
    justify-content: flex-start; /* Changed from space-between */
    align-items: center;
    padding: 0 16px;
    background-color: rgba(0, 0, 0, 0.7); /* More transparent */
    backdrop-filter: blur(20px); /* Stronger blur */
    -webkit-backdrop-filter: blur(20px);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: background-color 0.2s; /* Removed border-bottom transition */
}

.app-header.merged {
    background-color: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-bottom-color: transparent; /* Changed from border-bottom: none for better transition handling if any */
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
}

.logo img {
    height: 24px; /* Reduced to 24px */
    width: auto;
    object-fit: contain;
}

.server-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #ffffff; /* Pure white */
    background-color: transparent; /* Remove background */
    padding: 4px 8px;
    border-radius: 12px;
    margin-top: 4px; /* Move down 4px */
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #66DC51; /* Server Online Green */
}

.server-time {
    color: rgba(255, 255, 255, 0.9); /* Brighter text, kept from improvement */
    margin-left: 2px;
}

.status-dot.maintenance {
    background-color: #FF5C53; /* Maintenance Red */
}

.header-actions i {
    font-size: 20px;
    color: var(--text-secondary);
}

/* Content Area */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding-top: 0; /* REMOVED: Moved padding to .page to fix sticky header calculation */
    padding-bottom: calc(var(--nav-height) + 20px + env(safe-area-inset-bottom)); /* Add safe area padding */
    position: relative;
}

.page {
    display: none;
    padding: calc(var(--header-height) + 12px) 16px 12px 16px; /* Base padding */
    animation: fadeIn 0.3s ease;
}

#page-character {
    /* Header (44px) + Padding (12px) = 56px */
    padding-top: 56px;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-header {
    margin-bottom: 4px; /* Reduced from 12px to minimize gap */
}

/* Specific adjustment for Vote Page to add more breathing room */
#page-vote .page-header {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* Ensure left alignment */
}

.page-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 0; /* Ensure no padding */
}

.vote-streak {
    font-size: 12px;
    font-weight: normal;
    color: var(--text-secondary);
    opacity: 0.8;
    display: inline-block; /* Ensure it respects margins */
    margin-top: 4px; /* Add space between title and streak */
    margin-left: 0; /* Ensure no left margin */
}

.page-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Components */
/* Search Box */
.search-box {
    margin-bottom: 8px; /* Reduced from 12px */
    padding: 0; /* Remove padding to fill width */
}

.input-group {
    display: flex;
    background-color: var(--card-bg);
    border-radius: 12px; /* Adapted for 40px height */
    padding: 0;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    height: 40px;
    align-items: center;
    overflow: hidden;
}

.input-group input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    height: 100%;
    padding: 0 12px; 
    font-size: 14px; /* Increased for better readability */
    outline: none;
}

.input-group button {
    background-color: transparent; /* Changed from var(--primary-color) */
    color: var(--text-secondary); /* Changed from white */
    border: none;
    height: 100%;
    padding: 0 16px; 
    border-radius: 0; 
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 14px; /* Increased for better readability */
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: -8px; /* Compensate for padding to align with edge */
}

.btn-sort {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s, color 0.2s;
}

.btn-sort:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.btn-sort i {
    font-size: 14px;
}

.more-menu-container {
    position: relative;
}

.btn-more {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 2px; /* Reduced gap from 6px */
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s, color 0.2s;
}

.btn-more:hover, .btn-more.active {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.btn-more i {
    font-size: 10px; /* Smaller chevron icon */
    opacity: 0.8;
}

/* More Dropdown Menu */
.more-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    /* Glassmorphism background - Darker with slight tint */
    background-color: rgba(30, 30, 35, 0.6); 
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    min-width: 180px;
    padding: 8px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.92);
    transform-origin: top right;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                visibility 0.25s;
    pointer-events: none;
}

.more-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Override global hidden class behavior for dropdown */
.more-dropdown.hidden {
    display: block !important; /* Ensure it's not removed from layout */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.92);
    pointer-events: none;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.dropdown-item i {
    width: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 16px;
}

/* Toggle Switch Style */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    margin-left: auto; /* Push to right */
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #48484a;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(16px);
}


button {
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
}

button:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--accent-blue);
    color: white; /* Changed from black for better contrast with Apple Blue */
}

.btn-secondary {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.1);
}

/* Account List & Cards */
.account-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.account-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 0; /* Remove gap, control spacing with margins for precise collapse handling */
    position: relative;
    border: 1px solid rgba(255,255,255,0.05);
    /* 拖拽相关样式 */
    cursor: grab; /* 提示可拖拽 */
    /* touch-action: pan-y; REMOVED: 让 Sortable 全权控制，防止冲突 */
    user-select: none; /* 防止拖拽时选中文本 */
}

.account-card:active {
    cursor: grabbing;
}

/* 拖拽时的幽灵元素样式 */
.sortable-ghost {
    opacity: 0.4;
    background-color: rgba(255,255,255,0.1);
    border: 1px dashed var(--accent-blue);
}

/* 拖拽选中时的样式 */
.sortable-drag {
    background-color: var(--card-bg);
    opacity: 1;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    transform: scale(1.02);
}

/* 模拟拖拽的样式 (当 forceFallback: true 时使用) */
.sortable-fallback {
    /* 必须确保克隆元素完全不接收事件，且层级最高 */
    pointer-events: none !important; 
    z-index: 99999 !important;
    position: fixed !important; 
    
    /* 视觉样式 */
    background-color: var(--card-bg);
    opacity: 0.9;
    box-shadow: 0 15px 30px rgba(0,0,0,0.6);
    transform: scale(1.05);
    border: 1px solid var(--accent-blue); /* 加个边框让人知道在拖拽 */
    border-radius: 12px;
    cursor: grabbing;
    /* 关键：防止 margin 导致偏移 */
    margin: 0 !important;
}

/* 确保拖拽时所有子元素也不响应事件 */
.sortable-fallback * {
    pointer-events: none !important;
}

.account-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.account-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.vote-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 0; /* Remove margin, let following elements handle spacing */
}

.btn-vote {
    flex: 1;
    display: flex;
    flex-direction: column; /* 垂直排列 */
    align-items: center;
    justify-content: center;
    gap: 2px; /* 元素间距 */
    padding: 6px 8px; /* 稍微减小垂直内边距 */
    border-radius: 8px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
    text-align: center;
    line-height: 1.2;
    min-height: 44px; /* 增加一点最小高度以容纳两行 */
}

/* 标签部分（图标+文字） */
.vote-label {
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

/* 倒计时/副文案 */
.vote-subtitle {
    font-size: 10px;
    font-weight: normal;
    opacity: 0.8;
    white-space: nowrap;
}

/* 验证文字 */
.verified-text {
    font-size: 10px;
    font-weight: normal;
    opacity: 0.9;
    white-space: nowrap;
}

/* 图标 */
.btn-vote i {
    font-size: 0.9em;
    margin-right: 4px;
    opacity: 0.9;
}

.btn-vote.red {
    background: linear-gradient(135deg, #FF3871, #FF0051);
    color: white;
    box-shadow: none;
}

.btn-vote.blue {
    background: linear-gradient(135deg, #069BFF, #006AFF);
    color: white;
    box-shadow: none;
}

.btn-vote.voted {
    background: rgba(255, 255, 255, 0.1); /* Neutral gray for disabled state */
    color: var(--text-secondary);
    box-shadow: none;
    /* cursor: not-allowed; */ /* 允许点击 */
    /* pointer-events: none; */ /* 允许点击 */
}

/* Hide the original vote timer */
.vote-timer {
    display: none !important;
}

.btn-icon.delete {
    background: transparent;
    color: var(--text-secondary);
    padding: 10px;
}

.btn-icon.delete:hover {
    color: var(--accent-red);
}

/* Account List Blur Effect - Only blur specific text elements */
.account-list.blurred .account-name {
    filter: blur(5px);
    transition: filter 0.3s ease;
}

/* Footer Actions */
.account-actions-footer {
    display: flex;
    justify-content: center;
    margin-top: 16px;
    margin-bottom: 8px;
}

.btn-secondary-outline {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-secondary-outline:hover, .btn-secondary-outline.active {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.4);
    color: var(--text-primary);
}

.btn-text-subtle {
    background: transparent;
    border: none;
    color: var(--text-secondary); /* Apple gray */
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: color 0.2s;
    width: 100%; /* Full width for easier tap */
    text-align: center;
}

.btn-text-subtle:hover {
    color: #ff3b30; /* Red on hover/active to indicate destructive action */
}

/* Tutorial Section */
.tutorial-section {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    margin-bottom: 24px;
}

.tutorial-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
}

.tutorial-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.tutorial-btn i {
    font-size: 16px;
}

/* Info Card Container */
.info-card-container {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 20px;
    border: none;
    margin-top: 20px;
}

.info-section {
    margin-bottom: 0;
}

.info-title {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.info-content p {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 8px;
}

.info-content p:last-child {
    margin-bottom: 0;
}

.info-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 16px 0;
    width: 100%;
}

/* Character List Grid */
.character-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)); /* Mobile: 2 columns, fixed equal width */
    gap: 12px;
    margin-top: 8px; /* Further reduced from 12px to minimize gap */
}

@media (min-width: 768px) {
    .character-grid {
        /* Desktop: Adaptive but keep spacing consistent with mobile */
        /* Use auto-fill to keep column sizes consistent */
        /* Set card width to at least 192px as requested */
        grid-template-columns: repeat(auto-fill, minmax(192px, 1fr)); 
        gap: 12px; /* Force consistent gap with mobile */
    }
}

.character-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.05);
    display: flex;
    flex-direction: column; /* Vertical layout */
    align-items: center;
    gap: 4px; /* Reduced gap between avatar and details */
    position: relative;
    transition: transform 0.2s, border-color 0.2s;
    width: 100%; /* Ensure card takes full width of grid cell */
    height: 100%; /* Ensure card takes full height of grid cell */
    overflow: visible; /* Allow content to overflow (e.g., large avatars) */
    cursor: grab; /* Indicate draggable */
    z-index: 1; /* Ensure base z-index */
}

.character-card:active {
    cursor: grabbing;
    z-index: 100; /* Bring to front while dragging */
}

/* Hover effect for devices that support hover (mouse) */
@media (hover: hover) {
    .character-card:hover {
        transform: translateY(-2px);
        border-color: var(--accent-blue);
        z-index: 50; /* Bring to front on hover */
    }
}

.char-avatar-container {
    width: 100%;
    height: 96px; /* Adjusted to 96px as requested */
    flex-shrink: 0;
    background: transparent;
    border-radius: 0;
    display: flex;
    justify-content: center;
    align-items: flex-end; /* Align avatars to the bottom */
    overflow: visible; /* Allow avatars to overflow */
    border: none;
    margin-bottom: 0; /* Remove margin to reduce gap */
    position: relative;
}

.char-avatar {
    /* Removed max-width/max-height to allow original size */
    max-width: none;
    max-height: none;
    object-fit: none;
    /* Ensure image is not scaled down */
    flex-shrink: 0;
    /* Adjust z-index if needed */
    position: relative;
    z-index: 2;
}

.char-details {
    width: 100%;
    text-align: center;
    flex: 1; /* Allow details to fill remaining space */
    display: flex;
    flex-direction: column;
}

.char-details h3 {
    margin: 0 0 4px 0; /* Reduced from 12px */
    font-size: 16px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

.banned-badge {
    background-color: #ff4757;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: normal;
    white-space: nowrap;
}

.admin-badge {
    background-color: #2ed573; /* Green for admin */
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: normal;
    white-space: nowrap;
}

.char-stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)); /* Force equal width columns */
    gap: 8px;
    margin-top: 8px; /* Increased from 4px to give more breathing room */
    width: 100%; /* Ensure full width */
}

/* Character Tabs */
.tabs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px; /* Reduced from 16px */
    
    /* Sticky Header Implementation */
    position: sticky;
    top: var(--header-height); /* Exactly 44px */
    z-index: 90;
    
    /* REMOVED: Direct background and backdrop-filter to prevent stacking context conflict with child dropdowns */
    background-color: transparent; 
    /* backdrop-filter: blur(20px); */
    /* -webkit-backdrop-filter: blur(20px); */
    
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    
    /* Full width adjustment */
    margin-left: -16px;
    margin-right: -16px;
    padding: 4px 16px; /* Reduced from 8px 16px */
    border-top: none; /* Ensure no top border */
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background-color 0.2s;
}

/* Use pseudo-element for background blur to avoid interfering with children's backdrop-filter */
.tabs-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: -1;
}

.tabs-header.is-stuck {
    /* Transparent when stuck because we use a different pseudo-element technique or just rely on the main one */
    background-color: transparent;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.tabs-header.is-stuck::before {
    /* Extend height when stuck to cover header area if needed, or just maintain blur */
    top: calc(var(--header-height) * -1); /* -44px */
    height: calc(100% + var(--header-height) + 1px);
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.character-tabs {
    display: flex;
    justify-content: flex-start;
    gap: 20px;
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    border: none;
    position: relative;
    margin-left: -4px; /* Compensate for tab-item padding */
}

.tab-item {
    padding: 8px 4px;
    border-radius: 0;
    background-color: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    user-select: none;
    border: none;
    position: relative;
    transition: color 0.2s;
}

.tab-item:hover {
    color: var(--text-primary);
}

.tab-item.active {
    background-color: transparent;
    color: var(--text-primary);
    font-weight: 600;
    box-shadow: none;
}

.tab-item.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background-color: var(--primary-color);
    border-radius: 2px;
}

.stat-item {
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden; /* Contain overflow */
    min-width: 0; /* Allow shrinking below content size */
}

.stat-item .label {
    font-size: 11px;
    color: #8e8e93;
}

.stat-item .value,
.stat-item .value-sm {
    font-size: 13px;
    color: white;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block; /* Ensure block display for truncation */
    width: 100%; /* Ensure full width for truncation */
}

/* 中文职业名称字体微调 */
.stat-item .value.chinese-text {
    font-size: 12px; /* 恢复为 12px */
    letter-spacing: 0.5px;
}

/* 无公会状态样式 */
.stat-item .value.no-guild {
    color: var(--text-secondary);
    font-size: 12px;
    opacity: 0.7;
    /* Removed font-style: italic */
}

.stat-item .value-sm {
    font-size: 11px;
}

.delete-card-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    background: transparent; /* No background */
    color: rgba(255, 255, 255, 0.4); /* Weak cross */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    font-size: 14px;
    transition: all 0.2s;
    z-index: 10;
    padding: 0;
}

.delete-card-btn:hover {
    color: rgba(255, 255, 255, 0.8); /* Brighter on hover */
    background: transparent;
}

@keyframes highlight-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 rgba(46, 213, 115, 0); border-color: rgba(255,255,255,0.05); }
    10% { transform: scale(1.05); box-shadow: 0 0 25px rgba(46, 213, 115, 0.6); border-color: #2ed573; }
    40% { transform: scale(1.05); box-shadow: 0 0 25px rgba(46, 213, 115, 0.6); border-color: #2ed573; }
    100% { transform: scale(1); box-shadow: 0 0 0 rgba(46, 213, 115, 0); border-color: rgba(255,255,255,0.05); }
}

@keyframes scan-sweep {
    0% { left: -100%; opacity: 0; }
    10% { opacity: 1; }
    100% { left: 200%; opacity: 0; }
}

.card-highlight {
    animation: highlight-pulse 3s ease-out forwards;
    position: relative;
    overflow: hidden;
    z-index: 10;
}

.card-highlight::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(
        to right,
        transparent 0%,
        rgba(255, 255, 255, 0.2) 30%,
        rgba(255, 255, 255, 0.6) 50%,
        rgba(255, 255, 255, 0.2) 70%,
        transparent 100%
    );
    transform: skewX(-25deg);
    animation: scan-sweep 1.5s cubic-bezier(0.4, 0.0, 0.2, 1);
    pointer-events: none;
    z-index: 11;
}

.toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.toast.show {
    opacity: 1;
}

/* Home Page Specifics */
/* NEW HOME PAGE STYLES */
#page-home {
    display: none; /* Controlled by JS */
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Center vertically */
    height: 100%;
    width: 100%;
    padding: 0 20px;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 40px); /* Lift up slightly */
    position: relative; /* Ensure absolute children are relative to this */
}

#page-home.active {
    display: flex;
}

.home-logo-container {
    margin-bottom: 32px;
    display: flex;
    justify-content: center;
    width: 100%;
}

.home-logo-container img {
    max-width: 240px; /* Adjust size as needed */
    height: auto;
    object-fit: contain;
}

.home-search-wrapper {
    width: 100%;
    max-width: 600px; /* Limit width on large screens */
    margin-bottom: 40px;
}

.home-search-box {
    background: rgba(28, 28, 30, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Input Area */
.home-search-box .search-input-area {
    display: flex;
    align-items: center;
    gap: 0px; /* Reduced gap to 0 */
    border-bottom: 1px solid rgba(255, 255, 255, 0.05); /* Weaker divider */
    padding-bottom: 12px;
}

.home-search-box .search-icon {
    color: var(--text-secondary);
    font-size: 18px;
    margin-left: 2px; /* Reduced from 4px */
}

#home-search-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px; /* Reduced from 16px */
    outline: none;
    height: 24px;
    padding: 0 0 0 2px; /* Reduced from 4px */
    width: 100%; /* Ensure full width */
}

#home-search-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Search Engine Selector */
.search-engine-selector {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 4px; /* Reduced gap from 8px */
    overflow-x: auto; /* Allow scrolling on very small screens if needed */
    scrollbar-width: none; /* Hide scrollbar */
}

.search-engine-selector::-webkit-scrollbar {
    display: none;
}

.engine-btn {
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px; /* Reduced gap from 6px */
    padding: 8px 6px; /* Reduced horizontal padding from 12px */
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-secondary);
    font-size: 12px;
    flex: 1; /* Distribute space evenly */
    min-width: fit-content; /* Prevent shrinking below content size */
}

.engine-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.engine-btn.active {
    background-color: rgba(255, 255, 255, 0.1); /* Reduced opacity from 0.15 */
    color: var(--text-primary);
    font-weight: 600;
}

.engine-btn img {
    width: 14px; /* User said 10px, but 10px is very small. I'll use 14px for better visibility, or stick to 10px if strictly required. User said "图标都10px尺寸". I will use 10px. */
    height: 14px; /* Fixed to 10px as requested */
    width: auto;
    object-fit: contain;
}

.engine-btn span {
    white-space: nowrap;
}

/* Hide Google on Mobile if screen is too narrow (Allow on iPad 768px+) */
@media (max-width: 767px) {
    .engine-btn[data-engine="google"] {
        display: none;
    }
}

/* Footer Info */
.home-footer-info {
    position: absolute;
    /* Use fixed positioning relative to container if container is relative, or viewport if needed. */
    /* Since #page-home is flex column centered, we want this pinned to bottom padding. */
    /* But absolute inside a flex item can be tricky. */
    /* Let's keep absolute but ensure bottom is stable */
    bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + 12px); /* Reduced from 24px to 12px */
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    pointer-events: none; /* Let clicks pass through */
}

.home-server-status {
    display: none; /* Initially hidden, shown by JS on success */
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    background-color: rgba(255, 255, 255, 0.05);
    padding: 6px 12px;
    border-radius: 16px;
}

.online-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.server-time {
    opacity: 0.9;
    font-variant-numeric: tabular-nums;
    font-size: 11px; /* Increased font size */
    color: var(--text-secondary);
    font-weight: 400;
}

/* Quick Access Grid */
.quick-access-grid {
    display: flex;
    justify-content: flex-start; /* Changed from center to allow scrolling start from left */
    gap: 20px; /* Restore comfortable gap */
    margin-top: 32px; /* Increased spacing */
    width: 100%;
    max-width: 100%; /* Allow full width of wrapper */
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0 4px 8px 4px; /* Padding for scrollbar/shadow */
    scrollbar-width: none; /* Hide scrollbar */
    -webkit-overflow-scrolling: touch;
    
    /* Gradient Mask for right fade effect - Mobile Only - Very Short */
    mask-image: linear-gradient(to right, black 98%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 98%, transparent 100%);
}

.quick-access-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    min-width: 56px; /* Ensure minimum touch target width */
    position: relative;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    margin: 0;
    padding: 0;
}

/* Custom Context Menu / Popover */
.shortcut-popover {
    position: fixed;
    background-color: rgba(28, 28, 30, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    min-width: 120px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
    transition: opacity 0.2s, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.shortcut-popover.visible {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}

/* Triangle Arrow */
.shortcut-popover::after {
    content: '';
    position: absolute;
    bottom: -6px; /* Default arrow at bottom */
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: rgba(28, 28, 30, 0.9) transparent transparent transparent;
}

.shortcut-popover.arrow-top::after {
    top: -6px;
    bottom: auto;
    border-width: 0 6px 6px;
    border-color: transparent transparent rgba(28, 28, 30, 0.9) transparent;
}

.popover-item {
    padding: 12px 16px;
    font-size: 14px;
    color: #ff453a; /* Red for delete */
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.popover-item:active {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
}

/* On Desktop, left align */
@media (min-width: 768px) {
    .quick-access-grid {
        justify-content: flex-start; /* Left align as requested */
        flex-wrap: wrap; 
        mask-image: none; 
        -webkit-mask-image: none;
        overflow-x: visible; 
    }
}

.quick-access-grid::-webkit-scrollbar {
    display: none;
}

.quick-access-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    min-width: 56px; /* Ensure minimum touch target width */
    position: relative; /* Context for badge */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.icon-circle {
    width: 34px; /* Fixed size as requested */
    height: 34px;
    background-color: rgba(44, 44, 46, 0.8); /* Apple Dark Gray */
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative; /* Ensure it stays in flow */
}

/* Edit Mode Styles (iOS Jiggle) */
@keyframes jiggle {
    0% { transform: rotate(-2deg); }
    50% { transform: rotate(2deg); }
    100% { transform: rotate(-2deg); }
}

.quick-access-grid.edit-mode .quick-access-item:not(.static-item) {
    animation: jiggle 0.3s infinite;
    cursor: grab;
    z-index: 10;
}

/* Delete Badge - Positioned relative to icon-circle via JS or CSS structure */
/* But since item is relative, we can position absolute to item */
.delete-badge {
    position: absolute;
    /* Center it on the top-right corner of the icon circle (34px wide) */
    /* Icon is centered in 56px wide item. Left offset = (56-34)/2 = 11px */
    /* So right edge of icon is at 11+34 = 45px from left */
    /* Let's position it from top/right of item container to be safe */
    top: -5px;
    right: 8px; /* 56px width, centered icon is 34px. 11px gap on sides. Badge at right 8px puts it slightly over edge */
    width: 16px; /* Smaller size */
    height: 16px;
    background-color: #ff3b30; /* Apple Red */
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 9px; /* Smaller icon */
    z-index: 20;
    opacity: 0;
    transform: scale(0);
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    border: 1.5px solid #000; /* Dark border to separate from background */
}

.quick-access-grid.edit-mode .delete-badge {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
    cursor: pointer;
}

.icon-circle img {
    width: 16px; /* Fixed size as requested */
    height: 16px;
    object-fit: contain;
}

.add-shortcut-circle {
    width: 34px;
    height: 34px;
    background-color: rgba(44, 44, 46, 0.6);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px dashed rgba(255, 255, 255, 0.2);
    color: var(--text-secondary);
    font-size: 14px;
}

.item-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 64px; /* Limit width */
    line-height: 1.2;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

.modal-content.apple-style-modal {
    background-color: #1C1C1E; /* Apple System Gray 6 Dark */
    width: 90%;
    max-width: 360px;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalPopUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPopUp {
    from { transform: scale(0.96) translateY(10px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 16px;
    padding: 4px;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.input-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group-vertical label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 4px;
}

.input-group-vertical input[type="text"],
.input-group-vertical input[type="url"] {
    background-color: rgba(118, 118, 128, 0.24); /* Apple Fill Gray */
    border: none;
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

.input-group-vertical input:focus {
    background-color: rgba(118, 118, 128, 0.3);
    box-shadow: 0 0 0 2px var(--accent-blue);
}

/* Icon Grid in Modal */
.icon-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    max-height: 160px;
    overflow-y: auto;
    padding: 4px;
}

.icon-option {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.icon-option:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.icon-option.selected {
    background-color: rgba(10, 132, 255, 0.2);
    border-color: var(--accent-blue);
}

.icon-option img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.modal-footer {
    padding: 16px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-footer button {
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    flex: 1;
}

/* ==========================================
   Vote Account Character List Styles
   ========================================== */

/* Delete Account Button (Top Right X) */
.account-card-header-actions {
    display: flex;
    gap: 4px;
    margin-left: auto; /* Push to right in flex container */
    align-items: center;
}

.delete-account-btn {
    width: 24px;
    height: 24px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    opacity: 0.6;
}

.delete-account-btn:hover {
    background: rgba(255, 59, 48, 0.1);
    color: var(--accent-red);
    opacity: 1;
}

.toggle-chars-btn {
    width: 24px;
    height: 24px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    opacity: 0.6;
}

.toggle-chars-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    opacity: 1;
}

.toggle-chars-btn.active {
    color: var(--primary-color);
    background: rgba(10, 132, 255, 0.1);
    opacity: 1;
}

/* Character List Container */
.account-chars-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Hide scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;
    
    /* Toggle Transition - Silky smooth, no bounce */
    max-height: 0;
    opacity: 0;
    overflow-y: hidden;
    padding: 0 4px 0 0; /* Remove left padding for alignment */
    margin: 0; /* Reset margins when collapsed */
    
    transition: max-height 0.3s cubic-bezier(0.25, 0.1, 0.25, 1.0), 
                opacity 0.2s ease-out, 
                padding 0.3s ease,
                margin 0.3s ease;
    
    /* Gradient Mask for scrolling fade effect */
    mask-image: linear-gradient(to right, black 90%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 90%, transparent 100%);
}

.account-chars-container.open {
    max-height: 120px; /* Increased to accommodate padding */
    opacity: 1;
    padding: 10px 4px 6px 0; /* Vertical padding + Right padding only */
    margin-top: 12px; /* Add spacing above when expanded */
    margin-bottom: 0;
}

/* Toggle Button Rotation */
.toggle-chars-btn i {
    transition: transform 0.3s ease;
}

.toggle-chars-btn.active i {
    transform: rotate(180deg);
}

/* Mini Character Banned Status */
.mini-char-banned {
    font-size: 10px;
    color: var(--accent-red);
    font-weight: 600;
}

/* Mini Character EXP */
.mini-char-exp {
    font-size: 10px;
    color: var(--text-tertiary);
    margin-left: 4px;
}

.account-chars-container::-webkit-scrollbar {
    display: none;
}

.account-chars-list {
    display: flex;
    gap: 8px;
    align-items: center;
    /* Ensure height for button and cards */
    min-height: 44px; 
}

/* Mini Character Card */
.mini-char-card {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 4px 8px; /* Compact padding */
    min-width: 120px;
    position: relative;
    transition: all 0.2s;
    height: 44px; /* Fixed height */
    user-select: none;
    cursor: pointer; /* Clickable */
}

.mini-char-card:active {
    transform: scale(0.96);
    background: rgba(255, 255, 255, 0.12);
}

.mini-char-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

.mini-char-avatar {
    width: 32px;
    height: 32px;
    object-fit: contain;
    margin-right: 8px;
    /* No background */
}

.mini-char-info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
}

.mini-char-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1;
}

.mini-char-job {
    font-size: 10px;
    color: var(--text-secondary);
    line-height: 1;
}

/* Add Character Button */
.add-char-btn {
    flex: 0 0 auto;
    width: 36px; /* Slightly smaller than card height */
    height: 36px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    color: var(--text-secondary);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
    padding: 0;
}

.add-char-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.add-char-btn.empty {
    width: auto;
    padding: 0 12px;
    gap: 6px;
}

.add-char-btn.empty span {
    font-size: 13px;
    white-space: nowrap;
}

/* Delete Character Button (Hover only) */
.delete-char-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-red);
    color: white;
    border: 2px solid var(--card-bg); /* Match card bg to create 'cutout' effect */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 10px;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.mini-char-card:hover .delete-char-btn {
    opacity: 1;
    transform: scale(1);
}

/* Mobile: Always show delete button but subtle */
@media (hover: none) {
    .delete-char-btn {
        opacity: 1;
        transform: scale(1);
        background: rgba(60, 60, 60, 0.9);
        top: -4px;
        right: -4px;
    }
}

/* Inline Input Styles */
.mini-char-input-wrapper {
    flex: 0 0 auto;
    width: 120px;
    height: 44px;
    display: flex;
    align-items: center;
    animation: fadeIn 0.2s ease-out;
}

.mini-char-input {
    width: 100%;
    height: 36px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--primary-color);
    border-radius: 8px;
    color: white;
    padding: 0 10px;
    font-size: 12px;
    outline: none;
    transition: all 0.2s;
}

.mini-char-loading {
    flex: 0 0 auto;
    width: 120px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

/* Hide progress bar container to fit 2x2 grid cleanly, just show value */
.progress-bar {
    display: none;
}

.value-sm {
    float: none;
    margin-top: 0;
}

.search-feedback {
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
    margin-top: 0;
}

.search-feedback.show {
    opacity: 1;
    max-height: 40px;
    margin-top: 8px;
    margin-bottom: 16px;
}

.search-feedback.error {
    color: var(--accent-red);
}

.btn-secondary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.error-message {
    color: var(--text-secondary);
}

/* Use a more specific selector for the modal/utility hidden class to avoid conflict with animated dropdowns */
.modal.hidden, .hidden {
    display: none !important;
}

/* Home Page Search (Quark/Apple Style) */
.home-search-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 60px;
    margin-bottom: 40px;
    width: 100%;
    padding: 0 16px;
}

.quark-search-bar {
    width: 100%;
    max-width: 600px;
}

.search-input-wrapper {
    display: flex;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 24px;
    padding: 14px 20px;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.search-input-wrapper:focus-within {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.search-icon {
    color: var(--text-secondary);
    font-size: 18px;
    margin-right: 12px;
    opacity: 0.7;
}

.search-input-wrapper input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    width: 100%;
    font-weight: 500;
}

.search-input-wrapper input::placeholder {
    color: var(--text-tertiary);
    font-weight: 400;
}

/* Home Menu Grid */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 30px;
    width: 100%;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 16px;
}

.menu-item {
    background-color: transparent;
    padding: 10px 0;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-decoration: none;
    height: auto;
    color: var(--text-primary);
}

.menu-item:hover {
    transform: translateY(-4px);
    background-color: transparent;
}

.menu-item:active {
    transform: scale(0.95);
}

.menu-item img {
    width: 48px; /* Larger, app-icon style */
    height: 48px;
    object-fit: contain;
    margin-bottom: 4px;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.2));
}

.menu-item span {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.2;
    white-space: nowrap;
    font-weight: 500;
}

/* Bottom Nav */
.bottom-nav {
    min-height: var(--nav-height); /* Changed from fixed height to min-height */
    background-color: rgba(0, 0, 0, 0.7); /* Match header transparency */
    backdrop-filter: blur(20px); /* Match header blur */
    display: flex;
    justify-content: space-around;
    align-items: center;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    border-top: 1px solid rgba(255,255,255,0.1);
    z-index: 1000;
    max-width: 1024px; /* Match container */
    margin: 0 auto;
    padding-bottom: env(safe-area-inset-bottom); /* Adapt to iPhone home indicator */
}

.nav-item {
    text-decoration: none;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 10px;
    gap: 4px;
    flex: 1;
    position: relative;
    transition: color 0.2s;
}

.nav-item i {
    font-size: 20px;
}

.nav-item.active {
    color: var(--text-primary);
}

/* Removed center-btn styles */

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

/* Loading Card */
.loading-card {
    /* Match character-card base styles */
    background: var(--card-bg);
    border-radius: 12px;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-secondary);
    /* Ensure height matches character card content roughly */
    min-height: 200px; /* Approximate height of a filled card */
    width: 100%;
    height: 100%;
    box-shadow: none;
}

.loading-spinner {
    font-size: 24px;
    color: var(--primary-color);
    margin-bottom: 0;
}

.loading-text {
    font-size: 13px;
    font-weight: 500;
}

/* Empty State for Character List */
.empty-state {
    grid-column: 1 / -1; /* Span full width of the grid */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    width: 100%;
    background-color: var(--card-bg); /* Added background color */
    border-radius: var(--border-radius); /* Added border radius */
    margin-top: 0; /* Reset margin to 0 to match normal spacing */
    border: 1px solid rgba(255,255,255,0.05); /* Match card border */
}

.empty-state-img {
    /* width: auto; Use natural size */
    max-width: 100%; /* Prevent overflow on small screens */
    height: auto;
    margin-bottom: 16px;
    opacity: 1; /* Changed from 0.8 */
    image-rendering: pixelated; /* Optimize for pixel art */
}

.empty-state-text {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
}

.empty-state-btn {
    min-width: 120px;
    height: 36px;
    font-size: 14px;
    border-radius: 18px; /* Rounded pill shape */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px; /* Added gap for icon spacing */
    /* Colors handled by btn-primary */
    border: none;
    cursor: pointer;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4); /* Lighter dimmer */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.2s, visibility 0.2s;
    backdrop-filter: blur(8px); /* Stronger blur */
    -webkit-backdrop-filter: blur(8px);
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-content {
    background-color: rgba(28, 28, 30, 0.85); /* Apple-style translucent dark */
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border-radius: 16px; /* Smooth corners */
    width: 90%;
    max-width: 360px; /* Smaller, cleaner width */
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    border: 0.5px solid rgba(255, 255, 255, 0.15); /* Thin border */
    transform: scale(1);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    text-align: center;
}

.modal.hidden .modal-content {
    transform: scale(0.95);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 16px;
    padding: 0; /* Remove padding */
    border-bottom: none; /* Remove border */
}

.modal-header h3 {
    margin: 0;
    font-size: 17px; /* Apple title size */
    font-weight: 600;
    color: var(--text-primary);
    width: 100%;
    text-align: center;
}

.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
    aspect-ratio: 1;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
}

.modal-body {
    padding: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-desc {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 16px;
    line-height: 1.4;
}

#import-textarea, #speak-input, #add-character-input {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: var(--text-primary);
    padding: 12px;
    font-size: 16px; /* Larger font for input */
    margin-bottom: 24px;
    font-family: inherit;
    transition: border-color 0.2s, background-color 0.2s;
    text-align: left;
}

#import-textarea:focus, #speak-input:focus, #add-character-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    background-color: rgba(0, 0, 0, 0.4);
}

.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
}

.btn-secondary, .btn-primary {
    height: 44px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.btn-primary {
    background-color: var(--accent-blue);
    color: white;
}

.btn-primary:hover {
    background-color: #0071e3;
}

/* Specific scaling for added characters */
.scene-object .selection-container.char-scale {
    transform: scale(1.2);
    transform-origin: bottom center;
}

/* Full Screen Character Detail Page */
#page-character-detail {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000; /* Above everything else */
    background-color: #000;
    padding: 0;
    display: none; /* Hidden by default */
    flex-direction: column;
}

#page-character-detail.active {
    display: flex;
}

.detail-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('img/bg/school.png');
    background-size: cover;
    background-position: center bottom; /* Anchor to bottom for the floor */
    z-index: -1;
}

.detail-header {
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
    display: grid;
    grid-template-columns: 40px 1fr 1fr; /* Default grid, adjusted below */
    align-items: center;
    position: relative;
    z-index: 50;
    pointer-events: none; /* Allow clicks to pass through */
}

.header-left {
    justify-self: start;
    pointer-events: none;
}

.header-left > * {
    pointer-events: auto;
}

.header-center {
    justify-self: center;
    /* Ensure it doesn't overlap if screen is narrow */
    white-space: nowrap;
    pointer-events: none;
}

.header-center > * {
    pointer-events: auto;
}

.header-right {
    justify-self: end;
    display: flex;
    gap: 12px;
    pointer-events: none;
}

.header-right > * {
    pointer-events: auto;
}

/* Update grid for balanced centering */
.detail-header {
    grid-template-columns: 1fr auto 1fr;
}

/* Common Header Icon Button Style */
.header-icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    border: none;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
    font-size: 16px;
}

.header-icon-btn:hover {
    background: rgba(0, 0, 0, 0.6);
}

/* Ensure icons are centered */
.header-icon-btn i {
    font-size: 18px;
}

.header-btn-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Adjust dropdown position for right-aligned icon buttons */
.header-btn-wrapper .detail-more-dropdown {
    right: -10px; /* Slight offset to align better with edge */
    top: calc(100% + 8px);
}


.scene-selector {
    background: rgba(0, 0, 0, 0.4);
    border: none;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 20px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: white;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    transition: background 0.2s;
}

.scene-selector:hover {
    background: rgba(0, 0, 0, 0.6);
}

.scene-selector i {
    font-size: 12px;
    opacity: 0.7;
}

#scene-dropdown {
    position: absolute;
    top: 100%;
    left: 50%;
    /* Combine transform for centering + animation */
    transform: translateX(-50%) translateY(0) scale(1);
    transform-origin: top center;
    margin-top: 8px;
    background-color: rgba(28, 28, 30, 0.65); /* Match stat-box opacity */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    min-width: 140px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    /* overflow: hidden; Removed to avoid potential backdrop-filter clipping issues */
    
    /* Animation properties */
    opacity: 1;
    visibility: visible;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                visibility 0.25s;
    pointer-events: auto;
}

/* Pseudo-element removed to simplify stacking context and ensure blur works */

#scene-dropdown.hidden {
    display: flex !important;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(-8px) scale(0.92);
    pointer-events: none;
}

.scene-option {
    display: flex;
    align-items: center;
    justify-content: center; /* Center text since no icons yet */
    padding: 12px 16px; /* Match .dropdown-item padding */
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px; /* Match .dropdown-item font size */
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.scene-option:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.scene-option.active {
    background-color: rgba(255, 255, 255, 0.15); /* Slightly lighter for active state */
    font-weight: 600;
}

/* Action Buttons Bar (Flip, Speak, Delete, More) */
.action-buttons {
    position: absolute;
    bottom: -40px; /* Position below character */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    z-index: 100;
    white-space: nowrap;
}

.action-buttons.hidden {
    display: none;
}

.action-btn {
    height: 28px;
    padding: 0 10px;
    border-radius: 14px;
    border: none;
    color: white;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: transform 0.1s;
}

.action-btn:active {
    transform: scale(0.95);
}

.flip-btn {
    background-color: #409EFF; /* Blue */
}

.speak-btn {
    background-color: #F5A623; /* Orange */
}

.delete-btn {
    background-color: #F56C6C; /* Red */
}


/* Hide legacy standalone flip button if present */
.scene-object > .flip-btn {
    display: none !important; 
}
#close-detail-btn {
    border: none;
    /* Other properties handled by .header-icon-btn */
}

.detail-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative; /* Context for absolute positioning */
    padding: 10px 20px 20px 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    pointer-events: none; /* Allow clicks to pass through to scene */
}

.stats-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 5px;
    z-index: 20; /* Ensure stats are above character if they overlap on small screens */
    transition: opacity 0.3s ease;
    pointer-events: none !important; /* Ensure stats don't block scene interaction */
}

/* Force all children of stats container to ignore pointer events */
.stats-container * {
    pointer-events: none !important;
}

.stat-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    pointer-events: none;
}

.stat-box {
    flex: 1;
    background: rgba(28, 28, 30, 0.65); /* Apple-style dark glass */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 12px;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    min-width: 0; /* Prevent overflow */
    max-width: 106px;
    pointer-events: none; /* Allow clicks to pass through */
    user-select: none; /* Prevent text selection */
}

.stat-label {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 13px;
    font-weight: 600;
    color: white;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.character-display {
    position: absolute;
    bottom: 155px; /* Fixed distance from bottom */
    left: 50%;
    width: auto;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10;
    cursor: grab;
    padding: 10px;
    border-radius: 16px;
    transition: background 0.2s;
    /* Do NOT transition transform/left/top as it conflicts with drag */
    user-select: none;
    -webkit-user-select: none;
}

.character-display:active {
    cursor: grabbing;
}



.avatar-wrapper {
    /* No strict size, let the image determine size but scale up if needed */
    /* margin-bottom: -10px; Removed for consistent 8px spacing */
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

.detail-avatar-img {
    /* Scale up the pixel art character */
    image-rendering: pixelated;
}

.name-tag {
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: 8px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px; /* Horizontal padding for text breathing room */
    margin-top: 8px; /* Changed to 8px spacing */
    /* Removed border as requested for "pure black 50%" look */
}

#detail-name-tag,
.name-tag-text {
    color: white;
    font-size: 16px; /* Changed to 16px */
    font-weight: 500;
    line-height: 1; /* Ensure text fits nicely in 24px height */
    font-family: 'Arial', sans-serif; /* Fallback */
}

/* Sky Background Layer */
.sky-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, #069BFF, #FFFFFF);
    z-index: -3; /* Lowest layer */
    pointer-events: none;
}

/* Cloud Container */
.cloud-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 60%; /* Clouds only in upper portion */
    z-index: -2; /* Above sky, below scene (-1) */
    pointer-events: none;
    overflow: hidden;
}

.cloud {
    position: absolute;
    opacity: 0.8;
    background-repeat: no-repeat;
    background-size: contain;
    will-change: transform;
}

@keyframes moveCloud {
    from {
        transform: translateX(100vw);
    }
    to {
        transform: translateX(-150%); /* Move completely off screen to left */
    }
}

/* Landscape/Desktop adjustments */
@media (min-width: 768px) {
    .detail-content {
        max-width: 1024px;
        margin: 0 auto;
        width: 100%;
    }
    
    /* Removed .stat-box, .stat-label, .stat-value overrides to keep mobile size on desktop */
}

/* ==========================================
   More Options & Header Group Styles
   ========================================== */

/* Removed .header-right-group in favor of .header-right flex container */
/* .detail-more-selector is replaced by .header-icon-btn, but keeping ID specific overrides if needed */


.detail-more-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background-color: rgba(28, 28, 30, 0.65); /* Match stat-box opacity */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    min-width: 260px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    
    /* Animation properties */
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    transform-origin: top right;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                visibility 0.25s;
    pointer-events: auto;
}

/* 滚动提示遮罩容器 (需要一个内层包裹，但这里我们用伪元素叠加在父容器上，需要父容器 relative) */
/* 为了让遮罩不随内容滚动，我们需要调整结构。目前的结构是 dropdown 直接 overflow-y: auto */
/* 如果直接加伪元素在 dropdown 上，伪元素会随内容滚动或者被裁剪 */
/* 最佳方案：利用 background-attachment: local, scroll 来实现纯 CSS 的滚动阴影提示 */
.detail-more-dropdown {
    background-color: rgba(28, 28, 30, 0.85); /* 基础背景色 */
}

.detail-more-dropdown.hidden {
    display: flex !important;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px) scale(0.92);
    pointer-events: none;
}

.detail-more-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detail-more-label {
    font-size: 12px;
    color: #dcdde1; /* text-secondary */
    font-weight: 600;
}

.detail-more-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Face Grid */
.face-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.face-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    color: #f5f6fa; /* text-primary */
    padding: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.face-btn.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.face-btn.loading {
    opacity: 0.7;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.15);
}

/* Animal Grid */
.animal-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.animal-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 4px;
    cursor: pointer;
    transition: all 0.2s;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.animal-btn img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

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

/* Custom Add Grid */
.custom-add-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 4px;
}

.custom-add-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: white;
    padding: 0 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: row; /* 水平排列 */
    align-items: center;
    justify-content: center;
    gap: 8px; /* 图标与文字间距 */
    height: 40px; /* 减小高度，更紧凑 */
}

.custom-add-btn i {
    font-size: 14px; /* 缩小图标 */
    opacity: 0.9;
    margin-bottom: 0; /* 移除底部间距 */
}

.custom-add-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.custom-add-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: #f5f6fa;
    padding: 10px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
}

.custom-add-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

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

/* Scene Object */
.scene-object {
    position: absolute;
    cursor: grab;
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.scene-object:active {
    cursor: grabbing;
}

.scene-object-img {
    display: block;
    image-rendering: pixelated; /* Keep pixel art crisp */
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.scene-object-img.flipped {
    transform: scaleX(-1);
}

.character-display.editing, .scene-object.editing,
.character-display.dragging, .scene-object.dragging {
    z-index: 100;
}

/* Detail Page Toggle Switch */
.detail-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.detail-switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.detail-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.2);
  -webkit-transition: .4s;
  transition: .4s;
  border-radius: 34px;
}

.detail-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .detail-slider {
  background-color: var(--accent-blue);
}

input:focus + .detail-slider {
  box-shadow: 0 0 1px var(--accent-blue);
}

input:checked + .detail-slider:before {
  -webkit-transform: translateX(20px);
  -ms-transform: translateX(20px);
  transform: translateX(20px);
}

/* Rounded sliders */
.detail-slider.round {
  border-radius: 34px;
}

.detail-slider.round:before {
  border-radius: 50%;
}

/* Ensure scene dropdown matches more dropdown style */
.scene-dropdown {
    z-index: 1000;
}

/* ==========================================
   Character Edit Mode Styles
   ========================================== */

.selection-container {
    position: relative;
    display: inline-block;
    /* Scale the entire container (image + border) */
    transform: scale(1);
    transform-origin: bottom center;
}

/* Specific scale for character avatar, keeping other scene objects at scale(1) */
.character-display .selection-container {
    transform: scale(1.2);
}

.detail-avatar-img {
    display: block;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    /* No scale here, it's on the container */
}

.detail-avatar-img.flipped {
    transform: scaleX(-1);
}

.selection-border {
    position: absolute;
    top: 0; /* Tight fit */
    left: 0;
    right: 0;
    bottom: 0;
    /* Use thinner border so it looks crisp when scaled */
    border: 1.5px solid #007AFF;
    pointer-events: none; /* Allow clicks to pass through */
    z-index: 10;
}

.selection-border.hidden {
    display: none;
}

.handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: white;
    border: 1px solid #007AFF;
    pointer-events: auto; /* Handles must be interactive */
    z-index: 20; /* Above border */
}

.handle-tl { top: -5px; left: -5px; cursor: nwse-resize; }
.handle-tr { top: -5px; right: -5px; cursor: nesw-resize; }
.handle-bl { bottom: -5px; left: -5px; cursor: nesw-resize; }
.handle-br { bottom: -5px; right: -5px; cursor: nwse-resize; }

.flip-btn {
    position: absolute;
    bottom: -36px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 122, 255, 0.9); /* System Blue */
    color: white;
    border: none;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    z-index: 20;
    transition: all 0.2s;
}

.flip-btn:hover {
    background: #0062cc;
    transform: translateX(-50%) scale(1.05);
}

.flip-btn:active {
    transform: translateX(-50%) scale(0.95);
}

.flip-btn.hidden {
    display: none;
}

/* Ensure avatar wrapper allows positioning */
.avatar-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

/* Action Buttons Container for Scene Objects */
.action-buttons {
    position: absolute;
    bottom: -46px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 20;
    pointer-events: auto; /* Ensure clickable */
}

.action-buttons.hidden {
    display: none;
}

/* Delete Button Style */
.delete-btn {
    background: #ff3b30; /* iOS Red */
    color: white;
    border: none;
    border-radius: 20px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    transition: all 0.2s;
}

.delete-btn:hover {
    background: #ff453a;
    transform: scale(1.05);
}

.delete-btn:active {
    transform: scale(0.95);
}

/* Override Flip Button when inside Action Buttons */
.action-buttons .flip-btn {
    position: static;
    transform: none;
    bottom: auto;
    left: auto;
    display: flex; /* Ensure flex is set */
}

/* Scene Scroll View & Mobile Scrolling */
#scene-scroll-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0; /* Behind everything */
    overflow: hidden; /* Default for desktop */
}

.scene-track {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0 auto;
}



/* Mobile Scrolling Logic */
@media (max-width: 767px) {
    #scene-scroll-view {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
    }
    
    #scene-scroll-view::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }

    .scene-track {
        /* Force desktop width on mobile to enable scrolling */
        width: 1024px; 
        height: 100%;
    }
    
    /* Ensure background covers the full track */
    .detail-background {
        width: 100%;
        height: 100%;
        background-size: cover;
        background-position: center bottom;
    }
}

/* Touch action for draggable elements to improve performance */
.character-display, .scene-object {
    touch-action: none;
}

/* Ensure buttons are clickable */
.action-buttons button, .flip-btn {
    touch-action: manipulation;
    cursor: pointer;
}

/* Speak Button & Speech Bubble Styles */
.speak-btn {
    position: absolute;
    bottom: -36px;
    left: 50%;
    transform: translateX(-50%);
    background: #FF9500;
    color: white;
    border: none;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    z-index: 20;
    transition: all 0.2s;
}

.speak-btn:hover {
    background: #E08900;
    transform: scale(1.05);
}

.speak-btn:active {
    transform: scale(0.95);
}

.speak-btn.hidden {
    display: none;
}

/* Inside .action-buttons, reset positioning */
.action-buttons .speak-btn {
    position: static;
    transform: none;
    bottom: auto;
    left: auto;
}

/* Speech Bubble */
.speech-bubble {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 0px;
    pointer-events: none;
    min-width: 40px;
    max-width: 200px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.speech-bubble.hidden {
    display: none;
}

.bubble-content {
    /* 
     * 优化气泡样式 (User Feedback v7 - Final Polish)
     * 1. 彻底解决“文字多时有缝隙，文字少时正常”的矛盾：
     *    - 问题根源：border-image-slice: 8 fill 在大尺寸拉伸时，中间的 fill 部分可能会出现渲染裂缝
     *    - 解决方案：移除 fill 关键字，完全依赖伪元素背景层。
     *    - 这样边框只负责画边框，背景只负责画背景，互不干扰，彻底消除缝隙。
     * 2. 进一步收紧边距：
     *    - padding 减小到 0px 4px，让文字更贴合上下边框
     *    - 视觉上会更像原版游戏的紧凑气泡
     */
    position: relative;
    z-index: 1;
    
    border: 8px solid transparent; 
    border-image-source: url('img/chatBubble.png');
    border-image-slice: 8; /* 移除 fill，只保留边框切割 */
    border-image-repeat: stretch; 
    
    padding: 0px 4px; /* 进一步减小内边距 */
    color: black;
    font-size: 12px;
    line-height: 1.2;
    text-align: center;
    word-break: break-all;
    min-height: 20px; /* 允许更小的高度 */
    min-width: 24px;
    box-sizing: border-box;
    
    white-space: pre-wrap; 
    max-width: 120px;
    width: max-content;
    display: block;
    
    background: none;
    box-shadow: none;
}

.bubble-content::before {
    content: "";
    position: absolute;
    z-index: -1;
    
    /* 
     * 背景层逻辑微调：
     * 确保背景色能够填满整个内容区域并延伸到边框下方
     * top/bottom/left/right: -4px 意味着背景延伸到边框宽度的 50% 处
     * 配合 border-radius: 3px (稍微减小圆角) 确保不溢出外层像素角
     */
    top: -4px; 
    bottom: -4px; 
    left: -4px; 
    right: -4px;
    
    background-color: #fff;
    border-radius: 3px; 
}

.bubble-tail {
    /* 
     * 优化气泡底部括弧 (User Feedback v8 - Enlarge Tail)
     * 稍微放大括弧尺寸，使其与气泡整体比例更协调
     * 13px -> 16px
     * 9px -> 11px
     * 同时微调 margin-top 确保连接处自然
     */
    width: 16px;
    height: 11px;
    background: url('img/chatBottom.png') no-repeat center top;
    background-size: contain;
    margin-top: -4px; /* 稍微增加负边距，让连接处更紧密 */
    position: relative;
    z-index: 101;
}

/* Modal Input Style */
#speak-input {
    width: 100%;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 0 12px;
    font-size: 14px;
    margin-bottom: 20px;
    font-family: inherit;
}

#speak-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Draggable Sub-elements (Name Tag, Speech Bubble) */
.draggable-sub {
    position: absolute;
    cursor: grab;
    z-index: 100; /* High enough to be on top */
    transition: transform 0.2s ease, background 0.2s ease;
}

.draggable-sub:active {
    cursor: grabbing;
}

.draggable-sub.selected {
    outline: 2px dashed #007AFF;
    outline-offset: 2px;
}

.delete-btn-sub {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ff3b30;
    color: white;
    border: 2px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 110;
}

.delete-btn-sub:hover {
    background: #cc2d24;
    transform: scale(1.1);
}

.delete-btn-sub.hidden {
    display: none;
}

/* ==========================================
   Custom Cursors (Global Override)
   ========================================== */

/* 1. 全局默认 & 点击状态：统一使用 aero_link.ani，提供 aero_arrow.cur 作为静态回退 */
/* 使用 * 通配符强制覆盖所有元素的默认光标 */
html, body, * {
    cursor: url('img/cursor/aero_link.ani'), url('img/cursor/aero_arrow.cur'), auto !important;
}

/* 2. 文本输入：保持系统文本光标 */
input[type="text"], input[type="number"], input[type="password"], 
input[type="email"], input[type="search"], textarea, [contenteditable="true"] {
    cursor: text !important;
}

/* 3. 拖拽相关 (保持之前的逻辑，避免拖拽时无反馈) */
/* 可拖拽状态 (Hover) */
.account-card, 
.account-card .account-info, 
.account-card .account-name,
.mini-char-card, 
.sortable-handle,
.draggable-sub {
    cursor: url('img/cursor/hand_open.cur'), grab !important;
}

/* 抓取中状态 (Active/Dragging) */
.account-card:active, 
.mini-char-card:active,
.sortable-drag, 
.sortable-fallback, 
.draggable-sub:active,
body.is-dragging,
body.is-dragging * { 
    cursor: url('img/cursor/grab.ani'), url('img/cursor/grab.cur'), grabbing !important;
}
