/* CSS Variables for theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #22c55e;
    --success-hover: #16a34a;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

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

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    color: white;
    padding: 1.5rem;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.header h1 {
    font-size: 1.75rem;
    margin-bottom: 0.25rem;
}

.header p {
    opacity: 0.9;
    font-size: 0.95rem;
}

/* Main container */
.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}

.toolbar-section {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

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

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

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

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

.btn-success {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: var(--success-hover);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

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

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

/* Workspace */
.workspace {
    display: grid;
    grid-template-columns: 220px 1fr 220px;
    gap: 1rem;
    flex: 1;
    min-height: 500px;
}

/* Sidebars */
.sidebar {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    overflow-y: auto;
    max-height: calc(100vh - 300px);
}

.sidebar h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-section {
    margin-bottom: 1.5rem;
}

.sidebar-section:last-child {
    margin-bottom: 0;
}

/* Character Library */
.character-library,
.background-library,
.bubble-library {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.library-item {
    aspect-ratio: 1;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: var(--background-color);
    transition: all 0.2s ease;
    user-select: none;
}

.library-item:hover {
    border-color: var(--primary-color);
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.library-item.dragging {
    opacity: 0.5;
}

.background-item {
    font-size: 1.5rem;
}

.bubble-item {
    font-size: 1.25rem;
    padding: 0.25rem;
}

/* Canvas container */
.canvas-container {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

/* Comic Strip */
.comic-strip {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    min-height: 300px;
    width: 100%;
}

.comic-strip.layout-horizontal {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.comic-strip.layout-vertical {
    flex-direction: column;
    align-items: center;
}

.comic-strip.layout-grid-2x2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    max-width: 700px;
}

/* Comic Panel */
.comic-panel {
    width: 320px;
    height: 280px;
    border: 3px solid #1e293b;
    border-radius: var(--radius-sm);
    position: relative;
    background: white;
    overflow: hidden;
    flex-shrink: 0;
}

.comic-strip.layout-grid-2x2 .comic-panel {
    width: 100%;
    height: 250px;
}

.comic-strip.layout-vertical .comic-panel {
    width: 100%;
    max-width: 400px;
    height: 300px;
}

.panel-background {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 8rem;
    opacity: 0.3;
    pointer-events: none;
}

.panel-content {
    position: absolute;
    inset: 0;
}

.panel-controls {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 100;
}

.comic-panel:hover .panel-controls {
    opacity: 1;
}

.panel-control-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
}

.panel-control-btn:hover {
    background: rgba(0, 0, 0, 0.9);
}

.panel-number {
    position: absolute;
    bottom: 0.5rem;
    left: 0.5rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
}

/* Draggable elements in panel */
.panel-element {
    position: absolute;
    cursor: move;
    user-select: none;
}

.panel-element.selected {
    outline: 2px dashed var(--primary-color);
    outline-offset: 2px;
}

.panel-character {
    font-size: 3.5rem;
    filter: drop-shadow(2px 2px 2px rgba(0, 0, 0, 0.2));
}

.panel-character:hover {
    transform: scale(1.05);
}

/* Speech Bubbles */
.speech-bubble {
    background: white;
    border: 2px solid #1e293b;
    border-radius: 1rem;
    padding: 0.5rem 0.75rem;
    min-width: 60px;
    max-width: 150px;
    text-align: center;
    font-size: 0.875rem;
    position: relative;
    word-wrap: break-word;
}

.speech-bubble::after {
    content: '';
    position: absolute;
    border: 10px solid transparent;
}

/* Tail positions */
.speech-bubble.tail-bottom-left::after {
    bottom: -20px;
    left: 15px;
    border-top-color: #1e293b;
}

.speech-bubble.tail-bottom-right::after {
    bottom: -20px;
    right: 15px;
    border-top-color: #1e293b;
}

.speech-bubble.tail-top-left::after {
    top: -20px;
    left: 15px;
    border-bottom-color: #1e293b;
}

.speech-bubble.tail-top-right::after {
    top: -20px;
    right: 15px;
    border-bottom-color: #1e293b;
}

/* Bubble styles */
.speech-bubble.style-thought {
    border-radius: 50%;
    border-style: dotted;
}

.speech-bubble.style-thought::after {
    display: none;
}

.speech-bubble.style-thought::before {
    content: '○ ○';
    position: absolute;
    bottom: -20px;
    left: 10px;
    font-size: 0.5rem;
    color: #1e293b;
}

.speech-bubble.style-shout {
    border-width: 3px;
    border-radius: 0;
    transform: rotate(-2deg);
    font-weight: bold;
    text-transform: uppercase;
}

.speech-bubble.style-whisper {
    border-style: dashed;
    opacity: 0.8;
    font-style: italic;
    font-size: 0.75rem;
}

.bubble-text {
    pointer-events: none;
}

.bubble-edit-hint {
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.625rem;
    color: var(--text-secondary);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s;
}

.speech-bubble:hover .bubble-edit-hint {
    opacity: 1;
}

/* Properties Panel */
.properties-content {
    font-size: 0.875rem;
}

.placeholder-text {
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem 1rem;
}

.property-group {
    margin-bottom: 1rem;
}

.property-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
}

.property-group input,
.property-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

.delete-element-btn {
    width: 100%;
    margin-top: 1rem;
}

/* Panel Arrangement */
.arrangement-controls {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1rem;
    margin-top: 1rem;
    text-align: center;
}

.arrangement-controls h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.layout-options {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.layout-btn {
    padding: 0.75rem 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface-color);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.75rem;
    line-height: 1.2;
    min-width: 70px;
}

.layout-btn:hover {
    border-color: var(--primary-color);
}

.layout-btn.active {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 450px;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.2s ease;
}

.modal-small {
    max-width: 350px;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.125rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--text-secondary);
}

.form-group textarea,
.form-group select,
.form-group input {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    font-family: inherit;
}

.form-group textarea:focus,
.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

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

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

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.footer a:hover {
    text-decoration: underline;
}

/* Drop zone visual feedback */
.comic-panel.drag-over {
    background-color: rgba(99, 102, 241, 0.1);
    border-color: var(--primary-color);
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-secondary);
    text-align: center;
    width: 100%;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    margin-bottom: 0.5rem;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .workspace {
        grid-template-columns: 180px 1fr 180px;
    }
}

@media (max-width: 992px) {
    .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    .sidebar {
        max-height: none;
    }

    .left-sidebar {
        order: 1;
    }

    .canvas-container {
        order: 2;
        min-height: 400px;
    }

    .right-sidebar {
        order: 3;
    }

    .character-library,
    .background-library,
    .bubble-library {
        grid-template-columns: repeat(4, 1fr);
    }

    .sidebar-section {
        margin-bottom: 1rem;
    }

    .comic-strip {
        flex-direction: column;
        align-items: center;
    }

    .comic-strip.layout-horizontal {
        flex-direction: column;
    }

    .comic-panel {
        width: 100%;
        max-width: 350px;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-section {
        justify-content: center;
    }

    .btn-text {
        display: none;
    }

    .btn {
        padding: 0.625rem;
    }

    .character-library,
    .background-library,
    .bubble-library {
        grid-template-columns: repeat(3, 1fr);
    }

    .comic-panel {
        height: 240px;
    }

    .layout-options {
        gap: 0.375rem;
    }

    .layout-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.625rem;
    }
}

@media (max-width: 480px) {
    .main-container {
        padding: 0.5rem;
    }

    .character-library,
    .background-library,
    .bubble-library {
        grid-template-columns: repeat(2, 1fr);
    }

    .library-item {
        font-size: 1.5rem;
    }

    .comic-panel {
        height: 200px;
    }

    .panel-character {
        font-size: 2.5rem;
    }

    .speech-bubble {
        min-width: 50px;
        max-width: 120px;
        font-size: 0.75rem;
        padding: 0.375rem 0.5rem;
    }
}

/* Print styles for download */
@media print {
    .header,
    .toolbar,
    .sidebar,
    .arrangement-controls,
    .footer,
    .panel-controls,
    .panel-number {
        display: none !important;
    }

    .main-container {
        padding: 0;
    }

    .workspace {
        display: block;
    }

    .canvas-container {
        box-shadow: none;
        padding: 0;
    }

    .comic-strip {
        page-break-inside: avoid;
    }

    .comic-panel {
        border-width: 2px;
    }
}
