body, html {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    height: 100%;
    overflow: hidden;
    background: 
        radial-gradient(circle at 0% 0%, rgba(245,201,25,0.45), transparent 55%),
        radial-gradient(circle at 100% 100%, rgba(209,191,75,0.6), transparent 60%),
        linear-gradient(135deg, #f4f4f2 0%, #fdfcf8 100%);
    color: #111827;
}
h2 {
    font-family: 'Old Standard TT', serif;
}
.app-container {
    display: flex;
    height: 100vh;
}
.sidebar {
    width: 250px;
    flex: 0 0 250px;
    color: #111827;
    padding: 0;
    overflow-y: auto;
    transform: translateX(0);
    transition: width 0.3s, opacity 0.3s, transform 0.35s ease;
    background: radial-gradient(circle at top left, rgba(245,201,25,0.28), rgba(255,255,255,0.9));
    backdrop-filter: blur(14px) saturate(135%);
    -webkit-backdrop-filter: blur(14px) saturate(135%);
    border-radius: 18px 0 0 18px;
    border: 1px solid rgba(245,201,25,0.4);
    box-shadow:
        0 18px 45px rgba(15, 23, 42, 0.18),
        0 0 0 1px rgba(255, 255, 255, 0.5);
    opacity: 0.82;
    transform: translateX(0) scale(0.98);
}
.app-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 16px 6px;
    font-family: 'Old Standard TT', serif;
    font-size: 18px;
    letter-spacing: 0.02em;
    color: #1f2937;
}
.app-brand img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 6px 14px rgba(15,23,42,0.18);
}
.sidebar,
.toolbar {
    transition: opacity 0.25s ease, transform 0.25s ease, filter 0.25s ease;
}
body:not(.edit-mode) #sidebar,
body:not(.edit-mode) #toolbar {
    opacity: 0;
    transform: translateY(-12px);
    pointer-events: none;
}
body.edit-mode #sidebar,
body.edit-mode #toolbar {
    opacity: 1;
    pointer-events: auto;
}
.sidebar:hover,
.sidebar:focus-within {
    opacity: 1;
    transform: translateX(0) scale(1);
}
.sidebar.collapsed {
    width: 0;
    opacity: 0;
}
.sidebar h2, .sidebar .element-button {
    display: block;
    opacity: 1;
    transition: opacity 0.3s;
    text-align: center;
}
.signage-toggle-btn {
    display: inline-flex;
}
.sidebar .element-button {
    width: 80%;
    margin: 10px auto;
}
.sidebar.collapsed h2, .sidebar.collapsed .element-button {
    opacity: 0;
}
.canvas-container {
    position: relative;
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    transition: margin-left 0.3s;
}
.canvas {
    position: relative;
    background-color: rgba(255, 255, 255, 0.96);
    overflow: hidden;
    transition: background-color 0.3s;
    z-index: 1;
    /* Fixed artboard size — JS sets actual dimensions; fit-to-container via transform */
    width: 1920px;
    height: 1080px;
    border-radius: 22px;
    box-shadow:
        0 22px 50px rgba(15,23,42,0.25),
        0 0 0 1px rgba(245,201,25,0.45);
}

.snap-guide {
    position: absolute;
    background: rgba(52, 152, 219, 0.6);
    pointer-events: none;
    z-index: 9998;
}

.snap-guide.horizontal {
    height: 1px;
    width: 100%;
}

.snap-guide.vertical {
    width: 1px;
    height: 100%;
}

.marquee-selection {
    position: absolute;
    border: 1px dashed #3498db;
    background: rgba(52, 152, 219, 0.08);
    pointer-events: none;
    box-sizing: border-box;
    z-index: 9999;
}
.frame-bar {
    position: fixed;
    right: 24px;
    bottom: 110px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: linear-gradient(135deg, rgba(15,23,42,0.9), rgba(30,41,59,0.88));
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 16px;
    box-shadow:
        0 18px 42px rgba(15,23,42,0.55),
        0 0 0 1px rgba(255,255,255,0.08);
    z-index: 4;
    font-size: 12px;
    color: #e2e8f0;
    opacity: 0.75;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
body:not(.has-multiframe) #frame-bar {
    opacity: 0;
    transform: translateY(24px);
    pointer-events: none;
}
body:not(.is-playing) #frame-bar {
    opacity: 0;
    transform: translateY(24px);
    pointer-events: none;
}
body.advanced-open #frame-bar {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}
.frame-bar label,
.frame-bar span {
    color: #e2e8f0;
}
.frame-bar:hover,
.frame-bar:focus-within {
    opacity: 1;
    transform: translateY(-2px);
}
.frame-bar button {
    padding: 4px 10px;
    font-size: 11px;
    color: #F8FAFC;
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.2);
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(15,23,42,0.45);
    transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.frame-bar button:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-1px);
    box-shadow: 0 14px 32px rgba(15,23,42,0.55);
}
.frame-bar button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
#frame-play-btn.is-playing {
    background: linear-gradient(135deg, #f87171, #dc2626);
    color: #fff5f5;
    border-color: rgba(255,255,255,0.35);
}
body.signage-mode-active #sidebar {
    transform: translateX(-120%);
    opacity: 0;
    pointer-events: none;
    width: 0;
    flex-basis: 0;
    background: linear-gradient(135deg, #f4f4f2 0%, #fdfcf8 100%);
    border-color: transparent;
    box-shadow: none;
}
body.signage-mode-active #toolbar {
    transform: translateY(-150%);
    opacity: 0;
    pointer-events: none;
}
body.signage-mode-active #frame-bar {
    transform: translateY(140%);
    opacity: 0;
    pointer-events: none;
}
body.signage-mode-active #widget {
    transform: translateX(120%);
    opacity: 0;
    pointer-events: none;
}
body.signage-mode-active #canvas {
    pointer-events: none;
    border-radius: 0;
    box-shadow: none;
}
/* Drag-to-pan cursor in fullscreen signage */
body.signage-mode-active .canvas-container {
    cursor: grab;
}
/* In fullscreen the canvas fills the viewport — no rounded corners or shadows */
:fullscreen .canvas {
    border-radius: 0 !important;
    box-shadow: none !important;
}
:fullscreen .canvas-container {
    background: inherit;
}
body.signage-mode-active .resize-handle,
body.signage-mode-active .text-format-toolbar,
body.signage-mode-active .inline-text-toolbar {
    display: none !important;
}
body.signage-mode-active .element {
    outline: none !important;
}
body.signage-mode-active .element.element--selected {
    outline: none !important;
    box-shadow: none;
}
body.signage-mode-active .element:not(.element--selected):hover {
    transform: none !important;
    box-shadow: none !important;
}
body.signage-mode-active .signage-exit-btn {
    opacity: 0.85;
    pointer-events: auto;
}
body.signage-mode-active .signage-exit-btn:hover,
body.signage-mode-active .signage-exit-btn:focus-visible {
    opacity: 1;
}
/* Center marker removed — center of weight is auto-calculated */

/* Onboarding overlay */
#onboarding-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: none;
}

.splash-screen {
    position: fixed;
    inset: 0;
    z-index: 21000;
    display: none;
}

.splash-backdrop {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(245,201,25,0.35), transparent 55%),
        radial-gradient(circle at 80% 30%, rgba(15,23,42,0.35), transparent 60%),
        linear-gradient(140deg, rgba(255,255,255,0.8), rgba(240,240,235,0.9));
    backdrop-filter: blur(6px);
}

.splash-card {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(520px, 92vw);
    padding: 26px 28px 22px;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 28px 70px rgba(15,23,42,0.3);
    text-align: center;
    border: 1px solid rgba(245,201,25,0.5);
}

.splash-card img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 14px;
    box-shadow: 0 12px 28px rgba(15,23,42,0.2);
    margin-bottom: 10px;
}

.splash-card h1 {
    margin: 0 0 6px;
    font-family: 'Old Standard TT', serif;
    font-size: 28px;
    color: #111827;
}

.splash-card p {
    margin: 0 0 16px;
    color: #4b5563;
    font-size: 14px;
}

.splash-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.splash-actions button {
    border-radius: 999px;
    border: 1px solid rgba(15,23,42,0.2);
    padding: 8px 16px;
    font-weight: 600;
    cursor: pointer;
    background: #111827;
    color: #f9fafb;
}

.splash-actions .splash-secondary {
    background: #f8fafc;
    color: #111827;
    border-color: rgba(15,23,42,0.15);
}

.onboarding-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.onboarding-panel {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: #ffffff;
    border-radius: 10px;
    padding: 20px 24px 16px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.onboarding-panel h2 {
    margin: 0 0 8px;
    font-size: 20px;
}

.onboarding-panel p {
    margin: 0 0 12px;
    font-size: 14px;
    line-height: 1.4;
}

.onboarding-steps {
    font-size: 12px;
    color: #666;
    margin-bottom: 12px;
}

.onboarding-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

#onboarding-skip,
#onboarding-next {
    border-radius: 4px;
    border: 1px solid #ccc;
    background: #f7f7f7;
    padding: 4px 10px;
    font-size: 13px;
    cursor: pointer;
}

#onboarding-next {
    background: #2c3e50;
    color: #fff;
    border-color: #2c3e50;
}
.element {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.95);
    border: none;
    padding: 10px;
    cursor: move;
    user-select: none;
    min-width: 100px;
    min-height: 50px;
    z-index: 2;
    box-sizing: border-box;
    border-radius: 14px;
    box-shadow:
        0 12px 28px rgba(15,23,42,0.28),
        0 0 0 1px rgba(245,201,25,0.45);
    transition:
        box-shadow 0.18s ease,
        transform 0.18s ease,
        background 0.18s ease;
}
.element.element--selected {
    outline: 2px solid rgba(245,201,25,0.98);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.95),
        0 0 0 6px rgba(245,201,25,0.32);
}
.element:not(.element--selected):hover {
    transform: translateY(-2px);
    box-shadow:
        0 16px 40px rgba(15,23,42,0.32),
        0 0 0 1px rgba(245,201,25,0.4);
}
.element.locked .resize-handle, .element.locked .text-format-toolbar {
    display: none;
}
.element img, .element video, .element audio, .element iframe, .element svg {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
    padding: 5px;
    box-sizing: border-box;
}
.element video, .element audio, .element iframe {
    pointer-events: auto;
}
.element-button {
    display: block;
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    background: linear-gradient(145deg, #f9fafb, #e5ecff);
    color: #111827;
    border-radius: 999px;
    border: 1px solid rgba(245,201,25,0.5);
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18);
    transition:
        transform 0.1s ease,
        box-shadow 0.15s ease,
        background 0.15s ease;
}
.element-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.25);
    background: linear-gradient(145deg, #ffffff, var(--mb-amber));
}
.toolbar {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0.7;
    transform-origin: top right;
    filter: drop-shadow(0 20px 35px rgba(15,23,42,0.35));
    transition: opacity 0.25s ease, transform 0.25s ease, filter 0.25s ease;
    z-index: 3;
}
.toolbar:hover,
.toolbar:focus-within {
    opacity: 1;
    transform: translateY(-2px);
    filter: drop-shadow(0 26px 45px rgba(15,23,42,0.45));
}
.toolbar-group {
    display: flex;
    gap: 6px;
    padding: 5px 8px;
    background: rgba(15,23,42,0.94);
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.15);
    backdrop-filter: blur(14px) saturate(135%);
    -webkit-backdrop-filter: blur(14px) saturate(135%);
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.45);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    opacity: 0.88;
}
.toolbar-group:hover,
.toolbar-group:focus-within {
    opacity: 1;
    border-color: rgba(245,201,25,0.45);
    box-shadow: 0 24px 52px rgba(15,23,42,0.55);
    transform: translateY(-1px);
}
.toolbar-divider {
    width: 1px;
    align-self: stretch;
    background: rgba(255,255,255,0.3);
    margin: 0 4px;
}
.toolbar button {
    padding: 6px 14px;
    background-color: rgba(255, 255, 255, 0.12);
    color: #F9FAFB;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 999px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    box-shadow: 0 8px 18px rgba(15,23,42,0.35);
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}
.toolbar button:hover,
.toolbar button:focus-visible {
    background-color: rgba(255, 255, 255, 0.92);
    color: #0F172A;
    transform: translateY(-1px);
    box-shadow: 0 16px 32px rgba(15,23,42,0.45);
    outline: none;
}
.toolbar.collapsed {
    opacity: 0.45;
}
.toolbar.collapsed:hover,
.toolbar.collapsed:focus-within {
    opacity: 1;
}
.context-menu {
    position: absolute;
    background-color: white;
    border: 1px solid #ccc;
    padding: 5px;
    z-index: 1000;
}
.context-menu button {
    display: block;
    width: 100%;
    padding: 5px;
    margin: 2px 0;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-weight: 600;
}
.context-menu button:hover {
    background-color: #f0f0f0;
}
.resize-handle {
    width: 10px;
    height: 10px;
    background-color: #3498db;
    position: absolute;
    right: -5px;
    bottom: -5px;
    cursor: se-resize;
}
.editable {
    min-height: 20px;
    padding: 5px;
    margin: 5px 0;
}
.editable:focus {
    outline: none;
    border-color: #3498db;
}
.inline-text-toolbar {
    position: absolute;
    display: none;
    padding: 4px 6px;
    background: rgba(0,0,0,0.8);
    color: #fff;
    border-radius: 4px;
    font-size: 12px;
    z-index: 10001;
    gap: 4px;
}

.inline-text-toolbar select,
.inline-text-toolbar input[type="number"] {
    font-size: 11px;
    padding: 2px 4px;
}

.inline-text-toolbar .color-swatches {
    display: flex;
    gap: 4px;
    margin-left: 4px;
}

.inline-text-toolbar .color-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.25);
    cursor: pointer;
}
.inline-text-toolbar button,
.inline-text-toolbar select {
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 12px;
}
.inline-text-toolbar button:hover,
.inline-text-toolbar select:hover {
    text-decoration: underline;
}
.widget {
    position: absolute;
    bottom: 10px;
    right: 10px;
    opacity: 0.18;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 3;
}
.widget:hover {
    opacity: 1;
}
.widget img {
    width: 100px;
    height: auto;
    cursor: pointer;
}
.advanced-panel {
    position: fixed;
    right: 18px;
    top: 170px;
    display: grid;
    gap: 8px;
    padding: 12px;
    background: rgba(15,23,42,0.9);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 16px;
    box-shadow: 0 18px 42px rgba(15,23,42,0.55);
    opacity: 0;
    pointer-events: none;
    transform: translateX(120%);
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 9997;
}
.advanced-section {
    display: grid;
    gap: 8px;
    padding: 6px 4px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 4px;
}
.advanced-section-title {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(248, 250, 252, 0.7);
}
.advanced-panel .frame-bar {
    position: static;
    right: auto;
    bottom: auto;
    padding: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 12px;
    box-shadow: none;
    opacity: 1;
    transform: none;
}
.advanced-panel .frame-bar button {
    padding: 4px 8px;
    font-size: 11px;
}
.advanced-panel .frame-bar label,
.advanced-panel .frame-bar span {
    color: #e2e8f0;
}
.advanced-panel button {
    padding: 8px 14px;
    background: rgba(255,255,255,0.1);
    color: #F8FAFC;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 999px;
    font-weight: 600;
    cursor: pointer;
}
.advanced-panel button:hover {
    background: rgba(255,255,255,0.2);
}
body.advanced-open .advanced-panel {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}
.signage-exit-btn {
    position: fixed;
    left: 22px;
    bottom: 22px;
    z-index: 5;
    padding: 10px 16px;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.6);
    background: rgba(15,23,42,0.85);
    color: #F9FAFB;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    box-shadow: 0 18px 34px rgba(15,23,42,0.45);
}
.signage-exit-btn:focus-visible {
    outline: 2px solid #facc15;
    outline-offset: 2px;
}
.popup {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 20px;
    background-color: white;
    border: 1px solid #ccc;
    z-index: 10000;
    box-shadow: 0 18px 50px rgba(15,23,42,0.35);
    border-radius: 12px;
    max-height: 80vh;
    overflow-y: auto;
}
.library-popup {
    width: min(760px, 92vw);
    max-height: 78vh;
}
.library-header h3 {
    margin: 0 0 6px;
    font-family: 'Old Standard TT', serif;
}
.library-header p {
    margin: 0 0 12px;
    font-size: 12px;
    color: #4b5563;
}
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}
.library-card {
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(245,201,25,0.45);
    background: linear-gradient(135deg, #0f172a, #1f2937);
    color: #f8fafc;
    text-align: left;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    font-weight: 600;
}
.library-card .lib-title {
    display: block;
    font-size: 13px;
    letter-spacing: 0.02em;
}
.library-card .lib-desc {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    font-weight: 500;
    opacity: 0.8;
}
.library-card:hover {
    transform: translateY(-2px);
    border-color: rgba(245,201,25,0.9);
    box-shadow: 0 16px 32px rgba(15,23,42,0.35);
}
.library-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.variation-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
    margin-top: 10px;
}
.variation-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.variation-row label {
    font-size: 12px;
    color: #1f2937;
}
.variation-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}
.popup input[type="text"], .popup input[type="number"], .popup select {
    margin: 5px 0;
    padding: 5px;
    width: calc(100% - 10px);
    box-sizing: border-box;
}
.popup button {
    padding: 10px;
    background-color: #3498db;
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
}
.popup button:hover {
    background-color: #2980b9;
}
.popup label {
    display: block;
    margin: 5px 0;
}
.popup input[type="color"] {
    margin-top: 5px;
}
.popup .color-preview {
    width: 100%;
    height: 60px;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.15);
    margin: 10px 0 15px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.08);
    background: linear-gradient(135deg, #F5C919, #FFF9E5);
}
.popup .cancel-btn {
    margin-left: 10px;
    background-color: #ccc;
    color: black;
}
.text-format-toolbar {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}
.text-format-toolbar button {
    padding: 5px;
    background-color: #ccc;
    border: none;
    cursor: pointer;
}
.text-format-toolbar button:hover {
    background-color: #bbb;
}
.grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-size: 20px 20px;
    background-image:
        linear-gradient(to right, rgba(148, 163, 184, 0.18) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(148, 163, 184, 0.18) 1px, transparent 1px);
    display: none;  /* Initially hidden */
}
@keyframes move1 {
    from { transform: translate(0, 0); }
    to { transform: translate(100px, 100px); }
}
@keyframes move2 {
    from { transform: translate(0, 0); }
    to { transform: translate(200px, 200px); }
}
@keyframes move3 {
    from { transform: translate(0, 0); }
    to { transform: translate(300px, 300px); }
}
@keyframes scale1 {
    from { transform: scale(1); }
    to { transform: scale(1.2); }
}
@keyframes scale2 {
    from { transform: scale(1); }
    to { transform: scale(1.5); }
}
@keyframes scale3 {
    from { transform: scale(1); }
    to { transform: scale(2); }
}
@keyframes rotate1 {
    from { transform: rotate(0deg); }
    to { transform: rotate(90deg); }
}
@keyframes rotate2 {
    from { transform: rotate(0deg); }
    to { transform: rotate(180deg); }
}
@keyframes rotate3 {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ── Generate Sign — conversational chat panel ── */

/* Hero floating action buttons */
.hero-fab {
    position: fixed;
    z-index: 9998;
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    cursor: pointer;
    font-family: system-ui, -apple-system, sans-serif;
    font-weight: 700;
    letter-spacing: 0.03em;
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.hero-fab:hover {
    transform: translateY(-3px) scale(1.03);
}
.hero-fab:active {
    transform: translateY(0) scale(0.97);
}
.hero-fab--generate {
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    padding: 16px 36px;
    font-size: 16px;
    color: #0F172A;
    background: linear-gradient(135deg, #fde047 0%, #facc15 50%, #f59e0b 100%);
    border-radius: 999px;
    box-shadow:
        0 8px 32px rgba(245, 158, 11, 0.45),
        0 0 0 1px rgba(255,255,255,0.3) inset,
        0 2px 0 rgba(255,255,255,0.4) inset;
    text-shadow: 0 1px 0 rgba(255,255,255,0.5);
    animation: hero-fab-glow 3s ease-in-out infinite;
}
.hero-fab--present {
    top: 22px;
    right: 22px;
    left: auto;
    padding: 12px 18px;
    font-size: 13px;
    color: #F8FAFC;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
    border-radius: 999px;
    box-shadow:
        0 10px 26px rgba(15, 23, 42, 0.45),
        0 0 0 1px rgba(255,255,255,0.12) inset;
}
.hero-fab--edit {
    top: 70px;
    right: 22px;
    left: auto;
    padding: 12px 18px;
    font-size: 13px;
    color: #F8FAFC;
    background: linear-gradient(135deg, #1f2937 0%, #0f172a 100%);
    border-radius: 999px;
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.45);
}
.hero-fab--advanced {
    top: 118px;
    right: 22px;
    left: auto;
    padding: 10px 16px;
    font-size: 12px;
    color: #F8FAFC;
    background: rgba(15,23,42,0.85);
    border-radius: 999px;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.4);
}
.hero-fab--present .hero-fab-icon {
    font-size: 18px;
}
.hero-fab--generate:hover {
    transform: translateX(-50%) translateY(-3px) scale(1.05);
    box-shadow:
        0 16px 48px rgba(245, 158, 11, 0.55),
        0 0 0 1px rgba(255,255,255,0.4) inset,
        0 2px 0 rgba(255,255,255,0.5) inset;
    filter: brightness(1.05);
}
.hero-fab--generate:active {
    transform: translateX(-50%) translateY(0) scale(0.97);
}
.hero-fab-icon {
    font-size: 20px;
    line-height: 1;
}
.hero-fab-label {
    line-height: 1;
}
@keyframes hero-fab-glow {
    0%, 100% { box-shadow: 0 8px 32px rgba(245,158,11,0.45), 0 0 0 1px rgba(255,255,255,0.3) inset; }
    50% { box-shadow: 0 8px 48px rgba(245,158,11,0.65), 0 0 20px rgba(250,204,21,0.3), 0 0 0 1px rgba(255,255,255,0.3) inset; }
}

/* Hide hero fabs when in signage mode (keep fullscreen visible) */
body.signage-mode-active .hero-fab--generate { display: none; }
body.signage-mode-active .hero-fab--edit { display: none; }
body.signage-mode-active .hero-fab--advanced { display: none; }

/* Mode toggle (Replace / Add) in panel header */
.gs-mode-toggle {
    display: flex;
    gap: 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(15,23,42,0.2);
}
.gs-mode-btn {
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: rgba(15,23,42,0.06);
    color: #475569;
    transition: background 0.15s, color 0.15s;
}
.gs-mode-btn:hover {
    background: rgba(15,23,42,0.12);
}
.gs-mode-btn--active {
    background: #0F172A;
    color: #fde047;
}

.gs-panel {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 380px;
    max-height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.35);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    font-family: system-ui, -apple-system, sans-serif;
    overflow: hidden;
}
.gs-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: linear-gradient(135deg, #fde047 0%, #facc15 100%);
}
.gs-panel-header h3 {
    margin: 0;
    font-size: 1.05em;
    font-weight: 700;
    color: #0F172A;
    font-family: 'Old Standard TT', serif;
}
.gs-close-btn {
    background: none;
    border: none;
    font-size: 1.5em;
    line-height: 1;
    cursor: pointer;
    color: #0F172A;
    padding: 0 4px;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.gs-close-btn:hover { opacity: 1; }

.gs-chat {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 180px;
    max-height: 340px;
}
.gs-msg {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
}
.gs-msg p { margin: 0; }
.gs-msg--ai {
    align-self: flex-start;
    background: #f1f5f9;
    color: #1e293b;
    border-bottom-left-radius: 4px;
}
.gs-msg--user {
    align-self: flex-end;
    background: #0F172A;
    color: #fde047;
    border-bottom-right-radius: 4px;
}
.gs-msg--status {
    align-self: center;
    background: transparent;
    color: #94a3b8;
    font-size: 12px;
    font-style: italic;
    padding: 4px 0;
}

/* Clarification question buttons */
.gs-questions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}
.gs-q-btn {
    display: block;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
    color: #1e293b;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.4;
    margin-top: 6px;
}
.gs-q-btn:hover {
    background: #f8fafc;
    border-color: #94a3b8;
}
.gs-q-btn.gs-q-answered {
    background: #f0fdf4;
    border-color: #86efac;
    cursor: default;
}
.gs-q-answer-input {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12.5px;
    margin-top: 4px;
    box-sizing: border-box;
    font-family: inherit;
}
.gs-q-answer-input:focus {
    outline: none;
    border-color: #facc15;
    box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.25);
}
.gs-q-submit-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-top: 8px;
}
.gs-q-submit-btn {
    background: linear-gradient(135deg, #fde047, #facc15);
    color: #0F172A;
    border: 1px solid rgba(15,23,42,0.15);
    border-radius: 8px;
    padding: 7px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
.gs-q-submit-btn.gs-q-secondary {
    background: #f8fafc;
    color: #0f172a;
    border-color: rgba(15,23,42,0.2);
}
.gs-q-submit-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(15,23,42,0.2);
}
.gs-q-submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Input bar */
.gs-input-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    background: #fafafa;
}
.gs-input-row input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 13.5px;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}
.gs-input-row input:focus {
    border-color: #facc15;
    box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.2);
}
.gs-mic-btn,
.gs-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
}
.gs-mic-btn {
    background: #f1f5f9;
    color: #475569;
}
.gs-mic-btn:hover { background: #e2e8f0; }
.gs-mic-btn.gs-mic-active {
    background: #ef4444;
    color: #fff;
    animation: gs-pulse 1s ease-in-out infinite;
}
@keyframes gs-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}
.gs-send-btn {
    background: #0F172A;
    color: #fde047;
}
.gs-send-btn:hover { transform: scale(1.05); }
.gs-send-btn:active { transform: scale(0.95); }

.gs-status {
    font-size: 11px;
    text-align: center;
    padding: 4px 12px;
    color: #94a3b8;
    min-height: 0;
}
.gs-status:empty { display: none; }

/* Loading dots */
.gs-loading {
    display: inline-flex;
    gap: 4px;
    padding: 8px 14px;
}
.gs-loading span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: gs-bounce 1.2s ease-in-out infinite;
    opacity: 0.88;
    scale: 0.95;
}

@keyframes gs-bounce {
    0%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    50% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex: 0 0 auto;
        border-radius: 0 0 18px 18px;
        max-height: 45vh;
    }

    .sidebar [role="group"] {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 8px;
        padding: 10px 12px 16px;
    }

    .sidebar .element-button {
        width: 100%;
        margin: 0;
    }

    .app-brand {
        padding: 12px 14px 4px;
        font-size: 16px;
    }

    .canvas-container {
        flex: 1 1 auto;
        min-height: 0;
    }

    .toolbar {
        top: auto;
        bottom: 12px;
        left: 12px;
        right: 12px;
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }

    .toolbar-group {
        flex-wrap: wrap;
        justify-content: center;
    }

    .frame-bar {
        left: 12px;
        right: 12px;
        bottom: 140px;
        justify-content: center;
        flex-wrap: wrap;
    }

    .advanced-panel {
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 140px;
        max-height: 45vh;
        overflow-y: auto;
    }

    .hero-fab--generate {
        bottom: 90px;
    }

    .widget {
        display: none;
    }
}

@media (max-width: 720px) {
    .hero-fab {
        font-size: 12px;
    }

    .hero-fab--generate {
        padding: 12px 18px;
        font-size: 13px;
        bottom: 110px;
    }

    .hero-fab--present,
    .hero-fab--edit,
    .hero-fab--advanced {
        right: 12px;
        padding: 10px 14px;
        font-size: 12px;
    }

    .hero-fab--present {
        top: 12px;
    }

    .hero-fab--edit {
        top: 52px;
    }

    .hero-fab--advanced {
        top: 92px;
    }

    .gs-panel {
        left: 12px;
        right: 12px;
        width: auto;
        max-height: 70vh;
    }

    .gs-chat {
        max-height: 40vh;
    }

    .popup {
        width: min(92vw, 420px);
    }

    .signage-exit-btn {
        left: 12px;
        bottom: 12px;
    }
}

@media (pointer: coarse) {
    .element-button {
        min-height: 44px;
        padding: 12px 14px;
    }

    .toolbar button {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 14px;
    }

    .frame-bar button,
    .advanced-panel button {
        min-height: 44px;
        padding: 10px 14px;
        font-size: 12px;
    }

    .context-menu button {
        min-height: 44px;
        padding: 10px 12px;
    }

    .gs-mic-btn,
    .gs-send-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
}
