/* 基礎重置和全域樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Serif TC', 'Noto Sans TC', serif;
    background-color: #ffffff;
    color: #000000;
    line-height: 1.6;
    min-height: 100vh;
}

/* 主容器 */
.container {
    display: flex;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    border: 1px solid #e0e0e0;
}

/* 左側按鈕面板 */
.button-panel {
    width: 350px;
    background-color: #fafafa;
    border-right: 1px solid #e0e0e0;
    padding: 20px;
    overflow-y: auto;
}

/* 面板標題區域 */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 10px;
}

.button-panel h2 {
    font-size: 18px;
    font-weight: 500;
    margin: 0;
    color: #333;
}

/* 面板內容區域 */
.panel-content {
    transition: max-height 0.3s ease, opacity 0.3s ease;
    overflow: hidden;
}

.button-panel h3 {
    font-size: 16px;
    font-weight: 400;
    margin: 30px 0 15px 0;
    color: #555;
}

/* 按鈕組 */
.button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.text-button {
    background-color: #ffffff;
    border: 1px solid #d0d0d0;
    color: #333;
    padding: 10px 15px;
    font-family: 'Noto Serif TC', 'Noto Sans TC', serif;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    border-radius: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.5;
}

.text-button:hover {
    background-color: #f0f0f0;
    border-color: #999;
}

.text-button:active {
    background-color: #e8e8e8;
    transform: translateY(1px);
}

/* 自訂文字區域 */
.custom-text-section {
    border-top: 1px solid #e0e0e0;
    padding-top: 20px;
    margin-top: 20px;
}

.custom-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.custom-section-header h3 {
    margin: 0;
}

.custom-input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

#customTextInput {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #d0d0d0;
    font-family: 'Noto Serif TC', 'Noto Sans TC', serif;
    font-size: 14px;
    border-radius: 2px;
    background-color: #ffffff;
    resize: vertical;
    min-height: 60px;
    line-height: 1.5;
}

#customTextInput:focus {
    outline: none;
    border-color: #666;
    background-color: #fafafa;
}

#addCustomButton {
    background-color: #333;
    color: #ffffff;
    border: none;
    padding: 10px 16px;
    font-family: 'Noto Serif TC', 'Noto Sans TC', serif;
    font-size: 14px;
    cursor: pointer;
    border-radius: 2px;
    transition: background-color 0.2s ease;
    align-self: flex-end;
    min-width: 80px;
}

#addCustomButton:hover {
    background-color: #555;
}

#addCustomButton:active {
    background-color: #222;
}

/* 右側輸入面板 */
.input-panel {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.input-panel h2 {
    font-size: 18px;
    font-weight: 500;
    margin-bottom: 20px;
    color: #333;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 10px;
}

/* 文字區域容器 */
.textarea-container {
    position: relative;
    flex: 1;
    display: flex;
}

#mainTextArea {
    flex: 1;
    padding: 15px;
    border: 1px solid #d0d0d0;
    font-family: 'Noto Serif TC', 'Noto Sans TC', serif;
    font-size: 16px;
    line-height: 1.8;
    resize: none;
    background-color: #ffffff;
    border-radius: 2px;
    min-height: 400px;
    z-index: 1;
}

#mainTextArea:focus {
    outline: none;
    border-color: #666;
    background-color: #fafafa;
}

#mainTextArea::placeholder {
    color: #999;
    font-style: italic;
}

/* 行數統計覆蓋層 */
.line-counter-overlay {
    position: absolute;
    top: 0;
    right: 0;
    width: 80px;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    padding: 15px 10px;
    font-family: 'Noto Sans TC', monospace;
    font-size: 12px;
    line-height: 1.8;
    color: #999;
    background: linear-gradient(to left, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.7) 70%, transparent 100%);
    border-radius: 0 2px 2px 0;
    display: block;
}

.line-counter-overlay .line-count {
    display: block;
    text-align: right;
    font-weight: 300;
    margin: 0;
    white-space: nowrap;
}

/* 文字區域控制按鈕 */
.textarea-controls {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    justify-content: flex-end;
}

.textarea-controls button {
    background-color: #ffffff;
    border: 1px solid #d0d0d0;
    color: #333;
    padding: 8px 16px;
    font-family: 'Noto Serif TC', 'Noto Sans TC', serif;
    font-size: 14px;
    cursor: pointer;
    border-radius: 2px;
    transition: all 0.2s ease;
}

.textarea-controls button:hover {
    background-color: #f0f0f0;
    border-color: #999;
}

.textarea-controls button:active {
    background-color: #e8e8e8;
    transform: translateY(1px);
}

/* 響應式設計 */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
        border: none;
        min-height: 100vh;
    }
    
    .button-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
        padding: 15px;
        /* 移除 max-height 限制，讓內容自然展開 */
        max-height: none;
        /* 讓按鈕區域可以收合 */
        order: 1;
    }
    
    .panel-header {
        margin-bottom: 15px;
    }
    
    .input-panel {
        min-height: 50vh;
        padding: 15px;
        order: 2;
        flex: 1;
    }
    
    #mainTextArea {
        min-height: 250px;
        font-size: 16px; /* 防止 iOS 縮放 */
    }
    
    /* 窄螢幕時隱藏字數統計 */
    .line-counter-overlay {
        display: none;
    }
    
    /* 窄螢幕時的按鈕樣式調整 */
    .button-group {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 8px;
        margin-bottom: 15px;
    }
    
    .text-button {
        padding: 12px 10px;
        font-size: 13px;
        text-align: center;
        min-height: 44px; /* 觸控友善的最小高度 */
    }
    
    .custom-input-group {
        flex-direction: column;
        gap: 10px;
    }
    
    #customTextInput {
        padding: 12px;
        font-size: 16px; /* 防止 iOS 縮放 */
        min-height: 80px;
    }
    
    #addCustomButton {
        padding: 12px 16px;
        min-height: 44px;
        font-size: 15px;
    }
    
    .textarea-controls {
        margin-top: 10px;
        gap: 8px;
    }
    
    .textarea-controls button {
        padding: 12px 20px;
        font-size: 15px;
        min-height: 44px;
        flex: 1;
    }
}

/* 更窄的螢幕（手機直向） */
@media (max-width: 480px) {
    .container {
        margin: 0;
        border: none;
    }
    
    .button-panel {
        padding: 10px;
    }
    
    .input-panel {
        padding: 10px;
    }
    
    .button-panel h2,
    .input-panel h2 {
        font-size: 16px;
        margin-bottom: 15px;
    }
    
    .button-panel h3 {
        font-size: 14px;
        margin: 20px 0 10px 0;
    }
    
    .button-group {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 6px;
    }
    
    .text-button {
        padding: 10px 8px;
        font-size: 12px;
        min-height: 40px;
    }
    
    #mainTextArea {
        min-height: 200px;
        padding: 12px;
    }
}

/* 平板橫向 */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 100%;
        margin: 0;
    }
    
    .button-panel {
        width: 300px;
    }
    
    #mainTextArea {
        font-size: 15px;
    }
}

/* 捲軸樣式 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}
