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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: #2c3e50;
    text-align: center;
}

h2 {
    font-size: 2rem;
    font-weight: 600;
    margin: 2rem 0 1rem;
    color: #34495e;
}

.tagline {
    font-size: 1.25rem;
    color: #7f8c8d;
    font-weight: 300;
    text-align: center;
    margin-bottom: 3rem;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin: 2rem 0;
}

.tool-card {
    background: white;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    text-decoration: none;
    color: inherit;
    display: block;
}

.tool-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.tool-card h3 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.tool-card p {
    color: #5a6c7d;
    font-size: 0.95rem;
}

.search-section {
    text-align: center;
    margin: 2rem 0;
}

.search-container {
    position: relative;
    display: inline-block;
    width: 100%;
    max-width: 400px;
}

#searchInput:focus {
    border-color: #3498db;
}

.search-result-item {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background-color 0.2s;
}

.search-result-item:hover {
    background-color: #f8f9fa;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-title {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 4px;
}

.search-result-desc {
    font-size: 0.9rem;
    color: #666;
}

.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 500;
    display: none;
}

.search-overlay.active {
    display: block;
}

#searchResults {
    z-index: 1000;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: #3498db;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 0.9rem;
    color: #666;
    font-weight: 500;
}

.preset-btn {
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.preset-btn:hover {
    border-color: #3498db;
    transform: translateY(-2px);
}

.preset-preview {
    width: 60px;
    height: 40px;
    background: #f8f9fa;
    border-radius: 4px;
}

.preset-btn span {
    font-size: 0.9rem;
    font-weight: 500;
    color: #333;
}

.tool-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.tool-container.with-sidebar {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 30px;
    align-items: start;
}

.main-tool-content {
    min-width: 0;
    width: 100%;
}

.sidebar-content {
    min-width: 0;
}

.tool-section {
    background: white;
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #34495e;
}

.input-group input,
.input-group textarea,
.input-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
}

.input-group textarea {
    min-height: 120px;
    resize: vertical;
}

.btn {
    background: #3498db;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    display: inline-block;
    text-decoration: none;
}

.btn:hover {
    background: #2980b9;
}

.btn-secondary {
    background: #95a5a6;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.result-box {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 16px;
    margin-top: 20px;
    word-break: break-all;
    font-family: 'Courier New', monospace;
}

.back-link {
    display: inline-block;
    margin-bottom: 20px;
    color: #3498db;
    text-decoration: none;
}

.back-link:hover {
    text-decoration: underline;
}

.ad-container {
    text-align: center;
    margin: 20px auto;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 4px;
}

.loading {
    display: none;
    text-align: center;
    margin: 20px 0;
}

.loading.active {
    display: block;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.related-tools-section {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: fixed;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    width: 300px;
    z-index: 100;
}

.related-tools-section h3 {
    font-size: 1.2rem;
    margin-bottom: 16px;
    color: #2c3e50;
    font-weight: 600;
}

.related-tools-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.related-tool-card {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 12px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
    position: relative;
    display: block;
}

.related-tool-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-color: #3498db;
}

.related-tool-card h4 {
    font-size: 0.9rem;
    margin-bottom: 6px;
    color: #2c3e50;
    font-weight: 600;
    line-height: 1.3;
}

.related-tool-card p {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 0;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tool-arrow {
    position: absolute;
    top: 12px;
    right: 12px;
    color: #3498db;
    font-weight: bold;
    font-size: 1rem;
}

/* 導航容器樣式 */
.nav-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 桌面版：隱藏手機版語言選擇器 */
.mobile-lang-selector {
    display: none;
}

.desktop-lang-selector {
    display: block;
}

/* File Upload Area Styles */
.file-upload-area {
    border: 2px dashed #3498db;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    background: #f8fafb;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.file-upload-area:hover {
    border-color: #2980b9;
    background: #ecf4f9;
    transform: translateY(-2px);
}

.file-upload-area.dragover {
    border-color: #27ae60;
    background: #e8f8f0;
    border-style: solid;
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: #3498db;
}

.file-upload-area p {
    font-size: 1.1rem;
    color: #34495e;
    margin: 0.5rem 0;
    font-weight: 500;
}

.upload-hint {
    font-size: 0.9rem !important;
    color: #7f8c8d !important;
    font-weight: 400 !important;
}

@media (max-width: 768px) {
    .container header {
        margin-top: 165px;
    }
    
    /* 手機版：隱藏桌面版語言選擇器，顯示手機版 */
    .desktop-lang-selector {
        display: none;
    }
    
    .mobile-lang-selector {
        display: block;
        text-align: right;
        margin-top: 10px;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    .tagline {
        font-size: 1rem;
    }
    
    .tools-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .tool-container {
        padding: 10px;
        padding-top: 180px;
        display: block !important;
        max-width: 800px;
        grid-template-columns: none !important;
        gap: 0 !important;
    }
    
    .container {
        padding: 10px;
        display: block !important;
        max-width: 800px;
        grid-template-columns: none !important;
        gap: 0 !important;
    }
    
    .tool-container.with-sidebar {
        display: block !important;
        grid-template-columns: none !important;
    }
    
    .tool-section {
        padding: 16px;
        margin-bottom: 15px;
    }
    
    .related-tools-section {
        padding: 16px;
        position: static !important;
        margin-top: 20px;
        width: auto !important;
        right: auto !important;
        top: auto !important;
        transform: none !important;
        z-index: auto !important;
    }
    
    .related-tools-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    /* 新工具特定的手機優化 */
    .palette-controls {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    
    .color-palette {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) !important;
        gap: 10px !important;
    }
    
    .preset-palettes {
        grid-template-columns: 1fr !important;
    }
    
    .file-list {
        margin: 15px 0 !important;
    }
    
    .pdf-options {
        margin: 15px 0 !important;
    }
    
    .pdf-options > div {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    
    /* 按鈕在手機上更大更易點擊 */
    .btn {
        padding: 12px 20px;
        font-size: 1rem;
        min-height: 44px;
    }
    
    /* 輸入框在手機上更友善 */
    input[type="file"] {
        padding: 15px !important;
    }
    
    /* 改善觸控體驗 */
    .color-item {
        min-height: 100px !important;
        padding: 15px !important;
    }
    
    .related-tool-card {
        padding: 15px !important;
        min-height: 80px;
    }
}

/* Japanese font support and consistent button sizing */
.btn {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Yu Gothic', 'Meiryo', sans-serif;
    min-width: 100px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    line-height: 1.2;
}

/* Ensure consistent button heights in unit converter */
#convertBtn, #swapBtn, #clearBtn {
    min-height: 44px;
    min-width: 120px;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

/* Practical calculators button styles */
.calculator-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 12px 20px;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: #495057;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.tab-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.tab-btn.active {
    background: #3498db;
    border-color: #3498db;
    color: white;
}

.calc-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.calc-tab-btn {
    padding: 10px 16px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: #495057;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.calc-tab-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.calc-tab-btn.active {
    background: #17a2b8;
    border-color: #17a2b8;
    color: white;
}

.tip-presets {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 15px 0;
    flex-wrap: wrap;
}

.tip-presets span {
    font-weight: 600;
    color: #495057;
    margin-right: 8px;
}

.tip-presets button {
    padding: 8px 12px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: #495057;
    min-height: 36px;
    min-width: 50px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.tip-presets button:hover {
    background: #28a745;
    border-color: #28a745;
    color: white;
}

.unit-toggle {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.unit-btn {
    padding: 10px 16px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    color: #495057;
    min-height: 38px;
    min-width: 80px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.unit-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.unit-btn.active {
    background: #6f42c1;
    border-color: #6f42c1;
    color: white;
}

/* Share Button Styles */
.page-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.share-button {
    background: #2c3e50;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-family: inherit;
    min-height: 36px;
}

.share-button:hover {
    background: #34495e;
    transform: translateY(-1px);
}

.share-button:active {
    transform: translateY(0);
}

.share-icon {
    font-size: 1rem;
}

/* QR Code Generator Styles */
.qr-options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 30px;
    margin: 30px 0;
}

.option-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #e9ecef;
}

.option-section h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #2c3e50;
    font-size: 1.1rem;
    font-weight: 600;
}

.color-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
}

.color-input-wrapper input[type="color"] {
    width: 50px;
    height: 40px;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
}

.color-input-wrapper input[type="text"] {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: monospace;
}

.color-presets {
    margin-top: 15px;
}

.preset-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.preset-btn {
    padding: 6px 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.preset-btn:hover {
    background: #f8f9fa;
    border-color: #3498db;
    color: #3498db;
}

.logo-preview {
    margin-top: 10px;
    width: 100px;
    height: 100px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f8f9fa;
    position: relative;
}

.logo-preview::after {
    content: attr(data-size-hint);
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    display: none;
}

.logo-preview.has-logo::after {
    display: block;
}

.logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Pattern Preview for QR Code Background */
.pattern-preview {
    margin-top: 10px;
    min-height: 120px;
    border: 2px dashed #ddd;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    position: relative;
    overflow: hidden;
}

.pattern-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.5;
}

.pattern-preview.has-pattern::before {
    content: "Pattern Preview";
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    z-index: 1;
}

#logoSizeValue, #textSizeValue, #patternOpacityValue {
    display: inline-block;
    min-width: 40px;
    text-align: center;
    font-weight: 500;
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-wrapper input[type="checkbox"] {
    margin: 0;
    width: 18px;
    height: 18px;
}

.checkbox-wrapper label {
    margin: 0;
    font-weight: 500;
    cursor: pointer;
}

.download-options {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.download-options label {
    font-weight: 500;
    margin: 0;
}

.download-options select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: white;
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        gap: 15px;
    }
    
    .page-header h1 {
        margin-bottom: 0;
    }
}

/* Percentage Formula Styles */
.percentage-formula {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin: 10px 0;
}

.formula-part {
    font-weight: 500;
    color: #495057;
    white-space: nowrap;
}

.formula-input {
    width: 80px;
    padding: 8px 12px;
    border: 2px solid #dee2e6;
    border-radius: 4px;
    font-size: 1rem;
    text-align: center;
    font-weight: 500;
}

.formula-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

@media (max-width: 480px) {
    .percentage-formula {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .formula-input {
        width: 100px;
    }
}

/* Image Compressor Card Styles */
.download-section {
    margin-bottom: 20px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
}

.summary-text {
    text-align: center;
    margin-bottom: 20px;
}

.summary-line {
    font-size: 1rem;
    color: #495057;
    margin: 0;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.summary-line strong {
    color: #2c3e50;
    font-weight: 600;
}

.summary-line .original-size {
    color: #dc3545;
    font-weight: 500;
}

.summary-line .compressed-size {
    color: #28a745;
    font-weight: 500;
}

.summary-line .savings-highlight {
    color: #27ae60;
    font-weight: 600;
    background: rgba(39, 174, 96, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
}


.results-grid {
    margin-top: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    justify-items: center;
}

.compression-result-item {
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 16px;
    transition: border-color 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    min-height: 220px;
    width: 100%;
    max-width: 220px;
}

.compression-result-item:hover {
    border-color: #3498db;
}

.result-preview-container {
    margin-bottom: 12px;
}

.result-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    margin-bottom: 12px;
}

.filename {
    font-size: 0.85rem;
    font-weight: 600;
    color: #2c3e50;
    margin: 0;
    line-height: 1.3;
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.size-comparison {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.8rem;
    color: #495057;
    white-space: nowrap;
    margin: 4px 0;
}

.reduction-info {
    display: flex;
    justify-content: center;
    margin: 4px 0;
}

.result-actions {
    width: 100%;
    margin-top: auto;
    padding-top: 10px;
}

.reduction-badge {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(39, 174, 96, 0.2);
}

.result-preview {
    width: 100px;
    height: 100px;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    object-fit: cover;
    background: #f8f9fa;
}

.original-size {
    font-weight: 500;
    color: #dc3545;
}

.arrow {
    color: #6c757d;
    font-weight: 500;
}

.compressed-size {
    font-weight: 500;
    color: #28a745;
}

.download-btn {
    align-self: flex-start;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.download-btn:hover {
    transform: translateY(-1px);
}

@media (max-width: 768px) {
    
    .results-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 15px;
    }
    
    .compression-result-item {
        padding: 12px;
        min-height: 200px;
        max-width: 180px;
    }
    
    .result-preview {
        width: 60px;
        height: 60px;
    }
    
    .filename {
        font-size: 0.85rem;
    }
    
    .download-btn {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
}