/* Word Mojo — sits on top of /assets/boggle.css for shared chrome. */

#game { display: flex; flex-direction: column; gap: 1.25rem; }

/* Legend | game | HUD.  At narrow widths everything stacks. */
.mojo-layout {
    display: grid;
    grid-template-columns: 15rem 1fr 18rem;
    gap: 1.25rem;
    align-items: start;
}
@media (max-width: 1100px) {
    .mojo-layout { grid-template-columns: 1fr; }
}

.hud-panel {
    background: var(--card);
    border: 1px solid var(--tile-edge);
    border-radius: 10px;
    padding: 1rem .8rem;
    display: flex; flex-direction: column; gap: .55rem;
    font-variant-numeric: tabular-nums;
}
.hud-panel .hud-cell {
    margin: 0;
    width: 100%;
    padding: .55rem .4rem;
    text-align: center;
}

/* Personal top-10 scoreboard */
.hud-scores { margin-top: .4rem; }
.hud-scores h3 {
    margin: .2rem 0 .5rem; font-size: .95rem; color: var(--accent);
    text-align: center;
}
.top-scores {
    list-style: none; margin: 0; padding: 0;
    counter-reset: rank;
    font-size: .95rem;
}
.top-scores li {
    display: flex; align-items: baseline; gap: .5rem;
    padding: .42rem .4rem;
    border-bottom: 1px solid var(--tile-edge);
}
.top-scores li::before {
    counter-increment: rank; content: counter(rank) '.';
    color: var(--muted); width: 1.5rem; flex: none; text-align: right;
}
.top-scores li b { color: var(--fg); min-width: 3rem; font-size: 1.02rem; }
.top-scores li span { color: var(--muted); margin-left: auto; white-space: nowrap; }
.top-scores li.empty { color: var(--muted); justify-content: center; }
.top-scores li.empty::before { content: none; }
.top-scores li:first-child b { color: #c47a17; font-weight: 800; }   /* best run pops */

.legend-panel {
    background: var(--card);
    border: 1px solid var(--tile-edge);
    border-radius: 10px;
    padding: 1rem 1.1rem;
    font-size: .9rem;
    color: var(--fg);
}
.legend-panel h3 {
    margin: 0 0 .5rem; color: var(--accent); font-size: 1rem;
}
.legend-panel .legend-h3-sep { margin-top: 1.25rem; }
.legend-list {
    list-style: none; padding: 0; margin: 0;
}
.legend-list li {
    display: flex; align-items: center; gap: .55rem;
    padding: .25rem 0;
}
.legend-notes {
    padding-left: 1.1rem;
    margin: .25rem 0 0;
    color: var(--muted);
    line-height: 1.4;
}
.legend-notes li { margin: .25rem 0; }
.legend-chip {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 2.1rem; height: 1.5rem;
    padding: 0 .4rem;
    border-radius: 4px;
    font-weight: 700; font-size: .72rem;
    flex-shrink: 0;
}
.legend-chip.bonus-dl   { background: #c6e2ff; color: #185f9f; }
.legend-chip.bonus-tl   { background: #5ca7e6; color: white; }
.legend-chip.bonus-dw   { background: #ffd3c9; color: #a83a25; }
.legend-chip.bonus-tw   { background: #ff6f53; color: white; }
.legend-chip.bonus-star { background: #ffd3c9; color: #a83a25; }

.legend-count {
    color: var(--muted);
    font-weight: 500;
    font-size: .8rem;
}
.bag-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: .25rem;
    margin-bottom: .25rem;
}
.bag-grid .bag-cell {
    background: rgba(61, 90, 128, .07);
    border-radius: 4px;
    padding: .25rem 0;
    text-align: center;
    font-size: .72rem;
    line-height: 1.1;
}
.bag-grid .bag-cell .letter {
    display: block;
    font-weight: 700; color: var(--fg);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.bag-grid .bag-cell .count {
    color: var(--muted); font-size: .65rem;
}
.bag-grid .bag-cell.empty { opacity: .35; }
.bag-grid .bag-cell.blank .letter { color: var(--accent); }

.mojo-stage {
    background: var(--card);
    border: 1px solid var(--tile-edge);
    border-radius: 10px;
    padding: .75rem 1.25rem 1rem;
    display: flex; flex-direction: column; align-items: center;
    gap: .9rem;
}

/* Board-size selector (9 / 12 / 15) */
.size-select { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.size-select .size-label {
    font-size: .78rem; color: var(--muted); font-weight: 600; margin-right: .25rem;
}
.size-select button {
    font: inherit; font-size: .82rem; font-weight: 700;
    padding: .28rem .7rem; border-radius: 7px; cursor: pointer;
    border: 1px solid var(--tile-edge); background: var(--card); color: var(--fg);
}
.size-select button:hover { background: rgba(61, 90, 128, .08); }
.size-select button.on {
    background: var(--accent, #3d5a80); color: #fff; border-color: transparent;
}

/* --- Board --------------------------------------------------------- */
.mojo-board {
    /* Cell size scales to fit the board on any screen (15 wide by default).
       NB: the grid-template repeat COUNT must be a literal integer — browsers
       don't accept a custom property there — so the JS sets it inline with the
       real column count; these literal-15 defaults just cover first paint. */
    --cell: clamp(1.2rem, calc((100vw - 2rem) / var(--cols, 15)), 2rem);
    display: grid;
    grid-template-columns: repeat(15, var(--cell));
    grid-template-rows:    repeat(15, var(--cell));
    gap: 2px;
    /* Darker, slightly-textured frame so the empty slots read as
       recessed into the board. */
    background: linear-gradient(180deg, #a4b0c2 0%, #8893a8 100%);
    padding: 7px;
    border-radius: 12px;
    box-shadow:
        0 1px 0 rgba(255, 255, 255, .35) inset,    /* top highlight */
        0 -2px 0 rgba(0, 0, 0, .15) inset,         /* bottom shade */
        0 8px 22px rgba(31, 42, 58, .25);          /* sit-on-table shadow */
    user-select: none;
}
/* Every cell is a recessed slot with an inner shadow. */
.mojo-cell {
    border-radius: 5px;
    background: linear-gradient(180deg, #cdd6e2 0%, #e2e7ee 100%);
    display: flex; align-items: center; justify-content: center;
    font-size: calc(var(--cell, 2rem) * 0.34); font-weight: 700;
    color: var(--muted);
    position: relative;
    box-shadow:
        inset 0 2px 3px rgba(0, 0, 0, .22),        /* depth from above */
        inset 0 -1px 0 rgba(255, 255, 255, .55);   /* tiny rim of light */
}
.mojo-cell.bonus-dl {
    background: linear-gradient(180deg, #a0caff 0%, #c6e2ff 100%);
    color: #185f9f;
}
.mojo-cell.bonus-tl {
    background: linear-gradient(180deg, #4292cf 0%, #5ca7e6 100%);
    color: white;
}
.mojo-cell.bonus-dw {
    background: linear-gradient(180deg, #ffbeb0 0%, #ffd3c9 100%);
    color: #a83a25;
}
.mojo-cell.bonus-tw {
    background: linear-gradient(180deg, #ff5a3d 0%, #ff7c5e 100%);
    color: white;
}
.mojo-cell.bonus-star {                          /* center = a double-word tile */
    background: linear-gradient(180deg, #ffbeb0 0%, #ffd3c9 100%);
    color: #a83a25;
}

/* Show bonus label inside its cell — driven by data-bonus from the JS. */
.mojo-cell[data-bonus]::after {
    content: attr(data-bonus);
    pointer-events: none;
}
.mojo-cell.bonus-star::after { content: '★'; font-size: calc(var(--cell, 2rem) * 0.5); }
/* Tile on top of a bonus cell completely hides the label. */
.mojo-cell.has-letter::after { content: none !important; }

/* Tile sits proud of the slot — a touch larger than the cell with a
   meaningful drop shadow so it really reads as "snapped into" the
   slot rather than "painted on top of" it. */
.mojo-cell .tile {
    position: absolute; inset: -1px;
    border-radius: 5px;
    background: linear-gradient(180deg, #fffaf2 0%, #e8c987 100%);
    border: 1px solid #8a6c33;
    display: flex; align-items: center; justify-content: center;
    font-size: calc(var(--cell, 2rem) * 0.6); font-weight: 800; color: #2a2622;
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, .9),
        inset 0 -3px 0 rgba(0, 0, 0, .15),
        0 2px 0 rgba(0, 0, 0, .35),
        0 4px 6px rgba(0, 0, 0, .25),
        0 6px 10px rgba(31, 42, 58, .15);
    user-select: none;
    z-index: 2;
}
.mojo-cell .tile .val {
    position: absolute; right: 2px; bottom: 0px;
    font-size: calc(var(--cell, 2rem) * 0.27); font-weight: 700; color: #6b4f1f;
}
.mojo-cell .tile.new {
    background: linear-gradient(180deg, #fffcef 0%, #ffd16a 100%);
    border-color: #a4801f;
    cursor: grab;
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, .95),
        inset 0 -3px 0 rgba(0, 0, 0, .15),
        0 2px 0 rgba(0, 0, 0, .35),
        0 5px 8px rgba(0, 0, 0, .3),
        0 8px 14px rgba(31, 42, 58, .18);
}
.mojo-cell.drop-target {
    outline: 3px dashed var(--accent);
    outline-offset: -3px;
}

/* --- Rack ---------------------------------------------------------- */
.rack-row {
    display: flex; gap: 1rem; align-items: center;
}
.rack-label {
    color: var(--muted); font-size: .85rem; text-transform: uppercase;
    letter-spacing: .04em;
}
.rack {
    display: flex; gap: .5rem;
    background: #e8edf3;
    padding: .5rem;
    border-radius: 8px;
    min-height: 3.6rem;
    align-items: center;
}
.rack-tile {
    width: 3rem; height: 3.4rem;
    border-radius: 6px;
    background: linear-gradient(180deg, #fffcef 0%, #ffd16a 100%);
    border: 1px solid #a4801f;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.7rem; font-weight: 800; color: #2a2622;
    cursor: grab; user-select: none;
    position: relative;
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, .95),
        inset 0 -3px 0 rgba(0, 0, 0, .15),
        0 2px 0 rgba(0, 0, 0, .35),
        0 5px 8px rgba(0, 0, 0, .25),
        0 8px 12px rgba(31, 42, 58, .18);
}
/* "placed" = currently lives on the board as a pending tile.
   "dragging" = lifted right now.
   Both cases hide the rack tile entirely (visibility, not display, so the
   slot stays where it is and other tiles don't shift). */
.rack-tile.placed,
.rack-tile.dragging {
    visibility: hidden;
}
.rack-tile.drop-target {
    outline: 3px dashed var(--accent);
    outline-offset: -3px;
    border-radius: 6px;
}
.rack.drop-target {
    outline: 3px dashed var(--accent);
    outline-offset: -2px;
}
.rack-tile .val {
    position: absolute; right: 3px; bottom: 1px;
    font-size: .55rem; font-weight: 700; color: #6b4f1f;
}
/* Recess the rack background so the rack tiles look like they're
   resting in a wooden tray. */
.rack {
    background: linear-gradient(180deg, #a4b0c2 0%, #8893a8 100%);
    box-shadow:
        inset 0 2px 3px rgba(0, 0, 0, .2),
        inset 0 -1px 0 rgba(255, 255, 255, .35);
}

/* --- Buttons + toast ---------------------------------------------- */
.actions {
    display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center;
}
.actions button {
    padding: .5rem 1rem;
    background: var(--accent); color: white;
    border: 0; border-radius: 6px;
    font-size: .9rem; font-weight: 600; cursor: pointer;
}
.actions button:hover { background: var(--accent-dark); }
.actions button.btn-secondary {
    background: white; color: var(--accent);
    border: 1px solid var(--tile-edge);
}
.actions button.btn-secondary:hover {
    background: #f0f4fa; border-color: var(--accent);
}
.actions button:disabled { opacity: .55; cursor: default; }

.toast {
    min-height: 1.4rem;
    font-weight: 600; color: var(--muted);
    text-align: center;
}
.toast.ok  { color: var(--ok); }
.toast.bad { color: var(--bad); }

#timer.warn { color: var(--bad); }

/* --- Drag ghost ---------------------------------------------------- */
.mojo-drag-ghost {
    position: fixed; pointer-events: none;
    width: 3.2rem; height: 3.6rem;
    border-radius: 6px;
    background: linear-gradient(180deg, #fffcef 0%, #ffd97a 100%);
    border: 1px solid #b39456;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.8rem; font-weight: 800;
    transform: translate(-50%, -50%) scale(1.05);
    box-shadow: 0 12px 24px rgba(31, 42, 58, .35);
    z-index: 1000;
}

/* --- Legend chips & help block ------------------------------------ */
.legend {
    align-self: stretch;
    margin-top: .5rem;
    color: var(--muted);
    font-size: .9rem;
    line-height: 1.45;
}
.legend summary {
    cursor: pointer;
    color: var(--accent); font-weight: 600;
}
.legend ul {
    margin: .5rem 0 0; padding-left: 1.4rem;
}
.legend-chip {
    display: inline-block; padding: 0 .35rem;
    border-radius: 3px; font-weight: 700; font-size: .75rem;
    vertical-align: baseline;
}
.legend-chip.bonus-dl { background: #c6e2ff; color: #185f9f; }
.legend-chip.bonus-tl { background: #5ca7e6; color: white; }
.legend-chip.bonus-dw { background: #ffd3c9; color: #a83a25; }
.legend-chip.bonus-tw { background: #ff6f53; color: white; }
.legend-chip.bonus-star { background: #ffd3c9; color: #a83a25; }

/* --- Blank-letter prompt ------------------------------------------ */
.blank-modal {
    position: fixed; inset: 0;
    background: rgba(31, 42, 58, .55);
    display: none; align-items: center; justify-content: center;
    z-index: 999;
}
.blank-modal.show { display: flex; }
.blank-card {
    background: white; border-radius: 10px;
    padding: 1.5rem 2rem;
    text-align: center;
    max-width: 24rem;
}
.blank-card h3 { margin: 0 0 .5rem; color: var(--accent); }
.blank-letter-grid {
    display: grid; grid-template-columns: repeat(7, 1fr);
    gap: .35rem; margin: 1rem 0;
}
.blank-letter-grid button {
    padding: .45rem 0;
    background: white; color: var(--accent);
    border: 1px solid var(--tile-edge);
    border-radius: 4px;
    font-weight: 700; cursor: pointer;
}
.blank-letter-grid button:hover {
    background: var(--accent); color: white;
}
