/* ==========================================================
   HORROR SOLITAIRE - layout
   ========================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* One number drives the whole board. Every pile, card and
       overlap is derived from it, so the layout scales without
       a pile of separate breakpoint numbers to keep in sync. */
    --card-width: clamp(46px, 12.2vw, 104px);
    --card-height: calc(var(--card-width) * 1.4);
    --card-radius: calc(var(--card-width) * 0.085);
    --gap: clamp(4px, 1.1vw, 14px);

    /* Vertical overlap of a face-up card in a tableau column. */
    --stack-step: calc(var(--card-height) * 0.26);

    --table: #151515;
    --accent: #9b111e;
    --ink: #ece6dc;
    --card-face: #f2ecdf;
    --card-edge: #241f19;
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100%;
    display: flex;
    flex-direction: column;

    background: var(--table);
    color: var(--ink);

    font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;

    overflow-x: hidden;

    /* Nothing on this page should be selectable by a drag. */
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body.dragging-active {
    cursor: grabbing;
}


/* ==========================================================
   HEADER
   ========================================================== */

.game-header {
    position: relative;
    z-index: 20;

    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;

    padding: 10px clamp(10px, 2.5vw, 26px);
    padding-top: max(10px, env(safe-area-inset-top));

    background: rgba(0, 0, 0, 0.72);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.game-header h1 {
    font-size: clamp(1.05rem, 3.4vw, 2rem);
    font-weight: normal;
    letter-spacing: 0.09em;
    text-shadow: 0 2px 6px #000;
}

.game-controls {
    display: flex;
    gap: 8px;
}

button {
    padding: 8px 14px;

    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 6px;

    background: linear-gradient(#2a2a2a, #1a1a1a);
    color: var(--ink);

    font-family: inherit;
    font-size: clamp(0.72rem, 1.9vw, 0.92rem);
    letter-spacing: 0.03em;

    cursor: pointer;

    transition: filter 0.15s ease, transform 0.1s ease;
}

button:hover:not(:disabled) {
    filter: brightness(1.35);
}

button:active:not(:disabled) {
    transform: translateY(1px);
}

button:disabled {
    opacity: 0.35;
    cursor: default;
}

#new-game,
#auto-complete,
#overlay-new-game {
    background: linear-gradient(
        var(--accent),
        color-mix(in srgb, var(--accent) 70%, #000)
    );
    border-color: rgba(255, 255, 255, 0.22);
}


/* ==========================================================
   BOARD
   ========================================================== */

#game-board {
    flex: 1;

    width: 100%;
    max-width: 1180px;
    margin: 0 auto;

    padding: clamp(10px, 2vw, 26px);

    /* Without this a drag on a phone scrolls the page instead
       of moving the card. */
    touch-action: none;
}

.top-row {
    display: grid;
    grid-template-columns:
        var(--card-width)
        var(--card-width)
        1fr
        repeat(4, var(--card-width));

    gap: var(--gap);

    margin-bottom: clamp(14px, 3vw, 34px);
}

.spacer {
    min-width: 0;
}

#tableau {
    display: grid;
    grid-template-columns: repeat(7, var(--card-width));
    justify-content: space-between;
    gap: var(--gap);
}


/* ==========================================================
   PILES
   ========================================================== */

.pile {
    position: relative;

    width: var(--card-width);
    height: var(--card-height);

    border-radius: var(--card-radius);
    border: 1px solid rgba(255, 255, 255, 0.14);

    background: rgba(0, 0, 0, 0.22);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.tableau-pile {
    /* Grows with its contents; --depth is the number of card
       steps the column currently needs. */
    height: calc(
        var(--card-height) + (var(--depth, 0) * var(--stack-step))
    );
    min-height: var(--card-height);
}

/* Empty-pile markers, drawn rather than loaded.

   The foundations are deliberately not labelled with a suit:
   in Klondike any suit may claim any foundation, and a fixed
   label tells the player something untrue. */
.foundation.empty::after {
    content: "A";

    position: absolute;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    color: rgba(255, 255, 255, 0.13);
    font-size: calc(var(--card-width) * 0.36);
    letter-spacing: 0.05em;
}

.tableau-pile.empty::after {
    content: "";

    position: absolute;
    inset: 22%;

    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 50%;
}

#stock.recycle::after {
    content: "↻";

    position: absolute;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    color: rgba(255, 255, 255, 0.28);
    font-size: calc(var(--card-width) * 0.42);
}


/* ==========================================================
   FOOTER
   ========================================================== */

.game-footer {
    display: flex;
    justify-content: center;
    gap: clamp(18px, 6vw, 44px);

    padding: 10px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));

    background: rgba(0, 0, 0, 0.78);
    border-top: 1px solid rgba(255, 255, 255, 0.08);

    font-size: clamp(0.72rem, 2vw, 0.9rem);
    letter-spacing: 0.06em;
}

.game-footer strong {
    color: #d8c39a;
}


/* ==========================================================
   WIN OVERLAY
   ========================================================== */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 200;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;

    background: rgba(0, 0, 0, 0.82);

    animation: fadeIn 0.4s ease-out;
}

.overlay[hidden] {
    display: none;
}

.overlay-card {
    max-width: 420px;
    padding: clamp(24px, 5vw, 40px);

    text-align: center;

    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 12px;

    background: linear-gradient(160deg, #1d1414, #0b0808);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.9);
}

.overlay-title {
    margin-bottom: 12px;

    font-size: clamp(1.3rem, 5vw, 2rem);
    font-weight: normal;
    letter-spacing: 0.06em;
    color: #d8c39a;
}

.overlay-detail {
    margin-bottom: 22px;
    opacity: 0.85;
    font-size: 0.95rem;
}
