/* APS Crossword Puzzle pages
 *
 * The puzzle grid itself lives inside iPuzzler's shadow DOM, so CSS in
 * this file intentionally styles only the APS-side wrapper (header,
 * hints, index list). Grid appearance is controlled by the CSS embedded
 * inside static/js/vendor/ipuzzler-1.0.0-aps.js.
 */

/* Local horizontal nav across individual puzzle pages. Hidden when only
 * one puzzle exists (the template gates on sibling count). */
.crossword-local-nav {
    margin-bottom: 0.5rem;
    border-bottom: 1px solid #e0e0dc;
}

.crossword-local-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.25rem 1.5rem;
}

.crossword-local-nav-link {
    display: inline-block;
    padding: 0.4rem 0;
    color: #555;
    text-decoration: none;
    font-weight: 500;
    border-bottom: 2px solid transparent;
}

.crossword-local-nav-link:hover {
    color: var(--aps-blue, #3a53a4);
    text-decoration: none;
}

.crossword-local-nav-link.is-active {
    color: var(--aps-blue, #3a53a4);
    border-bottom-color: var(--aps-blue, #3a53a4);
}

.crossword-page .crossword-header {
    margin-bottom: 1.25rem;
}

.crossword-page .crossword-header .page-top-header {
    margin-top: 29px;
}

.crossword-page .crossword-authors {
    font-size: 1.05rem;
    font-style: italic;
    color: #555;
}

.crossword-page .crossword-intro {
    margin-top: 1rem;
}

/* Grid dimensions kept in sync with the JS patch in
 * aps_site/static/js/vendor/ipuzzler-1.0.0-aps.js: cellSize=45 plus a
 * 1px gap per cell => 46px per cell, plus 1px for the outer border.
 * The cell counts come from the page model (grid_width / grid_height)
 * and are inlined as style attributes on .crossword-page; defaults
 * here keep the layout sane if dims haven't been backfilled yet. */
.crossword-page {
    --crossword-cell-px: 46px;
    --crossword-grid-w-cells: 15;
    --crossword-grid-h-cells: 15;
    --crossword-grid-width: calc(
        var(--crossword-grid-w-cells) * var(--crossword-cell-px) + 1px
    );
    --crossword-grid-height: calc(
        var(--crossword-grid-h-cells) * var(--crossword-cell-px) + 1px
    );
}

.crossword-page .crossword-container {
    position: relative;
    margin: 1.5rem 0 0;
    /* Reserve room for the absolutely-positioned hint, button group,
     * status line, and congrats banner that stack below the grid on
     * desktop. */
    min-height: calc(var(--crossword-grid-height) + 13rem);
}

.crossword-page ipuzzler-puzzle {
    display: block;
    width: 100%;
}

.crossword-page .crossword-hint {
    margin: 1rem 0 0;
}

.crossword-page .crossword-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0 0;
}

.crossword-page .crossword-buttons .btn-group {
    gap: 0;
}

.crossword-page .crossword-status {
    margin: 0.75rem 0 0;
    color: var(--aps-blue, #3a53a4);
    font-weight: 600;
}

.crossword-page .crossword-congrats {
    margin-top: 0.75rem;
    padding: 1rem 1.25rem;
    background-color: var(--aps-blue, #3a53a4);
    color: #fff;
    font-size: 1.25rem;
    font-weight: 600;
    border-radius: 6px;
    max-width: var(--crossword-grid-width);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.crossword-page .crossword-congrats[hidden] {
    display: none;
}

.crossword-page .crossword-congrats-emoji {
    font-size: 1.6rem;
    line-height: 1;
}

@media (min-width: 769px) {
    /* Stack the hint, buttons, status, and congrats banner in the
     * bottom-left of the grid footprint so they sit directly under the
     * puzzle (not below the taller Down clue column). Top offsets are
     * keyed to the grid height so taller grids (e.g. 21-row VJH) push
     * the stack down accordingly. */
    .crossword-page .crossword-hint {
        position: absolute;
        top: calc(var(--crossword-grid-height) + 0.75rem);
        left: 0;
        max-width: var(--crossword-grid-width);
        margin: 0;
    }
    .crossword-page .crossword-buttons {
        position: absolute;
        top: calc(var(--crossword-grid-height) + 4.25rem);
        left: 0;
        max-width: var(--crossword-grid-width);
        margin: 0;
    }
    .crossword-page .crossword-status {
        position: absolute;
        top: calc(var(--crossword-grid-height) + 9.5rem);
        left: 0;
        max-width: var(--crossword-grid-width);
        margin: 0;
    }
    .crossword-page .crossword-congrats {
        position: absolute;
        top: calc(var(--crossword-grid-height) + 11.25rem);
        left: 0;
        margin: 0;
    }
}

/* Index page */
.crossword-index-list .crossword-index-item {
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #eee;
}

.crossword-index-list .crossword-index-item:last-child {
    border-bottom: 0;
}

.crossword-index-list a {
    text-decoration: none;
}

.crossword-index-list a:hover {
    text-decoration: underline;
}

@media (max-width: 640px) {
    .crossword-page .crossword-container {
        margin-top: 1rem;
    }
}
