* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: Arial, sans-serif;
    background-color: #f4f4f9;
}

#canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    background-color: #ffffff;
    touch-action: none;
    z-index: 1;
}

.brand-container {
    position: absolute;
    top: 14px;
    right: 18px;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
}

.save-status-badge {
    font-size: 11px;
    font-weight: bold;
    padding: 6px 14px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border: 1px solid rgba(68, 126, 168, 0.4);
    color: #555;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.save-status-badge:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.22);
    border-color: #447ea8;
}

.save-status-badge.saving { color: #447ea8; border-color: #447ea8; }
.save-status-badge.saved { color: #28a745; border-color: #28a745; }

.brand-watermark {
    height: 75px;
    background: rgba(255, 255, 255, 0.95);
    padding: 6px 14px;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
    border: 2px solid rgba(68, 126, 168, 0.3);
    display: flex;
    align-items: center;
}

.brand-watermark img { height: 100%; object-fit: contain; }

.toolbar-v {
    position: absolute;
    top: 6px;
    left: 6px;
    bottom: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #447ea8;
    padding: 6px 4px;
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
    z-index: 500;
    width: 70px;
    align-items: center;
    
    /* Native Mobile Scroll Fixes */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    max-height: calc(100vh - 12px) !important;
    touch-action: pan-y !important;
    pointer-events: auto !important;
    overscroll-behavior-y: contain !important;
    transition: left 0.2s ease, right 0.2s ease;
}

/* Force all child containers and buttons inside toolbar to allow Y panning */
.tb-main-group,
.tb-item,
.tb-main-btn,
.tb-main-btn span,
.tb-main-btn img,
.tb-main-btn svg {
    touch-action: pan-y !important;
    -webkit-user-drag: none;
}

.tb-main-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-grow: 1;
    align-items: center;
    width: 100%;
    padding-bottom: 12px;
    flex-shrink: 0 !important; 
}
.canvas-widget input,
.canvas-widget select,
.canvas-widget textarea {
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.canvas-widget .widget-content-body {
    box-sizing: border-box !important;
    overflow-x: hidden !important;
}

.tb-item {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
}

.tb-main-btn {
    width: 58px;
    height: 50px;
    border: none;
    background-color: transparent;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease-in-out;
    outline: none;
    padding: 4px;
    color: white;
    flex-shrink: 0;
}

.toolbar-v.dock-right {
    left: auto !important;
    right: 6px !important;
}

.tb-drag-handle {
    width: 100%;
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: grab;
    padding: 4px 0;
    user-select: none;
    line-height: 1;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 2px;
    touch-action: none; /* Prevents scrolling while dragging the handle */
}

.tb-drag-handle:active {
    cursor: grabbing;
    color: #ffffff;
}


.tb-main-btn img, .tb-main-btn svg {
    width: 22px;
    height: 22px;
    object-fit: contain;
    pointer-events: none;
    stroke: currentColor;
}

.tb-main-btn span {
    font-size: 9px;
    font-weight: 600;
    margin-top: 3px;
    color: #ffffff;
    text-align: center;
    line-height: 1;
}

.tb-main-btn:hover { background-color: rgba(255, 255, 255, 0.2); }
.tb-main-btn.active { background-color: rgba(255, 255, 255, 0.35); box-shadow: inset 0 1px 3px rgba(0,0,0,0.15); }
.tb-main-btn:disabled { opacity: 0.4; cursor: not-allowed; background-color: transparent; }

.submenu {
    position: fixed;
    left: 68px;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    background: #447ea8;
    padding: 8px 8px 8px 16px;
    margin-left: -8px;
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.3);
    white-space: nowrap;
    z-index: 20000 !important;
    min-width: 180px;
    touch-action: pan-y !important;
    overflow-y: auto !important;
    max-height: 80vh;
}

.tb-item.submenu-open > .submenu { 
    display: flex !important; 
    z-index: 20000 !important; 
}

.submenu button, .submenu .sub-action-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: bold;
    text-align: left;
    cursor: pointer;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}

.submenu button img, .submenu .sub-action-btn img {
    width: 14px;
    height: 14px;
    object-fit: contain;
    filter: brightness(0) invert(1);
    pointer-events: none;
}

.submenu button:hover, .submenu .sub-action-btn:hover { background: rgba(255, 255, 255, 0.3); }

.separator-v {
    width: 80%;
    height: 1px;
    background-color: rgba(255, 255, 255, 0.3);
    margin: 4px 0;
    flex-shrink: 0;
}

#pageDrawer {
    position: absolute;
    top: 6px;
    left: 82px;
    bottom: 6px;
    width: 210px;
    background: #447ea8;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    z-index: 600;
    display: none;
    flex-direction: column;
    padding: 10px;
    gap: 8px;
    pointer-events: auto;
    touch-action: auto !important;
    color: white;
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: bold;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

.thumb-list {
    flex: 1;
    overflow-y: scroll !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-right: 4px;
    position: relative;
    scroll-behavior: smooth;
}

.thumb-card {
    position: relative;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: background 0.15s, border-color 0.15s;
    touch-action: pan-y;
}

.thumb-card:hover { background: rgba(255, 255, 255, 0.25); }
.thumb-card.active { border-color: #ffffff; background: rgba(255, 255, 255, 0.35); box-shadow: 0 0 8px rgba(255,255,255,0.4); }
.thumb-card.dragging { opacity: 0.6; transform: scale(1.02); z-index: 10; }

.thumb-canvas {
    width: 100%;
    height: 95px;
    background: white;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    pointer-events: none;
}

.thumb-footer {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    font-weight: bold;
    color: white;
}

.thumb-btns { display: flex; gap: 4px; }

.thumb-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    padding: 3px 6px;
    transition: background 0.15s;
}

.thumb-btn:hover { background: rgba(255, 255, 255, 0.4); }
.thumb-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.color-bar-bottom {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    box-sizing: border-box !important;
    max-height: 52px !important;
    height: 52px !important;
    overflow: hidden !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px;
    background: #447ea8;
    padding: 6px 16px;
    border-radius: 14px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    z-index: 1000 !important;
    pointer-events: auto !important;
}

.color-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.8);
    cursor: pointer;
    transition: transform 0.1s;
    pointer-events: auto !important;
}

.color-btn:hover { transform: scale(1.15); }
.color-btn.active { border-color: #ffffff; transform: scale(1.25); box-shadow: 0 0 6px rgba(255,255,255,0.8); }

.bottom-nav-group {
    display: flex;
    align-items: center;
    gap: 6px;
    border-left: 1px solid rgba(255, 255, 255, 0.3);
    padding-left: 10px;
    pointer-events: auto !important;
}

.bottom-nav-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    padding: 5px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 4px;
    pointer-events: auto !important;
}

.bottom-nav-btn img {
    width: 14px;
    height: 14px;
    object-fit: contain;
    filter: brightness(0) invert(1);
    pointer-events: none;
}

.bottom-nav-btn:hover { background: rgba(255, 255, 255, 0.3); }

.page-display-bottom {
    font-size: 11px;
    font-weight: bold;
    color: white;
    padding: 0 4px;
}

.undo-redo-bar {
    position: absolute;
    bottom: 8px;
    right: 12px;
    display: flex;
    gap: 6px;
    background: #447ea8;
    padding: 6px;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.3);
    z-index: 1000 !important;
    pointer-events: auto !important;
}

.tb-btn {
    width: 32px;
    height: 32px;
    border: none;
    background-color: rgba(255, 255, 255, 0.15);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease-in-out;
    outline: none;
    pointer-events: auto !important;
}

.tb-btn:hover:not(:disabled) { background-color: rgba(255, 255, 255, 0.3); }
.tb-btn:disabled { opacity: 0.35; cursor: not-allowed; }

#widgetLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.canvas-widget {
    position: absolute;
    background: rgba(68, 126, 168, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    overflow: hidden;
    color: #ffffff;
    padding: 10px;
    padding-bottom: 24px;
    pointer-events: auto;
    touch-action: none;
    font-family: Arial, sans-serif;
    transform-origin: 0 0;
    resize: none;

    display: flex;
    flex-direction: column;
    min-width: 220px;
    min-height: 180px;
    width: 280px;
    container-type: size; 
    container-name: widget;
}

body.teach-mode-active .widget-resize-handle,
body.teach-mode-active .widget-head-btns button {
    display: none !important;
}

body.teach-mode-active .widget-head {
    cursor: default !important;
    background: transparent !important;
}

.canvas-widget.selected {
    border-color: #28a745;
    box-shadow: 0 0 10px rgba(40, 167, 69, 0.5);
}

.widget-resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 22px;
    height: 22px;
    cursor: nwse-resize;
    background: #447ea8;
    border-top-left-radius: 10px;
    border-bottom-right-radius: 10px;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.widget-resize-handle::after {
    content: "◢";
    font-size: 11px;
    color: white;
    line-height: 1;
    pointer-events: none;
}

.widget-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #447ea8;
    color: #ffffff;
    margin: -10px -10px 8px -10px;
    padding: 8px 12px;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    cursor: move;
    font-weight: bold;
    font-size: 12px;
    flex-shrink: 0;
    user-select: none;
}

.widget-content-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding: 4px;
}

.widget-content-body svg,
.widget-content-body iframe,
.widget-content-body .widget-inner-box {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    flex: 1;
}

/* Allow canvas containers (like wheel-canvas-wrapper) to grow dynamically */
.widget-content-body .wheel-canvas-wrapper {
    flex: 1 !important;
    height: 100% !important;
    width: 100% !important;
    min-height: 0 !important;
}

/* Explicit rule for canvas elements inside widgets */
.widget-content-body canvas {
    max-width: 100% !important;
    max-height: 100% !important;
    flex: none !important;
}

.widget-content-body button,
.widget-content-body .thumb-btn,
.widget-content-body input,
.widget-content-body select {
    border-radius: 6px;
}

.widget-head-btns { display: flex; gap: 4px; }

.widget-head-btns button, .w-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #ffffff;
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.widget-head-btns button:hover, .w-btn:hover {
    background: rgba(255, 255, 255, 0.35);
}

.gdrive-modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
}

.gdrive-modal-box {
    background: #ffffff;
    width: 520px;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(68, 126, 168, 0.3);
    color: #2c3e50;
}

.gdrive-modal-header {
    background: #447ea8;
    color: #ffffff;
    padding: 12px 16px;
    font-weight: bold;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.gdrive-search-bar {
    background: #ffffff;
    padding: 10px;
    display: flex;
    gap: 6px;
    border-bottom: 1px solid #e2e6ea;
}

.gdrive-search-bar input {
    flex: 1;
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 12px;
    background: #ffffff;
    color: #2c3e50;
}

.gdrive-breadcrumb {
    background: #ffffff;
    padding: 8px 16px;
    font-size: 11px;
    font-weight: bold;
    color: #447ea8;
    display: flex;
    align-items: center;
    gap: 6px;
    border-bottom: 1px solid #e2e6ea;
    overflow-x: auto;
    white-space: nowrap;
}

.crumb-item { cursor: pointer; color: #447ea8; text-decoration: underline; }
.crumb-item:last-child { color: #2c3e50; text-decoration: none; cursor: default; }

.gdrive-modal-body {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 240px;
    max-height: 320px;
    overflow-y: auto;
    background: #ffffff;
    color: #2c3e50;
}

.gdrive-browser-item {
    padding: 8px 12px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: #2c3e50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
    margin-bottom: 6px;
}

.gdrive-browser-item:hover {
    background: #eef6fc;
    border-color: #447ea8;
}

.gdrive-browser-item span {
    color: #2c3e50;
}

.gdrive-browser-item.folder-item { color: #447ea8; }

.gdrive-modal-footer {
    padding: 12px 16px;
    background: #f8f9fa;
    border-top: 1px solid #e2e6ea;
    display: flex;
    gap: 8px;
    align-items: center;
}

/* --- Pixabay Image Search Modal Styles --- */

#imgSearchModal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 380px;
    background: #ffffff;
    border: 1px solid rgba(68, 126, 168, 0.3);
    border-radius: 14px;
    color: #2c3e50;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    z-index: 3000;
    display: none;
    flex-direction: column;
    padding: 0;
    gap: 0;
    pointer-events: auto;
    touch-action: auto !important;
    overflow: hidden;
}

.img-search-header {
    background: #447ea8;
    color: #ffffff;
    padding: 12px 16px;
    font-weight: bold;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.img-search-bar {
    padding: 10px 14px;
    display: flex;
    gap: 6px;
    border-bottom: 1px solid #e2e6ea;
    background: #ffffff;
}

.img-search-bar input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 12px;
    outline: none;
    color: #2c3e50;
    background: #ffffff;
}

.img-search-bar input:focus {
    border-color: #447ea8;
}

.img-search-btn {
    background: #447ea8;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.15s;
}

.img-search-btn:hover {
    background: #36678a;
}

.img-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    height: 240px;
    max-height: 240px;
    overflow-y: auto !important;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
    border: none;
    padding: 10px 14px;
    background: #ffffff;
}

.img-card-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    background: #f8f9fa;
    border: 1px solid #e2e6ea;
    border-radius: 6px;
    padding: 4px;
    transition: border-color 0.15s, transform 0.15s;
}

.img-card-wrap:hover { 
    border-color: #447ea8; 
    transform: scale(1.02);
}

.img-grid img { 
    width: 100%; 
    height: 65px; 
    object-fit: cover; 
    border-radius: 4px; 
    pointer-events: none; 
}

#fileInput, #pptxInput, #pdfInput, #pdfEmbedInput { display: none; }

#textOverlay {
    position: absolute;
    display: none;
    z-index: 2000;
    background: #ffffff;
    border: 2px dashed #447ea8;
    outline: none;
    font-family: 'Patrick Hand', cursive, Arial, sans-serif;
    resize: none;
    overflow: hidden;
    white-space: pre-wrap;
    padding: 2px 6px;
    margin: 0;
    line-height: 1.1;
    border-radius: 6px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.25);
    min-width: 60px;
    min-height: 30px;
    user-select: text !important;
    -webkit-user-select: text !important;
}

/* Popup container for shape fill color picker */
.shape-fill-popover {
    display: none;
    position: absolute;
    bottom: 50px;
    right: 180px;
    background: #2c3e50;
    border: 2px solid #447ea8;
    border-radius: 8px;
    padding: 8px;
    gap: 6px;
    align-items: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    z-index: 100000;
}
.shape-fill-popover.active {
    display: flex;
}
.shape-fill-tile {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 2px solid #ffffff;
    cursor: pointer;
    box-sizing: border-box;
    transition: transform 0.1s ease;
}
.shape-fill-tile:hover {
    transform: scale(1.15);
}
.shape-fill-tile.transparent-tile {
    background: linear-gradient(45deg, #ccc 25%, transparent 25%), 
                linear-gradient(-45deg, #ccc 25%, transparent 25%), 
                linear-gradient(45deg, transparent 75%, #ccc 75%), 
                linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
    border-color: #e74c3c;
    position: relative;
}
.shape-fill-tile.transparent-tile::after {
    content: '';
    position: absolute;
    top: 50%; left: 0; right: 0;
    height: 2px;
    background: #e74c3c;
    transform: rotate(-45deg);
}
/* Free Tier & Pro Lock UI Styles */
.pro-feature-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.pro-feature-btn.feature-disabled {
    opacity: 0.55;
    filter: grayscale(100%);
    cursor: not-allowed;
    background: #34495e !important;
}

.pro-feature-btn .lock-badge {
    font-size: 9px;
    font-weight: bold;
    background: #e74c3c;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}


/* Ensure dynamic color container fits tightly within the bottom bar height */
.color-bar-bottom > div[style*="position: relative"] {
    display: flex !important;
    align-items: center !important;
    height: 100% !important;
}

/* Fix shape fill popover positioning so it doesn't break parent height */
.shape-fill-popover {
    position: absolute !important;
    bottom: 58px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    z-index: 10000 !important;
}