/* ==========================================================================
   Sophicly Exercise Widget v1.0.0
   Drag-and-drop essay structure exercise.
   ========================================================================== */

.sce-widget {
    --sce-font: 'Proxima Soft', system-ui, -apple-system, sans-serif;
    --sce-text: #f0f0f2;
    --sce-text-muted: rgba(255,255,255,0.55);
    --sce-bg: #1C1D1F;
    --sce-card-bg: #2a2b2e;
    --sce-card-border: rgba(255,255,255,0.08);
    --sce-section-bg: rgba(255,255,255,0.03);
    --sce-drop-highlight: rgba(83,51,237,0.12);
    --sce-success: #1CD991;
    --sce-error: #E74C3C;
    --sce-accent: #51dacf;
    --sce-purple: #5333ed;

    font-family: var(--sce-font); max-width: 980px; margin: 24px auto;
    color: var(--sce-text); -webkit-font-smoothing: antialiased;
    animation: sceFadeIn 0.4s ease both;
}
.sce-widget *, .sce-widget *::before, .sce-widget *::after { box-sizing: border-box; }
@keyframes sceFadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

.sce-title { font-size: 20px; font-weight: 600; margin-bottom: 20px; text-align: center; }

/* ── Board (two-column) ────────────────────────────────────────────────── */

.sce-board { display: flex; gap: 16px; align-items: flex-start; }

/* Left column: sections */
.sce-sections-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }

/* Right column: unsorted pool (sticky) */
.sce-pool-col { width: 340px; min-width: 280px; flex-shrink: 1; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }

/* ── Unsorted Pool ─────────────────────────────────────────────────────── */

.sce-unsorted {
    border: 2px dashed var(--sce-card-border); border-radius: 12px;
    padding: 12px; background: var(--sce-section-bg);
}
.sce-unsorted-header {
    font-size: 13px; font-weight: 600; margin-bottom: 8px;
    color: var(--sce-text-muted); text-transform: uppercase; letter-spacing: 0.05em;
}
.sce-unsorted-items {
    display: flex; flex-direction: column; gap: 6px;
    min-height: 48px;
}

/* ── Sections ──────────────────────────────────────────────────────────── */

.sce-section {
    border: 1px solid var(--sce-card-border); border-radius: 12px;
    overflow: hidden;
}
.sce-section-header {
    padding: 10px 16px; font-size: 15px; font-weight: 600;
    letter-spacing: 0.03em; display: flex; align-items: center; gap: 8px;
    color: #fff;
}
.sce-section-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 6px;
    background: rgba(255,255,255,0.2); font-size: 12px; font-weight: 700;
    flex-shrink: 0;
}
.sce-section-items {
    padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
    min-height: 52px; background: var(--sce-section-bg);
    transition: background 0.2s ease, border 0.2s ease;
}
.sce-section-items.sce-drop-highlight {
    background: var(--sce-drop-highlight);
}
.sce-section-empty {
    font-size: 13px; color: var(--sce-text-muted); font-style: italic;
    padding: 8px 0; text-align: center;
}

/* ── Staggered entrance animation ──────────────────────────────────────── */

@keyframes sceCardEnter {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
.sce-item--entering {
    animation: sceCardEnter 0.35s cubic-bezier(0.22, 0.61, 0.36, 1) both;
    animation-delay: var(--sce-delay, 0ms);
}

/* ── Item Cards ────────────────────────────────────────────────────────── */

.sce-item {
    background: var(--sce-card-bg); border: 2px solid transparent;
    border-radius: 10px; padding: 8px 10px;
    cursor: grab; user-select: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    position: relative;
    display: flex; align-items: center; gap: 8px;
}
.sce-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.sce-item--selected {
    border-color: var(--sce-purple);
    box-shadow: 0 0 0 3px rgba(83,51,237,0.3);
}
.sce-item-content { flex: 1; min-width: 0; }
.sce-item-label {
    font-size: 14px; font-weight: 600; margin-bottom: 1px;
}
.sce-item-desc {
    font-size: 12.5px; color: var(--sce-text-muted); line-height: 1.3;
}
.sce-item-explanation {
    display: none; font-size: 12px; line-height: 1.4; margin-top: 6px;
    padding: 6px 8px; border-radius: 6px;
    background: rgba(231,76,60,0.1); color: var(--sce-error);
    border-left: 3px solid var(--sce-error);
}
.sce-item-explanation--visible { display: block; }
.sce-item--correct .sce-item-explanation { display: none !important; }

/* Quick-assign buttons */
.sce-item-quick {
    display: flex; gap: 3px; flex-shrink: 0;
}
.sce-quick-btn {
    width: 22px; height: 22px; border-radius: 6px; border: none;
    color: #fff; font-size: 11px; font-weight: 700;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: transform 0.15s ease, opacity 0.15s ease;
    opacity: 0.7;
}
.sce-quick-btn:hover { opacity: 1; transform: scale(1.15); }
.sce-quick-btn:active { transform: scale(0.9); }

/* Hide quick-assign buttons once item is in a section (not unsorted) */
.sce-section-items .sce-item-quick { display: none; }

/* Reorder arrows (visible in sections, hidden in pool) */
.sce-item-reorder {
    display: none; flex-direction: column; gap: 2px; flex-shrink: 0;
    opacity: 0; transition: opacity 0.15s ease;
}
.sce-section-items .sce-item-reorder { display: flex; }
.sce-section-items .sce-item:hover .sce-item-reorder { opacity: 1; }
.sce-reorder-btn {
    width: 22px; height: 18px; border-radius: 4px; border: none;
    background: rgba(255,255,255,0.08); color: var(--sce-text-muted);
    font-size: 9px; cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}
.sce-reorder-btn:hover { background: rgba(255,255,255,0.15); color: var(--sce-text); }

/* ── Drop Indicator (thin line between cards during drag) ──────────────── */

.sce-drop-indicator {
    height: 3px; border-radius: 2px;
    background: var(--sce-accent);
    opacity: 0; margin: 1px 0;
    pointer-events: none;
    transition: opacity 0.1s;
}

/* ── Feedback States ───────────────────────────────────────────────────── */

.sce-item--correct {
    border-color: var(--sce-success) !important;
    background: rgba(28,217,145,0.08) !important;
}
.sce-item--wrong {
    border-color: var(--sce-error) !important;
    background: rgba(231,76,60,0.08) !important;
}

/* ── Score ──────────────────────────────────────────────────────────────── */

.sce-score {
    font-size: 18px; font-weight: 700;
    margin-bottom: 12px; color: var(--sce-text); display: none;
}
.sce-score--visible { display: block; }
.sce-score--perfect { color: var(--sce-success); }
.sce-score-fraction { font-size: 20px; }
.sce-score-pct { font-size: 14px; color: var(--sce-text-muted); font-weight: 500; }
.sce-score-grade {
    display: inline-block; padding: 2px 12px; border-radius: 12px;
    background: var(--sce-purple); color: #fff; font-size: 14px; margin-left: 8px;
}

/* ── Actions Column (3rd column on wide screens) ──────────────────────── */

.sce-actions-col {
    position: sticky; top: 16px; flex-shrink: 0;
}
.sce-actions {
    display: flex; flex-direction: column; align-items: stretch;
    gap: 8px;
}
.sce-btn {
    padding: 7px 18px; border: none; border-radius: 24px;
    font-family: var(--sce-font); font-size: 14px; font-weight: 600;
    cursor: pointer; transition: background 0.2s ease, transform 0.15s ease;
}
.sce-btn:active { transform: scale(0.97); }
.sce-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.sce-btn--primary { background: var(--sce-accent); color: #1C1D1F; }
.sce-btn--primary:hover { background: #7DF9E9; }
.sce-btn--secondary { background: transparent; border: 1px solid var(--sce-card-border); color: var(--sce-text); }
.sce-btn--secondary:hover { background: rgba(255,255,255,0.05); }
.sce-btn--check { background: var(--sce-purple); color: #fff; }
.sce-btn--check:hover { background: #6b4fff; }
.sce-btn--checked { background: var(--sce-success); color: #1C1D1F; }
.sce-btn--checked:hover { background: #2ee8a6; }
.sce-status { font-size: 13px; font-weight: 500; text-align: center; display: block; }
.sce-status--saved { color: var(--sce-success); }
.sce-status--error { color: var(--sce-error); }

/* ── Results Banner (above board for visibility) ──────────────────────── */

.sce-results-banner {
    text-align: center; padding: 14px 20px; border-radius: 10px;
    margin-bottom: 16px; font-size: 16px; font-weight: 600;
    background: rgba(231,76,60,0.1); border: 1px solid var(--sce-error);
    color: var(--sce-text);
    animation: sceFadeIn 0.3s ease both;
}
.sce-results-banner--perfect {
    background: rgba(28,217,145,0.1); border-color: var(--sce-success);
}
.sce-results-fraction { font-size: 18px; font-weight: 700; }
.sce-results-pct { font-size: 14px; color: var(--sce-text-muted); font-weight: 500; }
.sce-results-grade {
    display: inline-block; padding: 2px 12px; border-radius: 12px;
    background: var(--sce-purple); color: #fff; font-size: 14px; margin-left: 8px;
}

/* ── Light Theme ───────────────────────────────────────────────────────── */

html[data-theme="light"] .sce-widget, html.light .sce-widget {
    --sce-text: #1a1a1e;
    --sce-text-muted: rgba(0,0,0,0.5);
    --sce-bg: #f5f5f7;
    --sce-card-bg: #fff;
    --sce-card-border: rgba(0,0,0,0.1);
    --sce-section-bg: rgba(0,0,0,0.02);
    --sce-drop-highlight: rgba(83,51,237,0.08);
}
html[data-theme="light"] .sce-btn--primary, html.light .sce-btn--primary { background: #5333ed; color: #fff; }
html[data-theme="light"] .sce-btn--primary:hover, html.light .sce-btn--primary:hover { background: #6b4fff; }

/* ── Focus Mode (fills available width inside LearnDash) ───────────────── */

.sophicly-focus-mode .sce-widget { max-width: none; margin: 24px 0; }

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .sce-board { flex-direction: column; }
    .sce-pool-col { width: 100%; min-width: 0; position: static; max-height: none; }
    .sce-actions-col { position: static; width: 100%; }
    .sce-actions { flex-direction: row; justify-content: center; flex-wrap: wrap; }
}

@media (max-width: 480px) {
    .sce-widget { margin: 16px 8px; }
    .sce-item { padding: 6px 8px; }
    .sce-item-label { font-size: 12px; }
    .sce-item-desc { font-size: 11px; }
    .sce-section-header { font-size: 12px; padding: 8px 12px; }
    .sce-quick-btn { width: 20px; height: 20px; font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .sce-widget *, .sce-widget *::before, .sce-widget *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
