/* ── Proportions Widget ───────────────────────────────────────────── */
.ama-proportions-widget {
    --apr-primary:  #0891b2;
    --apr-dark:     #0369a1;
    --apr-light:    #e0f2fe;
    --apr-green:    #81c171;
    --apr-red:      #f53a33;
    --apr-seg-a:    #2E68A1;
    --apr-seg-b:    #ff9130;
    --apr-radius:   14px;
    font-family: 'Segoe UI', Arial, sans-serif;
    position: relative;
    background: #fff;
    border-radius: var(--apr-radius);
    box-shadow: 0 4px 24px rgba(0,0,0,.10);
    overflow: hidden;
    max-width: 860px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

/* Header */
.apr-header {
    background: var(--apr-primary);
    color: #fff;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}
.apr-title { font-size: 1.1rem; font-weight: 700; white-space: nowrap; }
.apr-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: 1; justify-content: flex-end; }

/* Mode toggle */
.apr-mode-toggle { display: flex; gap: 4px; flex-wrap: wrap; }
.apr-mode-btn {
    background: rgba(255,255,255,.18);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.apr-mode-btn:hover { background: rgba(255,255,255,.28); }
.apr-mode-btn.apr-mode-active { background: #fff; color: var(--apr-primary); }

/* Level select */
.apr-ctrl-label {
    font-size: .78rem;
    color: rgba(255,255,255,.85);
    display: flex;
    align-items: center;
    gap: 5px;
}
.apr-diff-sel {
    background: rgba(255,255,255,.2);
    color: #fff;
    border: 1px solid rgba(255,255,255,.35);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: .78rem;
    cursor: pointer;
}
.apr-diff-sel option { background: var(--apr-dark); }

/* Buttons */
.apr-btn {
    background: #fddd54;
    color: #5a3e00;
    border: none;
    border-radius: 8px;
    padding: 7px 14px;
    font-size: .82rem;
    font-weight: 700;
    cursor: pointer;
    transition: filter .15s;
}
.apr-btn:hover { filter: brightness(1.08); }
.apr-btn-new { padding: 5px 10px; font-size: .78rem; }

/* Stats */
.apr-stats { display: flex; align-items: center; gap: 4px; font-size: .88rem; color: #fff; font-weight: 700; }
.apr-sep { opacity: .5; margin: 0 2px; }

/* Body */
.apr-body { flex: 1; overflow-y: auto; min-height: 0; }
.apr-problem { padding: 20px 24px 8px; }

/* ── SOLVE mode ───────────────────────────────────────────────────── */
.apr-solve-area { display: flex; flex-direction: column; align-items: center; gap: 20px; }

.apr-prop-eq {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
}
.apr-ratio-box {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--apr-light);
    border: 2px solid var(--apr-primary);
    border-radius: 12px;
    padding: 12px 20px;
}
.apr-rn {
    font-size: 2rem;
    font-weight: 800;
    color: var(--apr-dark);
    min-width: 2ch;
    text-align: center;
}
.apr-rn-miss {
    font-size: 2rem;
    font-weight: 800;
    color: #aaa;
}
.apr-rsep { font-size: 1.6rem; font-weight: 700; color: var(--apr-primary); }
.apr-eq-sign { font-size: 2rem; font-weight: 800; color: #555; }

/* Ratio table */
.apr-rt-wrap { overflow-x: auto; }
.apr-rt {
    border-collapse: collapse;
    font-size: .92rem;
    min-width: 220px;
}
.apr-rt th, .apr-rt td {
    border: 1px solid #ddd;
    padding: 8px 16px;
    text-align: center;
    width: 100px;
}
.apr-rt-lbl { width: 70px; }
.apr-rt thead { background: var(--apr-primary); color: #fff; }
.apr-rt-lbl { background: #f5f5f5; font-weight: 600; color: #555; }
.apr-rt-scaled { background: var(--apr-light); font-weight: 700; }
.apr-rt-miss { background: #fff8e1; }

/* ── SORT mode ────────────────────────────────────────────────────── */
.apr-sort-area { display: flex; flex-direction: column; gap: 12px; }
.apr-sort-ref { font-size: 1rem; font-weight: 600; color: var(--apr-dark); }
.apr-sort-hint { font-size: .78rem; color: #888; }

.apr-sort-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 44px;
    padding: 6px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px dashed #ccc;
}

.apr-sort-card {
    background: #fff;
    border: 2px solid var(--apr-primary);
    border-radius: 8px;
    padding: 8px 16px;
    font-size: .95rem;
    font-weight: 700;
    color: var(--apr-dark);
    cursor: pointer;
    user-select: none;
    transition: transform .1s, box-shadow .1s, border-color .15s;
}
.apr-sort-card:hover { transform: translateY(-2px); box-shadow: 0 3px 10px rgba(0,0,0,.12); }
.apr-sort-card.apr-card-selected {
    border-color: #fddd54;
    background: #fffbea;
    box-shadow: 0 0 0 3px rgba(253,221,84,.5);
    transform: scale(1.05);
}
.apr-sort-card.apr-card-correct { border-color: var(--apr-green); background: #edfaeb; cursor: default; }
.apr-sort-card.apr-card-wrong   { border-color: var(--apr-red);   background: #fff0f0; cursor: default; }

.apr-sort-buckets { display: flex; gap: 12px; flex-wrap: wrap; }
.apr-bucket {
    flex: 1;
    min-width: 140px;
    border-radius: 10px;
    border: 2px dashed;
    cursor: pointer;
    transition: background .15s;
}
.apr-bucket-yes { border-color: var(--apr-green); }
.apr-bucket-yes:hover { background: rgba(129,193,113,.08); }
.apr-bucket-no  { border-color: var(--apr-red); }
.apr-bucket-no:hover  { background: rgba(245,58,51,.06); }

.apr-bucket-title {
    padding: 8px 12px;
    font-size: .82rem;
    font-weight: 700;
    border-radius: 8px 8px 0 0;
}
.apr-bucket-yes .apr-bucket-title { color: #2a7a1a; background: rgba(129,193,113,.15); }
.apr-bucket-no  .apr-bucket-title { color: #a01010; background: rgba(245,58,51,.08); }

.apr-bucket-drop {
    min-height: 60px;
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-content: flex-start;
}

/* ── SCALE mode ───────────────────────────────────────────────────── */
.apr-scale-area { display: flex; flex-direction: column; gap: 14px; }
.apr-scale-ctx {
    background: var(--apr-light);
    border-left: 4px solid var(--apr-primary);
    padding: 12px 16px;
    border-radius: 0 8px 8px 0;
    font-size: 1rem;
    color: var(--apr-dark);
}
.apr-scale-q { font-size: 1.05rem; font-weight: 700; color: #333; }
.apr-scale-input-row { display: flex; align-items: center; gap: 10px; }
.apr-unit { font-size: .95rem; font-weight: 600; color: var(--apr-primary); }

/* ── VISUAL mode ──────────────────────────────────────────────────── */
.apr-visual-area { display: flex; flex-direction: column; gap: 10px; }
.apr-visual-intro { font-size: .92rem; color: #555; }
.apr-visual-q { font-size: 1rem; font-weight: 700; color: #333; margin-top: 6px; }

.apr-tape-row { display: flex; align-items: center; gap: 10px; }
.apr-tape-lbl { font-size: .8rem; font-weight: 600; color: #888; min-width: 58px; }
.apr-tape {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    padding: 4px;
    background: #f8f9fa;
    border-radius: 6px;
}

.apr-seg {
    width: 26px;
    height: 26px;
    border-radius: 4px;
    transition: background .3s;
}
.apr-seg-a       { background: var(--apr-seg-a); }
.apr-seg-b       { background: var(--apr-seg-b); }
.apr-seg-hidden  { background: #ddd; border: 2px dashed #bbb; }
.apr-seg-reveal  { animation: apr-reveal .35s ease; }
@keyframes apr-reveal { from { transform: scale(0); } to { transform: scale(1); } }

.apr-color-a { color: var(--apr-seg-a); font-weight: 700; }
.apr-color-b { color: var(--apr-seg-b); font-weight: 700; }

/* ── Shared inputs ────────────────────────────────────────────────── */
.apr-answer-inp {
    width: 100px;
    padding: 8px 12px;
    font-size: 1.2rem;
    font-weight: 700;
    text-align: center;
    border: 2px solid #ccc;
    border-radius: 8px;
    outline: none;
    transition: border-color .15s;
}
.apr-answer-inp:focus { border-color: var(--apr-primary); }
.apr-answer-inp.apr-inp-correct { border-color: var(--apr-green); background: #edfaeb; }
.apr-answer-inp.apr-inp-wrong   { border-color: var(--apr-red);   background: #fff0f0; animation: apr-shake .3s; }
@keyframes apr-shake {
    0%,100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.apr-check-btn { margin-top: 4px; }

/* Feedback */
.apr-feedback { min-height: 22px; font-size: .9rem; font-weight: 600; margin-top: 2px; }
.apr-feedback-success { color: #2a7a1a; }
.apr-feedback-error   { color: var(--apr-red); }

/* ── Victory overlay ──────────────────────────────────────────────── */
.apr-victory {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .35s;
    z-index: 10;
}
.apr-victory.apr-show { opacity: 1; pointer-events: auto; }

.apr-victory-box {
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 8px 40px rgba(0,0,0,.16);
    padding: 32px 40px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.apr-v-emoji { font-size: 2.8rem; }
.apr-v-title { font-size: 1.5rem; font-weight: 800; color: var(--apr-dark); }

.apr-star { font-size: 2rem; }
.apr-star-on  { color: #fddd54; }
.apr-star-off { color: #ddd; }

.apr-scorecard { display: flex; flex-direction: column; gap: 4px; width: 100%; margin: 4px 0; }
.apr-sc-row { display: flex; justify-content: space-between; gap: 24px; font-size: .92rem; }
.apr-sc-lbl { color: #888; }
.apr-sc-val { font-weight: 700; color: var(--apr-dark); }

/* Confetti */
.apr-confetti {
    position: absolute;
    top: -12px;
    animation: apr-fall linear forwards;
    pointer-events: none;
    z-index: 20;
}
@keyframes apr-fall {
    to { transform: translateY(calc(100% + 20px)) rotate(360deg); opacity: 0; }
}

/* Hint row */
.apr-hint-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px 14px;
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}
.apr-hint-cost { font-size: 0.72em; opacity: 0.7; }
.apr-btn-hint { background: #fff8dc; color: #5a3e00; border: 1.5px solid #fddd54; }
.apr-btn-hint:hover { background: #fddd54; filter: none; }
.apr-btn-hint:disabled { opacity: .45; cursor: default; }

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

