/*
   FreeCell. Same palette as the other six games and the MAUI app's
   Colors.xaml — if one changes, change the others.

   Two things here are unlike the rest of the suite. Cards keep a light face in
   dark mode, dimmed rather than inverted, because a dark-faced playing card
   stops reading as a playing card. And every size is derived from one number,
   --board-max, rather than from percentages: a fanned column's overlap has to
   be expressed in the same units as the card height, and percentage margins
   resolve against WIDTH, which makes that impossible to get right.
*/
:root {
    --page-top: #F4EBD8;
    --page-mid: #ECE0C4;
    --page-end: #E0D0AE;

    --ink: #3A2E1C;
    --ink-dim: #6B5B42;

    --accent: #7A4E0F;
    --on-accent: #F8F0DC;

    --tray-edge: #C2AE8A;

    --felt: rgba(122, 78, 15, 0.07);
    --slot-edge: #B9A179;

    --card-face: #FDF8EA;
    --card-edge: #B9A179;
    --card-black: #2E2616;
    --card-red: #A8371F;

    --placed: #2F6E59;
    --wrong: #9A3B2A;

    --key-face: #FDF8EA;
    --key-edge: #C6B694;

    /*
       The whole layout comes off this. Eight columns plus seven gaps have to
       fit inside it, and the card height and the fan overlap are both derived
       from the resulting card width.
    */
    --board-max: 356px;
    --gap: 4px;
    --card-w: calc((var(--board-max) - 7 * var(--gap)) / 8);
    --card-h: calc(var(--card-w) * 1.42);

    /* How much of a buried card stays visible, and therefore tappable. */
    --fan: calc(var(--card-h) * 0.36);
}

@media (max-width: 379.98px) {
    :root { --board-max: 318px; }
}

@media (min-width: 520px) {
    :root { --board-max: 440px; }
}

@media (prefers-color-scheme: dark) {
    :root {
        --page-top: #2A1D13;
        --page-mid: #1E150D;
        --page-end: #150F08;

        --ink: #E6DAC4;
        --ink-dim: #A3927A;

        --accent: #C9A227;
        --on-accent: #150F08;

        --tray-edge: #3E3226;

        --felt: rgba(201, 162, 39, 0.07);
        --slot-edge: #4C3D2E;

        /* Dimmed, not inverted. A dark playing card reads as a hole. */
        --card-face: #CFC3AA;
        --card-edge: #4C3D2E;
        --card-black: #241B12;
        --card-red: #8E2A17;

        --placed: #357A64;
        --wrong: #D08A72;

        --key-face: #3A2E22;
        --key-edge: #140E07;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
}

body {
    background: linear-gradient(180deg, var(--page-top) 0%, var(--page-mid) 52%, var(--page-end) 100%);
    background-attachment: fixed;
    color: var(--ink);
    font-family: "Outfit", system-ui, -apple-system, "Segoe UI", sans-serif;
    -webkit-text-size-adjust: 100%;
}

.booting {
    display: grid;
    place-items: center;
    min-height: 100svh;
    color: var(--ink-dim);
}

/*
   HEIGHT, not min-height, on 100svh, so the document can never scroll and the
   tray can never slide under iOS Safari's floating address bar. The tableau is
   the one region allowed to scroll inside itself, which it has to be: a column
   can grow well past the height of a phone.
*/
.fc-page {
    height: 100svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 10px calc(10px + env(safe-area-inset-bottom));
    max-width: 520px;
    margin: 0 auto;
}

header { text-align: center; flex: none; }

h1 {
    margin: 0;
    font-size: clamp(19px, 5.8vw, 26px);
    font-weight: 700;
    letter-spacing: 0.2em;
    /* Compensates for the trailing letter-space, which would otherwise push
       the word visually off-centre. */
    text-indent: 0.2em;
    color: var(--accent);
}

.deal-no {
    margin: 3px 0 0;
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-dim);
}

/* ---- cells, foundations, columns: one eight-wide grid ---- */

.topbar,
.tableau {
    width: var(--board-max);
    display: grid;
    grid-template-columns: repeat(8, var(--card-w));
    gap: var(--gap);
}

.topbar {
    flex: none;
    padding-bottom: 2px;
}

.card,
.slot {
    width: var(--card-w);
    height: var(--card-h);
    border-radius: 5px;
    padding: 0;
    font: inherit;
    cursor: pointer;
    display: flex;
    /* Top-aligned on purpose. In a fanned column only the top sliver of a
       buried card is visible, so that is the only place its rank and suit can
       usefully live. */
    align-items: flex-start;
    justify-content: center;
    /*
       The three properties that stop iOS interfering: no selection bubble on
       a held card, no double-tap zoom, no callout.
    */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

.slot {
    background: var(--felt);
    border: 1.5px dashed var(--slot-edge);
}

.card {
    background: var(--card-face);
    border: 1px solid var(--card-edge);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
    font-weight: 700;
    line-height: 1;
}

.card.red,
.face.red,
.ghost.red { color: var(--card-red); }

.card.black,
.face.black,
.ghost.black { color: var(--card-black); }

.card .r,
.face .r {
    font-size: calc(var(--card-w) * 0.42);
    padding: 3px 0 0 1px;
}

.card .s,
.face .s {
    font-size: calc(var(--card-w) * 0.36);
    padding: 3px 1px 0 1px;
}

.face {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-weight: 700;
    line-height: 1;
}

/* A free cell or foundation holding a card looks like a card, not a slot. */
.slot:has(.face) {
    background: var(--card-face);
    border: 1px solid var(--card-edge);
    border-style: solid;
}

.ghost {
    font-size: calc(var(--card-w) * 0.5);
    opacity: 0.3;
    padding-top: 4px;
}

/* Picked up and waiting for a destination. */
.card.lift,
.slot.lift {
    outline: 2.5px solid var(--accent);
    outline-offset: -1px;
    transform: translateY(-3px);
}

/*
   0 1 auto, not 1 1 auto. Growing to fill the column would leave a band of
   dead space between the cards and the controls at the start of every deal,
   when the longest column is only seven cards. Shrinking is still allowed, so
   once a column outgrows the screen this becomes the scrolling region exactly
   as before.
*/
.tablewrap {
    flex: 0 1 auto;
    min-height: 0;
    width: 100%;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    padding: 2px 0 6px;
    /* Vertical panning stays with the browser; everything else is ours. */
    touch-action: pan-y;
}

/*
   Do NOT remove. The tableau is a flex item, so without this it is shrunk to
   whatever room the column has left instead of overflowing — the lower cards
   get crushed out of the layout, the wrapper has nothing to scroll, and the
   drag falls through to the page.
*/
.tableau {
    flex: none;
    align-content: start;
}

.col {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: var(--card-h);
}

/* The fan. Every card after the first is pulled up over the one before it,
   leaving --fan of it showing. Later siblings paint on top, so the visible
   sliver of each card is also its tap target. */
.col > .card + .card {
    margin-top: calc(var(--fan) - var(--card-h));
}

/* ---- controls: directly under the cards, never scrolls ---- */

.controls {
    flex: none;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.message {
    margin: 0;
    min-height: 1.3em;
    font-size: 12.5px;
    font-weight: 600;
    text-align: center;
    text-wrap: balance;
}

.message.warn { color: var(--ink-dim); }
.message.win  { color: var(--placed); }

.actions,
.picker {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn {
    border: 1.5px solid var(--accent);
    border-radius: 18px;
    padding: 7px 16px;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.btn.small { padding: 5px 12px; font-size: 11px; }

.btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.picker {
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-dim);
    font-weight: 600;
}

.dealno {
    width: 78px;
    height: 30px;
    border: 1.5px solid var(--tray-edge);
    border-radius: 8px;
    background: var(--key-face);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}

.stats {
    margin: 0;
    min-height: 1.2em;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--ink-dim);
    text-align: center;
}

.stats .hint-line { font-weight: 500; opacity: 0.85; }

/* ---- site line ---- */

/* margin-top: auto pushes this to the bottom edge, so spare height on a tall
   phone collects between the controls and the footer instead of between the
   cards and the controls. */
.siteline {
    flex: none;
    margin-top: auto;
    padding-top: 10px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-align: center;
}

.siteline .home-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--ink-dim);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.siteline .home-link:hover { color: var(--ink); }

.siteline .home-link img { display: block; }

.siteline small {
    font-size: 10.5px;
    line-height: 1.35;
    color: var(--ink-dim);
    opacity: 0.7;
    max-width: 420px;
    text-wrap: balance;
}

/*
   On a desktop window the column stops filling the viewport and closes up.
   min-height is 0, not 100svh: filling the viewport is a phone behaviour, and
   on a monitor it strands the tray at the bottom with a void above it.
*/
@media (min-width: 520px) and (min-height: 760px) {
    .fc-page {
        height: auto;
        min-height: 0;
        padding-top: 24px;
        gap: 12px;
    }

    .tablewrap {
        overflow-y: visible;
        flex: none;
    }
}

.notfound { padding: 40px; text-align: center; }

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    padding: 12px 16px;
    background: #7A1F1F;
    color: #fff;
    font-size: 14px;
    z-index: 100;
}

#blazor-error-ui .reload { color: #fff; }
