/* ============================================================
   ABACUS TRAINER — Premium light app theme
   ============================================================ */

:root {
    --ag-bg-top: #eef3fb;
    --ag-bg-bottom: #f8fbff;
    --ag-card: #ffffff;
    --ag-card-border: #e2e8f0;
    --ag-text: #0f172a;
    --ag-muted: #475569;
    --ag-faint: #94a3b8;
    --ag-blue: #3b82f6;
    --ag-cyan: #0ea5e9;
    --ag-display: 'Space Grotesk', 'Inter', -apple-system, sans-serif;
}

.abacus-page {
    min-height: 100vh;
    color: var(--ag-text);
    padding: 3rem 1.5rem 4.5rem;
    background:
        radial-gradient(900px 500px at 82% -8%, rgba(59, 130, 246, 0.12), transparent 60%),
        radial-gradient(700px 420px at 8% 12%, rgba(14, 165, 233, 0.10), transparent 55%),
        linear-gradient(180deg, var(--ag-bg-top) 0%, var(--ag-bg-bottom) 100%);
}

/* ---------- Header ---------- */
.ag-header {
    max-width: 1240px;
    margin: 0 auto 2rem;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 2rem;
    flex-wrap: wrap;
}

.ag-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #0891b2;
}

.ag-title {
    font-family: var(--ag-display);
    font-size: clamp(1.9rem, 4vw, 2.6rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0.5rem 0 0.4rem;
    color: #0f172a;
}

.ag-title span {
    background: linear-gradient(90deg, #2563eb, #0ea5e9);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.ag-sub {
    max-width: 540px;
    margin: 0;
    font-size: 0.97rem;
    line-height: 1.65;
    color: var(--ag-muted);
}

/* ---------- Stats ---------- */
.ag-stats {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.ag-stat {
    min-width: 92px;
    padding: 0.7rem 1rem 0.65rem;
    text-align: center;
    background: var(--ag-card);
    border: 1px solid var(--ag-card-border);
    border-radius: 16px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
    transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.ag-stat:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.13);
}

.ag-stat__label {
    display: block;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ag-faint);
}

.ag-stat__value {
    display: block;
    margin-top: 0.15rem;
    font-family: var(--ag-display);
    font-size: 1.3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.ag-stat--score .ag-stat__value  { color: #2563eb; }
.ag-stat--streak .ag-stat__value { color: #f59e0b; }
.ag-stat--best .ag-stat__value   { color: #7c3aed; }
.ag-stat--digits .ag-stat__value { color: #0891b2; }

/* ---------- Layout ---------- */
.ag-glass {
    background: var(--ag-card);
    border: 1px solid var(--ag-card-border);
    border-radius: 22px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.10);
}

.ag-game {
    max-width: 1240px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(330px, 0.85fr);
    gap: 1.5rem;
    align-items: start;
}

/* ---------- Board card ---------- */
.ag-board { padding: 1.5rem; }

.ag-board__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.1rem;
    flex-wrap: wrap;
}

.ag-tool-label {
    font-size: 0.82rem;
    color: var(--ag-muted);
}

.ag-tool-label i { color: #0ea5e9; margin-right: 0.4rem; }

.ag-live {
    display: inline-flex;
    align-items: baseline;
    gap: 0.6rem;
    padding: 0.35rem 0.95rem;
    border-radius: 999px;
    background: linear-gradient(135deg, #e0efff, #e6f7fc);
    border: 1px solid #bcd9f8;
}

.ag-live small {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #64748b;
}

.ag-live b {
    font-family: var(--ag-display);
    font-size: 1.15rem;
    font-weight: 700;
    color: #1d4ed8;
}

/* ---------- Abacus board ---------- */
.abacus-frame {
    position: relative;
    padding: 26px 28px 30px;
    background: linear-gradient(180deg, #1c2740 0%, #162036 55%, #111a2c 100%);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.5), 0 18px 44px rgba(15, 23, 42, 0.28);
}

.abacus-frame::before,
.abacus-frame::after {
    content: '';
    position: absolute;
    top: 18px;
    bottom: 18px;
    width: 10px;
    background: linear-gradient(180deg, #33405f, #1c2640);
    border-radius: 8px;
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.6), 0 0 1px rgba(255, 255, 255, 0.15);
    z-index: 0;
}

.abacus-frame::before { left: 14px; }
.abacus-frame::after { right: 14px; }

.abacus-beam {
    height: 6px;
    margin: 0 4px 16px;
    border-radius: 999px;
    background: linear-gradient(90deg, #3b82f6, #22d3ee);
    box-shadow: 0 0 14px rgba(59, 130, 246, 0.45);
    opacity: 0.85;
}

.abacus-row {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    justify-content: center;
    position: relative;
    z-index: 1;
}

.rod {
    width: 72px;
    height: 440px;
    background: linear-gradient(180deg, #25324f 0%, #1c2740 45%, #18223a 100%);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 16px;
    padding: 18px 10px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    box-shadow: inset 0 6px 16px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.2);
}

.rod-wire {
    width: 3px;
    flex: 1;
    background: linear-gradient(180deg, #3d4d73, #2a3552);
    border-radius: 999px;
    position: absolute;
    left: 50%;
    top: 14px;
    bottom: 14px;
    transform: translateX(-50%);
    z-index: 1;
}

.beads {
    width: 100%;
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 8px;
    box-sizing: border-box;
    position: relative;
    z-index: 2;
}

.rod-color-0 { --bead: #60a5fa; --bead-deep: #2563eb; --glow: rgba(96, 165, 250, 0.55); }
.rod-color-1 { --bead: #22d3ee; --bead-deep: #0891b2; --glow: rgba(34, 211, 238, 0.55); }
.rod-color-2 { --bead: #a78bfa; --bead-deep: #7c3aed; --glow: rgba(167, 139, 250, 0.55); }
.rod-color-3 { --bead: #34d399; --bead-deep: #059669; --glow: rgba(52, 211, 153, 0.55); }
.rod-color-4 { --bead: #fbbf24; --bead-deep: #d97706; --glow: rgba(251, 191, 36, 0.55); }

.bead {
    width: 46px;
    height: 40px;
    border-radius: 50%;
    margin: 2px 0;
    cursor: pointer;
    position: relative;
    z-index: 2;
    opacity: 0.75;
    background:
        radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.30), rgba(255, 255, 255, 0) 42%),
        linear-gradient(160deg, var(--bead) 0%, var(--bead-deep) 78%);
    box-shadow:
        inset 0 2px 2px rgba(255, 255, 255, 0.25),
        inset 0 -4px 8px rgba(0, 0, 0, 0.30),
        0 5px 12px rgba(0, 0, 0, 0.30);
    transition: transform 0.24s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.24s ease, box-shadow 0.24s ease, filter 0.24s ease;
}

.bead:hover { filter: brightness(1.18); opacity: 1; }

.bead:active { transform: scale(0.92); }

.bead.moved {
    opacity: 1;
    filter: brightness(1.12);
    transform: translateX(-36px);
    box-shadow:
        inset 0 2px 2px rgba(255, 255, 255, 0.30),
        inset 0 -4px 8px rgba(0, 0, 0, 0.25),
        0 0 16px var(--glow),
        0 5px 12px rgba(0, 0, 0, 0.30);
}

/* ---------- Place-value legend ---------- */
.ag-board__footer {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.2rem;
    flex-wrap: wrap;
}

.ag-pv {
    font-family: var(--ag-display);
    font-size: 0.68rem;
    font-weight: 600;
    color: #64748b;
    padding: 0.3rem 0.7rem;
    border-radius: 9px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
}

/* ---------- Side panel ---------- */
.ag-side {
    position: sticky;
    top: 104px;
    padding: 1.6rem;
    display: flex;
    flex-direction: column;
    gap: 1.4rem;
}

.ag-problem {
    padding: 1.5rem 1.2rem;
    text-align: center;
    background: linear-gradient(160deg, #f8fafc, #eef4ff);
    border: 1px solid #dbeafe;
    border-radius: 18px;
    position: relative;
}

.ag-problem__label {
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ag-faint);
}

.problem-display {
    min-height: 3.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.4rem;
    font-family: var(--ag-display);
    font-size: clamp(2rem, 5vw, 2.7rem);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #0f172a;
    text-shadow: 0 0 34px rgba(59, 130, 246, 0.25);
    font-variant-numeric: tabular-nums;
}

.ag-pop { animation: ag-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes ag-pop {
    0%   { transform: scale(0.6); opacity: 0; }
    60%  { transform: scale(1.08); opacity: 1; }
    100% { transform: scale(1); }
}

.ag-message {
    min-height: 2.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.8rem;
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    color: transparent;
    opacity: 0;
    border: 1px solid transparent;
    transform: translateY(4px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.ag-message--success {
    opacity: 1;
    transform: translateY(0);
    color: #166534;
    background: #dcfce7;
    border-color: #bbf7d0;
}

.ag-message--error {
    opacity: 1;
    transform: translateY(0);
    color: #991b1b;
    background: #fee2e2;
    border-color: #fecaca;
}

.problem-card--bounce { animation: ag-bounce 0.45s ease; }
.problem-card--shake  { animation: ag-shake 0.4s ease; }

@keyframes ag-bounce {
    0%   { transform: translateY(0); }
    35%  { transform: translateY(-8px) scale(1.02); }
    70%  { transform: translateY(2px); }
    100% { transform: translateY(0); }
}

@keyframes ag-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-7px); }
    40% { transform: translateX(7px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

/* ---------- Controls ---------- */
.ag-controls {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.ag-controls__label {
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ag-faint);
}

.digits-select-wrap { position: relative; }

.digits-select {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    padding: 0.8rem 2.6rem 0.8rem 1.1rem;
    background: #fff;
    border: 1.5px solid #dbe0ea;
    border-radius: 14px;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--ag-text);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.digits-select:hover { border-color: #c3cbd9; }

.digits-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

.digits-select__chevron {
    position: absolute;
    right: 1.1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ag-faint);
    pointer-events: none;
    font-size: 0.8rem;
}

.ag-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.85rem 1.1rem;
    border: none;
    border-radius: 14px;
    font-size: 0.92rem;
    font-weight: 700;
    color: #fff;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.ag-btn:hover { transform: translateY(-2px); filter: brightness(1.07); }
.ag-btn:active { transform: translateY(0) scale(0.98); }

.ag-btn--primary {
    background: linear-gradient(135deg, #2563eb, #38bdf8);
    box-shadow: 0 10px 24px rgba(59, 130, 246, 0.35);
}

.ag-btn--success {
    background: linear-gradient(135deg, #059669, #34d399);
    box-shadow: 0 10px 24px rgba(16, 185, 129, 0.30);
}

.ag-btn--ghost {
    color: #475569;
    background: #f1f5f9;
    border: 1.5px solid #e2e8f0;
}

.ag-btn--ghost:hover { background: #e8eef7; filter: none; }

/* ---------- Tip ---------- */
.ag-tip {
    max-width: 1240px;
    margin: 1.3rem auto 0;
    text-align: center;
    font-size: 0.85rem;
    color: var(--ag-faint);
}

.ag-tip i { color: #f59e0b; margin-right: 0.35rem; }

.ag-tip kbd {
    padding: 0.15rem 0.45rem;
    border-radius: 6px;
    background: #f1f5f9;
    border: 1px solid #dbe0ea;
    font-size: 0.75rem;
    font-family: var(--ag-display);
    color: #475569;
}

/* ---------- Responsive ---------- */
@media (max-width: 1020px) {
    .ag-game { grid-template-columns: 1fr; }
    .ag-side { position: static; }
}

@media (max-width: 720px) {
    .abacus-page { padding: 2rem 0.9rem 3.5rem; }
    .ag-header { flex-direction: column; align-items: flex-start; gap: 1.2rem; }
    .ag-stats { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
    .ag-stat { min-width: 0; padding: 0.6rem 0.4rem; }
    .ag-stat__value { font-size: 1.1rem; }
    .ag-board { padding: 1.1rem; border-radius: 18px; }
    .abacus-frame { padding: 18px 12px 20px; border-radius: 18px; }
    .abacus-row { gap: 8px; }
    .rod { width: 48px; height: 340px; padding: 14px 6px; }
    .bead { width: 32px; height: 28px; margin: 1.5px 0; }
    .bead.moved { transform: translateX(-24px); }
    .ag-live { order: -1; }
    .ag-side { padding: 1.2rem; }
    .problem-display { font-size: 2rem; }
}
