/* ============================================================
   Desmos Calculator Plugin – Frontend Styles
   ============================================================ */

/* Wrapper */
.desmos-calculator-wrap {
    display: block;
    box-sizing: border-box;
    margin: 1.5em auto;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    /* Subtle shadow */
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.10);
    transition: box-shadow 0.2s ease;
}

.desmos-calculator-wrap:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* The actual embed element */
.desmos-calculator-embed {
    display: block;
    width: 100%;
    min-height: 200px;
    background: #f9f9f9;
    position: relative;
}

/* Loading state */
.desmos-calculator-embed:not(.desmos-ready)::before {
    content: '';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    z-index: 1;
}

.desmos-calculator-embed:not(.desmos-ready)::after {
    content: 'Loading Desmos…';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #888;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    z-index: 2;
    animation: desmos-pulse 1.4s ease-in-out infinite;
}

@keyframes desmos-pulse {
    0%, 100% { opacity: 0.5; }
    50%       { opacity: 1;   }
}

/* ──────────────────────────────────────────────
   RESPONSIVE BEHAVIOUR
   ────────────────────────────────────────────── */

/* Ensure full width on small screens */
@media (max-width: 767px) {
    .desmos-calculator-wrap {
        width: 100% !important;
        margin-left: 0;
        margin-right: 0;
        border-radius: 0;
        border-left: none !important;
        border-right: none !important;
    }
}

/* Tablets – slight height reduction */
@media (max-width: 600px) {
    .desmos-calculator-embed {
        /* Reduce minimum height a bit on small phones */
        min-height: 280px;
    }
}

/* ──────────────────────────────────────────────
   DARK THEME WRAPPER
   ────────────────────────────────────────────── */

/* When Desmos uses inverted/dark mode, make the wrapper match */
.desmos-calculator-embed.desmos-type-graphing[data-config*='"theme":"dark"'] ~ *,
.desmos-calculator-wrap.desmos-theme-dark {
    background: #1a1a1a;
    border-color: #333 !important;
}

/* ──────────────────────────────────────────────
   BLOCK EDITOR COMPATIBILITY
   ────────────────────────────────────────────── */

.wp-block .desmos-calculator-wrap,
.editor-block-list__block .desmos-calculator-wrap {
    pointer-events: none; /* prevent editing conflicts in editor */
    opacity: 0.75;
}

/* ──────────────────────────────────────────────
   ALIGNMENT CLASSES (Gutenberg / Classic)
   ────────────────────────────────────────────── */

.aligncenter .desmos-calculator-wrap,
.desmos-calculator-wrap.aligncenter {
    margin-left: auto;
    margin-right: auto;
}

.alignleft .desmos-calculator-wrap,
.desmos-calculator-wrap.alignleft {
    float: left;
    margin-right: 1.5em;
}

.alignright .desmos-calculator-wrap,
.desmos-calculator-wrap.alignright {
    float: right;
    margin-left: 1.5em;
}

/* Clearfix for floated calculators */
.desmos-calculator-wrap::after {
    content: '';
    display: table;
    clear: both;
}

/* ──────────────────────────────────────────────
   HIGH DPI / RETINA
   ────────────────────────────────────────────── */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .desmos-calculator-wrap {
        /* Sharper border on retina */
        box-shadow: 0 1px 6px rgba(0,0,0,0.12);
    }
}

/* ──────────────────────────────────────────────
   TOUCH DEVICES – remove box-shadow for perf
   ────────────────────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
    .desmos-calculator-wrap {
        box-shadow: 0 1px 4px rgba(0,0,0,0.10);
        transition: none;
    }
}

/* ──────────────────────────────────────────────
   PRINT
   ────────────────────────────────────────────── */
@media print {
    .desmos-calculator-wrap {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc !important;
    }
}
