/* Animate the ring arc angle so the fill transitions smoothly. */
@property --progress-degree {
    syntax: "<angle>";
    inherits: false;
    initial-value: 0deg;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

:root {
    --bg-1: #120029;
    --bg-2: #001f3f;
    --glass: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.14);
    --text: #f8fafc;
    --muted: #cbd5e1;
    --track: rgba(255, 255, 255, 0.1);
    --inner: #140a2e;

    --cyan: #22d3ee;
    --pink: #ff3d9a;
    --violet: #a855f7;
    --orange: #fb923c;
    --lime: #a3e635;
    --yellow: #facc15;
    --rose: #f43f5e;
    --emerald: #34d399;
}

body {
    position: relative;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
    color: var(--text);
    background: linear-gradient(135deg, var(--bg-1), var(--bg-2), #2a0845);
    background-size: 300% 300%;
    animation: drift 16s ease infinite;
    overflow-x: hidden;
}

@keyframes drift {
    0%, 100% { background-position: 0% 50%; }
    50%      { background-position: 100% 50%; }
}

/* ---------- Floating background orbs (2D, infinite) ---------- */

.orbs {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: 0.55;
    animation: orbFloat 18s ease-in-out infinite alternate;
}

.orb-1 { width: 340px; height: 340px; background: var(--pink);   top: -80px;  left: -60px; }
.orb-2 { width: 280px; height: 280px; background: var(--cyan);   bottom: -60px; right: -40px; animation-duration: 22s; }
.orb-3 { width: 220px; height: 220px; background: var(--yellow); top: 40%;     left: 55%;   animation-duration: 15s; }
.orb-4 { width: 180px; height: 180px; background: var(--violet); bottom: 20%;  left: 10%;   animation-duration: 26s; }

@keyframes orbFloat {
    0%   { transform: translate(0, 0) scale(1); }
    33%  { transform: translate(60px, -40px) scale(1.15); }
    66%  { transform: translate(-40px, 50px) scale(0.9); }
    100% { transform: translate(30px, 20px) scale(1.05); }
}

/* ---------- Layout ---------- */

.container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 880px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding: 2.5rem;
    border-radius: 28px;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(16px);
    transform-style: preserve-3d;
    animation: fadeUp 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both;
    transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Subtle 3D tilt when the card is hovered (mouse devices only, see media queries) */
.container:hover {
    transform: perspective(1400px) rotateX(2deg) rotateY(-2deg);
}

/* Entrance uses translate/opacity so hover transform is not blocked */
@keyframes fadeUp {
    from { opacity: 0; translate: 0 24px; }
    to   { opacity: 1; translate: 0 0; }
}

.header {
    text-align: center;
}

h1 {
    font-size: 2.4rem;
    font-weight: 800;
    letter-spacing: 0.5px;
}

/* Infinitely shimmering gradient text */
h1 span {
    background: linear-gradient(90deg, var(--cyan), var(--pink), var(--yellow), var(--cyan));
    background-size: 300% auto;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: shimmer 4s linear infinite;
}

@keyframes shimmer {
    to { background-position: 300% center; }
}

.subtitle {
    margin-top: 0.5rem;
    color: var(--muted);
    font-size: 0.95rem;
}

/* ---------- Search ---------- */

.search {
    display: flex;
    gap: 0.75rem;
}

#user-input {
    flex: 1;
    min-width: 0;
    padding: 0.95rem 1.1rem;
    border-radius: 14px;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.96);
    color: #120029;
    font-size: 1rem;
    outline: none;
    transition: box-shadow 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
}

#user-input:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 5px rgba(34, 211, 238, 0.3), 0 10px 30px rgba(34, 211, 238, 0.25);
    transform: translateY(-2px);
}

#user-input.shake {
    animation: shake 0.45s ease;
}

@keyframes shake {
    0%, 100% { translate: 0 0; }
    20%, 60% { translate: -10px 0; }
    40%, 80% { translate: 10px 0; }
}

#search {
    position: relative;
    padding: 0.95rem 1.7rem;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--pink), var(--violet), var(--cyan));
    background-size: 200% 200%;
    color: #fff;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    animation: gradientMove 5s ease infinite, pulseGlow 2.4s ease-in-out infinite;
    transition: transform 0.25s ease, filter 0.25s ease;
}

@keyframes gradientMove {
    0%, 100% { background-position: 0% 50%; }
    50%      { background-position: 100% 50%; }
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 61, 154, 0.45); }
    50%      { box-shadow: 0 0 0 12px rgba(255, 61, 154, 0); }
}

#search:hover:not(:disabled) {
    transform: translateY(-3px) scale(1.04);
    filter: brightness(1.12) saturate(1.2);
}

#search:active:not(:disabled) {
    transform: translateY(0) scale(0.97);
}

#search:disabled {
    opacity: 0.8;
    cursor: wait;
    animation: none;
}

/* Spinner shown while the request runs */
#search.is-loading {
    color: transparent;
}

#search.is-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Message ---------- */

.message {
    min-height: 1.4rem;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 600;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.message.show {
    opacity: 1;
    transform: translateY(0);
}

.message.error   { color: #fda4af; }
.message.success { color: #6ee7b7; }

/* ---------- Rings ---------- */

.rings {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 2rem;
    perspective: 900px;
}

/* 3D entrance: each ring flips up into place, staggered */
.ring-item {
    display: flex;
    justify-content: center;
    opacity: 0;
    animation: flipIn 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.ring-item:nth-child(1) { animation-delay: 0.2s; }
.ring-item:nth-child(2) { animation-delay: 0.4s; }
.ring-item:nth-child(3) { animation-delay: 0.6s; }

@keyframes flipIn {
    from {
        opacity: 0;
        transform: rotateX(-80deg) translateY(30px);
    }
    to {
        opacity: 1;
        transform: rotateX(0deg) translateY(0);
    }
}

.sphere {
    --c: var(--cyan);
    --glow: rgba(34, 211, 238, 0.55);
    position: relative;
    isolation: isolate;
    width: 170px;
    height: 170px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: conic-gradient(var(--c) var(--progress-degree), var(--track) 0deg);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
    cursor: default;
    /* translate is used for the infinite float; transform is used for hover tilt.
       Separate properties let both run at the same time. */
    animation: floatY 4s ease-in-out infinite;
    transition:
        --progress-degree 1.2s cubic-bezier(0.2, 0.8, 0.2, 1),
        transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1),
        filter 0.4s ease,
        box-shadow 0.4s ease;
}

/* Infinite vertical float (2D) */
@keyframes floatY {
    0%, 100% { translate: 0 0; }
    50%      { translate: 0 -10px; }
}

/* Stagger the float so the rings don't move in unison */
.ring-item:nth-child(2) .sphere { animation-delay: -1.3s; }
.ring-item:nth-child(3) .sphere { animation-delay: -2.6s; }

/* Inner disc that turns the arc into a donut */
.sphere::before {
    content: "";
    position: absolute;
    inset: 14px;
    border-radius: 50%;
    background: var(--inner);
    box-shadow: inset 0 6px 16px rgba(0, 0, 0, 0.5);
    z-index: 0;
}

/* Rotating outer halo (infinite) */
.sphere::after {
    content: "";
    position: absolute;
    inset: -9px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent 0deg, var(--c) 90deg, transparent 180deg);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
            mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
    animation: spin 5s linear infinite;
    z-index: -1;
    opacity: 0.8;
}

/* 3D tilt on hover. Uses its own perspective() so it works without a parent setting. */
.sphere:hover {
    transform: perspective(700px) rotateX(12deg) rotateY(-14deg) scale(1.06);
    filter: drop-shadow(0 16px 26px var(--glow));
    box-shadow: 0 20px 40px var(--glow);
}

.easy-level   { --c: var(--emerald); --glow: rgba(52, 211, 153, 0.6); }
.medium-level { --c: var(--yellow);  --glow: rgba(250, 204, 21, 0.6); }
.hard-level   { --c: var(--rose);    --glow: rgba(244, 63, 94, 0.6); }

.ring-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

/* Numbers pulse softly forever */
.sphere .count {
    font-size: 2.1rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--c);
    text-shadow: 0 0 14px var(--glow);
    animation: breathe 2.6s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}

.sphere .label {
    font-size: 0.78rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* ---------- Total card ---------- */

.stats-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 1.6rem;
    border-radius: 18px;
    background: linear-gradient(90deg, rgba(34, 211, 238, 0.12), rgba(255, 61, 154, 0.12), rgba(250, 204, 21, 0.12));
    background-size: 200% 100%;
    border: 1px solid var(--glass-border);
    color: var(--muted);
    font-size: 1rem;
    animation: bgSweep 8s linear infinite;
}

@keyframes bgSweep {
    to { background-position: 200% 0; }
}

.stats-card strong {
    font-size: 1.7rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    background: linear-gradient(90deg, var(--cyan), var(--pink));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: heartbeat 3s ease-in-out infinite;
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    15%      { transform: scale(1.1); }
    30%      { transform: scale(1); }
}

/* =========================================================
   MEDIA QUERIES
   ========================================================= */

/* Large desktops: bigger rings and headings */
@media (min-width: 1100px) {
    .container {
        padding: 3rem;
    }

    h1 {
        font-size: 2.9rem;
    }

    .sphere {
        width: 200px;
        height: 200px;
    }

    .sphere .count {
        font-size: 2.5rem;
    }
}

/* Tablets */
@media (min-width: 601px) and (max-width: 900px) {
    .container {
        width: 90%;
        padding: 2rem;
    }

    .sphere {
        width: 150px;
        height: 150px;
    }
}

/* Phones */
@media (max-width: 600px) {
    body {
        padding: 1rem;
    }

    .container {
        padding: 1.5rem;
        gap: 1.5rem;
        border-radius: 22px;
    }

    h1 {
        font-size: 1.8rem;
    }

    .search {
        flex-direction: column;
    }

    #search {
        width: 100%;
    }

    .sphere {
        width: 140px;
        height: 140px;
    }

    .sphere::before {
        inset: 12px;
    }

    .sphere .count {
        font-size: 1.7rem;
    }

    .stats-card {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
}

/* Very small phones */
@media (max-width: 380px) {
    .sphere {
        width: 120px;
        height: 120px;
    }

    .sphere .count {
        font-size: 1.4rem;
    }

    .rings {
        gap: 1rem;
    }
}

/* Landscape phones and short windows */
@media (orientation: landscape) and (max-height: 600px) {
    body {
        align-items: flex-start;
        padding: 0.75rem;
    }

    .container {
        gap: 1rem;
        padding: 1.25rem 1.5rem;
    }

    .header {
        text-align: left;
    }

    h1 {
        font-size: 1.6rem;
    }

    .sphere {
        width: 120px;
        height: 120px;
    }
}

/* Touch devices: no hover, so skip hover-based 3D tilts */
@media (hover: none) {
    .container:hover,
    .sphere:hover {
        transform: none;
    }

    .sphere:active {
        transform: scale(0.96);
    }
}

/* Users who asked for more contrast */
@media (prefers-contrast: more) {
    .container {
        background: rgba(10, 6, 25, 0.9);
        border-color: #fff;
    }

    .sphere .label {
        color: #fff;
    }
}

/* Reduced motion: stop the loops and keep the content visible */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .orb,
    .sphere,
    .sphere::after,
    .sphere .count,
    .stats-card strong {
        animation: none !important;
    }
}/* "of 800" line under each count */
.sphere .of {
    font-size: 0.75rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}