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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #10b981;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --error-color: #ef4444;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Main Content */
main {
    flex: 1;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    gap: 0.5rem;
    background: var(--surface);
    padding: 0.5rem;
    border-radius: 12px;
    margin-bottom: 2rem;
}

.mode-btn {
    flex: 1;
    padding: 0.875rem 1.5rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.mode-btn.active {
    background: var(--primary-color);
    color: white;
}

/* Section */
.section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.section.hidden {
    display: none;
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 16px;
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.05);
}

.upload-area.hidden {
    display: none;
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.upload-icon {
    width: 48px;
    height: 48px;
    color: var(--text-secondary);
}

.upload-content p {
    font-size: 1.1rem;
    color: var(--text-primary);
}

.upload-content span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.file-btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.file-btn:hover {
    background: var(--primary-hover);
}

/* Preview Container */
.preview-container {
    background: var(--surface);
    border-radius: 16px;
    padding: 1.5rem;
    display: none;
}

.preview-container.visible {
    display: block;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.preview-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.clear-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.clear-btn:hover {
    border-color: var(--error-color);
    color: var(--error-color);
}

.image-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--background);
    border-radius: 8px;
    padding: 1rem;
    overflow: hidden;
}

.image-wrapper canvas {
    max-width: 100%;
    max-height: 400px;
    border-radius: 4px;
}

.image-info {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Text Input Area */
.text-input-area {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.text-input-area label {
    font-weight: 500;
    font-size: 0.95rem;
}

.text-input-area textarea {
    width: 100%;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.2s ease;
}

.text-input-area textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.text-input-area textarea::placeholder {
    color: var(--text-secondary);
}

.char-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.capacity-info {
    color: var(--secondary-color);
}

.capacity-info.warning {
    color: var(--warning-color);
}

.capacity-info.error {
    color: var(--error-color);
}

/* Action Button */
.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.action-btn svg {
    width: 24px;
    height: 24px;
}

/* Result Area */
.result-area {
    background: var(--surface);
    border-radius: 16px;
    padding: 1.5rem;
    display: none;
}

.result-area.visible {
    display: block;
}

.result-area h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.download-btn,
.copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    margin-top: 1rem;
    padding: 0.875rem 1.5rem;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.download-btn:hover,
.copy-btn:hover {
    background: #0d9668;
    transform: translateY(-1px);
}

.download-btn svg,
.copy-btn svg {
    width: 20px;
    height: 20px;
}

/* Decoded Message */
.decoded-message {
    background: var(--background);
    border-radius: 8px;
    padding: 1rem;
    min-height: 80px;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Courier New', monospace;
    line-height: 1.5;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 0 1rem;
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
}

footer p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

footer a:hover {
    color: var(--secondary-color);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--error-color);
}

.toast.info {
    border-left: 4px solid var(--primary-color);
}

/* Responsive Design */
@media (max-width: 640px) {
    .container {
        padding: 1.5rem 1rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .mode-toggle {
        flex-direction: column;
    }

    .mode-btn {
        padding: 0.75rem 1rem;
    }

    .upload-area {
        padding: 2rem 1rem;
    }

    .upload-icon {
        width: 40px;
        height: 40px;
    }

    .upload-content p {
        font-size: 1rem;
    }

    .image-wrapper canvas {
        max-height: 300px;
    }

    .image-info {
        flex-direction: column;
        gap: 0.25rem;
    }

    .action-btn {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    .char-count {
        flex-direction: column;
        gap: 0.25rem;
    }
}

/* Animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.preview-container.visible,
.result-area.visible {
    animation: fadeIn 0.3s ease;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
