/* Study Tank — the Arena's virtual companion.
   A floating aquarium panel, opened from a topbar pill. It sits bottom-LEFT, under
   the Question Navigator column. The Arcanium brand float shares this edge and must
   always win: the float is z 1320, so the tank stays one step BELOW it — if the two
   ever meet, the brand pill covers the tank, never the other way around. */

.study-tank-panel {
    position: fixed;
    left: 22px;
    bottom: 22px;
    z-index: 1310; /* above the session page (1300), below the brand float (1320) */
    width: min(320px, calc(100vw - 32px));
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(243, 248, 255, 0.96));
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.18);
    overflow: hidden;
    transform-origin: bottom left;
    animation: studyTankPopIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.study-tank-panel[hidden] {
    display: none;
}

@keyframes studyTankPopIn {
    0% { opacity: 0; transform: scale(0.8) translateY(14px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.study-tank-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px 10px;
    /* The whole header is the drag handle. touch-action:none keeps pointer-dragging
       from turning into a page scroll on touch screens. */
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.study-tank-panel.is-dragging .study-tank-head {
    cursor: grabbing;
}

.study-tank-panel.is-dragging {
    animation: none;
}

/* Compact mode: about two-thirds size, chrome trimmed to the essentials. */
.study-tank-panel.is-compact {
    width: 216px;
}

.study-tank-panel.is-compact .study-tank-head span {
    display: none;
}

.study-tank-panel.is-compact .study-tank-foot {
    display: none;
}

.study-tank-panel.is-compact .study-tank-viewport {
    margin-bottom: 10px;
}

.study-tank-head strong {
    font-size: 14px;
    letter-spacing: -0.02em;
    color: #0f3d91;
}

.study-tank-head span {
    flex: 1 1 auto;
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
}

.study-tank-close {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    background: rgba(248, 250, 252, 0.95);
    color: #475569;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    box-shadow: none;
}

.study-tank-close:hover {
    background: #fff;
    border-color: rgba(15, 23, 42, 0.16);
}

.study-tank-viewport {
    position: relative;
    margin: 0 10px;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: inset 0 2px 10px rgba(2, 44, 91, 0.25);
}

.study-tank-viewport svg {
    display: block;
    width: 100%;
    height: auto;
}

/* Rising bubbles live in an HTML layer over the SVG so they can be spawned and
   discarded freely without touching the scene graph. */
.study-tank-bubbles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.study-tank-bubble {
    position: absolute;
    bottom: -12px;
    border-radius: 999px;
    background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.25) 60%, rgba(255, 255, 255, 0.05));
    border: 1px solid rgba(255, 255, 255, 0.35);
    animation: studyTankBubbleRise var(--rise, 3.6s) linear forwards;
}

@keyframes studyTankBubbleRise {
    0% { opacity: 0; transform: translate(0, 0) scale(0.6); }
    12% { opacity: 0.9; }
    100% { opacity: 0; transform: translate(var(--drift, 6px), calc(-1 * var(--height, 190px))) scale(1); }
}

/* Celebration toast ("+1 tank mate!", "On fire!") floats up from the sand. */
.study-tank-toast {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(10, 132, 255, 0.18);
    color: #0f3d91;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
    pointer-events: none;
    animation: studyTankToast 1.6s ease-out forwards;
}

@keyframes studyTankToast {
    0% { opacity: 0; transform: translate(-50%, 10px) scale(0.85); }
    18% { opacity: 1; transform: translate(-50%, 0) scale(1.03); }
    30% { transform: translate(-50%, 0) scale(1); }
    75% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -16px) scale(0.96); }
}

.study-tank-foot {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 16px 12px;
}

.study-tank-foot span {
    color: #64748b;
    font-size: 11px;
    font-weight: 700;
}

.study-tank-foot em {
    color: #94a3b8;
    font-size: 10.5px;
    font-style: normal;
}

/* Gentle idle motion inside the scene. transform-box makes the rotation pivot on
   each part's own geometry rather than the SVG origin. */
.study-tank-panel svg .tank-plant {
    transform-box: fill-box;
    transform-origin: 50% 100%;
    animation: studyTankSway var(--sway, 5s) ease-in-out infinite alternate;
}

@keyframes studyTankSway {
    0% { transform: rotate(-4deg); }
    100% { transform: rotate(5deg); }
}

.study-tank-panel svg .tank-ray {
    transform-box: fill-box;
    transform-origin: 50% 0;
    animation: studyTankRay 7s ease-in-out infinite alternate;
}

@keyframes studyTankRay {
    0% { opacity: 0.12; transform: rotate(-2deg); }
    100% { opacity: 0.3; transform: rotate(2deg); }
}

.tank-fish .tank-fish-tail {
    transform-box: fill-box;
    transform-origin: 8% 50%;
    animation: studyTankTail 0.55s ease-in-out infinite alternate;
}

.tank-fish .tank-fish-fin {
    transform-box: fill-box;
    transform-origin: 20% 12%;
    animation: studyTankFin 0.8s ease-in-out infinite alternate;
}

.tank-fish.is-dashing .tank-fish-tail {
    animation-duration: 0.18s;
}

@keyframes studyTankTail {
    0% { transform: rotate(-14deg); }
    100% { transform: rotate(14deg); }
}

@keyframes studyTankFin {
    0% { transform: rotate(-10deg); }
    100% { transform: rotate(16deg); }
}

/* The loop-the-loop: a full roll around the fish's own centre, layered on top of
   the JS swim transform by living on an inner group. */
.tank-fish .tank-fish-body-wrap {
    transform-box: fill-box;
    transform-origin: center;
}

.tank-fish.is-celebrating .tank-fish-body-wrap {
    animation: studyTankLoop 0.75s cubic-bezier(0.45, 0.05, 0.35, 1);
}

@keyframes studyTankLoop {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(-360deg); }
}

.tank-fish.is-encouraging .tank-fish-body-wrap {
    animation: studyTankSigh 0.9s ease-in-out;
}

@keyframes studyTankSigh {
    0%, 100% { transform: rotate(0deg); }
    30% { transform: rotate(7deg) translateY(2px); }
    65% { transform: rotate(-5deg); }
}

/* Small tank mates wiggle on arrival. */
.tank-mate {
    transform-box: fill-box;
    transform-origin: center;
}

.tank-mate.is-arriving {
    animation: studyTankArrive 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes studyTankArrive {
    0% { opacity: 0; transform: scale(0.2) rotate(40deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

/* Topbar toggle pill: matches .arena-topbar-pill but is a real button, and does a
   happy bounce when a catch lands while the tank is closed. */
.study-tank-toggle {
    cursor: pointer;
}

.study-tank-toggle.is-bouncing {
    animation: studyTankToggleBounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes studyTankToggleBounce {
    0% { transform: scale(1); }
    35% { transform: scale(1.14) rotate(-3deg); }
    70% { transform: scale(0.96) rotate(2deg); }
    100% { transform: scale(1); }
}

@media (max-width: 720px) {
    .study-tank-panel {
        left: 12px;
        bottom: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .study-tank-panel,
    .study-tank-bubble,
    .study-tank-toast,
    .study-tank-panel svg .tank-plant,
    .study-tank-panel svg .tank-ray,
    .tank-fish .tank-fish-tail,
    .tank-fish .tank-fish-fin,
    .tank-fish.is-celebrating .tank-fish-body-wrap,
    .tank-fish.is-encouraging .tank-fish-body-wrap,
    .tank-mate.is-arriving,
    .study-tank-toggle.is-bouncing {
        animation: none;
    }
}
