/* ═══════════════════════════════════════════════════════════════════
   Place Value Blocks Widget
   ═══════════════════════════════════════════════════════════════════ */

.ama-place-value-widget {
    --apv-blue:      #b86000;
    --apv-blue-dark: #8a4500;
    --apv-blue-lt:   #e0830a;
    --apv-green:     #81c171;
    --apv-green-bg:  #edf7ea;
    --apv-green-fg:  #4a7a3d;
    --apv-orange:    #ff9130;
    --apv-yellow:    #fddd54;
    --apv-danger:    #f53a33;
    --apv-radius:    18px;

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

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

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

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

/* Mode toggle */
.apv-mode-toggle {
    display: flex;
    background: rgba(0,0,0,0.2);
    border-radius: 9px;
    padding: 3px;
    gap: 3px;
}
.apv-mode-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    border-radius: 7px;
    padding: 4px 12px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.apv-mode-btn.apv-mode-active {
    background: rgba(255,255,255,0.25);
    color: #fff;
}
.apv-mode-btn:hover:not(.apv-mode-active) { color: #fff; }

.apv-ctrl-label {
    font-size: 0.78rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    opacity: 0.9;
}
.apv-diff-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;
}
.apv-diff-sel option { background: #8a4500; }

.apv-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;
}
.apv-btn:hover  { background: rgba(255,255,255,0.28); transform: translateY(-1px); }
.apv-btn:active { transform: translateY(0); }

.apv-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;
}
.apv-sep { opacity: 0.5; }

/* ── Body ────────────────────────────────────────────────────────── */
.apv-body {
    flex: 1;
    display: flex;
    align-items: stretch;
    overflow: hidden;
    min-height: 0;
}

/* ════════════════════════════════
   READ MODE
   ════════════════════════════════ */
.apv-read-area {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 20px;
    padding: 16px 20px;
    overflow: hidden;
    min-height: 0;
}

/* Block display — horizontal strip of columns, no scroll */
.apv-blocks-display {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    justify-content: center;
    gap: 16px;
    overflow: hidden;
}

/* One column per place value */
.apv-place-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.apv-place-label {
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
}
.apv-label-ones      { background: #fffde7; color: #7a5c00; border: 1.5px solid #fddd54; }
.apv-label-tens      { background: #fff4eb; color: #8a4500; border: 1.5px solid #e0830a; }
.apv-label-hundreds  { background: #edf7ea; color: #4a7a3d; border: 1.5px solid #81c171; }
.apv-label-thousands { background: #fff4eb; color: #8a3d00; border: 1.5px solid #ff9130; }

/* Grid containers */
.apv-blocks-grid {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
}
/* max-width controls blocks-per-row; calculated to prevent scroll */
.apv-grid-ones      { gap: 3px; max-width: 80px;  min-height: 14px; } /* 5/row: 5×13+4×3=77 */
.apv-grid-tens      { gap: 4px; max-width: 90px;  min-height: 60px; } /* 5/row: 5×14+4×4=86 */
.apv-grid-hundreds  { gap: 5px; max-width: 165px; min-height: 52px; } /* 3/row: 3×52+2×5=166 */
.apv-grid-thousands { gap: 6px; max-width: 110px; min-height: 52px; } /* 2/row: 2×52+6=110 */

/* Count badge under blocks */
.apv-count-badge {
    font-size: 1.1rem;
    font-weight: 900;
    min-width: 24px;
    text-align: center;
    border-radius: 8px;
    padding: 2px 8px;
}
.apv-badge-ones      { background: #fffde7; color: #7a5c00; }
.apv-badge-tens      { background: #fff4eb; color: #8a4500; }
.apv-badge-hundreds  { background: #edf7ea; color: #4a7a3d; }
.apv-badge-thousands { background: #fff4eb; color: #8a3d00; }

/* Empty slot */
.apv-empty-slot {
    font-size: 1.6rem;
    font-weight: 900;
    color: #cbd5e1;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed #e2e8f0;
    border-radius: 8px;
}

/* ── Block elements ──────────────────────────────────────────────── */
.apv-block {
    flex-shrink: 0;
    border-radius: 3px;
    animation: apv-pop-in 0.28s cubic-bezier(0.34,1.56,0.64,1) both;
}
.apv-block-instant { animation: none !important; }

@keyframes apv-pop-in {
    0%   { transform: scale(0) rotate(-12deg); opacity: 0; }
    60%  { transform: scale(1.1) rotate(2deg); opacity: 1; }
    100% { transform: scale(1)   rotate(0deg); opacity: 1; }
}

/* Ones — small yellow square */
.apv-block-ones {
    width:  13px;
    height: 13px;
    background: #fddd54;
    border: 1.5px solid #b86000;
}

/* Tens — tall blue rod with horizontal lines (10 divisions) */
.apv-block-tens {
    width:  14px;
    height: 60px;
    background: #e0830a;
    border: 1.5px solid #1a4171;
    background-image: linear-gradient(rgba(255,255,255,0.35) 1px, transparent 1px);
    background-size: 100% 6px; /* 10 cells × 6px = 60px */
}

/* Hundreds — green flat with 10×10 grid */
.apv-block-hundreds {
    width:  52px;
    height: 52px;
    background: #81c171;
    border: 1.5px solid #4a7a3d;
    background-image:
        linear-gradient(rgba(255,255,255,0.38) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.38) 1px, transparent 1px);
    background-size: 5.2px 5.2px; /* 10 cells each */
}

/* Thousands — orange cube with 3D shadow */
.apv-block-thousands {
    width:  52px;
    height: 52px;
    background: #ff9130;
    border: 1.5px solid #8a3d00;
    background-image:
        linear-gradient(rgba(255,255,255,0.25) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.25) 1px, transparent 1px);
    background-size: 5.2px 5.2px;
    box-shadow: 4px 4px 0 rgba(0,0,0,0.2);
}

/* ── Read panel (input side) ─────────────────────────────────────── */
.apv-read-panel {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 24px 28px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    min-width: 180px;
}

.apv-read-prompt {
    font-size: 0.9rem;
    font-weight: 700;
    color: #475569;
    text-align: center;
    line-height: 1.4;
}

.apv-read-input {
    font-size: 2.2rem;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    color: var(--apv-blue-dark);
    text-align: center;
    width: 140px;
    border: 3px solid #e2e8f0;
    border-radius: 12px;
    padding: 8px 12px;
    outline: none;
    background: #f8fafc;
    transition: border-color 0.15s;
    -webkit-user-select: text;
    user-select: text;
}
.apv-read-input:focus { border-color: var(--apv-blue); background: #fff; }

.apv-read-panel .apv-btn {
    background: var(--apv-blue);
    border-color: var(--apv-blue-dark);
    font-size: 0.9rem;
    padding: 8px 22px;
    border-radius: 10px;
    width: 100%;
}
.apv-read-panel .apv-btn:hover { background: var(--apv-blue-dark); }

/* ════════════════════════════════
   BUILD MODE
   ════════════════════════════════ */
.apv-build-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 28px;
    gap: 20px;
}

/* Target number */
.apv-build-number {
    font-size: 3.4rem;
    font-weight: 900;
    color: var(--apv-blue-dark);
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    background: #fff4eb;
    border: 3px solid var(--apv-blue-lt);
    border-radius: 16px;
    padding: 10px 36px;
    line-height: 1.1;
}

/* Columns table */
.apv-build-table {
    display: flex;
    flex-direction: row;
    gap: 16px;
    align-items: flex-start;
    flex-wrap: wrap;
    justify-content: center;
}

.apv-build-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 14px;
    padding: 14px 12px 12px;
    min-width: 90px;
}

/* Build input (one digit per place value) */
.apv-build-inp {
    font-size: 2.2rem;
    font-weight: 900;
    text-align: center;
    width: 64px;
    border: 3px solid #e2e8f0;
    border-radius: 10px;
    padding: 6px 4px;
    background: #f8fafc;
    color: var(--apv-blue-dark);
    outline: none;
    font-variant-numeric: tabular-nums;
    transition: border-color 0.15s, background 0.15s;
    -webkit-user-select: text;
    user-select: text;
}
.apv-build-inp:focus { border-color: var(--apv-blue); background: #fff; }

/* Live block preview below each input */
.apv-build-preview {
    min-height: 24px;
}
.apv-grid-ones.apv-build-preview      { gap: 3px; max-width: 60px; flex-wrap: wrap; }
.apv-grid-tens.apv-build-preview      { gap: 4px; max-width: 70px; flex-wrap: wrap; }
.apv-grid-hundreds.apv-build-preview  { gap: 5px; max-width: 80px; flex-wrap: wrap; }
.apv-grid-thousands.apv-build-preview { gap: 6px; max-width: 80px; flex-wrap: wrap; }

/* Build preview uses same sizes as read mode blocks (already small) */
.apv-build-preview .apv-block-ones      { width: 11px; height: 11px; }
.apv-build-preview .apv-block-tens      { width: 12px; height: 50px; background-size: 100% 5px; }
.apv-build-preview .apv-block-hundreds  { width: 44px; height: 44px; background-size: 4.4px 4.4px; }
.apv-build-preview .apv-block-thousands { width: 44px; height: 44px; background-size: 4.4px 4.4px; box-shadow: 3px 3px 0 rgba(0,0,0,0.18); }

.apv-build-area .apv-btn {
    background: var(--apv-blue);
    border-color: var(--apv-blue-dark);
    font-size: 0.95rem;
    padding: 10px 36px;
    border-radius: 10px;
}
.apv-build-area .apv-btn:hover { background: var(--apv-blue-dark); }

/* ── Input states ────────────────────────────────────────────────── */
.apv-inp-correct {
    border-color: var(--apv-green) !important;
    background: var(--apv-green-bg) !important;
    color: var(--apv-green-fg) !important;
}
.apv-inp-wrong {
    border-color: var(--apv-danger) !important;
    background: #fde8e7 !important;
    animation: apv-shake 0.5s ease both;
}
@keyframes apv-shake {
    0%,100% { transform: translateX(0); }
    20%     { transform: translateX(-6px); }
    40%     { transform: translateX(6px); }
    60%     { transform: translateX(-4px); }
    80%     { transform: translateX(4px); }
}

/* ── Feedback ────────────────────────────────────────────────────── */
.apv-feedback { font-size: 0.9rem; font-weight: 700; min-height: 1.2em; text-align: center; }
.apv-feedback-success { color: var(--apv-green-fg); }
.apv-feedback-error   { color: var(--apv-danger); }

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

/* ── Victory overlay ─────────────────────────────────────────────── */
.apv-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(--apv-radius);
    backdrop-filter: blur(4px);
}
.apv-victory.apv-show { display: flex; animation: apv-fadein 0.4s ease; }
@keyframes apv-fadein { from { opacity: 0; } to { opacity: 1; } }

.apv-victory-box {
    background: #fff;
    border-radius: 22px;
    padding: 40px 52px;
    text-align: center;
    box-shadow: 0 24px 64px rgba(0,0,0,0.3);
    animation: apv-slidein 0.42s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes apv-slidein {
    from { transform: scale(0.65) translateY(40px); opacity: 0; }
    to   { transform: scale(1)    translateY(0);    opacity: 1; }
}
.apv-victory-emoji { font-size: 3rem; line-height: 1; margin-bottom: 10px; }
.apv-victory-title { font-size: 2rem; font-weight: 900; color: var(--apv-blue-dark); margin-bottom: 8px; }

.apv-scorecard {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 20px;
    margin-bottom: 24px;
    min-width: 180px;
}
.apv-sc-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid #f1f5f9; font-size: 0.88rem; }
.apv-sc-row:last-child { border-bottom: none; }
.apv-sc-lbl { color: #64748b; font-weight: 600; }
.apv-sc-val { color: var(--apv-blue-dark); font-weight: 800; }

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

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

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .apv-read-area { flex-direction: column; padding: 16px; gap: 16px; }
    .apv-read-panel { width: 100%; }
    .apv-build-number { font-size: 2.4rem; padding: 8px 20px; }
    .apv-build-inp { width: 52px; font-size: 1.8rem; }
    .apv-header { flex-direction: column; align-items: flex-start; }
    .apv-victory-box { padding: 28px 20px; }
}

/* Hint row */
.apv-hint-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px 14px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

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

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

