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

body {
    font-family: '微軟正黑體', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 30px;
    text-align: center;
}

header h1 {
    font-size: 28px;
    font-weight: 600;
}

.toolbar {
    background: #f8f9fa;
    padding: 20px;
    border-bottom: 2px solid #e0e0e0;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
}

.tool-group {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.text-tools {
    flex-wrap: wrap;
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    background: #e9ecef;
    color: #495057;
}

.btn:hover {
    background: #dee2e6;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #218838;
}

#textInput {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    min-width: 200px;
    transition: border-color 0.3s;
}

#textInput:focus {
    outline: none;
    border-color: #667eea;
}

#fontFamily {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    background: white;
}

#fontFamily:focus {
    outline: none;
    border-color: #667eea;
}

#textColor {
    width: 50px;
    height: 38px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
}

#fontSize {
    width: 80px;
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
}

#fontSize:focus {
    outline: none;
    border-color: #667eea;
}

.canvas-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    background: #f0f2f5;
    min-height: 500px;
}

#canvas {
    border: 2px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: white;
}

.info {
    background: #f8f9fa;
    padding: 15px 30px;
    text-align: center;
    color: #6c757d;
    font-size: 14px;
    border-top: 1px solid #e0e0e0;
}

.download-group {
    margin-left: auto;
}

/* 圖片庫樣式 */
.image-library {
    background: #ffffff;
    padding: 20px 30px;
    border-bottom: 2px solid #e0e0e0;
}

.image-library h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 18px;
    font-weight: 600;
}

.image-gallery {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
}

.gallery-item {
    width: 80px;
    aspect-ratio: 1/1;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: grab;
    transition: all 0.3s ease;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.gallery-item:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    transform: translateY(-2px);
}

.gallery-item:active {
    cursor: grabbing;
}

.gallery-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.gallery-item-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 10px;
    padding: 4px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s;
}

.gallery-item:hover .gallery-item-name {
    opacity: 1;
}

/* Modal 樣式 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    min-width: 400px;
    animation: slideIn 0.3s ease;
}

.modal-content h3 {
    margin-bottom: 20px;
    color: #333;
}

#editTextArea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 20px;
}

#editTextArea:focus {
    outline: none;
    border-color: #667eea;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 響應式設計 */
@media (max-width: 1200px) {
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .tool-group {
        justify-content: center;
    }

    .download-group {
        margin-left: 0;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    header h1 {
        font-size: 22px;
    }

    .canvas-wrapper {
        padding: 20px;
    }

    #canvas {
        max-width: 100%;
        height: auto !important;
    }

    .modal-content {
        min-width: 90%;
        margin: 20px;
    }

    #textInput {
        min-width: 150px;
    }
}

/* 提示訊息 */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #333;
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: slideInUp 0.3s ease;
    z-index: 2000;
}

.toast.success {
    background: #28a745;
}

.toast.error {
    background: #dc3545;
}

@keyframes slideInUp {
    from {
        transform: translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}
