/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --bg-surface: #0f3460;
    --accent: #e94560;
    --accent-hover: #d63851;
    --success: #2ecc71;
    --success-hover: #27ae60;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b8;
    --border-color: #2a2a4a;
    --panel-border: #000000;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --radius: 10px;
    --radius-sm: 6px;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden { display: none !important; }
.hidden-input { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

/* ===== Gallery View ===== */
.gallery-header {
    text-align: center;
    padding: 48px 24px 32px;
}

.logo {
    font-family: 'Bangers', cursive;
    font-size: 56px;
    letter-spacing: 3px;
    color: var(--accent);
    text-shadow: 3px 3px 0 #000, -1px -1px 0 #000;
    margin-bottom: 8px;
}

.tagline {
    font-size: 16px;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 24px;
    padding: 24px 48px 64px;
    max-width: 1400px;
    margin: 0 auto;
}

.template-card {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.template-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 8px 32px rgba(233, 69, 96, 0.2);
}

.template-card-preview {
    aspect-ratio: 3 / 2;
    background: #0d0d1a;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.template-card-preview.portrait {
    aspect-ratio: 2 / 3;
}

.template-card-preview canvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: 4px;
}

.template-card-info {
    padding: 14px 16px;
    border-top: 1px solid var(--border-color);
}

.template-card-info h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 2px;
}

.template-card-info span {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ===== Editor View ===== */
#editor-view {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
    flex-shrink: 0;
    z-index: 100;
}

.toolbar-center {
    flex: 1;
    text-align: center;
}

.template-name-display {
    font-family: 'Bangers', cursive;
    font-size: 22px;
    letter-spacing: 1px;
    color: var(--accent);
}

.toolbar-actions {
    display: flex;
    gap: 10px;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    font-family: 'Inter', sans-serif;
}

.toolbar-btn:hover {
    background: #1a4a7a;
    border-color: #3a5a8a;
}

.toolbar-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
}

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

.toolbar-btn.success {
    background: var(--success);
    border-color: var(--success);
    color: #000;
}

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

/* Dropdown */
.dropdown {
    position: relative;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 200;
    min-width: 160px;
    overflow: hidden;
}

.dropdown-menu.open {
    display: block;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
}

.dropdown-item:hover {
    background: var(--bg-surface);
}

/* Workspace */
.editor-workspace {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: auto;
    background: #0d0d1a;
}

.canvas-container {
    position: relative;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
    line-height: 0;
}

.canvas-container canvas {
    display: block;
}

/* Panel dividers (draggable borders between panels) */
.panel-divider {
    position: absolute;
    pointer-events: all;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.15s;
}

.panel-divider:hover,
.panel-divider:active {
    opacity: 1;
}

.panel-divider.vertical {
    background: linear-gradient(to right, transparent 25%, rgba(99, 179, 237, 0.6) 40%, rgba(99, 179, 237, 0.6) 60%, transparent 75%);
}

.panel-divider.horizontal {
    background: linear-gradient(to bottom, transparent 25%, rgba(99, 179, 237, 0.6) 40%, rgba(99, 179, 237, 0.6) 60%, transparent 75%);
}

/* Panel highlights (interactive areas) */
.panel-highlights {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.panel-highlight {
    position: absolute;
    cursor: pointer;
    pointer-events: all;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.panel-highlight:hover {
    background: rgba(233, 69, 96, 0.1);
}

.panel-highlight.empty:hover {
    background: rgba(233, 69, 96, 0.15);
}

.panel-highlight .panel-label {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.4);
    pointer-events: none;
    text-align: center;
    font-weight: 500;
}

.panel-highlight.has-image .panel-label {
    display: none;
}

.panel-highlight.has-image:hover .panel-label {
    display: block;
    color: rgba(255, 255, 255, 0.8);
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
}

/* Panel zoom controls */
.panel-zoom-controls {
    position: absolute;
    bottom: 6px;
    right: 6px;
    display: none;
    gap: 3px;
    z-index: 3;
}

.panel-highlight.has-image:hover .panel-zoom-controls {
    display: flex;
}

.panel-zoom-btn {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    pointer-events: all;
    transition: background 0.15s;
    font-family: 'Inter', sans-serif;
}

.panel-zoom-btn:hover {
    background: rgba(233, 69, 96, 0.8);
}

.panel-zoom-label {
    min-width: 40px;
    height: 28px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-family: 'Inter', sans-serif;
    pointer-events: none;
}

/* Overlay container */
.overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

/* Text overlays */
.text-overlay {
    position: absolute;
    pointer-events: all;
    cursor: move;
    user-select: none;
    min-width: 100px;
    min-height: 50px;
}

.text-overlay .overlay-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.text-overlay .overlay-text {
    font-family: 'Comic Neue', cursive;
    font-weight: 700;
    font-size: 16px;
    line-height: 1.3;
    color: #000;
    text-align: center;
    padding: 12px 18px;
    outline: none;
    word-break: break-word;
    white-space: pre-wrap;
    min-width: 40px;
    z-index: 1;
    position: relative;
}

.text-overlay .overlay-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Speech bubble */
.text-overlay.speech .overlay-bg {
    background: white;
    border: 3px solid #000;
    border-radius: 50%;
}

/* Speech bubble pointer via child element */
.text-overlay.speech .bubble-pointer {
    position: absolute;
    width: 0;
    height: 0;
}

.text-overlay.speech .bubble-pointer-fill {
    position: absolute;
    width: 0;
    height: 0;
}

/* Bottom-left pointer (default) */
.text-overlay.speech[data-pointer="bottom-left"] .bubble-pointer {
    bottom: -16px;
    left: 25%;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 18px solid #000;
}
.text-overlay.speech[data-pointer="bottom-left"] .bubble-pointer-fill {
    bottom: -12px;
    left: calc(25% + 3px);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 15px solid white;
}

/* Bottom-right pointer */
.text-overlay.speech[data-pointer="bottom-right"] .bubble-pointer {
    bottom: -16px;
    right: 25%;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 18px solid #000;
}
.text-overlay.speech[data-pointer="bottom-right"] .bubble-pointer-fill {
    bottom: -12px;
    right: calc(25% + 3px);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 15px solid white;
}

/* Top-left pointer */
.text-overlay.speech[data-pointer="top-left"] .bubble-pointer {
    top: -16px;
    left: 25%;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-bottom: 18px solid #000;
}
.text-overlay.speech[data-pointer="top-left"] .bubble-pointer-fill {
    top: -12px;
    left: calc(25% + 3px);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 15px solid white;
}

/* Top-right pointer */
.text-overlay.speech[data-pointer="top-right"] .bubble-pointer {
    top: -16px;
    right: 25%;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-bottom: 18px solid #000;
}
.text-overlay.speech[data-pointer="top-right"] .bubble-pointer-fill {
    top: -12px;
    right: calc(25% + 3px);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 15px solid white;
}

/* Thought bubble */
.text-overlay.thought .overlay-bg {
    background: white;
    border: 3px solid #000;
    border-radius: 50%;
}

/* Thought bubble dots via child elements */
.text-overlay.thought .thought-dot-big,
.text-overlay.thought .thought-dot-small {
    position: absolute;
    background: white;
    border-radius: 50%;
}

.text-overlay.thought .thought-dot-big {
    width: 12px;
    height: 12px;
    border: 3px solid #000;
}

.text-overlay.thought .thought-dot-small {
    width: 8px;
    height: 8px;
    border: 2px solid #000;
}

/* Thought bottom-left */
.text-overlay.thought[data-pointer="bottom-left"] .thought-dot-big {
    bottom: -18px; left: 30%;
}
.text-overlay.thought[data-pointer="bottom-left"] .thought-dot-small {
    bottom: -30px; left: 28%;
}

/* Thought bottom-right */
.text-overlay.thought[data-pointer="bottom-right"] .thought-dot-big {
    bottom: -18px; right: 30%;
}
.text-overlay.thought[data-pointer="bottom-right"] .thought-dot-small {
    bottom: -30px; right: 28%;
}

/* Thought top-left */
.text-overlay.thought[data-pointer="top-left"] .thought-dot-big {
    top: -18px; left: 30%;
}
.text-overlay.thought[data-pointer="top-left"] .thought-dot-small {
    top: -30px; left: 28%;
}

/* Thought top-right */
.text-overlay.thought[data-pointer="top-right"] .thought-dot-big {
    top: -18px; right: 30%;
}
.text-overlay.thought[data-pointer="top-right"] .thought-dot-small {
    top: -30px; right: 28%;
}

/* Scream bubble */
.text-overlay.scream .overlay-bg {
    background: #fff;
    border: 3px solid #000;
    clip-path: polygon(
        50% 0%, 61% 8%, 72% 0%, 76% 12%, 90% 5%, 86% 18%,
        100% 22%, 90% 32%, 100% 42%, 90% 48%, 100% 58%,
        90% 62%, 98% 75%, 86% 72%, 80% 88%, 72% 76%,
        60% 92%, 55% 78%, 42% 100%, 40% 82%, 28% 92%,
        28% 76%, 12% 85%, 18% 72%, 2% 65%, 12% 58%,
        0% 48%, 10% 42%, 0% 32%, 10% 25%, 2% 15%,
        14% 16%, 18% 2%, 26% 14%, 38% 0%, 40% 12%
    );
}

.text-overlay.scream .overlay-text {
    font-family: 'Bangers', cursive;
    font-weight: 400;
    letter-spacing: 1px;
}

/* Scream bubble pointer via child element */
.text-overlay.scream .bubble-pointer {
    position: absolute;
    width: 0;
    height: 0;
}

.text-overlay.scream .bubble-pointer-fill {
    position: absolute;
    width: 0;
    height: 0;
}

/* Scream bottom-left pointer */
.text-overlay.scream[data-pointer="bottom-left"] .bubble-pointer {
    bottom: -16px;
    left: 25%;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 18px solid #000;
}
.text-overlay.scream[data-pointer="bottom-left"] .bubble-pointer-fill {
    bottom: -12px;
    left: calc(25% + 3px);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 15px solid white;
}

/* Scream bottom-right pointer */
.text-overlay.scream[data-pointer="bottom-right"] .bubble-pointer {
    bottom: -16px;
    right: 25%;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 18px solid #000;
}
.text-overlay.scream[data-pointer="bottom-right"] .bubble-pointer-fill {
    bottom: -12px;
    right: calc(25% + 3px);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 15px solid white;
}

/* Scream top-left pointer */
.text-overlay.scream[data-pointer="top-left"] .bubble-pointer {
    top: -16px;
    left: 25%;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-bottom: 18px solid #000;
}
.text-overlay.scream[data-pointer="top-left"] .bubble-pointer-fill {
    top: -12px;
    left: calc(25% + 3px);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 15px solid white;
}

/* Scream top-right pointer */
.text-overlay.scream[data-pointer="top-right"] .bubble-pointer {
    top: -16px;
    right: 25%;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-bottom: 18px solid #000;
}
.text-overlay.scream[data-pointer="top-right"] .bubble-pointer-fill {
    top: -12px;
    right: calc(25% + 3px);
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 15px solid white;
}

/* Caption box */
.text-overlay.caption .overlay-bg {
    background: #fffde7;
    border: 3px solid #000;
    border-radius: 4px;
}

.text-overlay.caption .overlay-text {
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    font-style: italic;
    font-size: 14px;
}

/* Overlay controls */
.text-overlay .overlay-controls {
    position: absolute;
    top: -34px;
    right: 0;
    display: none;
    gap: 4px;
    z-index: 10;
    /* Extend clickable area downward to bridge gap to bubble */
    padding-bottom: 8px;
}

.text-overlay:hover .overlay-controls,
.text-overlay.selected .overlay-controls {
    display: flex;
}

/* Invisible hover bridge: extends the text-overlay hit area upward so
   moving the mouse to the controls doesn't leave the hover zone */
.text-overlay::after {
    content: '';
    position: absolute;
    top: -40px;
    left: -10px;
    right: -10px;
    height: 44px;
    /* transparent, just extends hover zone */
}

.overlay-ctrl-btn {
    width: 26px;
    height: 26px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-card);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background 0.15s;
}

.overlay-ctrl-btn:hover {
    background: var(--accent);
}

/* Resize handle */
.text-overlay .resize-handle {
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 12px;
    height: 12px;
    background: var(--accent);
    border: 2px solid white;
    border-radius: 2px;
    cursor: nwse-resize;
    display: none;
    z-index: 5;
}

.text-overlay:hover .resize-handle,
.text-overlay.selected .resize-handle {
    display: block;
}

/* Cover template special fields */
.cover-title-field,
.cover-subtitle-field {
    position: absolute;
    pointer-events: all;
    cursor: text;
    text-align: center;
    outline: none;
    z-index: 5;
}

.cover-title-field {
    font-family: 'Bangers', cursive;
    font-size: 32px;
    color: white;
    text-shadow: 3px 3px 0 #000, -1px -1px 0 #000;
    letter-spacing: 2px;
}

.cover-subtitle-field {
    font-family: 'Comic Neue', cursive;
    font-size: 16px;
    color: #ddd;
    text-shadow: 1px 1px 0 #000;
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: #3a3a5a;
}
