/* Shared TechlabCL styling. Button content lives in /data/buttons.js. */
body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    .container {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        grid-auto-rows: minmax(140px, auto);
        gap: 15px;
        padding: 15px;
        position: relative;
        align-items: stretch;
    }

    @media screen and (max-width: 1200px) {
        .container {
            grid-template-columns: repeat(4, 1fr);
        }
    }

    @media screen and (max-width: 900px) {
        .container {
            grid-template-columns: repeat(3, 1fr);
        }
    }

    @media screen and (max-width: 600px) {
        .container {
            grid-template-columns: repeat(2, 1fr);
        }
    }

    @media screen and (max-width: 400px) {
        .container {
            grid-template-columns: 1fr;
        }
    }

    .grid-item {
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        text-align: center;
        border: 1px solid #ddd;
        padding: 7.5px;
        background-color: #f9f9f9;
        border-radius: 10px;
        transition: transform 0.5s, background-color 0.5s;
        text-decoration: none;
        color: #333;
        min-height: 140px;
        height: 100%;
        align-self: stretch;
        overflow: hidden;
    }

    .grid-item:hover {
        transform: scale(1.05);
        background: linear-gradient(45deg, 
            rgba(255, 0, 0, 0.2),   
            rgba(255, 165, 0, 0.2), 
            rgba(255, 255, 0, 0.2), 
            rgba(0, 128, 0, 0.2),   
            rgba(0, 0, 255, 0.2),   
            rgba(75, 0, 130, 0.2),  
            rgba(238, 130, 238, 0.2)
        );
        background-size: 600% 600%;
        animation: rainbow 3s ease infinite;
        animation-direction: alternate;
        background-color: rgba(255, 255, 255, 0.8);
    }

    @keyframes rainbow {
        0% { background-position: 0% 0%; }
        100% { background-position: 100% 100%; }
    }

    .grid-item img {
        width: 112.5px;
        height: 112.5px;
        min-width: 100%;
        object-fit: contain;
        border-radius: 10px;
    }

    .grid-item span {
        margin-top: 7.5px;
        font-size: 14px;
        font-weight: bold;
    }

    .grid-item:hover span {
        color: #007BFF;
    }

    .menu-container {
        position: relative;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        min-height: 140px;
        height: 100%;
        align-self: stretch;
    }

    .menu-container > .menu-trigger {
        flex: 1 1 auto;
        min-height: 140px;
        height: 100%;
    }

    .sub-buttons {
        position: absolute;
        /* Explicit top: in-flow static position breaks with flex + full-height trigger; anchor below the tile. */
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        margin-top: 10px;
        z-index: 1000;
        background-color: #f9f9f9;
        border: 1px solid #ddd;
        border-radius: 8px;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        display: none;
        flex-direction: row;
        gap: 8px;
        padding: 8px;
        max-height: 160px;
        max-width: calc(100vw - 20px);
        overflow-y: auto;
        overflow-x: auto;
        white-space: nowrap;
        pointer-events: auto;
        /* Stretch row height to tallest chip so all items match */
        align-items: stretch;
    }

    /* TinkerCAD submenu becomes: year row (top) + classes row (below). */
    .sub-buttons.tinkercad-sub {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        white-space: normal;
        overflow-y: visible; /* vertical overflow is controlled by expanded state */
        overflow-x: visible;

        /* Dynamically size to content, but never beyond the viewport. */
        width: auto;
        max-width: calc(100vw - 20px);

        /* Remove outer wrapper "box" styling so the two inner bars
           (years row + classes row) look like separate bars. */
        background-color: transparent;
        border: none;
        box-shadow: none;
        padding: 0;
    }

    .sub-buttons.tinkercad-sub.tinkercad-expanded {
        max-height: none; /* prevent clipping when a year expands */
        overflow-y: visible;
    }

    /* When a jaarlaag is open: all jaarlagen stay grey/muted; active one full colour. All remain clickable. */
    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle {
        filter: grayscale(58%) !important;
        opacity: 0.88 !important;
        background-color: #e2e2e2 !important;
        border-color: #c2c2c2 !important;
    }

    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle.active-year-toggle {
        filter: none !important;
        opacity: 1 !important;
        background-color: #f9f9f9 !important;
        border-color: #ddd !important;
    }

    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle:not(.active-year-toggle):hover,
    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle:not(.active-year-toggle):focus-visible {
        filter: grayscale(12%) !important;
        opacity: 1 !important;
        background-color: #ececec !important;
    }

    /* While expanded: no rainbow hover on jaarlagen (keeps muted vs active readable) */
    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle:hover,
    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle:focus-visible {
        animation: none !important;
    }

    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle.active-year-toggle:hover,
    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle.active-year-toggle:focus-visible {
        background-color: #efefef !important;
        background-image: none !important;
    }

    .tinkercad-years-row {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: flex-start;
        gap: 10px;
        overflow-x: visible;
        overflow-y: hidden;
        white-space: nowrap;
        width: fit-content;
        max-width: 100%;

        /* Make the years row look like its own menu bar */
        box-sizing: border-box;
        background-color: #f9f9f9;
        border: 1px solid #ddd;
        border-radius: 8px;
        padding: 8px;
    }

    .tinkercad-years-row .grid-item {
        flex: 0 0 auto;
    }

    .tinkercad-year-classes {
        display: none;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
        overflow-x: hidden; /* no horizontal scrolling */
        overflow-y: hidden;
        white-space: normal;

        /* Use as much width as available. When items don't fit, they wrap. */
        box-sizing: border-box;
        width: fit-content;
        max-width: calc(100vw - 20px);

        /* Make the classes row look like its own menu bar */
        background-color: #f9f9f9;
        border: 1px solid #ddd;
        border-radius: 8px;
        padding: 8px;
    }

    .tinkercad-year-classes.active {
        display: flex;
    }

    .tinkercad-year-classes .grid-item {
        /* Keep normal button width; wrap to next line only when needed. */
        flex: 0 0 112.5px;
        min-width: 112.5px;
        max-width: 112.5px;
    }

    /* Allow long class names to wrap inside the (small) button width. */
    .tinkercad-year-classes .grid-item span {
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    /* Placeholder button shown when no class links are configured yet. */
    .tinkercad-year-classes .tinkercad-placeholder {
        opacity: 0.6;
        pointer-events: none;
    }

    .sub-buttons .grid-item {
        /* Override hub .grid-item min-height so submenu chips stay compact */
        min-height: 0;
        align-self: stretch;
        width: auto;
        max-width: 112.5px;
        height: auto;
        max-height: none;
        border: 1px solid #ddd;
        background-color: #f9f9f9;
        border-radius: 8px;
        padding: 6px 8px;
        text-align: center;
        transition: transform 0.5s, background-color 0.5s;
        position: relative;
        /* Same visual height as siblings in the row; content centred vertically */
        justify-content: center;
    }

    .sub-buttons .grid-item span {
        margin-top: 4px;
        font-size: 12px;
    }

    .sub-buttons .grid-item img {
        width: 32px;
        height: 32px;
    }

    .sub-buttons .grid-item:hover {
        transform: scale(1.1);
        background: linear-gradient(45deg, 
            rgba(255, 0, 0, 0.2),   
            rgba(255, 165, 0, 0.2), 
            rgba(255, 255, 0, 0.2), 
            rgba(0, 128, 0, 0.2),   
            rgba(0, 0, 255, 0.2),   
            rgba(75, 0, 130, 0.2),  
            rgba(238, 130, 238, 0.2)
        );
        background-size: 600% 600%;
        animation: rainbow 3s ease infinite;
        animation-direction: alternate;
        background-color: rgba(255, 255, 255, 0.8);
    }

    /* Jaarlagen: normal look until one is chosen; divs need pointer cursor + keyboard ring */
    .tinkercad-years-row .tinker-year-toggle {
        cursor: pointer;
    }

    .tinkercad-years-row .tinker-year-toggle:focus-visible {
        outline: 2px solid #007bff;
        outline-offset: 2px;
    }

    .container.greyed-out .grid-item {
        filter: grayscale(80%);
        pointer-events: none;
    }

    .container.greyed-out .menu-container .grid-item {
        filter: none;
        pointer-events: auto;
    }

    .container.greyed-out .menu-container .sub-buttons {
        display: flex;
    }

    .container.greyed-out .grid-item.inactive {
        filter: grayscale(100%);
        pointer-events: none;
    }

    .container .grid-item.active {
        filter: none;
        pointer-events: auto;
    }

    /* Menu triggers: echte knoppen met dezelfde look als tegels (UA-styles neutraliseren) */
    button.grid-item.menu-trigger {
        font: inherit;
        font-family: Arial, sans-serif;
        cursor: pointer;
        width: 100%;
        max-width: none;
        margin: 0;
        box-sizing: border-box;
        -webkit-appearance: none;
        appearance: none;
        border: 1px solid #ddd;
        background-color: #f9f9f9;
        color: #333;
        line-height: 1.2;
        text-align: center;
    }

    :root {
        --tl-bg: #ffffff;
        --tl-fg: #222222;
        --tl-card: #f9f9f9;
        --tl-card-border: #dddddd;
        --tl-card-text: #333333;
        --tl-card-hover-text: #007bff;
        --tl-menu-shadow: rgba(0, 0, 0, 0.2);
        --tl-muted-card: #e2e2e2;
        --tl-muted-border: #c2c2c2;
        --tl-muted-hover: #ececec;
        --tl-active-card: #f9f9f9;
        --tl-active-hover: #efefef;
        --tl-focus: #007bff;
        --tl-switcher-bg: rgba(255, 255, 255, 0.92);
        --tl-switcher-border: rgba(0, 0, 0, 0.12);
        --tl-switcher-shadow: rgba(0, 0, 0, 0.12);
    }

    html.tcl-theme-dark {
        --tl-bg: #131316;
        --tl-fg: #ececf1;
        --tl-card: #222228;
        --tl-card-border: rgba(255, 255, 255, 0.12);
        --tl-card-text: #ececf1;
        --tl-card-hover-text: #5eb0ff;
        --tl-menu-shadow: rgba(0, 0, 0, 0.55);
        --tl-muted-card: #2d2d34;
        --tl-muted-border: #454550;
        --tl-muted-hover: #3a3a43;
        --tl-active-card: #2f3038;
        --tl-active-hover: #373843;
        --tl-focus: #5eb0ff;
        --tl-switcher-bg: rgba(18, 18, 24, 0.98);
        --tl-switcher-border: rgba(255, 255, 255, 0.07);
        --tl-switcher-shadow: rgba(0, 0, 0, 0.55);
    }

    body {
        background: var(--tl-bg);
        color: var(--tl-fg);
        transition: background-color 0.2s ease, color 0.2s ease;
    }

    .theme-switcher {
        position: fixed;
        top: 12px;
        right: 12px;
        z-index: 1200;
        display: flex;
        flex-direction: row;
        gap: 4px;
        align-items: center;
        padding: 4px 6px;
        background: var(--tl-switcher-bg);
        border: 1px solid var(--tl-switcher-border);
        border-radius: 10px;
        box-shadow: 0 2px 8px var(--tl-switcher-shadow);
        backdrop-filter: blur(6px);
    }

    .theme-switcher .theme-btn {
        margin: 0;
        padding: 4px;
        line-height: 0;
        border: 2px solid transparent;
        border-radius: 6px;
        background: transparent;
        color: var(--tl-card-text);
        cursor: pointer;
        opacity: 0.55;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: opacity 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
    }

    .theme-switcher .theme-btn:hover {
        opacity: 0.92;
        transform: scale(1.06);
    }

    .theme-switcher .theme-btn:focus-visible {
        outline: 2px solid var(--tl-focus);
        outline-offset: 2px;
    }

    .theme-switcher .theme-btn.active {
        opacity: 1;
        border-color: var(--tl-focus);
    }

    .theme-switcher .theme-btn svg {
        display: block;
        width: 22px;
        height: 22px;
    }

    body.has-theme-switcher .container {
        padding: 64px 15px 56px;
    }

    .grid-item,
    button.grid-item.menu-trigger,
    .sub-buttons .grid-item {
        background-color: var(--tl-card);
        border-color: var(--tl-card-border);
        color: var(--tl-card-text);
    }

    .grid-item:hover span {
        color: var(--tl-card-hover-text);
    }

    .sub-buttons,
    .tinkercad-years-row,
    .tinkercad-year-classes {
        background-color: var(--tl-card);
        border-color: var(--tl-card-border);
        box-shadow: 0 4px 8px var(--tl-menu-shadow);
    }

    .sub-buttons.tinkercad-sub {
        background-color: transparent;
        box-shadow: none;
    }

    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle {
        background-color: var(--tl-muted-card) !important;
        border-color: var(--tl-muted-border) !important;
    }

    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle.active-year-toggle {
        background-color: var(--tl-active-card) !important;
        border-color: var(--tl-card-border) !important;
    }

    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle:not(.active-year-toggle):hover,
    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle:not(.active-year-toggle):focus-visible {
        background-color: var(--tl-muted-hover) !important;
    }

    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle.active-year-toggle:hover,
    .sub-buttons.tinkercad-sub.tinkercad-expanded .tinker-year-toggle.active-year-toggle:focus-visible {
        background-color: var(--tl-active-hover) !important;
    }

    .tinkercad-years-row .tinker-year-toggle:focus-visible {
        outline-color: var(--tl-focus);
    }

    html.tcl-theme-dark img[alt="Everything3D"],
    html.tcl-theme-dark img[alt="Zelfreflectie"] {
        filter: invert(1) hue-rotate(180deg) brightness(1.12) contrast(1.08);
    }

    /* everything3d-logo-fix */

#copyright-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--tl-footer-bg, rgba(20, 20, 20, 0.9));
    color: var(--tl-footer-text, #fff);
    text-align: center;
    padding: 8px 0;
    font-size: 14px;
    font-family: "Inter", sans-serif;
    z-index: 1000;
    backdrop-filter: blur(6px);
  }

  #copyright-bar a {
    color: #00bfff;
    text-decoration: none;
  }

  #copyright-bar a:hover {
    text-decoration: underline;
  }