/* ============================================
   愛小說 - 全站樣式
   深色主題，暖色調點綴
   ============================================ */

:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-card-hover: #1a2744;
    --bg-input: #0d1b2a;
    --bg-chat: #111827;
    --bg-message: #1e293b;
    --bg-cot: #0c1322;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #f59e0b;
    --accent-hover: #fbbf24;
    --accent-dim: rgba(245, 158, 11, 0.15);
    --border: #1e293b;
    --border-light: #334155;
    --danger: #ef4444;
    --success: #22c55e;
    --info: #3b82f6;
    --pink: #ec4899;
    --purple: #a855f7;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ============ 頂部導航 ============ */

.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 24px;
    background: rgba(15, 15, 26, 0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.navbar .logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}

.navbar .logo span {
    color: var(--text-primary);
    font-weight: 400;
}

.search-bar {
    flex: 1;
    max-width: 480px;
    position: relative;
}

.search-bar input {
    width: 100%;
    padding: 8px 16px 8px 40px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border var(--transition);
}

.search-bar input:focus {
    border-color: var(--accent);
}

.search-bar .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.nav-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:hover {
    background: var(--bg-card);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #000;
}

.btn-ghost {
    border: none;
    padding: 8px 12px;
}

/* ============ 分類標籤列 ============ */

.tag-bar {
    display: flex;
    gap: 8px;
    padding: 12px 24px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
}

.tag-bar::-webkit-scrollbar { display: none; }

.tag-pill {
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.tag-pill:hover, .tag-pill.active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* ============ 故事卡片網格 ============ */

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    padding: 24px;
}

.story-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid transparent;
}

.story-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: var(--accent);
}

.story-card .card-cover {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    background: var(--bg-secondary);
}

.story-card .card-body {
    padding: 14px;
}

.story-card .card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.story-card .card-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.story-card .card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.story-card .card-tag {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

/* ============ 聊天頁佈局 ============ */

.chat-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

.chat-sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
}

.chat-sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.chat-sidebar-bottom {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding: 8px;
}

.member-panel-compact {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.member-compact-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.member-avatar-sm {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.member-name-sm {
    font-size: 0.8rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member-points-sm {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.btn-recharge {
    font-size: 0.7rem;
    padding: 2px 8px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    margin-left: auto;
}

.btn-recharge:hover {
    background: var(--accent-hover);
}

.chat-sidebar.collapsed {
    width: 48px;
}

.chat-sidebar.collapsed .sidebar-brand {
    display: none;
}

.chat-sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 12px 8px;
}

.chat-sidebar.collapsed .chat-sidebar-scroll,
.chat-sidebar.collapsed .chat-sidebar-bottom {
    display: none;
}

.chat-sidebar .sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-sidebar .story-info {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.chat-sidebar .story-info h3 {
    font-size: 0.95rem;
    margin-bottom: 8px;
}

.chat-sidebar .story-info p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.chat-sidebar .story-info p.story-desc-clamped {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.story-desc-toggle {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 4px 0 0;
    display: block;
    width: 100%;
    text-align: center;
}

.story-desc-toggle:hover {
    text-decoration: underline;
}

/* ==================== 評分 + 評論入口（sidebar） ==================== */

.rating-comment-entry {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.star-rating-display {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 8px;
}

.star-rating-display .star {
    font-size: 1.3rem;
    color: var(--text-muted);
    user-select: none;
}

.star-rating-display .star.active {
    color: var(--accent);
}

.star-avg-number {
    margin-left: 6px;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--accent);
}

.comment-entry-btn {
    display: block;
    width: 100%;
    padding: 8px 0;
    background: none;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.comment-entry-btn:hover {
    background: var(--accent);
    color: #000;
}

/* ==================== 評論 Modal ==================== */

.comment-overlay {
    z-index: 350;
}

.comment-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    width: min(560px, 90vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.comment-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 24px 12px;
    border-bottom: 1px solid var(--border);
}

.comment-panel-header h3 {
    font-size: 1.1rem;
    margin-bottom: 2px;
}

.comment-panel-header p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.comment-input-area {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.comment-star-select {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.comment-star-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.star-rating-select {
    display: flex;
    gap: 2px;
}

.star-rating-select .star {
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s;
    user-select: none;
}

.star-rating-select .star.active {
    color: var(--accent);
}

.star-rating-select .star:hover,
.star-rating-select .star.hover {
    color: var(--accent-hover);
}

.comment-input-row {
    display: flex;
    gap: 8px;
}

.comment-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 0.85rem;
    resize: none;
    font-family: inherit;
}

.comment-input:focus {
    outline: none;
    border-color: var(--accent);
}

.comment-submit-btn {
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0 16px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.comment-submit-btn:hover {
    background: var(--accent-hover);
}

.comment-submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.comment-list {
    overflow-y: auto;
    padding: 8px 16px;
    flex: 1;
    min-height: 0;
}

.comment-loading, .comment-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 24px;
}

.comment-item {
    display: flex;
    gap: 10px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--border);
}

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

.comment-reply {
    margin-left: 16px;
    padding-left: 12px;
    border-left: 2px solid var(--border);
    border-bottom: none;
    padding-top: 8px;
    padding-bottom: 4px;
}

.comment-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.comment-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.comment-body {
    flex: 1;
    min-width: 0;
}

.comment-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.comment-nickname {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.comment-rounds {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 8px;
}

.comment-content {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
    word-break: break-word;
    margin-bottom: 4px;
}

.comment-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
}

.comment-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.comment-like-btn,
.comment-reply-btn,
.comment-delete-btn {
    background: none;
    border: none;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
}

.comment-like-btn:hover { color: var(--pink); }
.comment-like-btn.liked { color: var(--pink); }
.comment-reply-btn:hover { color: var(--accent); }
.comment-delete-btn:hover { color: var(--danger); }

.comment-replies {
    margin-top: 4px;
}

.comment-reply-input {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: flex-end;
}

.comment-reply-input textarea {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 8px 10px;
    font-size: 0.8rem;
    resize: none;
    font-family: inherit;
}

.comment-reply-input textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.comment-reply-submit {
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.comment-load-more {
    display: block;
    width: calc(100% - 32px);
    margin: 4px 16px 12px;
    padding: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    flex-shrink: 0;
}

.comment-load-more:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 8px 8px;
}

.member-panel {
    padding: 12px;
    background:
        radial-gradient(circle at top left, rgba(245, 158, 11, 0.12), transparent 45%),
        linear-gradient(180deg, rgba(15, 15, 26, 0.96), rgba(10, 10, 18, 0.98));
}

.member-card {
    border: 1px solid rgba(245, 158, 11, 0.18);
    border-radius: 20px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.03);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.member-top {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.member-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.85), rgba(251, 191, 36, 0.5));
    color: #140f06;
    font-weight: 800;
    font-size: 1rem;
    flex-shrink: 0;
}

.member-meta {
    min-width: 0;
}

.member-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

.member-email {
    font-size: 0.75rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
}

.member-points {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.15);
}

.member-points-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.member-points strong {
    color: var(--accent);
    font-size: 1.15rem;
}

.member-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.member-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border-radius: 12px;
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition);
}

.member-action-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.member-action-primary {
    background: rgba(245, 158, 11, 0.14);
    color: var(--accent);
    border-color: rgba(245, 158, 11, 0.22);
}

.session-list .session-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.session-item {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: background var(--transition);
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.session-item:hover { background: var(--bg-card); }
.session-item.active {
    background: var(--accent-dim);
    color: var(--accent);
}

.session-item-content {
    min-width: 0;
    flex: 1;
}

.session-item-preview {
    font-size: 0.85em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-item-time {
    font-size: 0.75em;
    color: var(--text-muted);
}

.session-item-delete {
    width: 36px;
    height: 36px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    border-radius: 10px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition);
}

.session-item-delete svg {
    width: 18px;
    height: 18px;
    display: block;
    margin: 0 auto;
}

.session-item-delete:hover {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.12);
}

.sidebar-toggle {
    display: none;
    position: fixed;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 150;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 1rem;
    padding: 8px 4px;
    cursor: pointer;
    transition: all var(--transition);
}

.sidebar-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* 手機版側邊欄遮罩 */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
}

/* ============ 聊天主區域 ============ */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: rgba(15, 15, 26, 0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

/* 手機版返回按鈕（桌面版隱藏，sidebar 已有返回） */
.chat-back-btn {
    display: none;
    font-size: 1.2rem;
    color: var(--text-secondary);
    padding: 4px 8px;
    transition: color var(--transition);
    text-decoration: none;
}

.chat-back-btn:hover {
    color: var(--accent);
}

.sidebar-collapse-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    transition: color var(--transition);
}

.sidebar-collapse-btn:hover { color: var(--accent); }

.chat-header .title {
    font-size: 1rem;
    font-weight: 600;
    flex: 1;
    color: var(--text-primary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
}

/* ============ 開場白區域 ============ */

.opening-layout {
    max-width: 800px;
    margin: 0 auto 32px;
}

.opening-hero {
    text-align: center;
    margin-bottom: 18px;
}

.opening-title {
    font-size: clamp(1.85rem, 3vw, 2.4rem);
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: 0.03em;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.opening-subtitle {
    margin: 0;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
}

.opening-grid {
    display: grid;
    gap: 14px;
}

.opening-layout-tabs .opening-grid {
    display: none;
}

.opening-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
    overflow-x: auto;
}

.opening-tab-btn {
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.92rem;
    font-weight: 600;
    padding: 10px 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: color var(--transition), border-color var(--transition);
}

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

.opening-tab-btn.is-active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.opening-tab-panels {
    margin-bottom: 12px;
}

.opening-tab-panel {
    display: none;
}

.opening-tab-panel.is-active {
    display: block;
}

.opening-tab-footer {
    max-width: 800px;
    margin: 0 auto 4px;
}

.opening-start-btn {
    margin-top: 0;
}

.opening-card {
    background: var(--bg-message);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.opening-card-title {
    margin: 0 0 10px;
    color: var(--accent);
    font-size: 1rem;
    font-weight: 700;
}

.opening-card-body {
    color: var(--text-primary);
    font-size: 0.95rem;
    line-height: 1.8;
    white-space: pre-line;
}

.opening-card-body em {
    color: var(--accent);
    font-style: normal;
}

.opening-card-body-html {
    white-space: normal;
}

.opening-character-media {
    width: min(220px, 100%);
    aspect-ratio: 3 / 4;
    margin: 2px auto 12px;
    border-radius: 12px;
    border: 1px solid var(--border-light);
    overflow: hidden;
    background: var(--bg-card);
}

.opening-character-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.opening-card-setup .opening-card-hint {
    margin: 0 0 12px;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.opening-card-setup .setup-form {
    max-width: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
}

/* ============ 路線卡片 ============ */

.route-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
    max-width: 800px;
    margin: 0 auto 32px;
}

.route-card {
    background: var(--bg-message);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: left;
}

.route-card .route-title {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.route-card .route-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ============ 角色設定表單 ============ */

.setup-form {
    max-width: 800px;
    margin: 0 auto 32px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
}

.setup-form .setup-title {
    text-align: center;
    color: var(--accent);
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.setup-form .setup-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 24px;
}

.setup-field {
    margin-bottom: 20px;
}

.setup-field .field-label {
    font-size: 0.9rem;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.setup-options {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.setup-option {
    padding: 8px 20px;
    border: 1px solid var(--border-light);
    border-radius: 24px;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
}

.setup-option:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.setup-option.selected {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 600;
}

.setup-option.gender-male.selected {
    background: var(--info);
    border-color: var(--info);
}

.setup-option.gender-female.selected {
    background: var(--pink);
    border-color: var(--pink);
}

.setup-input {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border var(--transition);
}

.setup-input:focus {
    border-color: var(--accent);
}

.setup-input::placeholder {
    color: var(--text-muted);
}

.setup-submit {
    width: 100%;
    padding: 14px;
    margin-top: 8px;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(245, 158, 11, 0.05));
    color: var(--accent);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 1px;
}

.setup-submit:hover {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.3), rgba(245, 158, 11, 0.1));
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.2);
}

.setup-submit:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ============ 對話訊息 ============ */

.message {
    max-width: 800px;
    margin: 0 auto 20px;
}

.message-ai {
    background: var(--bg-message);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.message-user {
    background: var(--accent-dim);
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-left: 60px;
}

.message-user::before {
    content: '🎮 你';
    display: block;
    font-size: 0.75rem;
    color: var(--accent);
    margin-bottom: 6px;
    font-weight: 600;
}

/* ============ 思維鏈折疊 ============ */

.cot-block {
    margin-bottom: 16px;
}

.cot-block details {
    background: var(--bg-cot);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.cot-block summary {
    padding: 10px 16px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.8rem;
    user-select: none;
    transition: color var(--transition);
    list-style: none;
}

.cot-block summary::-webkit-details-marker { display: none; }

.cot-block summary::before {
    content: '▸ ';
    transition: transform var(--transition);
    display: inline-block;
}

.cot-block details[open] summary::before {
    content: '▾ ';
}

.cot-block summary:hover { color: var(--accent); }

.cot-block .cot-content {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.7;
    white-space: pre-line;
}

/* ============ 數值狀態條 ============ */

.stats-panel {
    margin-bottom: 16px;
    padding: 16px;
    background: var(--bg-cot);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
}

.stats-scene-header {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.stats-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
    white-space: pre-wrap;
    margin-top: 10px;
}

.route-tag {
    text-align: center;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.route-tag {
    display: inline-block;
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    color: var(--success);
    background: rgba(34, 197, 94, 0.08);
    padding: 4px 12px;
    border-radius: 12px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 70px;
}

.stat-bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
}

.stat-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.stat-fill.trust { background: linear-gradient(90deg, #22c55e, #86efac); }
.stat-fill.fear { background: linear-gradient(90deg, #ef4444, #fca5a5); }
.stat-fill.intimacy { background: linear-gradient(90deg, #ec4899, #f9a8d4); }
.stat-fill.self { background: linear-gradient(90deg, #a855f7, #d8b4fe); }
.stat-fill.dependency { background: linear-gradient(90deg, #f59e0b, #fde68a); }
.stat-fill.default { background: linear-gradient(90deg, #3b82f6, #93c5fd); }

.stat-value {
    font-size: 0.7rem;
    color: var(--text-secondary);
    min-width: 24px;
    text-align: right;
}

.stat-change {
    font-size: 0.65rem;
    font-weight: 600;
}

.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--danger); }

/* ============ 角色正文 ============ */

.story-text {
    font-size: 1rem;
    line-height: 1.9;
    color: var(--text-primary);
    white-space: pre-line;
    margin-bottom: 16px;
}

.story-text .dialogue {
    color: var(--text-primary);
}

/* ============ 內心話（可折疊） ============ */

.inner-thought-block {
    margin: 12px 0;
}

.inner-thought-block details {
    background: rgba(168, 85, 247, 0.06);
    border: 1px solid rgba(168, 85, 247, 0.15);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.inner-thought-block summary {
    padding: 10px 16px;
    cursor: pointer;
    color: rgba(216, 180, 254, 0.8);
    font-size: 0.85rem;
    list-style: none;
    user-select: none;
}

.inner-thought-block summary::-webkit-details-marker { display: none; }

.inner-thought-block .thought-preview {
    color: rgba(216, 180, 254, 0.5);
    font-style: italic;
}

.inner-thought-block .expand-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.6;
}

.inner-thought-block details[open] .expand-hint { display: none; }

.inner-thought {
    background: transparent;
    padding: 0 16px 12px;
    font-style: italic;
    color: rgba(216, 180, 254, 0.9);
    font-size: 0.9rem;
    line-height: 1.7;
    white-space: pre-line;
}

/* ============ 狀態總結區（可折疊） ============ */

.status-block {
    margin: 12px 0;
}

.status-block details {
    background: rgba(100, 116, 139, 0.08);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.status-block summary {
    padding: 10px 16px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.85rem;
    list-style: none;
    user-select: none;
}

.status-block summary::-webkit-details-marker { display: none; }

.status-block .status-round {
    background: rgba(100, 116, 139, 0.2);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-block .expand-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.6;
}

.status-block details[open] .expand-hint { display: none; }

.status-content {
    padding: 0 16px 12px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.6;
    white-space: pre-line;
}

/* ============ 選項按鈕 ============ */

.options-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.option-btn {
    width: 100%;
    padding: 12px 20px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    transition: all var(--transition);
    line-height: 1.5;
}

.option-btn:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.1);
}

.option-btn .option-num {
    color: var(--accent);
    font-weight: 600;
    margin-right: 8px;
}

.message-usage {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed rgba(245, 158, 11, 0.18);
    color: rgba(245, 158, 11, 0.92);
    font-size: 0.82rem;
    line-height: 1.5;
}

.options-free-hint {
    text-align: center;
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.8rem;
    padding: 6px 0 2px;
}

/* ============ 輸入區域 ============ */

.chat-input-area {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.chat-input-wrap {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    resize: none;
    min-height: 44px;
    max-height: 150px;
    line-height: 1.5;
    font-family: inherit;
    transition: border var(--transition);
}

.chat-input:focus {
    border-color: var(--accent);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: #000;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

/* ============ 載入動畫 ============ */

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* ============ 內容警告 ============ */

.content-warning {
    max-width: 800px;
    margin: 0 auto 24px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.content-warning .warning-title {
    color: var(--danger);
    font-weight: 600;
    margin-bottom: 4px;
}

.content-warning .warning-text {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ============ 滾動條 ============ */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============ 響應式 ============ */

/* --- 平板 & 大手機（≤768px）--- */
@media (max-width: 768px) {
    /* 導航列 */
    .navbar {
        padding: 10px 12px;
        gap: 8px;
    }

    .search-bar {
        display: none;
    }

    .nav-actions .btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    /* 標籤列 */
    .tag-bar {
        padding: 8px 12px;
    }

    /* 畫廊 */
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 12px;
    }

    .story-card .card-body {
        padding: 10px;
    }

    /* 聊天側邊欄：手機上預設隱藏 */
    .chat-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        height: 100dvh;
        z-index: 200;
        width: 280px;
        transition: transform 0.3s ease, opacity 0.3s ease;
    }

    .chat-sidebar.collapsed {
        transform: translateX(-100%);
        width: 280px;
        opacity: 0;
        pointer-events: none;
    }

    /* 手機版顯示返回按鈕 */
    .chat-back-btn {
        display: block;
    }

    /* 聊天區域 */
    .chat-header {
        padding: 10px 12px;
    }

    .chat-messages {
        padding: 12px;
    }

    .message {
        max-width: 100%;
    }

    .message-ai {
        padding: 14px;
    }

    .message-user {
        margin-left: 20px;
        padding: 12px 14px;
    }

    /* 開場白 */
    .opening-layout {
        max-width: 100%;
    }

    .opening-title {
        font-size: 1.6rem;
    }

    .opening-grid {
        gap: 10px;
    }

    .opening-tabs {
        gap: 2px;
    }

    .opening-tab-btn {
        font-size: 0.86rem;
        padding: 9px 10px;
    }

    .opening-card {
        padding: 14px;
    }

    .opening-card-body {
        font-size: 0.93rem;
    }

    .opening-character-media {
        width: min(190px, 100%);
    }

    /* 路線卡 */
    .route-cards {
        grid-template-columns: 1fr;
        max-width: 100%;
    }

    /* 設定表單 */
    .setup-form {
        max-width: 100%;
        padding: 20px 16px;
    }

    /* 輸入區域 */
    .chat-input-area {
        padding: 8px 12px;
    }

    .chat-input-wrap {
        max-width: 100%;
    }

    /* 內容警告 */
    .content-warning {
        max-width: 100%;
    }

    /* 選項按鈕 */
    .option-btn {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .history-panel {
        width: 96vw;
        max-height: 88vh;
    }

    .history-panel-header,
    .history-toolbar,
    .history-grid {
        padding-left: 16px;
        padding-right: 16px;
    }

    .history-grid {
        grid-template-columns: 1fr;
    }
}

/* --- 手機（≤480px）--- */
@media (max-width: 480px) {
    /* 導航列 */
    .navbar {
        padding: 8px 10px;
        gap: 6px;
    }

    .navbar .logo {
        font-size: 1.25rem;
    }

    /* 畫廊：手機上保持兩欄，卡片更緊湊 */
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 8px;
    }

    .story-card .card-body {
        padding: 8px;
    }

    .story-card .card-title {
        font-size: 0.85rem;
        margin-bottom: 4px;
    }

    .story-card .card-desc {
        font-size: 0.7rem;
        -webkit-line-clamp: 2;
        margin-bottom: 6px;
    }

    .story-card .card-tag {
        font-size: 0.6rem;
        padding: 1px 6px;
    }

    /* 聊天訊息 */
    .message-user {
        margin-left: 12px;
    }

    .message-ai {
        padding: 12px;
    }

    /* 開場白 */
    .opening-title {
        font-size: 1.35rem;
    }

    .opening-subtitle {
        font-size: 0.92rem;
    }

    .opening-card {
        padding: 12px;
    }

    .opening-tabs {
        margin-left: -2px;
        margin-right: -2px;
    }

    .opening-tab-btn {
        font-size: 0.82rem;
        padding: 8px 8px;
    }

    .opening-card-body {
        font-size: 0.9rem;
        line-height: 1.7;
    }

    .opening-character-media {
        width: min(160px, 100%);
    }

    /* 設定表單 */
    .setup-form {
        padding: 16px 12px;
    }

    .setup-form .setup-title {
        font-size: 1rem;
    }

    .setup-option {
        padding: 6px 14px;
        font-size: 0.85rem;
    }

    /* 數值面板 */
    .stats-panel {
        padding: 12px;
    }

    .stat-label {
        min-width: 55px;
        font-size: 0.7rem;
    }

    /* 正文字體 */
    .story-text {
        font-size: 0.95rem;
        line-height: 1.8;
    }

    /* 內心話 */
    .inner-thought {
        font-size: 0.85rem;
    }

    /* 設定面板 */
    .settings-panel {
        width: 95%;
        padding: 16px;
    }

    .setting-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    /* 空狀態 */
    .empty-state {
        padding: 40px 16px;
    }
}

/* ============ 設定面板 ============ */

.settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
}

.settings-overlay.open { display: flex; }

.settings-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.settings-panel h3 {
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.setting-row label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.setting-row select, .setting-row input[type="text"] {
    padding: 6px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.history-overlay {
    z-index: 320;
}

.history-panel {
    width: min(1120px, 92vw);
    max-height: 84vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-radius: 24px;
    border: 1px solid var(--border);
    background:
        radial-gradient(circle at top left, rgba(245, 158, 11, 0.08), transparent 35%),
        var(--bg-secondary);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.history-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.history-panel-header h3 {
    margin: 0 0 6px;
    font-size: 1.3rem;
}

.history-panel-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.history-close {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: all var(--transition);
}

.history-close:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.history-toolbar {
    padding: 16px 24px 0;
}

.history-search-input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text-primary);
    font-size: 0.92rem;
    outline: none;
}

.history-search-input:focus {
    border-color: var(--accent);
}

.history-grid {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px 24px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    align-content: start;
}

.history-card {
    overflow: hidden;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.history-card:hover {
    transform: translateY(-3px);
    border-color: rgba(245, 158, 11, 0.28);
    box-shadow: 0 18px 30px rgba(0, 0, 0, 0.28);
}

.history-card-cover {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.16), rgba(59, 130, 246, 0.12));
}

.history-card-body {
    padding: 14px;
}

.history-card-title {
    font-size: 0.98rem;
    font-weight: 700;
    line-height: 1.45;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-card-author,
.history-card-preview,
.history-card-time {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.history-card-author {
    margin-bottom: 8px;
}

.history-card-preview {
    min-height: 2.8em;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 10px;
}

.history-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.history-card-badge {
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    color: var(--accent);
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.18);
}

/* ============ 會員中心頁 ============ */

.profile-container {
    max-width: 800px;
    margin: 40px auto;
    padding: 0 20px;
}
.profile-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 32px;
    padding: 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8em;
    color: #000;
    font-weight: 700;
    flex-shrink: 0;
}
.profile-avatar img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }
.profile-info { flex: 1; }
.profile-name { font-size: 1.3em; font-weight: 600; margin-bottom: 4px; }
.profile-email { color: var(--text-secondary); font-size: 0.9em; }
.profile-points { text-align: right; }
.points-value { font-size: 2em; font-weight: 700; color: var(--accent); }
.points-label { color: var(--text-secondary); font-size: 0.85em; }
.profile-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}
.profile-tab {
    padding: 12px 20px;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-size: 0.95em;
    transition: var(--transition);
}
.profile-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }
.tab-content.active { display: block; }
.section-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.section-card h3 { font-size: 1em; color: var(--text-secondary); margin-bottom: 16px; font-weight: 500; }
.log-list { display: flex; flex-direction: column; gap: 8px; }
.log-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9em;
}
.log-item:last-child { border-bottom: none; }
.log-desc { color: var(--text-primary); }
.log-date { color: var(--text-secondary); font-size: 0.85em; }
.log-amount-pos { color: #4ade80; font-weight: 600; }
.log-amount-neg { color: var(--danger); font-weight: 600; }
.referral-code-box {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}
.referral-code-text { font-family: monospace; font-size: 1.4em; letter-spacing: 3px; color: var(--accent); flex: 1; }
.btn-copy {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85em;
}
.btn-copy:hover { border-color: var(--accent); }
.referral-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-item { background: var(--bg-input); border-radius: var(--radius-sm); padding: 16px; text-align: center; }
.stat-value { font-size: 1.6em; font-weight: 700; color: var(--accent); }
.stat-label { color: var(--text-secondary); font-size: 0.85em; margin-top: 4px; }
.empty-hint { text-align: center; color: var(--text-secondary); padding: 24px; font-size: 0.9em; }
.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }
.page-btn {
    padding: 5px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85em;
}
.page-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.9em;
    z-index: 9999;
}
.toast-success { background: #16a34a; color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

/* ============ 首頁側邊欄佈局 ============ */

.app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: width 0.3s ease;
    overflow: hidden;
}

.app-sidebar.collapsed {
    width: 64px;
}

.app-sidebar .sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    overflow: hidden;
}

.brand-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

.brand-text {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
    overflow: hidden;
}

/* 側邊欄使用者區塊 */
.app-sidebar .sidebar-user {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(245,158,11,0.85), rgba(168,85,247,0.7));
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    min-width: 0;
    overflow: hidden;
}

.sidebar-username {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-points {
    font-size: 0.75rem;
    color: var(--accent);
    white-space: nowrap;
}

/* 側邊欄導航 */
.app-sidebar .sidebar-nav {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
    overflow-x: hidden;
}

.app-sidebar .sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all var(--transition);
    white-space: nowrap;
    overflow: hidden;
    border: none;
    background: none;
    width: 100%;
    cursor: pointer;
}

.app-sidebar .sidebar-link:hover {
    background: var(--accent-dim);
    color: var(--accent);
}

.app-sidebar .sidebar-link.active {
    background: var(--accent-dim);
    color: var(--accent);
    font-weight: 600;
}

.app-sidebar .sidebar-link.danger {
    color: var(--danger);
}

.app-sidebar .sidebar-link.danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.nav-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 側邊欄底部 */
.app-sidebar .sidebar-footer {
    padding: 8px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* 收合按鈕 */
.app-sidebar-toggle {
    position: fixed;
    left: 240px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 201;
    width: 18px;
    height: 48px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: left 0.3s ease, color var(--transition), background var(--transition);
    padding: 0;
    line-height: 1;
}

.app-sidebar-toggle:hover {
    color: var(--accent);
    background: var(--bg-card);
}

.app-sidebar-toggle.collapsed {
    left: 64px;
}

/* 主內容區 */
.app-main {
    margin-left: 240px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
}

.app-main.expanded {
    margin-left: 64px;
}

/* 頂部欄 */
.app-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 15, 26, 0.95);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.page-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    flex-shrink: 0;
}

.app-topbar .search-bar {
    flex: 1;
    max-width: 420px;
}

/* 登入提示（未登入時的 sidebar-user 區塊） */
.sidebar-login-prompt {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
}

.app-sidebar.collapsed .sidebar-login-prompt .btn {
    opacity: 0;
    pointer-events: none;
}

/* 側邊欄收合時隱藏文字 */
.app-sidebar.collapsed .nav-label,
.app-sidebar.collapsed .brand-text,
.app-sidebar.collapsed .sidebar-user-info,
.app-sidebar.collapsed .sidebar-points {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* RWD：手機版收合為 overlay */
@media (max-width: 768px) {
    .app-sidebar {
        transform: translateX(-100%);
        width: 240px;
    }

    .app-sidebar.mobile-open {
        transform: translateX(0);
    }

    .app-sidebar.collapsed {
        width: 240px;
        transform: translateX(-100%);
    }

    .app-sidebar-toggle {
        left: 0 !important;
        border-left: 1px solid var(--border);
        border-radius: 0 6px 6px 0;
        top: 16px;
        transform: none;
    }

    .app-main {
        margin-left: 0 !important;
    }
}

/* ============ v2 純 Express 補齊 ============ */

.app-sidebar .sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-sidebar.collapsed .sidebar-brand {
    display: none;
}

.app-sidebar.collapsed .sidebar-header {
    justify-content: center;
}

.sidebar-menu-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    flex-shrink: 0;
    transition: color var(--transition);
}

.sidebar-menu-btn:hover {
    color: var(--accent);
}

.sidebar-float-btn {
    display: none;
}

.page-content {
    padding: 24px;
}

.profile-form-group {
    margin-bottom: 24px;
}

.profile-form-label {
    display: block;
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.profile-form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95em;
    outline: none;
    transition: var(--transition);
    box-sizing: border-box;
}

.profile-form-input:focus {
    border-color: var(--accent);
}

.profile-form-input.readonly {
    opacity: 0.6;
    cursor: default;
}

.profile-avatar-edit {
    display: flex;
    align-items: center;
    gap: 16px;
}

.profile-save-btn {
    padding: 10px 28px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.profile-save-btn:hover {
    opacity: 0.85;
}

.profile-save-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.topbar-points {
    display: flex;
    align-items: center;
    margin-left: auto;
}

.points-badge {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--accent);
}

.checkin-success-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
}

.checkin-success-emoji {
    font-size: 1.5rem;
}

.checkin-success-banner strong {
    display: block;
    color: var(--success);
    margin-bottom: 2px;
}

.checkin-success-banner span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.checkin-action {
    margin-top: 20px;
}

.checkin-page-btn {
    width: 100%;
    padding: 14px 0;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), #d97706);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
}

.checkin-page-btn:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.checkin-page-btn:disabled {
    cursor: default;
}

.checkin-page-btn.done {
    background: var(--bg-input);
    color: var(--success);
    border: 1px solid var(--success);
}

.checkin-progress {
    display: flex;
    gap: 12px;
}

.checkin-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.checkin-day-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 2px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 600;
    transition: all var(--transition);
}

.checkin-day.done .checkin-day-circle {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.checkin-day.next .checkin-day-circle,
.checkin-modal-dot.next {
    border-color: var(--accent);
    animation: dot-pulse 1.5s ease-in-out infinite;
}

@keyframes dot-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}

.checkin-day-pts {
    font-size: 0.8rem;
    color: var(--accent);
    font-weight: 600;
}

.checkin-day-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.checkin-rules {
    list-style: none;
    padding: 0;
}

.checkin-rules li {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 4px 0;
}

.checkin-rules li::before {
    content: '·';
    margin-right: 8px;
    color: var(--accent);
}

.checkin-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkin-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 28px 24px;
    width: 90%;
    max-width: 380px;
    text-align: center;
    box-shadow: var(--shadow);
}

.checkin-modal-emoji {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.checkin-modal-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.checkin-modal-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.checkin-modal-desc strong {
    color: var(--accent);
}

.checkin-modal-dots {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 20px;
}

.checkin-modal-dot {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 2px solid var(--border-light);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.checkin-modal-dot .dot-num {
    font-size: 0.65rem;
    color: var(--text-muted);
    line-height: 1;
}

.checkin-modal-dot .dot-pts {
    font-size: 0.55rem;
    color: var(--text-muted);
    line-height: 1;
    margin-top: 1px;
}

.checkin-modal-dot.done {
    background: var(--accent-dim);
    border-color: var(--accent);
}

.checkin-modal-dot.done .dot-num {
    color: var(--accent);
    font-weight: 700;
}

.checkin-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkin-modal-btn {
    width: 100%;
    padding: 10px 0;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), #d97706);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.checkin-modal-btn:hover:not(:disabled) {
    filter: brightness(1.1);
}

.checkin-modal-btn:disabled {
    cursor: default;
    opacity: 0.7;
}

.checkin-btn-skip {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px;
}

.checkin-btn-skip:hover {
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .app-sidebar {
        z-index: 300;
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 299;
    }

    .sidebar-backdrop.open {
        display: block;
    }

    .sidebar-float-btn {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 301;
        background: transparent;
        border: none;
        color: var(--text-secondary);
        font-size: 1.2rem;
        cursor: pointer;
        width: 44px;
        height: 47px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: color var(--transition);
    }

    .sidebar-float-btn:hover {
        color: var(--accent);
    }

    .app-topbar {
        padding: 12px 16px 12px 44px;
        gap: 8px;
    }

    .app-topbar .search-bar {
        max-width: none;
    }

    .page-title {
        font-size: 1rem;
    }

    .page-content {
        padding: 16px;
    }

    .checkin-progress {
        flex-wrap: wrap;
    }
}

.session-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.session-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

.session-card:hover {
    border-color: var(--accent);
    transform: translateX(4px);
}

.session-card-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-card);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4em;
    flex-shrink: 0;
}

.session-card-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.session-card-body {
    flex: 1;
    min-width: 0;
}

.session-card-title {
    font-weight: 600;
    font-size: 0.95em;
    margin-bottom: 4px;
}

.session-card-preview {
    font-size: 0.82em;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-card-time {
    font-size: 0.78em;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.session-card-delete {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1em;
    padding: 6px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity var(--transition), background var(--transition);
    flex-shrink: 0;
}

.session-card:hover .session-card-delete {
    opacity: 0.6;
}

.session-card-delete:hover {
    opacity: 1 !important;
    background: rgba(255, 80, 80, 0.15);
}

.session-card-delete:disabled {
    cursor: not-allowed;
    opacity: 0.3 !important;
}
