/* css/grid/grid.css — Grid app testbed (Step 1) */

.grid-testbed {
    max-width: 100%;
    margin: 0 auto;
    padding: 24px 16px;
    text-align: center;
}

.grid-title {
    margin: 0 0 4px;
    font-size: 1.5rem;
}

.grid-limits {
    margin: 0 0 4px;
    color: var(--ink-2);
    font-size: 0.9rem;
    font-weight: 600;
}

.grid-remaining {
    margin: 0 0 16px;
    color: #2563eb;
    font-size: 0.95rem;
    font-weight: 700;
}

.grid-board {
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    grid-template-rows: repeat(var(--rows), 1fr);
    gap: 0;
    width: 100vw;
    aspect-ratio: var(--cols) / var(--rows);
    margin-left: calc(50% - 50vw);   /* full-bleed: escape the centered .container */
    background: transparent;
    /* Cells draw their own right and bottom hairline, so the board closes the
       frame on the other two sides. Inset, so it costs no layout width. */
    box-shadow: inset 1px 1px 0 #8593a5;
}

/* Big screens: stop the board going full-bleed — cap it and centre it.
   Stays square via the aspect-ratio above; small screens keep full-bleed. */
@media (min-width: 768px) {
    .grid-board {
        width: min(768px, 100%);
        margin-left: auto;
        margin-right: auto;
    }
}

.grid-cell {
    background: #dbe1e8;            /* darker than page so each cell reads clearly */
    border: 0;
    border-radius: 0;
    /* The grid line: 1px inside the right and bottom edge. Drawn as an inset
       shadow rather than a border so it never doubles with the neighbour's and
       never eats into the cell's size — at 13px a cell has none to spare. */
    box-shadow: inset -1px -1px 0 #8593a5;
    cursor: pointer;
}

/* A painted cell drops the line entirely, so neighbours of one colour read as
   a single block of that colour instead of a tiled patch. A triangle keeps its
   line — half the cell is still empty. It matches the variable rather than
   [style], because erasing leaves an empty style attribute behind and that
   cell must keep its line. */
.grid-cell[style*="--fill"]:not([data-shape]) {
    box-shadow: none;
}

/* Every colour arrives as a --fill hex on the element itself — from the
   palette table for Mosaic, from the faction for War. A square paints it
   whole, a triangle paints half of it, the brush preview wears it too. */
.grid-cell[style*="--fill"] {
    background-color: var(--fill);
}

/* ---- triangles: 1 = top-left, 2 = top-right, 3 = bottom-right, 4 = bottom-left
   (clockwise). Stack the same corner down a step and the 45' edges join into one
   clean diagonal, which a grid of squares can only stair-step.
   Painted as a hard-stop gradient rather than a clipped box, so the cell keeps
   its own grid line and its unpainted half stays empty-cell grey instead of
   showing the page through a hole. The half-pixel either side of the stop is
   what keeps the diagonal from going ragged. */
.grid-cell[data-shape] { background-color: #dbe1e8; }

[data-shape="1"] { background-image: linear-gradient(to bottom right,
    var(--fill) 0 calc(50% - 0.5px), transparent calc(50% + 0.5px) 100%); }
[data-shape="2"] { background-image: linear-gradient(to bottom left,
    var(--fill) 0 calc(50% - 0.5px), transparent calc(50% + 0.5px) 100%); }
[data-shape="3"] { background-image: linear-gradient(to top left,
    var(--fill) 0 calc(50% - 0.5px), transparent calc(50% + 0.5px) 100%); }
[data-shape="4"] { background-image: linear-gradient(to top right,
    var(--fill) 0 calc(50% - 0.5px), transparent calc(50% + 0.5px) 100%); }

/* The brush: one button that cycles square -> each corner. It shows the stroke
   it will lay down rather than naming it, in the colour that is selected. */
.shape-picker {
    display: flex;
    justify-content: center;
    margin: 0 0 16px;
}

.shape-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px 5px 5px;
    border: 1px solid var(--dark-ink-2);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink-2);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
}

.shape-brush {
    width: 22px;
    height: 22px;
    border-radius: 3px;
    background-color: var(--fill, #dbe1e8);
    box-shadow: inset 0 0 0 1px #8593a5;
}

.shape-brush[data-shape] { background-color: #dbe1e8; }

.color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin: 0 0 16px;
}

.color-btn {
    width: 84px;                   /* fixed width so every button is identical */
    padding: 6px 0;
    border: none;
    border-radius: 6px;
    color: var(--surface);
    font-weight: 600;
    text-align: center;
    cursor: pointer;
}

.color-btn.active {
    box-shadow: 0 0 0 3px var(--dark-surface);
}

@media (max-width: 480px) {
    .grid-testbed {
        padding: 12px 4px;        /* minimum padding on small screens */
    }
    .grid-title  { font-size: 1.2rem; }
    .grid-limits { font-size: 0.875rem; }
    .grid-remaining { font-size: 0.875rem; }
    .color-picker { gap: 6px; }
    .shape-picker { margin-bottom: 12px; }
    .color-btn {
        width: 74px;
        padding: 5px 0;
        font-size: 0.875rem;
    }
}

/* Live presence badge — ink pill, palette-green pulsing dot.
   Hidden by default; JS adds .is-live when 2+ people are on the board. */
.grid-presence {
    display: none;
    margin: 0 0 10px;
}

.grid-presence.is-live {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 13px;
    border-radius: 999px;
    background: #1f2937;
    color: var(--surface);
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.presence-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ecc71;            /* same green as the paint palette */
    animation: presence-pulse 2s ease-out infinite;
}

@keyframes presence-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.55); }
    70%  { box-shadow: 0 0 0 7px rgba(46, 204, 113, 0); }
    100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

@media (max-width: 480px) {
    .grid-presence.is-live {
        font-size: 0.875rem;
        padding: 3px 11px;
    }
}

.grid-watch,
.grid-faction,
.grid-countdown {
    margin: 0 0 8px;
    font-weight: 600;
    color: var(--ink-2);
}

.grid-countdown {
    color: #b91c1c;
}

.war-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-right: 6px;
    vertical-align: middle;
}

.grid-ownership {
    max-width: 420px;
    margin: 20px auto 0;
}

.grid-ownership table {
    width: 100%;
    border-collapse: collapse;
}

.grid-ownership th,
.grid-ownership td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}
