/* ----- GLOBAL STYLES ----- */
:root {
    /* Color scheme */
    --primary-color: #1877f2;
    --primary-hover: #0d47a1;
    --primary-dark: #3d00a0c7;
    --bg-color: #f0f2f5;
    --text-color: #050505;
    --container-bg: #ffffff;
    --button-gray: #e4e6eb;
    --button-hover: #d8dadf;
    --border-color: #ddd;
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 6px 12px rgba(0, 0, 0, 0.15);
    
    /* Layout */
    --radius: 8px;
    --spacing-sm: 30px;
    --spacing-md: 35px;
    --spacing-lg: 40px;
    
    /* Typography */
    --font-size-base: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 24px;

    /* Component-specific styles */
    --form-border: 3px solid #007bff;
    --display-border: 3px solid #4c00ff;
    --divider: 1px solid var(--border-color);

    /* Interactive states */
    --hover-lift: translateY(-2px);
    --focus-ring: 0 0 0 2px rgba(24, 119, 242, 0.3);
    
    /* Layout constants */
    --container-width-mobile: 100%;
    --container-width-desktop: 900px;
    --sticky-top-distance: 20px;

    /* Medium-specific styles */
    --medium-black: rgba(0, 0, 0, 0.84);
    --medium-dark-gray: rgba(0, 0, 0, 0.68);
    --medium-gray: rgba(0, 0, 0, 0.54);
    --medium-light-gray: rgba(0, 0, 0, 0.34);
    --medium-lighter-gray: rgba(0, 0, 0, 0.15);
    --medium-green: #03a87c;
    --medium-background: #fff;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Helvetica Neue", Arial, sans-serif;
    --font-serif: "Source Serif Pro", "Noto Serif TC", Georgia, Cambria, "Times New Roman", Times, serif;
    --font-mono: "Menlo", "Monaco", "Consolas", "Courier New", monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', var(--font-sans), var(--font-serif), var(--font-mono);
    /* background-color: var(--bg-color); */
    /* color: var(--text-color); */
    display: flex;
    flex-direction: column;
    align-items: center;
    /* padding: var(--spacing-lg); */
    /* margin: 0; */
    /* line-height: 1.6; */
    /* font-size: var(--font-size-base); */

    color: var(--medium-black);
    line-height: 1.6;
    background: var(--medium-background);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

.medium-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
  }

/* ----- FORM ELEMENTS ----- */
.input-form {
    background-color: var(--container-bg);
    border-radius: var(--radius);
    border: 3px solid #007bff; /* 粗邊框，使用鮮明的主色 */
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    padding: var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    width: 100%;
    max-width: 400px;
    transition: box-shadow 0.3s ease;
}

.input-form:hover {
    box-shadow: var(--shadow-lg);
}

.input-form label {
    font-weight: 500;
    margin-bottom: var(--spacing-sm);
    font-size: var(--font-size-lg);
}

.input-form input,
.input-form select {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: var(--spacing-md);
    font-size: var(--font-size-base);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.input-form input:focus,
.input-form select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.2);
}

.input-form select#topic {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  width: 100%; /* 確保使用全寬 */
  max-width: 100%; /* 防止溢出 */
}

/* 增加下拉選單顯示時的樣式 */
.input-form select#topic option {
  white-space: normal; /* 允許選項文字換行 */
  padding: 8px 10px; /* 增加內邊距使文字更易讀 */
}

.input-form button,
#generate_button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 12px 15px;
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.input-form button:hover,
#generate_button:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
}

/* ----- CONTENT DISPLAY ----- */
#problems_display {
    background-color: var(--container-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 3px solid #4c00ff; /* 粗邊框，使用鮮明的主色 */
    width: 100%;
    max-width: 900px;
    padding: var(--spacing-lg);
    margin-top: var(--spacing-lg);
}

/* ----- ANSWER AREA ----- */
#answerArea {
    position: sticky;
    top: 20px;
    background-color: #ffffff; /* 白色背景，與淺灰背景形成對比 */
    border-radius: 8px; /* 圓角設計 */
    border: 3px solid #007bff; /* 粗邊框，使用鮮明的主色 */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); /* 更深的陰影 */
    width: 100%;
    max-width: 900px;
    padding: 20px; /* 增加內邊距 */
    margin-top: 20px; /* 外邊距分離其他元素 */
    margin-bottom: 20px;
    transition: all 0.3s ease; /* 滑順的過渡效果 */
    width: 100%;        /* 在小屏幕上佔據全寬 */
    max-width: 900px;   /* 在大屏幕上限制最大寬度為 900px */
}

#htmlAnswerArea {
    position: sticky;
    top: 20px;
    background-color: #ffffff; /* 白色背景，與淺灰背景形成對比 */
    border-radius: 8px; /* 圓角設計 */
    border: 3px solid #007bff; /* 粗邊框，使用鮮明的主色 */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); /* 更深的陰影 */
    width: 100%;
    max-width: 900px;
    padding: 20px; /* 增加內邊距 */
    margin-top: 20px; /* 外邊距分離其他元素 */
    margin-bottom: 20px;
    transition: all 0.3s ease; /* 滑順的過渡效果 */
    width: 100%;        /* 在小屏幕上佔據全寬 */
    max-width: 900px;   /* 在大屏幕上限制最大寬度為 900px */
}


#answerArea::before {
    content: "解答區:"; /* 標題文字 */
    display: block;
    font-weight: 700; /* 粗體字 */
    font-size: 24px; /* 加大字體 */
    color: #007bff; /* 使用主色 */
    margin-bottom: 15px; /* 與內容分隔 */
    padding-bottom: 10px;
    border-bottom: 2px solid #007bff; /* 粗底線，與邊框一致 */
}

/* ----- PROBLEM LIST ----- */
#problem_list {
    list-style-type: none;
    padding: 0;
}

#problem_list li {
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
}

#problem_list li:last-child {
    border-bottom: none;
}

#problem_list li button {
    background-color: var(--button-gray);
    color: var(--text-color);
    border: none;
    border-radius: 4px;
    padding: 8px 12px;
    font-size: var(--font-size-base);
    font-weight: 500;
    cursor: pointer;
    margin-right: var(--spacing-md);
    transition: background-color 0.2s ease, transform 0.2s ease;
}

#problem_list li button:hover {
    background-color: var(--button-hover);
    transform: translateY(-2px);
}

#problem_list li button:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.3);
}

/* ----- LAYOUT COMPONENTS ----- */
.container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

/* ----- FORM COMPONENTS ----- */
.form-group {
    margin-bottom: var(--spacing-md);
}

.form-hint {
    display: block;
    font-size: 0.8rem;
    color: #666;
    margin-top: var(--spacing-sm);
}

.btn-primary {
    background-color: #1877f2;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 15px 20px;
    font-size: 1.2em;
    cursor: pointer;
    transition: background-color 0.3s ease;
    width: 100%;
}

.btn-primary:hover {
    background-color: #0d47a1;
}

.form-spacer {
  height: 20px; /* Adjust the height as needed */
  width: 100%;  /* Optional: ensures the spacer spans the full width */
  clear: both;  /* Optional: prevents floating elements from wrapping */
}

/* ----- CONTENT ELEMENTS ----- */
.problem-items {
    list-style-position: inside;
    margin-bottom: var(--spacing-md);
}

.divider {
    margin: calc(var(--spacing-lg) * 2) 0;
    border: 0;
    border-top: var(--divider);
}

/* Responsive layout */
@media (min-width: 992px) {
    .container {
        display: flex;
        flex-direction: row;
        gap: var(--spacing-lg);
        align-items: flex-start;
        flex-wrap: nowrap;
    }
    
    .generator-panel {
        flex: 0 0 350px;
        position: sticky;
        top: 20px;
    }
    
    .problems-panel {
        flex: 1;
    }
}

/* ----- RESPONSIVE DESIGN ----- */
@media (max-width: 768px) {
    .generator-panel {
        padding-left: 10px;
        padding-right: 10px;
    }

    .input-form {
        width: 100%;
        padding: 10px;
        padding-left: 10px;
        padding-right: 10px;
    }

    #problems_display,
    #answerArea {
        width: 100%;
    }

    #problem_list li {
        flex-direction: column;
        align-items: flex-start;
    }

    #problem_list li button {
        margin-top: 8px;
        margin-bottom: 8px;
    }

    .btn-primary {
        max-width: 80%;
        margin: 10px 0;
    }

    /* Mobile responsive adjustments */
    .feature-cards {
        flex-direction: column;
    }
    
    .feature-card {
        width: 100%;
        margin-bottom: 20px;
    }
    
    .example-container {
        flex-direction: column;
    }
    
    .example-card {
        width: 100%;
        margin-bottom: 20px;
    }
    
    .hero h1 {
        font-size: 1.8em;
    }
    .medium-container {
        padding: 20px 16px;
        }

    h1 {
    font-size: 32px;
    }

    h2 {
    font-size: 28px;
    }

    p, .article-content {
    font-size: 18px;
    }

    .article-cards {
    grid-template-columns: 1fr;
    }

    .platform-cards {
    flex-direction: column;
    }        
}

@media (min-width: 1200px) {
    body {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .input-form {
        margin-right: var(--spacing-lg);
    }

    #problems_display {
        flex: 1;
        margin-right: var(--spacing-lg);
        max-width: 100%;
    }

    #answerArea {
        flex: 1;           /* 平均分配空間 */
        max-width: 900px;  /* 保持一致的最大寬度 */
        margin-right: var(--spacing-lg);
    }
}

/* ----- ANIMATIONS ----- */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-10px); }
}

/* ----- LOADING ELEMENTS ----- */
.loading-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 30px;
    width: 100%;
}

.spinner-container {
    text-align: center;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 4px solid var(--primary-color);
    width: 40px;
    height: 40px;
    margin: 0 auto 10px;
    animation: spin 1s linear infinite;
}

.spinner-small {
    display: inline-block;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 2px solid #fff;
    width: 16px;
    height: 16px;
    margin-right: 8px;
    animation: spin 1s linear infinite;
}

/* ----- PROBLEM LIST ANIMATIONS ----- */
.problem-item {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.3s ease;
    animation: fadeIn 0.5s ease forwards;
    animation-delay: calc(var(--item-index, 0) * 100ms);
}

.active-problem {
    background-color: rgba(24, 119, 242, 0.1);
    border-left: 3px solid var(--primary-color);
    padding-left: 12px !important;
}

/* ----- ANSWER AREA ANIMATIONS ----- */
#answerArea {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.answer-fade-in {
    animation: fadeIn 0.3s ease forwards;
}

.answer-fade-out {
    animation: fadeOut 0.3s ease forwards;
}

/* ----- BUTTON ANIMATIONS ----- */
.button-loading {
    position: relative;
    color: transparent !important;
}

.button-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

/* ----- SLIDES AND PRESENTATIONS ----- */
.slides {
    width: 100%;
    max-width: 600px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: var(--spacing-lg);
    background-color: var(--container-bg);
    margin: var(--spacing-md) auto;
    transition: box-shadow 0.3s ease;
}

.slides:hover {
    box-shadow: var(--shadow-lg);
}

.slide {
    display: none;
    animation: fadeIn 0.4s ease-in-out;
    opacity: 0;
}

.slide:first-child,
.slide.active {
    display: block;
    opacity: 1;
}

.slide img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: transform 0.3s ease;
}

.slide img:hover {
    transform: scale(1.02);
}

/* Navigation controls for slides could go here */
.slide-controls {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    padding: 10px 0;
}

.slide-nav-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 8px 15px;
    cursor: pointer;
    transition: background-color 0.2s ease, opacity 0.2s ease;
}

.slide-nav-btn:hover {
    background-color: var(--primary-dark);
}

.slide-nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ----- FORMAT TOGGLE ----- */
.format-toggle {
    margin-bottom: var(--spacing-md);
    background-color: var(--container-bg);
    padding: var(--spacing-sm);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.format-toggle .radio-group {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-xs);
}

.format-toggle label {
    font-weight: 500;
}

/* Custom image size */
.custom-image-size {
    width: 50%;
    height: auto;
}

/* Toast notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    min-width: 250px;
    transform: translateY(-100px);
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.visible {
    transform: translateY(0);
    opacity: 1;
}

.toast.error {
    border-left: 4px solid #ff3b30;
}

.toast.success {
    border-left: 4px solid #34c759;
}

.toast.warning {
    border-left: 4px solid #ff9500;
}

/* Navigation */
.medium-nav {
    border-bottom: 1px solid var(--medium-lighter-gray);
    padding: 16px 24px;
    position: sticky;
    top: 0;
    background: white;
    z-index: 100;
    width: 100%;          /* Force full width */
    align-self: stretch;  /* Override parent's align-items: center */
    max-width: 100vw;     /* Ensure it doesn't exceed viewport width */
    margin-left: calc(-1 * var(--spacing-lg));  /* Compensate for body padding */
    margin-right: calc(-1 * var(--spacing-lg)); /* Compensate for body padding */
    padding-left: calc(var(--spacing-lg) + 24px);  /* Restore original padding plus nav padding */
    padding-right: calc(var(--spacing-lg) + 24px); /* Restore original padding plus nav padding */
}
  
.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--medium-black);
    text-decoration: none;
}

.nav-brand-logo {
    height: 58px;
    width: auto;
    margin-right: 8px;
    vertical-align: middle;
  }

.nav-links {
    display: flex;
}

.nav-links a {
    margin-left: 24px;
    color: var(--medium-gray);
    text-decoration: none;
    font-family: var(--font-sans);
    font-size: 16px;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: var(--medium-black);
}

/* Mark the active navigation link */
.nav-links a.active {
    font-weight: 700;
    border-bottom: 2px solid #0066cc;
}

  /* About page styles */
.about-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem 0 3rem;
    font: 400 1.125rem/1.5 var(--font-sans);
    color: var(--medium-black);
}

.about-content h2 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    font-size: 1.75rem;
    color: #333;
}

.about-content p {
    margin-bottom: 1.25rem;
    line-height: 1.7;
}

.about-content ul {
    margin-bottom: 1.5rem;
    padding-left: 1.5rem;
}

.about-content li {
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

.about-content a {
    color: #0066cc;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s ease;
}

.about-content a:hover {
    border-color: #0066cc;
}

section svg {
  display: block;
  /* margin-bottom: 12px; */
}

.about-content h2 svg {
  vertical-align: middle;
  margin-right: 12px;
  display: inline-block;
}

/* Adjust position for mobile */
@media (max-width: 768px) {
  .about-content h2 svg {
    width: 28px;
    height: 28px;
    margin-right: 8px;
  }
}