/*
 * Yi Cheng Perspective - Main Stylesheet
 * 主要樣式表，包含基礎樣式與按鈕互動效果
 */

/* ========================================
   CSS Variables (主題系統)
   ======================================== */
:root {
    /* Dark Theme (預設) */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --text-muted: #a0a0a0;
    --accent-color: #e94560;
    --accent-hover: #ff6b6b;
    --border-color: #2a2a4a;
    --shadow-color: rgba(0, 0, 0, 0.3);
}

[data-theme="natural"] {
    /* Natural Theme (羊皮紙色) */
    --bg-primary: #f5deb3;
    --bg-secondary: #faebd7;
    --bg-card: #fffaf0;
    --text-primary: #333333;
    --text-secondary: #555555;
    --text-muted: #777777;
    --accent-color: #8b4513;
    --accent-hover: #a0522d;
    --border-color: #d2b48c;
    --shadow-color: rgba(139, 69, 19, 0.2);
}

[data-theme="custom"] {
    /* Custom Theme (可由使用者自訂) */
    --bg-primary: #2d2d2d;
    --bg-secondary: #3d3d3d;
    --bg-card: #4d4d4d;
    --text-primary: #f0f0f0;
    --text-secondary: #d0d0d0;
    --text-muted: #a0a0a0;
    --accent-color: #00bcd4;
    --accent-hover: #26c6da;
    --border-color: #5d5d5d;
    --shadow-color: rgba(0, 0, 0, 0.4);
}

/* ========================================
   Base Styles
   ======================================== */
body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

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

/* ========================================
   Button Styles (FR-31)
   ======================================== */
.btn {
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px var(--shadow-color);
}

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

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

/* ========================================
   Card Styles
   ======================================== */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--shadow-color);
}

/* ========================================
   Sidebar Styles (FR-07)
   ======================================== */
.sidebar {
    position: sticky;
    top: 20px;
    height: fit-content;
}

/* ========================================
   Content Protection (FR-08)
   ======================================== */
.content-protected,
.content-protected *,
.article-content,
.article-content * {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    -webkit-user-drag: none !important;
    cursor: default;
}

/* 隱藏意外選取的文字 */
.content-protected::selection,
.content-protected *::selection,
.article-content::selection,
.article-content *::selection {
    background: transparent !important;
    color: inherit !important;
}

.content-protected::-moz-selection,
.content-protected *::-moz-selection,
.article-content::-moz-selection,
.article-content *::-moz-selection {
    background: transparent !important;
    color: inherit !important;
}

.content-protected pre,
.content-protected code,
.content-protected pre *,
.content-protected code *,
.article-content pre,
.article-content code,
.article-content pre *,
.article-content code * {
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    cursor: text;
}

/* 程式碼區塊允許可見選取 */
.content-protected pre::selection,
.content-protected code::selection,
.content-protected pre *::selection,
.content-protected code *::selection,
.article-content pre::selection,
.article-content code::selection,
.article-content pre *::selection,
.article-content code *::selection {
    background: rgba(100, 149, 237, 0.4) !important;
    color: inherit !important;
}

.content-protected pre::-moz-selection,
.content-protected code::-moz-selection,
.content-protected pre *::-moz-selection,
.content-protected code *::-moz-selection,
.article-content pre::-moz-selection,
.article-content code::-moz-selection,
.article-content pre *::-moz-selection,
.article-content code *::-moz-selection {
    background: rgba(100, 149, 237, 0.4) !important;
    color: inherit !important;
}

/* ========================================
   Touch Targets (FR-42)
   ======================================== */
.social-icon,
.nav-link,
.btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ========================================
   Responsive Utilities
   ======================================== */
@media (max-width: 768px) {
    .sidebar {
        position: relative;
        top: 0;
    }
}

/* ========================================
   Responsive Images (US-19, FR-22)
   圖片自動符合視窗大小
   ======================================== */
.post-content img,
.article-content img,
article img {
    max-width: 100% !important;
    width: auto !important;
    height: auto !important;
    max-height: 70vh;
    /* 最大高度不超過視窗 70% */
    object-fit: contain;
    display: block;
    margin: 1.5rem 0;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow-color);
}

/* 限制圖片容器寬度以提升閱讀體驗 */
.post-content,
.article-content {
    max-width: 100%;
    margin: 0 auto;
}

/* ========================================
   Magnetic Parallax Effect (US-20)
   圖片懸停微互動視覺增強
   ======================================== */
.post-content img,
.article-content img,
article img {
    cursor: pointer;
    transition: transform 0.2s ease-out, box-shadow 0.3s ease;
}

.post-content img:hover,
.article-content img:hover,
article img:hover {
    box-shadow: 0 8px 24px var(--shadow-color);
}

/* ========================================
   Next Article Card (Article Navigation)
   ======================================== */
.next-article-section {
    max-width: 100%;
    margin: 1.5rem auto;
}

.next-article-card {
    position: relative;
    border-radius: 16px;
    background: linear-gradient(135deg,
            rgba(var(--accent-color-rgb, 233, 69, 96), 0.1) 0%,
            rgba(var(--accent-color-rgb, 233, 69, 96), 0.05) 100%);
    border: 1px solid rgba(var(--accent-color-rgb, 233, 69, 96), 0.3);
    backdrop-filter: blur(10px);
    overflow: hidden;
    transition: all 0.3s ease;
}

.next-article-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 16px;
    padding: 2px;
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-hover) 100%);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: exclude;
    -webkit-mask-composite: xor;
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.next-article-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(var(--accent-color-rgb, 233, 69, 96), 0.2);
}

.next-article-card:hover::before {
    opacity: 1;
}

.next-article-inner {
    padding: 1.5rem;
    position: relative;
    z-index: 1;
}

.next-article-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent-color);
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.next-article-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    line-height: 1.3;
}

.next-article-lead {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.6;
    margin-bottom: 1rem;
    opacity: 0.9;
}

.next-article-cta {
    display: inline-flex;
    align-items: center;
    color: var(--accent-color);
    font-weight: 600;
    font-size: 0.95rem;
    transition: transform 0.2s ease;
}

.next-article-card:hover .next-article-cta {
    transform: translateX(4px);
}

/* ========================================
   Recommended Articles Section
   ======================================== */
.recommended-section {
    max-width: 100%;
    margin: 1.5rem auto;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.recommended-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
}

.recommended-title i {
    color: var(--accent-color);
}

.recommended-card {
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: all 0.3s ease;
}

.recommended-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 32px var(--shadow-color);
    border-color: var(--accent-color);
}

.recommended-card-inner {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.recommended-card-image {
    height: 140px;
    overflow: hidden;
}

.recommended-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
    margin: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    max-height: none !important;
}

.recommended-card:hover .recommended-card-image img {
    transform: scale(1.05);
}

.recommended-card-content {
    padding: 1.25rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.recommended-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.recommended-card-lead {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 0.75rem;
    flex: 1;
}

.recommended-card-tags {
    margin-bottom: 0.75rem;
}

.recommended-card-tags .badge {
    background: rgba(var(--accent-color-rgb, 233, 69, 96), 0.15);
    color: var(--accent-color);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.25em 0.6em;
    margin-right: 0.25rem;
    border-radius: 4px;
}

.recommended-card-cta {
    display: inline-flex;
    align-items: center;
    color: var(--accent-color);
    font-size: 0.9rem;
    font-weight: 600;
    transition: transform 0.2s ease;
}

.recommended-card:hover .recommended-card-cta {
    transform: translateX(4px);
}

/* ========================================
   Theme-specific accent RGB values
   ======================================== */
:root {
    --accent-color-rgb: 233, 69, 96;
}

[data-theme="natural"] {
    --accent-color-rgb: 139, 69, 19;
}

[data-theme="custom"] {
    --accent-color-rgb: 0, 188, 212;
}

/* ========================================
   Responsive adjustments
   ======================================== */
@media (max-width: 576px) {
    .next-article-inner {
        padding: 1.5rem;
    }

    .next-article-title {
        font-size: 1.25rem;
    }

    .recommended-card-image {
        height: 120px;
    }
}

/* ========================================
   Back to Top Button (FR-New)
   ======================================== */
#back-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--accent-color);
    color: #fff;
    border: none;
    box-shadow: 0 4px 12px var(--shadow-color);
    z-index: 1050;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

#back-to-top.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

#back-to-top:hover {
    background-color: var(--accent-hover);
    transform: translateY(-5px);
    box-shadow: 0 8px 20px var(--shadow-color);
}

/* Tooltip hint */
#back-to-top::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 60px;
    right: 50%;
    transform: translateX(50%);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    box-shadow: 0 2px 8px var(--shadow-color);
    border: 1px solid var(--border-color);
    z-index: 1051;
}

#back-to-top:hover::after {
    opacity: 1;
}