*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', cursive, sans-serif;
    background: linear-gradient(135deg, #87CEEB, #98FB98);
    margin: 0;
    padding: 0.75rem;
    text-align: center;
    min-height: 100vh;
    overflow-x: hidden;
    font-size: 1rem;
    line-height: 1.5;
}

body.modal-open {
    overflow: hidden;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.site-nav {
    background-color: #FFD700;
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.12);
    margin-bottom: 1rem;
    transition: margin-bottom 0.3s ease, box-shadow 0.3s ease;
}

header {
    background-color: #FFD700;
    padding: 1.25rem 1rem;
    border-radius: 1rem;
    box-shadow: 0 0.375rem 0.75rem rgba(0, 0, 0, 0.15);
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.nav-container {
    max-width: 50rem;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0.5rem 1rem;
    position: relative;
    transition: padding 0.25s ease;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.75rem;
    line-height: 1;
    color: #FF4500;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: background 0.2s ease, transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.nav-toggle:hover,
.nav-toggle:focus {
    background: rgba(255, 69, 0, 0.15);
    outline: none;
}

.nav-toggle[aria-expanded="true"] .hamburger-icon {
    transform: rotate(90deg);
}

.hamburger-icon {
    display: inline-block;
    transition: transform 0.25s ease;
}

.nav-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 0.5rem 1.25rem;
    flex-wrap: wrap;
    justify-content: center;
    transition: gap 0.25s ease;
}

.nav-link {
    display: inline-block;
    color: #4B0082;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.05rem;
    padding: 0.5rem 0.85rem;
    border-radius: 2rem;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease, padding 0.25s ease, font-size 0.25s ease, border-radius 0.25s ease;
}

.nav-link:hover,
.nav-link:focus {
    background-color: #FF69B4;
    color: white;
    outline: none;
    transform: scale(1.05);
}

.nav-link[aria-current="page"] {
    background-color: #FF4500;
    color: white;
}

#name {
    font-size: 2.5rem;
    color: #FF4500;
    margin: 0 0 0.75rem 0;
    text-shadow: 0.125rem 0.125rem 0 #FFF, 0.25rem 0.25rem 0 #FF6347;
    animation: bounce 2s infinite;
    word-break: break-word;
}

.header-image {
    width: 100%;
    max-width: 16rem;
    height: auto;
    border-radius: 1rem;
    margin: 0.5rem 0 0.75rem 0;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.2);
    object-fit: cover;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.header-image:hover {
    transform: scale(1.05);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.3);
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-0.75rem); }
}

.welcome {
    font-size: 1.25rem;
    color: #4B0082;
    margin: 0.5rem 0 0 0;
}

main {
    max-width: 50rem;
    margin: 0 auto;
    width: 100%;
}

.fun-section, .facts, .image-grid-section, .video-section {
    background-color: white;
    padding: 1.125rem 0.75rem;
    margin: 1rem 0;
    border-radius: 0.75rem;
    box-shadow: 0 0.1875rem 0.375rem rgba(0, 0, 0, 0.1);
    scroll-margin-top: 5rem;
}

h2 {
    color: #228B22;
    font-size: 1.5rem;
    margin-top: 0;
    margin-bottom: 0.75rem;
    text-align: center;
}

.video-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    width: 100%;
}

.video-item {
    width: 100%;
    height: auto;
    border-radius: 0.75rem;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.2);
    background: #000;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    width: 100%;
}

.image-grid img {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 0.5rem;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease, filter 0.3s ease;
}

.image-grid img:hover {
    transform: scale(1.08);
    box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.3);
    filter: brightness(1.1);
}

#funButton {
    background-color: #FF69B4;
    color: white;
    font-size: 1.25rem;
    padding: 1rem 1.75rem;
    border: none;
    border-radius: 3.125rem;
    cursor: pointer;
    box-shadow: 0 0.3125rem 0 #C71585;
    transition: all 0.1s;
    min-height: 3rem;
    min-width: 10rem;
    -webkit-tap-highlight-color: transparent;
}

#funButton:hover {
    background-color: #FF1493;
}

#funButton:active {
    transform: translateY(0.1875rem);
    box-shadow: 0 0.125rem 0 #C71585;
}

#message {
    font-size: 1.125rem;
    color: #1E90FF;
    min-height: 3rem;
    margin-top: 0.75rem;
    font-weight: bold;
    padding: 0 0.5rem;
}

ul {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 1.125rem;
}

li {
    background-color: #E6E6FA;
    margin: 0.5rem 0;
    padding: 0.875rem 0.625rem;
    border-radius: 0.625rem;
    color: #4B0082;
}

footer {
    margin-top: 1.875rem;
    color: #555;
    font-size: 1rem;
    padding-bottom: 0.625rem;
}

/* Modal Carousel */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(0.25rem);
}

.modal-content {
    position: relative;
    z-index: 1001;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    animation: modalPop 0.3s ease;
}

.modal-content img {
    display: block;
    max-width: min(80vw, 40rem);
    max-height: 85vh;
    border-radius: 1rem;
    box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, 0.5);
    transition: opacity 0.25s ease;
}

.modal-close {
    position: absolute;
    top: -0.75rem;
    right: -0.75rem;
    background: #FF4500;
    color: white;
    border: none;
    border-radius: 50%;
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.3);
    z-index: 1002;
}

.modal-close:hover {
    background: #FF6347;
}

.modal-arrow {
    background: #1E90FF;
    color: white;
    border: none;
    border-radius: 50%;
    width: 3rem;
    height: 3rem;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
    transition: background 0.2s ease, transform 0.2s ease;
}

.modal-arrow:hover {
    background: #187bcd;
    transform: scale(1.1);
}

.modal-arrow:active {
    transform: scale(0.95);
}

@keyframes modalPop {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Extra small devices */
@media (max-width: 30em) {
    body {
        padding: 0.5rem;
    }

    #name {
        font-size: 2.25rem;
        text-shadow: 0.1rem 0.1rem 0 #FFF, 0.2rem 0.2rem 0 #FF6347;
        margin-bottom: 0.5rem;
    }

    .header-image {
        max-width: 12rem;
        margin: 0.375rem 0 0.5rem 0;
        border-radius: 0.75rem;
    }

    .welcome {
        font-size: 1.125rem;
    }

    h2 {
        font-size: 1.375rem;
    }

    .image-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    #funButton {
        font-size: 1.125rem;
        padding: 0.875rem 1.5rem;
        min-width: 9rem;
    }

    #message, ul {
        font-size: 1rem;
    }

    .modal-content {
        gap: 0.375rem;
        max-width: 96vw;
    }

    .modal-content img {
        max-width: 70vw;
    }

    .modal-close {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 1.5rem;
        top: -0.5rem;
        right: -0.5rem;
    }

    .modal-arrow {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 1.5rem;
    }

    .nav-link {
        font-size: 1rem;
        padding: 0.65rem 1rem;
    }
}

/* Small devices / mobile nav */
@media (max-width: 48em) {
    .nav-toggle {
        display: block;
    }

    .nav-container {
        justify-content: flex-start;
    }

    .nav-menu {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background-color: #FFD700;
        padding: 0.75rem 1rem 1rem;
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
        gap: 0.4rem;
        border-radius: 0 0 0.75rem 0.75rem;
        z-index: 201;
        max-height: 70vh;
        max-height: 70dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        scrollbar-color: #FF4500 #FFE066;
    }

    .nav-menu::-webkit-scrollbar {
        width: 8px;
    }

    .nav-menu::-webkit-scrollbar-track {
        background: #FFE066;
        border-radius: 4px;
    }

    .nav-menu::-webkit-scrollbar-thumb {
        background: #FF4500;
        border-radius: 4px;
    }

    .nav-menu::-webkit-scrollbar-thumb:hover {
        background: #FF6347;
    }

    .nav-menu.active {
        display: flex;
    }

    .nav-link {
        display: block;
        text-align: center;
        padding: 0.7rem 1rem;
    }

    .fun-section, .image-grid-section, .video-section {
        scroll-margin-top: 4.5rem;
    }
}

/* Small devices */
@media (min-width: 30.0625em) and (max-width: 48em) {
    body {
        padding: 0.875rem;
    }

    #name {
        font-size: 3rem;
    }

    .header-image {
        max-width: 18rem;
    }

    .welcome {
        font-size: 1.375rem;
    }

    header {
        padding: 1.5rem 1.25rem;
    }

    .fun-section, .facts, .image-grid-section, .video-section {
        padding: 1.25rem 1rem;
    }

    .image-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .video-grid {
        grid-template-columns: 1fr;
    }
}

/* Medium devices / tablets */
@media (min-width: 48.0625em) and (max-width: 64em) {
    body {
        padding: 1.25rem;
    }

    #name {
        font-size: 3.75rem;
        text-shadow: 0.15rem 0.15rem 0 #FFF, 0.3rem 0.3rem 0 #FF6347;
    }

    .header-image {
        max-width: 22rem;
        border-radius: 1.25rem;
    }

    .welcome {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.75rem;
    }

    header {
        padding: 1.75rem;
        border-radius: 1.25rem;
    }

    .fun-section, .facts, .image-grid-section, .video-section {
        padding: 1.5rem;
        border-radius: 0.875rem;
    }

    .image-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
    }

    .video-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    #funButton {
        font-size: 1.375rem;
        padding: 1rem 2rem;
    }

    .nav-menu {
        gap: 0.75rem 1rem;
    }

    @keyframes bounce {
        0%, 100% { transform: translateY(0); }
        50% { transform: translateY(-1rem); }
    }
}

/* Large devices / desktops */
@media (min-width: 64.0625em) {
    body {
        padding: 1.5rem;
    }

    #name {
        font-size: 4.5rem;
        text-shadow: 0.1875rem 0.1875rem 0 #FFF, 0.375rem 0.375rem 0 #FF6347;
    }

    .header-image {
        max-width: 24rem;
        margin: 0.75rem 0 1rem 0;
    }

    .welcome {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 2rem;
    }

    header {
        padding: 2rem;
        border-radius: 1.25rem;
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.2);
    }

    .fun-section, .facts, .image-grid-section, .video-section {
        padding: 1.75rem;
        margin: 1.25rem 0;
        border-radius: 1rem;
        box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
    }

    .image-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 1rem;
    }

    .video-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.25rem;
    }

    #funButton {
        font-size: 1.5rem;
        padding: 1rem 2.25rem;
        box-shadow: 0 0.375rem 0 #C71585;
    }

    #message {
        font-size: 1.375rem;
    }

    ul {
        font-size: 1.3rem;
    }

    footer {
        font-size: 1.1rem;
        margin-top: 2.5rem;
    }

    .nav-link {
        font-size: 1.15rem;
        padding: 0.55rem 1rem;
    }

    @keyframes bounce {
        0%, 100% { transform: translateY(0); }
        50% { transform: translateY(-1.25rem); }
    }
}

/* Extra large desktops */
@media (min-width: 90em) {
    body {
        padding: 2rem;
    }

    main {
        max-width: 56rem;
    }

    #name {
        font-size: 5rem;
    }

    .header-image {
        max-width: 28rem;
    }

    .image-grid {
        gap: 1.25rem;
    }

    .nav-container {
        max-width: 56rem;
    }
}

/* ===== Math Page Styles ===== */
.math-intro p,
.place-value p {
    font-size: 1.1rem;
    color: #333;
    max-width: 40rem;
    margin-left: auto;
    margin-right: auto;
}

.place-value-box {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 1rem auto;
    flex-wrap: wrap;
}

.place-digit {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    min-width: 5rem;
    box-shadow: 0 0.25rem 0.5rem rgba(0,0,0,0.15);
}

.digit-label {
    display: block;
    font-size: 0.85rem;
    font-weight: bold;
    color: #4B0082;
}

.digit-example {
    display: block;
    font-size: 2rem;
    font-weight: bold;
    color: #FF4500;
    margin-top: 0.25rem;
}

.place-list {
    text-align: left;
    max-width: 28rem;
    margin: 1rem auto;
    background: #E6E6FA;
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
}

.place-list li {
    background: transparent;
    margin: 0.4rem 0;
    padding: 0.25rem 0;
}

.input-area {
    margin: 1rem 0;
}

.input-area label {
    display: block;
    font-weight: bold;
    color: #228B22;
    margin-bottom: 0.4rem;
    font-size: 1.1rem;
}

#numberInput {
    font-size: 1.4rem;
    padding: 0.6rem 1rem;
    border: 3px solid #FF69B4;
    border-radius: 2rem;
    width: 12rem;
    text-align: center;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

#numberInput:focus {
    border-color: #FF4500;
}

.round-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin: 1rem 0 1.5rem;
}

.math-btn {
    background-color: #1E90FF;
    color: white;
    font-size: 1.1rem;
    padding: 0.85rem 1.5rem;
    border: none;
    border-radius: 2rem;
    cursor: pointer;
    box-shadow: 0 0.25rem 0 #187bcd;
    font-family: inherit;
    font-weight: bold;
    transition: all 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.math-btn:hover {
    background-color: #187bcd;
}

.math-btn:active {
    transform: translateY(0.15rem);
    box-shadow: 0 0.1rem 0 #187bcd;
}

.number-line-container {
    background: #f0f8ff;
    border-radius: 1rem;
    padding: 1.25rem 0.75rem;
    margin: 1rem 0;
    min-height: 8rem;
    border: 2px dashed #1E90FF;
}

.placeholder-text {
    color: #666;
    font-style: italic;
    margin: 1.5rem 0;
}

.number-line {
    position: relative;
    height: 4.5rem;
    margin: 1rem 1.5rem 2rem;
}

.number-line-bar {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 0.4rem;
    background: #32CD32;
    border-radius: 0.2rem;
    transform: translateY(-50%);
}

.number-line-marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.number-line-marker .dot {
    width: 1.1rem;
    height: 1.1rem;
    background: #FF4500;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 0 0 2px #FF4500;
    z-index: 2;
}

.number-line-marker .label {
    margin-top: 0.4rem;
    font-weight: bold;
    font-size: 0.95rem;
    color: #FF4500;
    white-space: nowrap;
}

.number-line-end {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
    color: #228B22;
    font-size: 1rem;
}

.number-line-end::before {
    content: '';
    display: block;
    width: 0.6rem;
    height: 0.6rem;
    background: #228B22;
    border-radius: 50%;
    margin: 0 auto 0.3rem;
}

.explanation {
    background: #FFF8DC;
    border-left: 6px solid #FFD700;
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    margin: 1rem auto;
    max-width: 40rem;
    text-align: left;
    font-size: 1.05rem;
    line-height: 1.6;
}

.explanation strong {
    color: #FF4500;
}

.explanation .result {
    font-size: 1.4rem;
    color: #228B22;
    font-weight: bold;
    text-align: center;
    margin-top: 0.75rem;
}

.example-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
}

.example-card {
    background: #E6E6FA;
    border-radius: 0.75rem;
    padding: 1rem;
    text-align: left;
}

.example-card h3 {
    margin: 0 0 0.5rem 0;
    color: #4B0082;
    font-size: 1.1rem;
}

.example-card p {
    margin: 0;
    font-size: 0.95rem;
}

@media (max-width: 30em) {
    .round-buttons {
        flex-direction: column;
        align-items: center;
    }

    .math-btn {
        width: 90%;
    }

    #numberInput {
        width: 10rem;
        font-size: 1.25rem;
    }

    .place-digit {
        min-width: 4.5rem;
        padding: 0.5rem 0.75rem;
    }

    .digit-example {
        font-size: 1.6rem;
    }
}

/* ===== Giant Prehistoric Millipede Theme ===== */
.millipede-theme {
    background: linear-gradient(180deg, #f5f0e1 0%, #e8f5e9 100%);
    border: 3px solid #5d4037;
    position: relative;
    overflow: hidden;
}

.millipede-theme::before {
    content: "🐛";
    position: absolute;
    font-size: 2rem;
    opacity: 0.08;
    top: 0.5rem;
    right: 1rem;
    pointer-events: none;
}

.millipede-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.milli-emoji {
    font-size: 2rem;
    animation: wiggle 1.5s ease-in-out infinite;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(-8deg); }
    50% { transform: rotate(8deg); }
}

.place-digit {
    background: linear-gradient(135deg, #8bc34a, #558b2f);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 3px solid #33691e;
}

.place-digit:hover,
.place-digit.active {
    transform: scale(1.08) translateY(-4px);
    box-shadow: 0 0.5rem 1rem rgba(51, 105, 30, 0.4);
    background: linear-gradient(135deg, #aed581, #689f38);
}

.place-digit .digit-label {
    color: #1b5e20;
}

.place-digit .digit-example {
    color: #fff8e1;
    text-shadow: 0 2px 2px rgba(0,0,0,0.3);
}

.segment-hint {
    font-style: italic;
    color: #5d4037;
    min-height: 1.5rem;
}

.milli-btn {
    background: linear-gradient(180deg, #689f38, #33691e);
    box-shadow: 0 0.3rem 0 #1b5e20;
    border: 2px solid #1b5e20;
}

.milli-btn:hover {
    background: linear-gradient(180deg, #7cb342, #558b2f);
}

.milli-btn.secondary {
    background: linear-gradient(180deg, #8d6e63, #5d4037);
    box-shadow: 0 0.3rem 0 #3e2723;
    border-color: #3e2723;
}

.milli-btn.secondary:hover {
    background: linear-gradient(180deg, #a1887f, #6d4c41);
}

.milli-line {
    background: #efebe9;
    border: 3px solid #5d4037;
    border-radius: 1.5rem;
    padding: 1.5rem 1rem 2rem;
}

.number-line-bar {
    background: repeating-linear-gradient(
        90deg,
        #689f38 0px,
        #689f38 12px,
        #558b2f 12px,
        #558b2f 24px
    );
    height: 0.8rem;
    border-radius: 0.4rem;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.number-line-marker .dot {
    background: #ff6f00;
    border-color: #fff;
    box-shadow: 0 0 0 3px #e65100;
    width: 1.4rem;
    height: 1.4rem;
}

.number-line-marker .label {
    color: #e65100;
    font-size: 1.1rem;
    background: #fff8e1;
    padding: 0.15rem 0.4rem;
    border-radius: 0.5rem;
    border: 2px solid #ff6f00;
}

.number-line-end {
    color: #33691e;
    font-size: 1.05rem;
}

.number-line-end::before {
    background: #33691e;
    width: 0.8rem;
    height: 0.8rem;
}

.milli-explanation {
    background: #fff8e1;
    border-left: 8px solid #689f38;
    border-radius: 1rem;
    color: #3e2723;
}

.milli-explanation .result {
    color: #33691e;
    font-size: 1.5rem;
}

.milli-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.crawling-milli {
    position: absolute;
    top: -1.8rem;
    font-size: 1.8rem;
    transition: left 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.3));
    z-index: 3;
}

.leaf-stop {
    position: absolute;
    top: -2.2rem;
    font-size: 1.4rem;
    transform: translateX(-50%);
}

@media (max-width: 30em) {
    .millipede-header h2 {
        font-size: 1.3rem;
    }
    .milli-emoji {
        font-size: 1.5rem;
    }
}

/* ===== Accurate Arthropleura Number Line ===== */
.arthro-ref-image {
    max-width: 100%;
    height: auto;
    max-height: 18rem;
    border-radius: 1rem;
    margin: 0.75rem auto 1rem;
    display: block;
    box-shadow: 0 0.4rem 1rem rgba(0,0,0,0.2);
    border: 3px solid #5d4037;
}

.milli-line {
    background: linear-gradient(180deg, #efebe9 0%, #d7ccc8 100%);
    border: 4px solid #4e342e;
    border-radius: 2rem;
    padding: 2rem 1rem 3rem;
    overflow-x: auto;
}

.arthro-body {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    min-width: min-content;
    padding: 0 0.5rem;
    position: relative;
}

.arthro-head {
    width: 4.5rem;
    height: 3.2rem;
    background: linear-gradient(135deg, #6d4c41, #4e342e);
    border-radius: 50% 40% 30% 50%;
    position: relative;
    margin-right: -0.5rem;
    box-shadow: inset -4px -4px 8px rgba(0,0,0,0.3), 0 4px 6px rgba(0,0,0,0.2);
    z-index: 2;
    flex-shrink: 0;
}

.arthro-head::before {
    content: "";
    position: absolute;
    width: 0.7rem;
    height: 0.7rem;
    background: #212121;
    border-radius: 50%;
    top: 0.8rem;
    left: 0.9rem;
    box-shadow: 1.4rem 0 0 #212121;
}

.arthro-head::after {
    content: "";
    position: absolute;
    width: 1.8rem;
    height: 0.15rem;
    background: #3e2723;
    top: 1.4rem;
    left: -1.2rem;
    border-radius: 1px;
    transform: rotate(-15deg);
    box-shadow: 0 0.6rem 0 #3e2723;
}

.arthro-segment {
    width: 2.2rem;
    height: 2.4rem;
    background: linear-gradient(180deg, #795548 0%, #5d4037 40%, #4e342e 100%);
    border: 2px solid #3e2723;
    border-radius: 0.4rem 0.4rem 0.2rem 0.2rem;
    margin: 0 1px;
    position: relative;
    flex-shrink: 0;
    box-shadow: inset 0 3px 4px rgba(255,255,255,0.15), 0 3px 4px rgba(0,0,0,0.25);
    transition: transform 0.3s ease, background 0.3s;
}

.arthro-segment::before {
    content: "";
    position: absolute;
    top: 0.3rem;
    left: 15%;
    right: 15%;
    height: 0.25rem;
    background: rgba(0,0,0,0.25);
    border-radius: 2px;
}

.arthro-segment.highlight {
    background: linear-gradient(180deg, #ff8f00, #ef6c00);
    transform: translateY(-6px) scale(1.08);
    z-index: 3;
    box-shadow: 0 6px 12px rgba(239, 108, 0, 0.4);
}

.arthro-segment.target {
    background: linear-gradient(180deg, #66bb6a, #388e3c);
    box-shadow: 0 0 0 3px #2e7d32, 0 4px 8px rgba(0,0,0,0.3);
}

.arthro-legs {
    position: absolute;
    bottom: -1.6rem;
    left: 10%;
    right: 10%;
    height: 1.5rem;
    display: flex;
    justify-content: space-around;
}

.arthro-legs span {
    width: 2px;
    height: 100%;
    background: #5d4037;
    border-radius: 1px;
    transform-origin: top center;
    animation: legWiggle 0.6s ease-in-out infinite alternate;
}

.arthro-legs span:nth-child(odd) { animation-delay: 0.1s; }
.arthro-legs span:nth-child(even) { animation-delay: 0.3s; }

@keyframes legWiggle {
    from { transform: rotate(-8deg); }
    to { transform: rotate(8deg); }
}

.arthro-tail {
    width: 2rem;
    height: 1.8rem;
    background: linear-gradient(90deg, #5d4037, #4e342e);
    border-radius: 0 50% 50% 0;
    margin-left: -0.3rem;
    flex-shrink: 0;
}

.segment-label {
    position: absolute;
    bottom: -2.8rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    font-weight: bold;
    color: #3e2723;
    white-space: nowrap;
    background: rgba(255,248,225,0.9);
    padding: 0.1rem 0.3rem;
    border-radius: 0.3rem;
}

.number-marker {
    position: absolute;
    top: -2.2rem;
    left: 50%;
    transform: translateX(-50%);
    background: #ff6f00;
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    padding: 0.2rem 0.5rem;
    border-radius: 1rem;
    white-space: nowrap;
    z-index: 4;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.number-marker::after {
    content: "";
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #ff6f00;
}

@media (max-width: 40em) {
    .arthro-segment {
        width: 1.6rem;
        height: 1.8rem;
    }
    .arthro-head {
        width: 3.2rem;
        height: 2.4rem;
    }
}

/* ===== Cartoon Arthropleura Overrides ===== */
.arthro-ref-image {
    border: 4px solid #66bb6a;
    box-shadow: 0 0.5rem 1.2rem rgba(102, 187, 106, 0.35);
}

.milli-line {
    background: linear-gradient(180deg, #e8f5e9 0%, #c8e6c9 100%);
    border: 4px solid #43a047;
    border-radius: 2.5rem;
}

.arthro-head {
    width: 5rem;
    height: 4rem;
    background: radial-gradient(circle at 30% 30%, #a5d6a7, #66bb6a 60%, #43a047);
    border-radius: 50% 45% 40% 55%;
    border: 3px solid #2e7d32;
    box-shadow: 0 4px 0 #1b5e20, inset 0 -4px 8px rgba(0,0,0,0.1);
}

.arthro-head::before {
    width: 1rem;
    height: 1rem;
    background: #fff;
    top: 1rem;
    left: 1.1rem;
    box-shadow: 1.6rem 0 0 #fff;
    border: 3px solid #212121;
}

.arthro-head::after {
    content: "";
    position: absolute;
    width: 0.5rem;
    height: 0.5rem;
    background: #212121;
    border-radius: 50%;
    top: 1.25rem;
    left: 1.35rem;
    box-shadow: 1.6rem 0 0 #212121;
}

/* Antennae via extra pseudo or keep simple */
.arthro-segment {
    width: 2.4rem;
    height: 2.8rem;
    background: linear-gradient(180deg, #aed581 0%, #7cb342 50%, #558b2f 100%);
    border: 3px solid #33691e;
    border-radius: 0.8rem 0.8rem 0.4rem 0.4rem;
    box-shadow: 0 3px 0 #33691e, inset 0 4px 6px rgba(255,255,255,0.3);
}

.arthro-segment::before {
    background: rgba(255,255,255,0.25);
    height: 0.35rem;
    border-radius: 4px;
}

.arthro-segment.highlight {
    background: linear-gradient(180deg, #ffcc80, #ff9800);
    border-color: #e65100;
    transform: translateY(-8px) scale(1.12);
    box-shadow: 0 6px 0 #e65100, 0 8px 16px rgba(255, 152, 0, 0.4);
}

.arthro-segment.target {
    background: linear-gradient(180deg, #42a5f5, #1565c0);
    border-color: #0d47a1;
    box-shadow: 0 0 0 4px #64b5f6, 0 4px 0 #0d47a1, 0 6px 14px rgba(21, 101, 192, 0.5);
    transform: translateY(-6px) scale(1.1);
    z-index: 3;
}

.arthro-legs span {
    width: 4px;
    background: #558b2f;
    border-radius: 2px;
    height: 1.4rem;
}

.arthro-tail {
    width: 2.2rem;
    height: 2rem;
    background: linear-gradient(90deg, #7cb342, #558b2f);
    border: 3px solid #33691e;
    border-radius: 0 60% 60% 0;
}

.number-marker {
    background: #ff6f00;
    border: 3px solid #fff;
    font-size: 1rem;
    padding: 0.25rem 0.6rem;
    border-radius: 1.2rem;
    top: -2.6rem;
}

.segment-label {
    background: #fff9c4;
    border: 2px solid #fbc02d;
    color: #e65100;
    font-size: 0.8rem;
    border-radius: 0.5rem;
}

/* ===== Multiplication Activities ===== */
.math-input {
    font-size: 1.4rem;
    padding: 0.6rem 1rem;
    border: 3px solid #FF69B4;
    border-radius: 2rem;
    width: 6rem;
    text-align: center;
    font-family: inherit;
    outline: none;
    margin: 0 0.5rem 0.5rem;
}

.math-input:focus {
    border-color: #FF4500;
}

.array-grid {
    display: inline-block;
    padding: 1rem;
    margin: 0.75rem auto;
    background: #e8f5e9;
    border: 3px solid #43a047;
    border-radius: 1.5rem;
    min-height: 3rem;
    min-width: 4rem;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.array-row {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.35rem;
    justify-content: center;
}

.array-cell {
    width: 2rem;
    height: 2rem;
    min-width: 2rem;
    min-height: 2rem;
    flex-shrink: 0;
    background: linear-gradient(180deg, #aed581 0%, #7cb342 100%);
    border: 2px solid #33691e;
    border-radius: 0.4rem;
    box-shadow: 0 2px 0 #33691e;
    transition: transform 0.2s ease;
}

.array-cell:hover {
    transform: scale(1.15) translateY(-2px);
}

.property-compare {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin: 1.5rem 0;
}

.property-box {
    background: #fff8e1;
    padding: 1rem;
    border-radius: 1rem;
    box-shadow: 0 0.25rem 0.5rem rgba(0,0,0,0.1);
    border: 2px solid #ffcc80;
    min-width: 12rem;
    text-align: center;
}

.equal-sign {
    font-size: 2.5rem;
    font-weight: bold;
    color: #228B22;
    align-self: center;
}

.calc-step {
    background: #E6E6FA;
    padding: 0.6rem 0.9rem;
    border-radius: 0.5rem;
    margin: 0.4rem 0;
    font-weight: bold;
    color: #4B0082;
    border-left: 5px solid #FF69B4;
}

#practiceArea {
    margin-top: 1rem;
}

#practiceFeedback {
    margin-top: 0.75rem;
}

/* Override the overflow:hidden on millipede sections so arrays are not clipped */
.millipede-theme {
    overflow: visible;
}

/* Mobile adjustments – keep the desktop visual language as much as possible */
@media (max-width: 48em) {
    .array-cell {
        width: 1.75rem;
        height: 1.75rem;
        min-width: 1.75rem;
        min-height: 1.75rem;
    }

    .array-grid {
        padding: 0.75rem;
    }

    .property-compare {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }

    .property-box {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .equal-sign {
        font-size: 2rem;
        margin: 0.25rem 0;
    }

    .math-input {
        width: 5rem;
        font-size: 1.25rem;
        margin: 0.25rem 0.35rem;
    }

    .calc-step {
        font-size: 1.05rem;
        padding: 0.7rem 1rem;
        background: #d1c4e9;
        border-left-width: 6px;
    }

    .input-area {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: 0.5rem;
    }
}

@media (max-width: 30em) {
    .array-cell {
        width: 1.5rem;
        height: 1.5rem;
        min-width: 1.5rem;
        min-height: 1.5rem;
    }

    .math-input {
        width: 4.5rem;
        font-size: 1.15rem;
    }
}
/* ===== Desktop Nav Collapse to Thin Bar ===== */
@media (min-width: 48.0625em) {
    .site-nav {
        overflow: hidden;
        max-height: 20rem;
        transition: max-height 0.3s ease, margin-bottom 0.3s ease, box-shadow 0.3s ease;
    }

    .site-nav.shrunk {
        max-height: 0.45rem;
        margin-bottom: 0.35rem;
        box-shadow: 0 0.1rem 0.3rem rgba(0, 0, 0, 0.15);
    }

    .site-nav.shrunk .nav-container,
    .site-nav.shrunk .nav-menu,
    .site-nav.shrunk .nav-link {
        opacity: 0;
        pointer-events: none;
        padding-top: 0;
        padding-bottom: 0;
        transition: opacity 0.2s ease, padding 0.2s ease;
    }
}
