/* ═══════════════════════════════════════════════════════════════════
   Multiplication Drag-and-Drop Widget
   Layout: fixed-height card, grid left · tile bank right.
   Tile size == cell size via CSS custom property --amd-cell (set by JS).
   ═══════════════════════════════════════════════════════════════════ */

/* ── Root variables (JS overrides cell size per grid) ─────────────── */
.ama-mult-drag-widget {
    --amd-cell:      44px;
    --amd-cell-font: 0.95rem;
    --amd-h-font:    0.82rem;

    /* Avatar brand palette */
    --amd-blue:      #2E68A1;   /* --ama-primary       */
    --amd-blue-dark: #235f90;   /* --ama-primary-dark  */
    --amd-blue-lt:   #5AACCF;   /* --ama-primary-light */
    --amd-green-bg:  #edf7ea;
    --amd-green-fg:  #4a7a3d;   /* --ama-success-text  */
    --amd-green-bd:  #81c171;   /* --ama-success       */
    --amd-danger:    #f53a33;   /* --ama-danger        */
    --amd-radius:    18px;
}

.ama-mult-drag-widget {
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--amd-radius);
    overflow: hidden;
    max-width: 860px;
    margin: 0 auto;
    box-shadow: 0 4px 28px rgba(30,64,175,0.09);
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
    display: flex;
    flex-direction: column;
}

/* ── Header ──────────────────────────────────────────────────────── */
.amd-header {
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--amd-blue-dark) 0%, var(--amd-blue) 100%);
    color: #fff;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.amd-title {
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.amd-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.amd-ctrl-label {
    font-size: 0.78rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    opacity: 0.9;
}

.amd-size-sel {
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.35);
    color: #fff;
    border-radius: 7px;
    padding: 4px 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
}
.amd-size-sel option { background: #235f90; }

.amd-btn {
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.38);
    color: #fff;
    border-radius: 8px;
    padding: 5px 13px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.14s, transform 0.1s;
    white-space: nowrap;
}
.amd-btn:hover  { background: rgba(255,255,255,0.28); transform: translateY(-1px); }
.amd-btn:active { transform: translateY(0); }

.amd-stats {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.86rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    background: rgba(0,0,0,0.18);
    border-radius: 8px;
    padding: 3px 11px;
}
.amd-sep { opacity: 0.5; }

/* ── Body: side-by-side, fills remaining height ──────────────────── */
.amd-body {
    flex: 1;
    display: flex;
    flex-direction: row;
    min-height: 0;          /* allow flex children to shrink */
    overflow: hidden;
}

/* ── Grid panel (left) ───────────────────────────────────────────── */
.amd-grid-wrap {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 16px 14px 16px 18px;
}

.amd-grid {
    border-collapse: separate;
    border-spacing: 4px;
    flex-shrink: 0;         /* never squash the table */
}

/* All header & data cells share the same box size = --amd-cell */
.amd-grid th,
.amd-grid td {
    width:      var(--amd-cell);
    height:     var(--amd-cell);
    min-width:  var(--amd-cell);
    text-align: center;
    vertical-align: middle;
    border-radius: 9px;
    font-weight: 800;
    font-size: var(--amd-cell-font);
    box-sizing: border-box;
}

/* Corner cell */
.amd-corner {
    background: transparent;
}
.amd-corner span {
    display: inline-flex;
    width:  calc(var(--amd-cell) - 14px);
    height: calc(var(--amd-cell) - 14px);
    align-items: center;
    justify-content: center;
    background: var(--amd-blue-dark);
    color: #fff;
    border-radius: 7px;
    font-size: var(--amd-h-font);
}

/* Column & Row headers */
.amd-col-h,
.amd-row-h {
    background: var(--amd-blue);
    color: #fff;
    font-size: var(--amd-h-font);
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.15);
}
.amd-col-h { border-radius: 9px 9px 5px 5px; }
.amd-row-h { border-radius: 9px 5px 5px 9px; }

/* Empty drop zone */
.amd-cell {
    background: #f1f5f9;
    border: 2px dashed #cbd5e1;
    transition: background 0.14s, border-color 0.14s, transform 0.12s, box-shadow 0.12s;
    cursor: default;
}

/* Hover while dragging over */
.amd-cell.amd-hover {
    background: #daeaf5;
    border: 2px dashed var(--amd-blue);
    transform: scale(1.1);
    box-shadow: 0 0 0 3px rgba(46,104,161,0.22);
    z-index: 2;
}

/* Correctly placed — always green */
.amd-cell.amd-correct {
    background:  var(--amd-green-bg);
    color:       var(--amd-green-fg);
    border: 2px solid var(--amd-green-bd);
    animation: amd-pop 0.38s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes amd-pop {
    0%   { transform: scale(0.55) rotate(-5deg); opacity: 0.5; }
    65%  { transform: scale(1.14) rotate(1deg);  }
    100% { transform: scale(1)    rotate(0deg);  opacity: 1; }
}

/* Wrong drop */
.amd-cell.amd-wrong {
    background:   #fde8e7 !important;
    border: 2px solid var(--amd-danger) !important;
    animation: amd-shake 0.55s ease both;
}

@keyframes amd-shake {
    0%,100% { transform: translateX(0) rotate(0); }
    15%     { transform: translateX(-7px) rotate(-2deg); }
    35%     { transform: translateX(7px)  rotate(2deg); }
    55%     { transform: translateX(-5px) rotate(-1deg); }
    75%     { transform: translateX(5px)  rotate(1deg); }
}

/* ── Tile bank panel (right) ─────────────────────────────────────── */
.amd-bank-wrap {
    flex-shrink: 0;
    width: calc(4 * var(--amd-cell) + 50px);
    border-left: 1px solid #e2e8f0;
    background: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 12px 10px 10px;
    gap: 4px;
}

.amd-bank-label {
    font-size: 0.72rem;
    font-weight: 800;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    flex-shrink: 0;
}

.amd-bank-sub {
    font-size: 0.68rem;
    color: #94a3b8;
    margin-bottom: 6px;
    flex-shrink: 0;
}

.amd-bank {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, var(--amd-cell));
    gap: 5px;
    overflow-y: auto;
    align-content: flex-start;
    padding: 2px 1px;
}

/* scrollbar */
.amd-bank::-webkit-scrollbar { width: 5px; }
.amd-bank::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ── Individual Tile ─────────────────────────────────────────────── */
/* Tiles are exactly --amd-cell × --amd-cell — same as grid cells */
.amd-tile {
    width:   var(--amd-cell);
    height:  var(--amd-cell);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    border: 2px solid;
    font-size:   var(--amd-cell-font);
    font-weight: 800;
    cursor: grab;
    transition: transform 0.12s, box-shadow 0.12s, opacity 0.15s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.09);
    touch-action: none;
    box-sizing: border-box;
    flex-shrink: 0;
}

.amd-tile:hover {
    transform: translateY(-3px) scale(1.07);
    box-shadow: 0 6px 16px rgba(0,0,0,0.17);
    z-index: 2;
    position: relative;
}

.amd-tile.amd-dragging {
    opacity: 0.2;
    cursor: grabbing;
    transform: scale(0.9);
}

/* ── Ghost (floating clone while dragging) ───────────────────────── */
.amd-ghost {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    touch-action: none;
    border-radius: 9px;
    border: 2px solid;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transform: rotate(6deg) scale(1.2);
    box-shadow: 0 12px 32px rgba(0,0,0,0.3);
    transition: none !important;
    box-sizing: border-box;
}

/* ── Victory overlay ─────────────────────────────────────────────── */
.amd-victory {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    border-radius: var(--amd-radius);
    backdrop-filter: blur(4px);
    animation: amd-fadein 0.4s ease;
}
.amd-victory.amd-show { display: flex; }

@keyframes amd-fadein { from { opacity: 0; } to { opacity: 1; } }

.amd-victory-box {
    background: #fff;
    border-radius: 22px;
    padding: 44px 52px;
    text-align: center;
    box-shadow: 0 24px 64px rgba(0,0,0,0.35);
    animation: amd-slidein 0.42s cubic-bezier(0.34,1.56,0.64,1) both;
}

@keyframes amd-slidein {
    from { transform: scale(0.65) translateY(40px); opacity: 0; }
    to   { transform: scale(1)    translateY(0);    opacity: 1; }
}

.amd-victory-emoji  { font-size: 3.2rem; line-height: 1; margin-bottom: 10px; }
.amd-victory-title  { font-size: 2.2rem; font-weight: 900; color: var(--amd-blue-dark); margin-bottom: 8px; letter-spacing: -0.03em; }
.amd-victory-sub    { font-size: 0.96rem; color: #64748b; margin-bottom: 28px; font-weight: 500; }

/* ── Stars ───────────────────────────────────────────────────────── */
.amd-victory-stars {
    font-size: 2.6rem;
    line-height: 1;
    margin-bottom: 20px;
    letter-spacing: 4px;
}
.amd-star-on  { color: #fddd54; text-shadow: 0 2px 6px rgba(180,130,0,0.35); }
.amd-star-off { color: #d1d5db; }

/* ── Scorecard ───────────────────────────────────────────────────── */
.amd-scorecard {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px 20px;
    margin-bottom: 24px;
    min-width: 200px;
    text-align: left;
}
.amd-sc-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.88rem;
}
.amd-sc-row:last-child { border-bottom: none; }
.amd-sc-lbl { color: #64748b; font-weight: 600; }
.amd-sc-val { color: var(--amd-blue-dark); font-weight: 800; }

/* ── Error counter in stats bar ──────────────────────────────────── */
.amd-errors-txt {
    font-variant-numeric: tabular-nums;
}

.amd-victory .amd-btn {
    background: var(--amd-blue);
    border-color: var(--amd-blue-dark);
    font-size: 1rem;
    padding: 13px 36px;
    border-radius: 12px;
}
.amd-victory .amd-btn:hover { background: var(--amd-blue-dark); }

/* ── Confetti ────────────────────────────────────────────────────── */
.amd-confetti {
    position: absolute;
    top: -20px;
    z-index: 199;
    pointer-events: none;
    animation: amd-fall linear forwards;
}
@keyframes amd-fall {
    0%   { top: -20px; opacity: 1; transform: rotate(0deg)   translateX(0); }
    80%  {             opacity: 1; }
    100% { top: 110%;  opacity: 0; transform: rotate(600deg) translateX(130px); }
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 680px) {
    .amd-body {
        flex-direction: column;
    }
    .amd-bank-wrap {
        width: 100%;
        border-left: none;
        border-top: 1px solid #e2e8f0;
        padding: 10px 12px;
        max-height: 160px;
    }
    .amd-bank-sub { display: none; }
    .amd-bank     { max-height: 110px; }
    .amd-grid-wrap { padding: 14px; }
    .amd-header    { flex-direction: column; align-items: flex-start; }
    .amd-victory-box { padding: 28px 22px; }
    .amd-victory-title { font-size: 1.7rem; }
}

/* Hint row */
.amd-hint-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px 14px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}
.amd-feedback { min-height: 20px; font-size: .9rem; font-weight: 600; }
.amd-feedback-success { color: var(--amd-green-fg); }
.amd-feedback-error   { color: var(--amd-danger); }

/* Hint button */
.amd-btn-hint { background: #fff8dc; color: #5a3e00; border: 1.5px solid #fddd54; font-size: .78rem; }
.amd-btn-hint:hover { background: #fddd54; filter: none; }
.amd-btn-hint:disabled { opacity: .45; cursor: default; }

/* New button — bright green, consistent across all widgets */
.amd-btn-new {
    background: #16a34a !important;
    color: #fff !important;
    border: none !important;
    font-weight: 700;
}
.amd-btn-new:hover { background: #15803d !important; filter: none !important; }

