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

body {
    font-family: 'Inter', 'Arial', 'Microsoft JhengHei', sans-serif;
    line-height: 1.6;
    color: #0f172a;
    background: #f8fafc;
    min-height: 100vh;
}

/* ========== Navigation ========== */
.navbar {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    padding: 0.75rem 0;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.nav-container {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2.5rem;
}

.logo {
    font-size: 1.125rem;
    font-weight: 700;
    color: #0f172a;
    text-decoration: none;
    letter-spacing: -0.025em;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo::before {
    content: "▲";
    display: inline-block;
    background: #eff6ff;
    color: #3b82f6;
    padding: 0.5rem;
    border-radius: 0.5rem;
    font-size: 1.75rem;
    line-height: 1;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 0.75rem;
}

.nav-links li {
    margin: 0;
}

.nav-links a {
    text-decoration: none;
    color: #64748b;
    font-weight: 500;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    padding: 0.625rem 1rem;
    border-radius: 0.5rem;
    display: inline-block;
}

.nav-links a:hover {
    color: #3b82f6;
    background: #f1f5f9;
}

/* ========== Main Content ========== */
.main-content {
    margin-top: 80px;
    padding: 2rem 1rem;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
}

/* ========== Calculator Section ========== */
.calculator-section {
    background: white;
    border-radius: 1rem;
    padding: 3rem;
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
    text-align: center;
}

.calculator-section h1 {
    color: #0f172a;
    margin-bottom: 0.5rem;
    font-size: 2.5rem;
    font-weight: 900;
    letter-spacing: -0.025em;
}

.calculator-section p {
    color: #64748b;
    margin-bottom: 2rem;
    font-size: 1rem;
}

/* ========== Form Styles ========== */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #0f172a;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.date-inputs {
    display: flex;
    gap: 1rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    position: relative;
    z-index: 10;
}

.date-input-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.date-input-group label {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: #64748b;
    text-transform: none;
    letter-spacing: normal;
}

select {
    padding: 0.625rem 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    background: white;
    color: #0f172a;
    transition: all 0.2s ease;
    min-width: 80px;
    position: relative;
    z-index: 20;
    font-weight: 500;
}

select:hover {
    border-color: #cbd5e1;
}

select:focus {
    border-color: #3b82f6;
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.submit-btn {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 1rem;
    box-shadow: 0 1px 2px rgba(59, 130, 246, 0.2);
}

.submit-btn:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(59, 130, 246, 0.25);
}

/* ========== Results Section ========== */
.results-section {
    background: white;
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
}

/* [新增] 頂部標題樣式 (原 triangle-container h2) */
.results-section .section-title {
    color: #0f172a;
    margin-bottom: 1.5rem; /* 增加底部間距，讓標題與 Grid 容器分離 */
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center; /* 標題置中 */
    text-align: center; /* 容錯 */
}

.results-section .section-title::before {
    content: "👁";
    display: inline-block;
    font-size: 1.25rem;
}

/* 修改：使用統一的 Grid 系統 */
.results-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    width: 100%;
}

/* 桌面版：使用 Grid 確保完美對齊 */
@media (min-width: 1024px) {
    .results-container {
        grid-template-columns: 1.2fr 1fr;
        align-items: start;
    }
    
    .triangle-container {
        grid-column: 1;
    }
    
    .results-table-container {
        grid-column: 2;
    }
}

.triangle-container {
    text-align: center;
    width: 100%;
}

/* [刪除] 原有的 .triangle-container h2 樣式 - 已替換為 .section-title */
/* .triangle-container h2 { ... } */
/* .triangle-container h2::before { ... } */

.canvas-container {
    background: white;
    border-radius: 0.75rem;
    padding: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
    border: 1px solid #e2e8f0;
    display: inline-block;
    position: relative;
    overflow: hidden;
}

.canvas-container::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.02) 0%, rgba(147, 51, 234, 0.02) 100%);
    pointer-events: none;
}

#triangleCanvas {
    max-width: 100%;
    height: auto;
    display: block;
    position: relative;
    z-index: 1;
}

/* ========== Results Table Styles ========== */
.results-table-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.results-grid {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.results-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: white;
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
    table-layout: fixed;
}

.results-table td {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid #f1f5f9;
    text-align: center;
    vertical-align: middle;
    font-size: 0.875rem;
}

.results-table tr:last-child td {
    border-bottom: none;
}

/* 頂部表格樣式 */
.results-table.top-table .label-cell {
    background-color: #f8fafc;
    font-weight: 600;
    width: 35%;
    color: #64748b;
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.results-table.top-table .value-cell {
    background-color: #eff6ff;
    font-size: 1.25rem;
    font-weight: 700;
    color: #3b82f6;
    width: 15%;
}

/* 底部表格樣式 */
.label-cell-wide {
    background-color: #f8fafc;
    font-weight: 600;
    width: 70%;
    color: #64748b;
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.bottom-table .value-cell {
    background-color: #eff6ff;
    font-size: 1.25rem;
    font-weight: 700;
    color: #3b82f6;
    width: 30%;
}

.results-table tr:hover {
    background-color: rgba(59, 130, 246, 0.03);
}

/* ========== Button Group ========== */
.button-group {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
    width: 100%;
}

.download-btn, .recalculate-btn {
    padding: 0.625rem 1.5rem;
    border-radius: 0.5rem;
    border: 1px solid #e2e8f0;
    color: #64748b;
    background: white;
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.download-btn::before {
    content: "⬇";
}

.recalculate-btn {
    background: #eff6ff;
    color: #3b82f6;
    border-color: transparent;
}

.recalculate-btn::before {
    content: "↻";
}

.download-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.recalculate-btn:hover {
    background: #dbeafe;
}

/* ========== Analysis Section ========== */

/* [新增] 分析區塊標題樣式 (原 .analysis-section > h2) */
.results-section .analysis-title {
    color: #0f172a;
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 2rem; 
    padding-top: 2rem; 
    border-top: 1px solid #e2e8f0; 
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: center; /* 置中 */
    text-align: center; /* 容錯 */
}

.results-section .analysis-title::before {
    content: "📊";
    display: inline-block;
    background: #eef2ff;
    color: #6366f1;
    padding: 0.5rem;
    border-radius: 0.5rem;
    font-size: 1.25rem;
}

/* [修改] analysis-section (現在是 analysis-section-wrapper，使用原 class) */
/* 移除 flex-basis，使用 grid-column 橫跨兩欄 */
.analysis-section {
    width: 100%;
    /* 刪除 margin-top/padding-top/border-top，這些已移到 .analysis-title 上 */
}

/* 桌面版：橫跨整個 Grid 的兩欄 */
@media (min-width: 1024px) {
    .analysis-section {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns:1fr;
        gap: 1.5rem;
        align-items: start;
    }
}

/* [刪除] 原有的 .analysis-section > h2 樣式 - 已替換為 .analysis-title */
/* .analysis-section > h2 { ... } */
/* .analysis-section > h2::before { ... } */

/* [刪除] 原有的 .analysis-section > h2 Grid 定位 */
/* @media (min-width: 1024px) { .analysis-section > h2 { grid-column: 1 / -1; } } */

/* 桌面版：方塊的 Grid 定位 (保持不變) */

.analysis-block {
    background: white;
    border-left: 4px solid #3b82f6;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
    border-left-width: 4px;
    position: relative;
    overflow: hidden;
    width: 100%;
}

.analysis-block::after {
    content: "🧠";
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    font-size: 6rem;
    opacity: 0.03;
    pointer-events: none;
}

.analysis-block h3 {
    color: #0f172a;
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
}

.analysis-block h3::before {
    content: "✨";
    font-size: 1.125rem;
}

.analysis-block .code-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #3b82f6;
    margin-left: 0.5rem;
    padding: 0.25rem 0.75rem;
    background: #eff6ff;
    border-radius: 0.375rem;
    border: 1px solid #dbeafe;
}

.analysis-block p {
    color: #334155;
    line-height: 1.8;
    white-space: pre-line;
    width: 100%;
    font-size: 1rem;
}

.analysis-block .description-text {
    margin-top: 1rem;
    font-size: 1rem;
    position: relative;
    z-index: 1;
}

/* ========== Ad Spaces ========== */
.ad-space {
    background: #f8fafc;
    border: 2px dashed #e2e8f0;
    padding: 2rem;
    text-align: center;
    margin: 2rem 0;
    border-radius: 0.75rem;
    color: #94a3b8;
}

/* ========== Footer ========== */
.footer {
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 2rem 0;
    text-align: center;
    margin-top: 3rem;
}

.footer-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 2rem;
    color: #64748b;
    font-size: 0.875rem;
}

.footer-links {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    gap: 2rem;
}

.footer-links a {
    color: #3b82f6;
    text-decoration: none;
    transition: color 0.2s ease;
    font-weight: 500;
}

.footer-links a:hover {
    color: #2563eb;
}

/* ========== Responsive Design ========== */
@media (max-width: 1023px) {
    .results-container {
        grid-template-columns: 1fr;
    }
    
    .triangle-container,
    .results-table-container {
        grid-column: 1;
    }
    
    /* [修改] analysis-section 在行動版不再是 Grid 容器，而是 Flex 容器 */
    .analysis-section { 
        grid-column: 1;
        display: flex;
        flex-direction: column;
    }
    
    .analysis-block {
        margin-bottom: 1rem;
    }
}

@media (max-width: 768px) {
    .nav-container {
        flex-direction: column;
        padding: 0 1rem;
        gap: 1rem;
    }

    .nav-links {
        width: 100%;
        justify-content: center;
    }

    .nav-links li {
        margin: 0;
    }

    .main-content {
        margin-top: 140px;
        padding: 1rem;
    }

    .calculator-section {
        padding: 2rem 1rem;
    }

    .calculator-section h1 {
        font-size: 2rem;
    }

    .date-inputs {
        flex-direction: column;
        gap: 1rem;
    }

    .date-input-group {
        width: 100%;
    }

    select {
        width: 100%;
        max-width: 200px;
    }

    .label-cell, .label-cell-wide {
        font-size: 0.7rem;
        padding: 0.75rem;
    }

    .value-cell {
        font-size: 1rem;
    }

    .button-group {
        flex-direction: column;
        gap: 0.75rem;
    }

    .button-group .download-btn,
    .button-group .recalculate-btn {
        width: 100%;
        max-width: 300px;
    }

    /* [修改] 使用新的標題 Class */
    .results-section .section-title,
    .results-section .analysis-title {
        font-size: 1.25rem;
    }

    .analysis-block {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .analysis-block h3 {
        font-size: 1.125rem;
    }
}

@media (max-width: 480px) {
    .logo {
        font-size: 1rem;
    }

    .calculator-section h1 {
        font-size: 1.75rem;
    }

    .submit-btn {
        padding: 0.625rem 1.5rem;
        font-size: 0.875rem;
    }

    .results-table td {
        padding: 0.625rem;
        font-size: 0.8rem;
    }

    .label-cell, .label-cell-wide {
        font-size: 0.65rem;
    }

    .value-cell {
        font-size: 0.95rem;
    }

    /* [刪除] 原有的 .triangle-container h2 樣式 */
}

/* ========== Custom Scrollbar ========== */
.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}