/* Design Tokens */
:root {
    --brand: #6366f1;
    --brand-hov: #4f46e5;
    --brand-light: #eef2ff;
    
    --g900: #18181b;
    --g700: #374151;
    --g500: #6b7280;
    --g300: #d4d4d8;
    --g200: #e5e7eb;
    --g100: #f3f4f6;
    --g50: white;
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    
    --fs-h1: 2.5rem;
    --fs-h2: 2rem;
    --fs-h3: 1.6rem;
    --fs-h4: 1.25rem;
    --fs-p: 1.05rem;
    --fs-meta: 0.95rem;
    --fs-small: 0.85rem;
    
    --sp1: 6px;
    --sp2: 10px;
    --sp3: 14px;
    --sp4: 18px;
    --sp5: 24px;
    --sp6: 32px;
    --sp8: 48px;
    
    --radius-card: 1.5rem;
    --radius-small: 8px;
    --shadow: 0 4px 32px rgba(0,0,0,0.06), 0 2px 12px rgba(99,102,241,0.10);
    --shadow-small: 0 2px 8px rgba(0,0,0,0.08);
    --glass-bg: rgba(255,255,255,0.65);
    --glass-bg-dark: rgba(24,24,27,0.55);
    --blur: 20px;
}

[data-theme="dark"] {
    --g900: #fafafa;
    --g700: #e5e5e5;
    --g500: #c5c5c5;
    --g300: #52525b;
    --g200: #3f3f46;
    --g100: #27272a;
    --g50: #27272a;
    background: #18181b;
}

/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font: 500 var(--fs-p)/1.6 Pretendard, system-ui, sans-serif;
    color: var(--g500);
    background: var(--g50);
    transition: background 0.3s, color 0.3s;
    min-height: 100vh;
}

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--sp8) var(--sp4);
}

/* Header */
.header {
    text-align: center;
    margin-bottom: var(--sp8);
}

.header h1 {
    font-size: var(--fs-h1);
    color: var(--brand);
    font-weight: 700;
    margin-bottom: var(--sp3);
}

.header p {
    font-size: var(--fs-p);
    color: var(--g500);
    margin-bottom: var(--sp5);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp3);
    margin-top: var(--sp5);
}

/* Container */
.container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp6);
    align-items: start;
    margin-bottom: var(--sp8);
}

@media (max-width: 1024px) {
    .container {
        grid-template-columns: 1fr;
    }
}

/* Card */
.card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--blur));
    border-radius: var(--radius-card);
    box-shadow: var(--shadow);
    padding: var(--sp6);
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.6s ease forwards;
}

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: none;
    }
}

/* Section Headers */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--sp5);
}

.section-header h2 {
    font-size: var(--fs-h2);
    color: var(--g900);
    font-weight: 700;
    border-bottom: 2px solid var(--g200);
    padding-bottom: var(--sp2);
    margin: 0;
}

/* Form Styles */
.form-section-group {
    margin-bottom: var(--sp6);
    padding-bottom: var(--sp5);
    border-bottom: 1px solid var(--g200);
}

.form-section-group:last-child {
    border-bottom: none;
}

.form-section-group h4 {
    font-size: var(--fs-h4);
    color: var(--g900);
    margin-bottom: var(--sp4);
    font-weight: 600;
}

.form-group {
    margin-bottom: var(--sp4);
}

.form-group label {
    display: block;
    margin-bottom: var(--sp2);
    font-size: var(--fs-meta);
    color: var(--g700);
    font-weight: 600;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp3);
}

.input, textarea {
    width: 100%;
    padding: var(--sp3) var(--sp4);
    background: var(--g100);
    border: 2px solid transparent;
    border-radius: var(--radius-small);
    transition: all 0.3s;
    color: var(--g900);
    font-size: var(--fs-p);
    font-family: inherit;
}

.input:focus, textarea:focus {
    outline: none;
    background: var(--g50);
    border-color: var(--brand);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* Style Selector */
.style-selector {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: var(--sp3);
}

.style-selector input[type="radio"] {
    display: none;
}

.style-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp2);
    padding: var(--sp3);
    border: 2px solid var(--g200);
    border-radius: var(--radius-small);
    cursor: pointer;
    transition: all 0.2s;
}

.style-option:hover {
    border-color: var(--brand);
    transform: translateY(-2px);
}

.style-selector input[type="radio"]:checked + .style-option {
    border-color: var(--brand);
    background: var(--brand-light);
}



.style-preview {
   width: 60px;
   height: 35px;
   border-radius: 4px;
   position: relative;
}

.style-preview.modern {
   background: linear-gradient(135deg, var(--brand), var(--g300));
}

.style-preview.classic {
   background: linear-gradient(135deg, #1f2937, #374151);
}

.style-preview.minimal {
   background: linear-gradient(135deg, #f9fafb, #e5e7eb);
   border: 1px solid var(--g300);
}

.style-preview.creative {
   background: linear-gradient(135deg, #ec4899, #8b5cf6);
}

/* Color Controls */
.color-controls {
   display: grid;
   grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
   gap: var(--sp4);
   margin-bottom: var(--sp4);
}

.color-control {
   display: flex;
   flex-direction: column;
   gap: var(--sp2);
}

.color-control label {
   font-size: var(--fs-small);
   margin-bottom: var(--sp1);
}

.color-picker {
   display: flex;
   gap: var(--sp2);
   align-items: center;
}

.color-picker input[type="color"] {
   width: 40px;
   height: 40px;
   border: none;
   border-radius: var(--radius-small);
   cursor: pointer;
}

.color-hex {
   flex: 1;
   text-transform: uppercase;
   width: 100%;
   padding: var(--sp3) var(--sp4);
   background: var(--g100);
   border: 2px solid transparent;
   border-radius: var(--radius-small);
   transition: all 0.3s;
   color: var(--g900);
   font-size: var(--fs-p);
   font-family: inherit;
}

.color-presets {
   display: flex;
   gap: var(--sp2);
   flex-wrap: wrap;
   margin-top: var(--sp3);
}

.preset-btn {
   padding: var(--sp2) var(--sp3);
   background: var(--g100);
   border: 1px solid var(--g200);
   border-radius: var(--radius-small);
   cursor: pointer;
   transition: all 0.2s;
   font-size: var(--fs-small);
}

.preset-btn:hover {
   background: var(--g200);
   transform: translateY(-1px);
}

/* Layout Controls */
.layout-controls,
.font-controls,
.qr-controls {
   display: flex;
   flex-direction: column;
   gap: var(--sp3);
}

.control-row {
   display: flex;
   justify-content: space-between;
   align-items: center;
   gap: var(--sp3);
}

.control-row label {
   margin: 0;
   min-width: 100px;
   font-size: var(--fs-small);
}

.range-control {
   display: flex;
   align-items: center;
   gap: var(--sp2);
   min-width: 150px;
}

.range-control input[type="range"] {
   flex: 1;
   height: 6px;
   background: var(--g200);
   border-radius: 3px;
   outline: none;
   -webkit-appearance: none;
}

.range-control input[type="range"]::-webkit-slider-thumb {
   -webkit-appearance: none;
   width: 20px;
   height: 20px;
   background: var(--brand);
   border-radius: 50%;
   cursor: pointer;
}

.range-control input[type="range"]::-moz-range-thumb {
   width: 20px;
   height: 20px;
   background: var(--brand);
   border-radius: 50%;
   cursor: pointer;
   border: none;
}

.range-control span {
   font-size: var(--fs-small);
   color: var(--g500);
   min-width: 50px;
   text-align: right;
}

/* Checkbox Styles */
.checkbox-label {
   display: flex;
   align-items: center;
   gap: var(--sp2);
   cursor: pointer;
   margin: 0;
}

.checkbox-label input[type="checkbox"] {
   display: none;
}

.checkmark {
   width: 20px;
   height: 20px;
   background: var(--g100);
   border: 2px solid var(--g200);
   border-radius: 4px;
   position: relative;
   transition: all 0.2s;
   display: inline-block;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
   background: var(--brand);
   border-color: var(--brand);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
   content: '✓';
   position: absolute;
   top: 50%;
   left: 50%;
   transform: translate(-50%, -50%);
   color: white;
   font-size: 12px;
   font-weight: bold;
}

/* Buttons */
.btn {
   display: inline-flex;
   align-items: center;
   justify-content: center;
   padding: var(--sp3) var(--sp5);
   font: 500 var(--fs-p)/1 Pretendard;
   border: none;
   border-radius: 9999px;
   cursor: pointer;
   transition: all 0.2s;
   text-decoration: none;
   position: relative;
   overflow: hidden;
}

.btn-primary {
   background: var(--brand);
   color: white;
}

.btn-primary:hover {
   background: var(--brand-hov);
   transform: translateY(-2px);
}

.btn-secondary {
   background: var(--g100);
   color: var(--g700);
}

.btn-secondary:hover {
   background: var(--g200);
   transform: translateY(-2px);
}

.btn-outline {
   background: none;
   border: 2px solid var(--brand);
   color: var(--brand);
}

.btn-outline:hover {
   background: var(--brand);
   color: white;
}

.btn-sm {
   padding: var(--sp2) var(--sp3);
   font-size: var(--fs-small);
}

.btn-large {
   padding: var(--sp4) var(--sp6);
   font-size: var(--fs-h4);
   font-weight: 600;
}

/* Form Actions */
.form-actions {
   display: flex;
   gap: var(--sp3);
   margin-top: var(--sp6);
   padding-top: var(--sp5);
   border-top: 2px solid var(--g200);
}

/* Toggle */
.toggle {
   position: relative;
   width: 51px;
   height: 27px;
   display: block;
}

.toggle input {
   opacity: 0;
   width: 0;
   height: 0;
}

.toggle-track {
   position: absolute;
   top: 0;
   left: 0;
   right: 0;
   bottom: 0;
   background: var(--g200);
   border-radius: 9999px;
   transition: 0.2s;
}

.toggle-thumb {
   position: absolute;
   top: 4px;
   left: 4px;
   width: 19px;
   height: 19px;
   background: white;
   border-radius: 50%;
   transition: 0.25s;
}

.toggle input:checked + .toggle-track {
   background: var(--brand);
}

.toggle input:checked + .toggle-track .toggle-thumb {
   transform: translateX(24px);
}

/* Preview Section */
.business-card-preview {
   margin-bottom: var(--sp5);
}

.canvas-container {
   position: relative;
   display: flex;
   justify-content: center;
   padding: var(--sp5);
   background: var(--g100);
   border-radius: var(--radius-card);
   margin-bottom: var(--sp4);
}

#businessCardCanvas {
   max-width: 100%;
   height: auto;
   border-radius: 12px;
   box-shadow: 0 8px 32px rgba(0,0,0,0.12);
   transition: all 0.3s;
}

.canvas-overlay {
   position: absolute;
   top: 0;
   left: 0;
   right: 0;
   bottom: 0;
   background: rgba(255,255,255,0.9);
   display: flex;
   flex-direction: column;
   align-items: center;
   justify-content: center;
   border-radius: var(--radius-card);
}

.loading-spinner {
   width: 40px;
   height: 40px;
   border: 4px solid var(--g200);
   border-top-color: var(--brand);
   border-radius: 50%;
   animation: spin 1s linear infinite;
   margin-bottom: var(--sp3);
}

@keyframes spin {
   to {
       transform: rotate(360deg);
   }
}

/* Card Info */
.card-info {
   display: flex;
   justify-content: space-around;
   padding: var(--sp3);
   background: var(--g50);
   border-radius: var(--radius-small);
   margin-bottom: var(--sp4);
   border: 1px solid var(--g200);
}

.info-item {
   text-align: center;
}

.info-label {
   display: block;
   font-size: var(--fs-small);
   color: var(--g500);
   margin-bottom: var(--sp1);
}

/* Download Section */
.download-section {
   display: grid;
   gap: var(--sp5);
}

.download-group {
   padding: var(--sp4);
   background: var(--g50);
   border-radius: var(--radius-small);
   border: 1px solid var(--g200);
}

.download-group h4 {
   font-size: var(--fs-h4);
   color: var(--g900);
   margin-bottom: var(--sp3);
   font-weight: 600;
}

.download-buttons {
   display: flex;
   gap: var(--sp2);
   flex-wrap: wrap;
}

/* Saved Section */
.saved-section {
   margin-top: var(--sp8);
}

.section-tabs {
   display: flex;
   border-bottom: 2px solid var(--g200);
   margin-bottom: var(--sp5);
}

.tab-btn {
   padding: var(--sp3) var(--sp5);
   background: none;
   border: none;
   font: 600 var(--fs-p)/1 Pretendard;
   color: var(--g500);
   cursor: pointer;
   transition: all 0.2s;
   border-bottom: 3px solid transparent;
}

.tab-btn.active,
.tab-btn:hover {
   color: var(--brand);
   border-bottom-color: var(--brand);
}

.tab-content {
   display: none;
}

.tab-content.active {
   display: block;
}

/* Template and History Items */
.template-item,
.history-item {
   display: flex;
   align-items: center;
   gap: var(--sp4);
   padding: var(--sp4);
   background: var(--g50);
   border: 1px solid var(--g200);
   border-radius: var(--radius-small);
   margin-bottom: var(--sp3);
   transition: all 0.2s;
}

.template-item:hover,
.history-item:hover {
   transform: translateY(-2px);
   box-shadow: var(--shadow-small);
}

.item-thumbnail {
   width: 80px;
   height: 50px;
   background: var(--g100);
   border-radius: var(--radius-small);
   overflow: hidden;
   flex-shrink: 0;
}

.item-thumbnail img {
   width: 100%;
   height: 100%;
   object-fit: cover;
}

.item-info {
   flex: 1;
}

.item-title {
   font-size: var(--fs-p);
   font-weight: 600;
   color: var(--g900);
   margin-bottom: var(--sp1);
}

.item-meta {
   font-size: var(--fs-small);
   color: var(--g500);
}

.item-actions {
   display: flex;
   gap: var(--sp2);
}

/* Settings Groups */
.settings-group {
   margin-bottom: var(--sp6);
   padding-bottom: var(--sp5);
   border-bottom: 1px solid var(--g200);
}

.settings-group:last-child {
   border-bottom: none;
}

.settings-group h4 {
   font-size: var(--fs-h4);
   color: var(--g900);
   margin-bottom: var(--sp2);
   font-weight: 600;
}

.settings-group p {
   color: var(--g500);
   margin-bottom: var(--sp4);
   line-height: 1.5;
}

.settings-buttons {
   display: flex;
   gap: var(--sp3);
   flex-wrap: wrap;
}

.auto-save-settings {
   display: flex;
   flex-direction: column;
   gap: var(--sp3);
}

/* Modal */
.modal-backdrop {
   position: fixed;
   top: 0;
   left: 0;
   right: 0;
   bottom: 0;
   background: rgba(0,0,0,0.5);
   display: flex;
   align-items: center;
   justify-content: center;
   z-index: 1000;
   opacity: 0;
   visibility: hidden;
   transition: all 0.3s;
}

.modal-backdrop.show {
   opacity: 1;
   visibility: visible;
}

.modal {
   background: var(--g50);
   border-radius: var(--radius-card);
   padding: var(--sp6);
   width: min(90vw, 500px);
   max-height: 90vh;
   overflow-y: auto;
   position: relative;
   transform: scale(0.9);
   transition: transform 0.3s;
}

.modal-backdrop.show .modal {
   transform: scale(1);
}

.modal-close {
   position: absolute;
   top: var(--sp3);
   right: var(--sp3);
   background: none;
   border: none;
   font-size: 1.5rem;
   cursor: pointer;
   color: var(--g500);
   width: 30px;
   height: 30px;
   display: flex;
   align-items: center;
   justify-content: center;
   border-radius: 50%;
   transition: all 0.2s;
}

.modal-close:hover {
   background: var(--g100);
   color: var(--g700);
}

.modal h3 {
   font-size: var(--fs-h3);
   color: var(--g900);
   margin-bottom: var(--sp5);
}

/* Empty States */
.empty-state {
   text-align: center;
   color: var(--g500);
   font-style: italic;
   padding: var(--sp8);
}

/* Animations */
.fade-in {
   animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
   from {
       opacity: 0;
       transform: scale(0.95);
   }
   to {
       opacity: 1;
       transform: scale(1);
   }
}

/* Notification Styles */
.notification {
   position: fixed;
   top: 20px;
   right: 20px;
   padding: var(--sp3) var(--sp4);
   border-radius: var(--radius-small);
   color: white;
   z-index: 1001;
   display: flex;
   align-items: center;
   gap: var(--sp3);
   max-width: 400px;
   animation: slideIn 0.3s ease;
   box-shadow: var(--shadow);
}

.notification-error { background: var(--danger); }
.notification-success { background: var(--success); }
.notification-info { background: var(--brand); }
.notification-warning { background: var(--warning); }

.notification button {
   background: none;
   border: none;
   color: white;
   cursor: pointer;
   font-size: 1.2em;
   padding: 0;
   width: 20px;
   height: 20px;
   display: flex;
   align-items: center;
   justify-content: center;
   border-radius: 50%;
   transition: background 0.2s;
}

.notification button:hover {
   background: rgba(255,255,255,0.2);
}

@keyframes slideIn {
   from { transform: translateX(100%); opacity: 0; }
   to { transform: translateX(0); opacity: 1; }
}

/* Dark Theme Overrides */
[data-theme="dark"] .card,
[data-theme="dark"] .modal {
   background: var(--glass-bg-dark);
}

[data-theme="dark"] .canvas-container,
[data-theme="dark"] .download-group,
[data-theme="dark"] .card-info,
[data-theme="dark"] .template-item,
[data-theme="dark"] .history-item {
   background: var(--g200);
   border-color: var(--g300);
}

[data-theme="dark"] .input,
[data-theme="dark"] textarea {
   background: var(--g300);
   color: var(--g900);
}

[data-theme="dark"] .input:focus,
[data-theme="dark"] textarea:focus {
   background: var(--g200);
}

[data-theme="dark"] .btn-secondary {
   background: var(--g300);
   color: var(--g900);
}

[data-theme="dark"] .btn-secondary:hover {
   background: var(--g200);
}

[data-theme="dark"] .canvas-overlay {
   background: rgba(39,39,42,0.9);
}

/* Responsive Design */
@media (max-width: 768px) {
   main {
       padding: var(--sp5) var(--sp3);
   }
   
   .form-row {
       grid-template-columns: 1fr;
   }
   
   .color-controls {
       grid-template-columns: 1fr;
   }
   
   .style-selector {
       grid-template-columns: repeat(2, 1fr);
   }
   
   .section-header {
       flex-direction: column;
       gap: var(--sp3);
       align-items: stretch;
   }
   
   .download-buttons,
   .settings-buttons {
       flex-direction: column;
   }
   
   .btn {
       width: 100%;
   }
   
   .section-tabs {
       flex-direction: column;
   }
   
   .tab-btn {
       text-align: left;
       border-bottom: none;
       border-left: 3px solid transparent;
   }
   
   .tab-btn.active,
   .tab-btn:hover {
       border-left-color: var(--brand);
       border-bottom-color: transparent;
   }
   
   .template-item,
   .history-item {
       flex-direction: column;
       text-align: center;
   }
   
   .item-actions {
       width: 100%;
       justify-content: center;
   }
   
   .notification {
       left: 10px;
       right: 10px;
       max-width: none;
   }
}

@media (max-width: 480px) {
   .card {
       padding: var(--sp4);
   }
   
   .header h1 {
       font-size: 2rem;
   }
   
   .control-row {
       flex-direction: column;
       align-items: stretch;
   }
   
   .control-row label {
       min-width: auto;
       margin-bottom: var(--sp2);
   }
   
   .range-control {
       min-width: auto;
   }
   
   .color-presets {
       justify-content: center;
   }
}

/* Print Styles */
@media print {
   .header,
   .form-section,
   .download-section,
   .saved-section {
       display: none;
   }
   
   .canvas-container {
       background: none;
       box-shadow: none;
   }
   
   #businessCardCanvas {
       max-width: 100%;
       page-break-inside: avoid;
   }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
   * {
       animation-duration: 0.01ms !important;
       animation-iteration-count: 1 !important;
       transition-duration: 0.01ms !important;
       scroll-behavior: auto !important;
   }
}

/* Focus Styles */
.btn:focus,
.input:focus,
textarea:focus,
.tab-btn:focus {
   outline: 2px solid var(--brand);
   outline-offset: 2px;
}

/* Loading States */
.btn.loading {
   opacity: 0.7;
   pointer-events: none;
}

.btn.loading::after {
   content: '';
   position: absolute;
   width: 16px;
   height: 16px;
   border: 2px solid transparent;
   border-top-color: currentColor;
   border-radius: 50%;
   animation: spin 1s linear infinite;
}