@import url('https://fonts.googleapis.com/css2?family=Crimson+Text:wght@700&display=swap');

:root {
   --text-size: 32px;
   --card-width: 7rem;
   --card-height: 182px;
   --card-empty-color: #306a4b;
   --suit-red-color: red;
   --suit-black-color: black;
   --board-color: #1E5C3A;
   --game-padding: 1rem;
   /*
    * In a Home Screen app iOS blurs a strip just below the status bar that is
    * a little taller than the safe-area inset, which smudged the header. Add
    * extra room whenever there is a top inset (0 in a normal browser tab).
    */
   --top-extra: min(env(safe-area-inset-top, 0px), 1rem);
}
body {
    font-size: var(--text-size);
    background-color: var(--board-color);
    margin: 0px;
}
#game {
    width: 100vw;
    height: 100vh;
    /*
     * In mobile Safari 100vh is the height with its toolbars hidden, so with
     * the address bar showing the bottom of the board (and the toolbar with
     * Settings) was off the screen. dvh is the height actually visible.
     */
    height: 100dvh;
    display: grid;
    grid-template-rows: auto calc(var(--card-height) + 10px) 1fr auto;
    /*
     * When installed to the Home Screen the page draws under the status bar and
     * notch (viewport-fit=cover + black-translucent status bar), so pad by the
     * safe-area insets. They are 0 in a normal browser tab.
     */
    padding:
        calc(var(--game-padding) + env(safe-area-inset-top, 0px) + var(--top-extra))
        calc(var(--game-padding) + env(safe-area-inset-right, 0px))
        calc(var(--game-padding) + env(safe-area-inset-bottom, 0px))
        calc(var(--game-padding) + env(safe-area-inset-left, 0px));
    box-sizing: border-box;
    column-gap: 1rem;
    row-gap: 0.5rem;
}
#header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    color: rgba(255, 255, 255, 0.85);
    font-family: 'Crimson Text', 'Georgia', serif;
    font-size: 1.25rem;
    line-height: 1.2;
    -webkit-user-select: none;
    user-select: none;
}
#header .stat span {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: white;
    margin-left: 0.25em;
}
#top-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1rem;
}
#deck {
    grid-column: 1;
    width: 100%;
    align-self: stretch;
    height: var(--card-height);
    display: flex;
    justify-content: center;
    align-items: center;
}
#deck:hover {
    cursor: pointer;
}
#flipped-deck {
    grid-column: 2;
    position: relative;
    width: 100%;
    align-self: stretch;
    height: var(--card-height);
    display: flex;
    justify-content: center;
    align-items: center;
}
#top-row-spacer {
    grid-column: 3;
}
#completed-stacks {
    grid-column: 4 / 8;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    height: 100%;
    height: var(--card-height);
    align-self: stretch;
}
#bottom-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1rem;
    align-items: start;
}
.completed-column {
    display: flex;
    align-items: center;
    justify-content: center;
    justify-self: center;
    align-self: stretch;
    width: var(--card-width);
    height: var(--card-height);
}
.border-red {
    border: 2px dashed var(--suit-red-color);
    border-radius: 4px;
}
.border-black {
    border: 2px dashed var(--suit-black-color);
    border-radius: 4px;
}
.column {
    display: flex;
    justify-content: center;
    position: relative;
    width: 100%;
}
.column .card {
    position: absolute;
}
.card {
    padding: 2px 5px 0px 5px;
    display: flex;
    width: var(--card-width);
    height: var(--card-height);
    background-color: white;
    border: 1px solid black;
    border-radius: 4px;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
}
.card svg {
    width: 100%;
    height: 100%;
    font-family: 'Crimson Text', 'Georgia', serif;
    pointer-events: none;
}

.card-rank {
   font-size: 30px;
}

.card-suit {
   font-size: 30px;
}

.card-suit-large {
   font-size: 64px;
}

.drag-ghost {
    position: fixed;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1000;
    will-change: transform;
}

.drag-ghost .card {
    position: relative;
    pointer-events: none;
}

.card-rank, .card-suit, .card-suit-large {
    fill: currentColor; /* Inherits from parent .red or .black class */
}
.deck-card {
    padding: 2px 5px 0px 5px;
    display: flex;
    width: var(--card-width);
    height: var(--card-height);
    background-color: cornflowerblue;
    border: 1px solid black;
    border-radius: 4px;
}
.card:not(.flipped) {
    color: cornflowerblue;
    background-color: cornflowerblue;
}
.empty {
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    width: var(--card-width);
    height: var(--card-height);
}
.bottom-column {
    min-height: 300px;
    height: 100%;
}
.bottom-column:empty::before {
    content: "";
    display: block;
    width: var(--card-width);
    height: var(--card-height);
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}
.bottom-column .card:nth-child(1) {
    top: 0px;
}
.bottom-column .card:nth-child(2) {
    top: 30px;
}
.bottom-column .card:nth-child(3) {
    top: 60px;
}
.bottom-column .card:nth-child(4) {
    top: 90px;
}
.bottom-column .card:nth-child(5) {
    top: 120px;
}
.bottom-column .card:nth-child(6) {
    top: 150px;
}
.bottom-column .card:nth-child(7) {
    top: 180px;
}
.bottom-column .card:nth-child(8) {
    top: 210px;
}
.bottom-column .card:nth-child(9) {
    top: 240px;
}
.bottom-column .card:nth-child(10) {
    top: 270px;
}
.bottom-column .card:nth-child(11) {
    top: 300px;
}
.bottom-column .card:nth-child(12) {
    top: 330px;
}
.bottom-column .card:nth-child(13) {
    top: 360px;
}
.bottom-column .card:nth-child(14) {
    top: 390px;
}
.bottom-column .card:nth-child(15) {
    top: 420px;
}
.bottom-column .card:nth-child(16) {
    top: 450px;
}
.bottom-column .card:nth-child(17) {
    top: 480px;
}
.bottom-column .card:nth-child(18) {
    top: 510px;
}
.bottom-column .card:nth-child(19) {
    top: 540px;
}
.bottom-column .card:nth-child(20) {
    top: 570px;
}
.red {
    color: var(--suit-red-color);
}
.black {
    color: var(--suit-black-color);
}
.card:not(.flipped), .deck-card:not(.flipped), .back-swatch {
    background: var(--back);
    box-shadow: var(--back-frame);
    color: transparent;
    cursor: default;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    :root {
        --text-size: 20px;
        --card-width: 2.5rem;
        --card-height: 4.5rem;
        --game-padding: 0.5rem;
    }

    #game {
        column-gap: 0.25rem;
        row-gap: 0.5rem;
    }
    
    #header {
        font-size: 1rem;
    }

    #top-row, #bottom-row, #completed-stacks {
        gap: 0.5rem;
    }
   
   .card-rank {
      font-size: 48px;
   }

   .card-suit {
      font-size: 48px;
   }

   .card-suit-large {
      font-size: 64px;
   }
}
/* Win celebration */
.celebration-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
}
.celebration-trails {
    z-index: 900;
}
.celebration-confetti {
    z-index: 950;
}
.win-banner {
    position: fixed;
    z-index: 1000;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%);
    padding: 1.25rem 2.5rem 1.5rem;
    border-radius: 12px;
    background: rgba(18, 56, 35, 0.92);
    border: 2px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
    color: white;
    text-align: center;
    font-family: 'Crimson Text', 'Georgia', serif;
    animation: win-banner-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.win-banner h2 {
    margin: 0;
    font-size: 2.75rem;
    line-height: 1.1;
}
.win-summary {
    margin: 0.25rem 0 1rem;
    font-size: 1.25rem;
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, 0.85);
}
.win-play-again {
    font: inherit;
    font-size: 1.25rem;
    font-weight: 700;
    padding: 0.4rem 1.5rem;
    border: none;
    border-radius: 999px;
    background: #facc15;
    color: #1E5C3A;
    cursor: pointer;
}
.win-play-again:hover {
    background: #fde047;
}
@keyframes win-banner-in {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
    .win-banner { animation: none; }
}
@media (max-width: 768px) {
    .win-banner {
        padding: 1rem 1.75rem 1.25rem;
        width: max-content;
        max-width: calc(100vw - 2rem);
    }
    .win-banner h2 { font-size: 2.25rem; }
}

/* Toolbar under the board: game controls and links to the other pages */
#toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    font-family: 'Crimson Text', 'Georgia', serif;
    font-size: 1.1rem;
    -webkit-user-select: none;
    user-select: none;
}
#toolbar .controls {
    display: flex;
    gap: 0.5rem;
}
#toolbar button, .confirm button {
    font: inherit;
    font-weight: 700;
    padding: 0.35rem 1.1rem;
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    color: white;
    cursor: pointer;
}
#toolbar button:hover:not(:disabled), .confirm button:hover {
    background: rgba(255, 255, 255, 0.24);
}
#toolbar button:disabled {
    opacity: 0.4;
    cursor: default;
}
.site-links {
    display: flex;
    gap: 1rem;
}
.site-links a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.95rem;
}
.site-links a:hover {
    color: white;
    text-decoration: underline;
}
.confirm {
    position: fixed;
    z-index: 1000;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%);
    width: max-content;
    max-width: calc(100vw - 2rem);
    padding: 1.25rem 1.75rem;
    border-radius: 12px;
    background: rgba(18, 56, 35, 0.96);
    border: 2px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
    color: white;
    text-align: center;
    font-family: 'Crimson Text', 'Georgia', serif;
    font-size: 1.25rem;
}
.confirm[hidden] {
    display: none;
}
.confirm p {
    margin: 0;
}
#new-game-confirm-title {
    font-size: 1.6rem;
    font-weight: 700;
}
.confirm-detail {
    color: rgba(255, 255, 255, 0.8);
    margin-top: 0.25rem !important;
}
.confirm-buttons {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1rem;
}
.confirm button.primary {
    background: #facc15;
    color: #1E5C3A;
}
.confirm button.primary:hover {
    background: #fde047;
}
@media (max-width: 768px) {
    #toolbar {
        font-size: 1rem;
        gap: 0.5rem;
    }
    .site-links {
        gap: 0.75rem;
    }
    .site-links a {
        font-size: 0.85rem;
    }
}

/*
 * Card backs, the same five designs as the iPhone app. The page's body
 * carries the player's choice; each swatch in Settings carries its own.
 */
:root, [data-card-back="classic"] {
    --back:
        repeating-linear-gradient(45deg, #dc2626 0px, #dc2626 10px, #991b1b 10px, #991b1b 20px),
        repeating-linear-gradient(-45deg, #dc2626 0px, #dc2626 10px, #991b1b 10px, #991b1b 20px);
    --back-frame: none;
}
[data-card-back="lattice"] {
    --back:
        repeating-linear-gradient(45deg, transparent 0 7px, rgba(216, 180, 96, 0.85) 7px 8px),
        repeating-linear-gradient(-45deg, transparent 0 7px, rgba(216, 180, 96, 0.85) 7px 8px),
        #1D2B4F;
    --back-frame: inset 0 0 0 3px #1D2B4F, inset 0 0 0 4px #D8B460, inset 0 0 0 6px #1D2B4F;
}
[data-card-back="dots"] {
    --back:
        radial-gradient(circle, #F1E6C8 0 2px, transparent 2.5px) 0 0 / 10px 9px,
        radial-gradient(circle, #F1E6C8 0 2px, transparent 2.5px) 5px 4.5px / 10px 9px,
        #1F5A3E;
    --back-frame: inset 0 0 0 3px #1F5A3E, inset 0 0 0 4px #F1E6C8, inset 0 0 0 6px #1F5A3E;
}
[data-card-back="rays"] {
    --back:
        radial-gradient(circle closest-side, #E8C990 0 22%, transparent 24%),
        repeating-conic-gradient(#8F2A3F 0deg 7.5deg, #6E1F30 7.5deg 15deg),
        #6E1F30;
    --back-frame: inset 0 0 0 3px #6E1F30, inset 0 0 0 4px #E8C990, inset 0 0 0 6px #6E1F30;
}
[data-card-back="monogram"] {
    --back:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Ctext x='20' y='31' font-size='34' text-anchor='middle' fill='%23EDE3CC' font-family='Georgia,serif'%3E%E2%99%A0%3C/text%3E%3C/svg%3E") center / 50% no-repeat,
        #2A2D33;
    --back-frame: inset 0 0 0 4px #2A2D33, inset 0 0 0 5px #EDE3CC, inset 0 0 0 7px #2A2D33, inset 0 0 0 8px rgba(237, 227, 204, 0.5);
}

/* Tables: Classic Green (the default) and Midnight */
:root, [data-theme="felt"] {
    --panel-color: #143a26;
    --slot-red: var(--suit-red-color);
    --slot-black: var(--suit-black-color);
}
[data-theme="midnight"] {
    --board-color: #1B2840;
    --panel-color: #0f1726;
    --slot-red: #CF3434;
    --slot-black: rgba(233, 237, 245, 0.6);
}
body[data-theme="midnight"] {
    background-color: var(--board-color);
}
.border-red {
    border-color: var(--slot-red);
}
.border-black {
    border-color: var(--slot-black);
}
/* The suit symbol in an empty foundation. ui.js colours it inline. */
body[data-theme="midnight"] .border-black {
    color: var(--slot-black) !important;
}
.confirm, .win-banner {
    background: var(--panel-color);
}
/* While Settings or a question is open, dim the board and keep it still. */
.panel, .confirm {
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45), 0 12px 40px rgba(0, 0, 0, 0.45);
}
body:has(.panel:not([hidden]), .confirm:not([hidden])) #game {
    pointer-events: none;
}

/* Draw pile on the right: mirror the top row. */
body[data-draw-pile="right"] #deck { grid-column: 7; grid-row: 1; }
body[data-draw-pile="right"] #flipped-deck { grid-column: 6; grid-row: 1; }
body[data-draw-pile="right"] #top-row-spacer { grid-column: 5; grid-row: 1; }
body[data-draw-pile="right"] #completed-stacks { grid-column: 1 / 5; grid-row: 1; }

/*
 * Draw 3: the waste shows its top three cards fanned toward the gap beside
 * it. ui.js sets --fan to 0, 1 or 2 on each.
 */
#flipped-deck.fanned .card {
    position: absolute;
    left: calc(50% - var(--card-width) / 2 + var(--fan, 0) * var(--fan-step));
}
:root {
    --fan-step: calc(var(--card-width) * 0.3);
}
body[data-draw-pile="right"] {
    --fan-step: calc(var(--card-width) * -0.3);
}

/* Settings panel */
.panel {
    position: fixed;
    z-index: 1000;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(30rem, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    box-sizing: border-box;
    padding: 1.25rem 1.5rem 1.5rem;
    border-radius: 14px;
    background: var(--panel-color);
    border: 2px solid rgba(255, 255, 255, 0.35);
    color: white;
    font-family: 'Crimson Text', 'Georgia', serif;
    font-size: 1.1rem;
}
.panel[hidden] {
    display: none;
}
.panel h2 {
    margin: 0 0 0.5rem;
    font-size: 1.75rem;
    text-align: center;
}
.panel h3 {
    margin: 1rem 0 0.4rem;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.7);
}
.panel button {
    font: inherit;
    color: white;
    cursor: pointer;
}
.segmented {
    display: flex;
    padding: 3px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
}
.segmented button {
    flex: 1;
    padding: 0.35rem 0.75rem;
    border: none;
    border-radius: 999px;
    background: transparent;
    font-weight: 700;
}
.segmented button[aria-pressed="true"] {
    background: #facc15;
    color: #1E5C3A;
}
.note {
    margin: 0.4rem 0 0;
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.75);
}
.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}
.swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.4rem;
    border: 2px solid transparent;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    font-size: 0.9rem !important;
}
.swatch[aria-pressed="true"] {
    border-color: #facc15;
}
.back-swatch {
    display: block;
    width: 2.6rem;
    height: 3.9rem;
    border: 1px solid black;
    border-radius: 4px;
}
.table-swatch {
    display: block;
    width: 5.5rem;
    height: 3.2rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}
.table-swatch[data-theme="felt"] { background: #1E5C3A; }
.table-swatch[data-theme="midnight"] { background: #1B2840; }
.panel-done {
    display: block;
    margin: 1.25rem auto 0;
    padding: 0.4rem 2rem;
    border: none;
    border-radius: 999px;
    background: #facc15;
    color: #1E5C3A;
    font-weight: 700;
}
@media (max-width: 768px) {
    .panel {
        padding: 1rem 1rem 1.25rem;
    }
    .swatches {
        gap: 0.35rem;
    }
    .swatch {
        padding: 0.3rem 0.2rem;
        flex: 1;
        font-size: 0.8rem !important;
    }
    .back-swatch {
        width: 2.2rem;
        height: 3.3rem;
    }
}

/* Statistics panel */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
    gap: 0.5rem;
    margin: 1rem 0 0.25rem;
}
.stat-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.6rem 0.4rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
}
.stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.stat-label {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.75);
}
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
