/* ==========================================================================
   Tools directory (/tools/, /tools/category/<slug>/, /tools/tag/<slug>/)
   base.html pages: the intro is a full-width .jg-paper band, everything else
   sits in .container. Open layout: rows and hairline rules, no boxed cards.
   Colours come from theme vars only.
   ========================================================================== */

.tools-dashboard {
    --tools-link: var(--brand-primary-strong);
    --tools-flag: var(--brand-secondary-strong);
    padding: 0 0 5rem;
    color: var(--text-primary);
}

[data-theme="dark"] .tools-dashboard {
    --tools-link: var(--brand-primary);
    --tools-flag: var(--brand-secondary);
}

/* --------------------------------------------------------------------------
   Intro + search
   -------------------------------------------------------------------------- */

.tools-intro {
    padding: clamp(2.5rem, 6vw, 5rem) 0 clamp(2rem, 4vw, 3.5rem);
    overflow: hidden;
}

.tools-intro__inner {
    position: relative;
}

/* Three real printouts fanned on the right, like the home page. Wide screens only. */
.tools-intro__art {
    display: none;
}

@media (min-width: 1200px) {
    .tools-intro__art {
        display: block;
        position: absolute;
        top: -1rem;
        right: var(--content-padding);
        width: 25rem;
        height: 100%;
        pointer-events: none;
    }

    .tools-intro__sheet {
        position: absolute;
        width: 11.5rem;
        height: auto;
        border-radius: 4px;
        box-shadow: 0 1px 2px rgba(14, 27, 44, 0.12), 0 18px 40px -16px rgba(14, 27, 44, 0.4);
    }

    .tools-intro__sheet--1 { right: 13rem; top: 3.5rem; transform: rotate(-9deg); }
    .tools-intro__sheet--2 { right: 6.5rem; top: 1rem; transform: rotate(2deg); z-index: 1; }
    .tools-intro__sheet--3 { right: 0; top: 4.5rem; transform: rotate(11deg); }
}

.tools-intro__breadcrumb {
    margin: 0 0 0.75rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.tools-intro__breadcrumb ol {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tools-intro__breadcrumb li + li::before {
    content: '/';
    margin-right: 0.375rem;
    color: var(--text-muted);
}

.tools-intro__breadcrumb a {
    color: var(--tools-link);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.tools-intro__title {
    max-width: 18ch;
    text-wrap: balance;
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 5.5vw, 4.5rem);
    font-weight: 700;
    line-height: 1.02;
    letter-spacing: -0.035em;
    color: var(--text-primary);
    margin: 0 0 1.25rem;
}

.tools-intro__lede {
    max-width: 56ch;
    margin: 0 0 2rem;
    font-size: clamp(1.0625rem, 1.4vw, 1.25rem);
    line-height: 1.55;
    color: var(--text-secondary);
}

.tools-search {
    max-width: 40rem;
}

.tools-search__label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
}

.tools-search__field {
    position: relative;
}

.tools-search__field i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.tools-search__input {
    width: 100%;
    min-height: 3.25rem;
    padding: 0.75rem 1rem 0.75rem 2.75rem;
    font: inherit;
    font-size: 1.0625rem;
    color: var(--text-primary);
    background: var(--input-bg);
    border: 1.5px solid var(--border-strong);
    border-radius: 8px;
    appearance: none;
}

.tools-search__input::placeholder {
    color: var(--text-muted);
}

.tools-search__input:focus {
    outline: none;
    border-color: var(--tools-link);
    box-shadow: 0 0 0 3px var(--brand-primary-20);
}

.tools-search__status {
    min-height: 1.25rem;
    margin: 0.5rem 0 0;
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Category colours: one tint per category, used by chips, section icons and
   card icon tiles. Unknown categories fall back to the brand blue.
   -------------------------------------------------------------------------- */

.tools-dashboard { --cat: var(--brand-primary); }
.tools-dashboard [data-category="math"]            { --cat: #1f6fb2; }
.tools-dashboard [data-category="language-arts"]   { --cat: #c2562e; }
.tools-dashboard [data-category="classroom-tools"] { --cat: #0f8f7c; }
.tools-dashboard [data-category="puzzles-games"]   { --cat: #b7791f; }
.tools-dashboard [data-category="coloring-art"]    { --cat: #c2417a; }
.tools-dashboard [data-category="pdf-tools"]       { --cat: #c53030; }
.tools-dashboard [data-category="image-tools"]     { --cat: #5a55c9; }
.tools-dashboard [data-category="developer-tools"] { --cat: #4a5a6d; }

[data-theme="dark"] .tools-dashboard [data-category="math"]            { --cat: #4ea8e6; }
[data-theme="dark"] .tools-dashboard [data-category="language-arts"]   { --cat: #f3a17c; }
[data-theme="dark"] .tools-dashboard [data-category="classroom-tools"] { --cat: #4fd1b9; }
[data-theme="dark"] .tools-dashboard [data-category="puzzles-games"]   { --cat: #fcd34d; }
[data-theme="dark"] .tools-dashboard [data-category="coloring-art"]    { --cat: #f48fbf; }
[data-theme="dark"] .tools-dashboard [data-category="pdf-tools"]       { --cat: #f87171; }
[data-theme="dark"] .tools-dashboard [data-category="image-tools"]     { --cat: #a5a3f5; }
[data-theme="dark"] .tools-dashboard [data-category="developer-tools"] { --cat: #9fb0c3; }

/* --------------------------------------------------------------------------
   Category chips
   -------------------------------------------------------------------------- */

.tools-chips {
    padding: 1.5rem 0 0.5rem;
}

.tools-chips__list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tools-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.5rem;
    padding: 0.4rem 1rem 0.4rem 0.8rem;
    border: 1px solid var(--border-medium);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.tools-chip i {
    color: var(--cat);
    font-size: 0.875rem;
}

.tools-chip:hover {
    border-color: var(--cat);
    background: color-mix(in srgb, var(--cat) 8%, var(--bg-card));
    color: var(--text-primary);
    text-decoration: none;
}

/* --------------------------------------------------------------------------
   Sections
   -------------------------------------------------------------------------- */

.tools-section {
    padding: 2.25rem 0 0.5rem;
    scroll-margin-top: calc(var(--header-height, 64px) + 1rem);
}

.tools-section[hidden] {
    display: none;
}

.tools-section__header {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-bottom: 1.1rem;
}

.tools-section__icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 12px;
    background: color-mix(in srgb, var(--cat) 14%, transparent);
    color: var(--cat);
    font-size: 1.05rem;
}

.tools-section__text {
    flex: 1;
    min-width: 0;
}

.tools-section__title {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    margin: 0;
    font-size: clamp(1.4rem, 2.2vw, 1.75rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

.tools-section__count {
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--text-muted);
}

.tools-section__desc {
    margin: 0.2rem 0 0;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.tools-section__link {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--tools-link);
    text-decoration: none;
}

.tools-section__link i {
    font-size: 0.75em;
    transition: transform 0.15s ease;
}

.tools-section__link:hover {
    color: var(--tools-link);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.tools-section__link:hover i {
    transform: translateX(2px);
}

/* --------------------------------------------------------------------------
   Tool cards
   -------------------------------------------------------------------------- */

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(16.5rem, 1fr));
    gap: 1rem;
    align-content: start;
    min-width: 0;
}

.tool-card {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 0.9rem;
    padding: 1.1rem 2.5rem 1.15rem 1.1rem;
    border: 1px solid var(--border-medium);
    border-radius: 14px;
    background: var(--bg-card);
    color: inherit;
    text-decoration: none;
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.tool-card[hidden] {
    display: none;
}

.tool-card:hover {
    border-color: var(--cat);
    box-shadow: 0 6px 18px -10px color-mix(in srgb, var(--cat) 55%, transparent);
    transform: translateY(-2px);
    color: inherit;
    text-decoration: none;
}

.tool-card__icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 12px;
    background: color-mix(in srgb, var(--cat) 14%, transparent);
    color: var(--cat);
    font-size: 1.15rem;
}

.tool-card__body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.tool-card__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.tool-card__title {
    font-family: var(--font-display);
    font-size: 1.0625rem;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.tool-card__flag {
    padding: 0.05rem 0.5rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--tools-flag) 14%, transparent);
    color: var(--tools-flag);
    font-size: 0.75rem;
    font-weight: 600;
}

.tool-card__desc {
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.tool-card__arrow {
    position: absolute;
    top: 1.35rem;
    right: 1.1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s ease;
}

.tool-card:hover .tool-card__arrow,
.tool-card:focus-visible .tool-card__arrow {
    opacity: 1;
    transform: none;
    color: var(--cat);
}

@media (hover: none) {
    .tool-card__arrow {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tool-card,
    .tool-card__arrow,
    .tools-section__link i {
        transition: none;
    }

    .tool-card:hover {
        transform: none;
    }
}

/* --------------------------------------------------------------------------
   Related links (category and tag pages)
   -------------------------------------------------------------------------- */

.tools-related {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.tools-related {
    gap: 0.5rem;
}

.tools-related a {
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    padding: 0.4rem 1rem;
    border: 1px solid var(--border-medium);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
}

.tools-related a:hover {
    border-color: var(--brand-primary);
    color: var(--text-primary);
    text-decoration: none;
}

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */

.empty-state {
    padding: 2.5rem 0;
}

.empty-state[hidden] {
    display: none;
}

.empty-state__text {
    margin: 0 0 1rem;
    font-size: 1rem;
    color: var(--text-secondary);
}

.empty-state__button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.5rem 1.25rem;
    font: inherit;
    font-weight: 600;
    color: var(--btn-primary-text, #fff);
    background: var(--brand-primary-strong);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
}

.empty-state__button:hover {
    color: var(--btn-primary-text, #fff);
    text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Focus + motion
   -------------------------------------------------------------------------- */

.tools-dashboard a:focus-visible,
.tools-dashboard button:focus-visible {
    outline: 2px solid var(--tools-link);
    outline-offset: 2px;
    border-radius: 4px;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
    .tools-dashboard {
        padding-bottom: 3rem;
    }
}

@media (max-width: 600px) {
    .tools-grid {
        grid-template-columns: 1fr;
    }

    .tools-section__desc {
        display: none;
    }

    .tools-chips__list {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 0.25rem;
        scrollbar-width: none;
    }

    .tools-chips__list::-webkit-scrollbar {
        display: none;
    }

    .tools-chip {
        flex: none;
    }
}

/* --------------------------------------------------------------------------
   Directory hero: the landing page's stage panel (library.css .lib-hero)
   with the search inside it
   -------------------------------------------------------------------------- */

.tools-hero {
    margin-top: 1.5rem;
}

.tools-hero .tools-search {
    max-width: 34rem;
    margin-top: 1.5rem;
}

.tools-hero .tools-search__input {
    min-height: 3.4rem;
    background: var(--bg-card);
    border: 1px solid color-mix(in srgb, var(--jg-accent) 25%, var(--border-medium));
    border-radius: 999px;
    box-shadow: 0 10px 24px -18px rgba(14, 27, 44, 0.5);
}

.tools-hero .tools-search__input:focus {
    border-color: var(--jg-accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--jg-accent) 22%, transparent);
}

.tools-hero .tools-search__status:empty {
    display: none;
}

.tools-hero .lib-hero__facts {
    margin-top: 1rem;
}

.tools-chip__count {
    min-width: 1.5rem;
    padding: 0 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-align: center;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-radius: 999px;
}

/* --------------------------------------------------------------------------
   Starting points: landing-style tiles, each with the sheet the tool prints
   -------------------------------------------------------------------------- */

.tools-picks {
    padding: 2.5rem 0 0.5rem;
}

.tools-picks__title {
    margin: 0 0 1.25rem;
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 1.2rem + 1.6vw, 2.4rem);
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -0.035em;
    color: var(--text-primary);
}

.tools-bento {
    display: grid;
    grid-template-columns: 1.25fr 1fr 1fr;
    grid-auto-rows: minmax(230px, auto);
    gap: 1.25rem;
}

.tools-tile {
    position: relative;
    display: flex;
    min-height: 230px;
    padding: 1.6rem 1.6rem 1.4rem;
    overflow: hidden;
    color: var(--text-primary);
    text-decoration: none;
    background: var(--tone);
    border-radius: 28px;
    isolation: isolate;
    transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.4s ease;
}

.tools-tile:first-child {
    grid-row: span 2;
}

.tools-tile:hover {
    color: var(--text-primary);
    text-decoration: none;
    box-shadow: 0 24px 40px -24px rgba(14, 27, 44, 0.5);
    transform: translateY(-4px);
}

.tools-tile__text {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-width: 56%;
}

.tools-tile:first-child .tools-tile__text {
    max-width: 70%;
}

.tools-tile__name {
    font-family: var(--font-display);
    font-size: clamp(1.3rem, 1rem + 0.8vw, 1.6rem);
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.025em;
}

.tools-tile:first-child .tools-tile__name {
    font-size: clamp(1.7rem, 1.2rem + 1.4vw, 2.3rem);
}

.tools-tile__desc {
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.tools-tile__go {
    margin-top: auto;
    padding-top: 0.75rem;
    font-weight: 700;
    color: var(--tone-ink);
}

.tools-tile__go span {
    display: inline-block;
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.tools-tile:hover .tools-tile__go span {
    transform: translateX(4px);
}

/* The printed sample peeks out of the bottom-right corner and rises on hover */
.tools-tile__sheet {
    position: absolute;
    z-index: -1;
    right: -4%;
    bottom: -30%;
    width: 44%;
    height: auto;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(14, 27, 44, 0.1), 0 18px 40px -14px rgba(14, 27, 44, 0.4);
    transform: rotate(8deg);
    transition: transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

.tools-tile:first-child .tools-tile__sheet {
    right: 6%;
    bottom: -12%;
    width: 58%;
    transform: rotate(-5deg);
}

.tools-tile:hover .tools-tile__sheet {
    transform: rotate(4deg) translateY(-8%);
}

.tools-tile:first-child:hover .tools-tile__sheet {
    transform: rotate(-2deg) translateY(-5%);
}

.tools-tile__glyph {
    position: absolute;
    z-index: -1;
    right: 1.4rem;
    bottom: 1.4rem;
    display: grid;
    place-items: center;
    width: 5rem;
    height: 5rem;
    font-size: 2rem;
    color: var(--tone-ink);
    background: color-mix(in srgb, var(--bg-card) 60%, transparent);
    border-radius: 24px;
    transform: rotate(-6deg);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.tools-tile:hover .tools-tile__glyph {
    transform: rotate(0) scale(1.08);
}

@media (max-width: 900px) {
    .tools-bento {
        grid-template-columns: 1fr 1fr;
    }

    .tools-tile:first-child {
        grid-column: 1 / -1;
        grid-row: auto;
    }

    .tools-tile:first-child .tools-tile__text {
        max-width: 56%;
    }

    .tools-tile:first-child .tools-tile__sheet {
        right: 4%;
        bottom: -40%;
        width: 36%;
        transform: rotate(6deg);
    }
}

@media (max-width: 600px) {
    .tools-bento {
        grid-template-columns: 1fr;
        grid-auto-rows: auto;
        gap: 0.9rem;
    }

    .tools-tile,
    .tools-tile:first-child {
        min-height: 180px;
    }

    .tools-tile:first-child .tools-tile__sheet {
        bottom: -30%;
        width: 44%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tools-tile,
    .tools-tile__sheet,
    .tools-tile__glyph,
    .tools-tile__go span {
        transition: none;
    }
}

/* --------------------------------------------------------------------------
   Directory sections: each category gets a tinted panel on the left that
   stays in view while its tools scroll past on the right
   -------------------------------------------------------------------------- */

@media (min-width: 1024px) {
    .tools-dashboard--index .tools-section {
        display: grid;
        grid-template-columns: 17rem minmax(0, 1fr);
        gap: 2rem;
        align-items: start;
    }

    .tools-dashboard--index .tools-section[hidden] {
        display: none;
    }

    .tools-dashboard--index .tools-section__header {
        position: sticky;
        top: calc(var(--header-height, 64px) + 1.25rem);
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin: 0;
        padding: 1.5rem;
        background:
            linear-gradient(color-mix(in srgb, var(--cat) 7%, transparent) 1px, transparent 1px) 0 0 / 22px 22px,
            linear-gradient(90deg, color-mix(in srgb, var(--cat) 7%, transparent) 1px, transparent 1px) 0 0 / 22px 22px,
            color-mix(in srgb, var(--cat) 9%, var(--bg-card));
        border-radius: 24px;
    }

    .tools-dashboard--index .tools-section__icon {
        width: 3rem;
        height: 3rem;
        font-size: 1.25rem;
        color: #fff;
        background: var(--cat);
        border-radius: 14px;
    }

    [data-theme="dark"] .tools-dashboard--index .tools-section__icon {
        color: var(--bg-primary);
    }

    .tools-dashboard--index .tools-section__title {
        font-family: var(--font-display);
        font-size: 1.6rem;
        font-weight: 800;
        letter-spacing: -0.03em;
    }

    .tools-dashboard--index .tools-section__link {
        margin-top: 0.25rem;
        color: var(--text-primary);
        text-decoration: underline;
        text-decoration-color: var(--cat);
        text-underline-offset: 4px;
    }

    .tools-dashboard--index .tools-section__link i {
        color: var(--cat);
    }

    .tools-dashboard--index .tools-grid {
        grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    }
}

/* Cards: quieter at rest, the category colour arrives on hover */
.tools-dashboard--index .tool-card {
    border-color: var(--border-light);
    box-shadow: 0 1px 2px rgba(14, 27, 44, 0.04);
}

.tools-dashboard--index .tool-card:hover {
    background: color-mix(in srgb, var(--cat) 4%, var(--bg-card));
}

.tools-dashboard--index .tool-card:hover .tool-card__icon {
    color: #fff;
    background: var(--cat);
}

[data-theme="dark"] .tools-dashboard--index .tool-card:hover .tool-card__icon {
    color: var(--bg-primary);
}

.tools-dashboard--index .tool-card__icon {
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* A hairline between categories so each one reads as its own shelf */
.tools-dashboard--index .tools-section {
    margin-top: 2.5rem;
    padding-top: 2.5rem;
    border-top: 1px solid var(--border-light);
}

@media (max-width: 1023px) {
    .tools-dashboard--index .tools-section {
        margin-top: 2rem;
        padding-top: 2rem;
    }
}
