:root {
    /* Kashan Spice Palette */
    --bg-color: #EADEC7;      /* Antique Paper */
    --surface-color: #DAC8AC; /* Latte Weave */
    --text-color: #3E2723;    /* Espresso */
    --primary-color: #8D4024; /* Burnt Henna */
    --accent-color: #556B2F;  /* Olive Garden */

    /* Mapped Variables */
    --wood-1: #DAC8AC;
    --wood-2: #C9B79B;
    --wood-3: #B8A68A;
    --brass-1: #556B2F;
    --brass-2: #445626;
    --ink: #3E2723;
    --paper: #FDF9F0;
    --paper-2: #EADEC7;
    --teal-1: #556B2F;
    --teal-2: #3E4E23;
    
    --shadow: 0 10px 30px rgba(62, 39, 35, 0.2);
    --shadow-soft: 0 6px 16px rgba(62, 39, 35, 0.15);
    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 14px;
    --maxw: 420px;

    /* Safely bounded app width for precise proportional scaling */
    --app-w: min(100vw, var(--maxw));

    /* FIX: Pasur Variables - Deducts the exact scoreboard width, ensuring cards never stretch too big */
    --flex-w: calc((var(--app-w) - 130px) / 4);
    --pasur-card-w: clamp(35px, min(var(--flex-w), 11.5vh), 58px);
    --pasur-card-h: calc(var(--pasur-card-w) * 1.45);

    /* Solitaire Variables */
    --sol-card-w: calc((var(--app-w) - 40px) / 7);
    --sol-card-h: calc(var(--sol-card-w) * 1.45);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    color: var(--text-color);
    background: var(--bg-color);
    background: radial-gradient(circle at 50% 30%, #f7f2e8 0%, var(--bg-color) 80%);
    font-family: Inter, system-ui, -apple-system, sans-serif;
    display: flex;
    justify-content: center;
    height: 100dvh; 
    overflow: hidden; 
    user-select: none;
    -webkit-user-select: none;
    width: 100vw;
    max-width: 100vw;
}

/* Hebrew & Persian Font Support */
body[lang="he"], body[lang="fa"] {
    font-family: 'Rubik', 'Vazirmatn', system-ui, -apple-system, sans-serif;
}
body[lang="he"] .brand-label, 
body[lang="he"] .title, 
body[lang="he"] .subtitle,
body[lang="he"] .modal-title,
body[lang="fa"] .brand-label, 
body[lang="fa"] .title, 
body[lang="fa"] .subtitle,
body[lang="fa"] .modal-title {
    font-family: 'Rubik', 'Vazirmatn', sans-serif;
}

.app {
    width: min(var(--maxw), 100%);
    padding: 10px 12px 14px; 
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-x: hidden;
}

/* Top Bar */
.topbar {
    background: linear-gradient(180deg, rgba(255,255,255,0.4), rgba(0,0,0,0.05)), var(--surface-color);
    border-radius: 24px;
    padding: 12px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(62, 39, 35, 0.1);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.topbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.icon-btn {
    width: 38px; height: 38px;
    border-radius: 12px;
    border: 1px solid rgba(62, 39, 35, 0.2);
    background: rgba(62, 39, 35, 0.05);
    color: var(--text-color);
    display: grid;
    place-items: center;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(62, 39, 35, 0.1);
    flex-shrink: 0;
}

.left-actions { display: flex; gap: 8px; z-index: 2; align-items: center; }
.right-actions { display: flex; gap: 8px; z-index: 2; width: 84px; justify-content: flex-end; align-items: center; }

.title-wrap { 
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    text-align: center; 
    line-height: 1.05; 
    z-index: 1;
    pointer-events: none;
}
.brand-label {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 8px;
    letter-spacing: 2px;
    color: var(--accent-color);
    text-transform: uppercase;
    margin-bottom: 2px;
    font-weight: 700;
}
.title {
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 700;
    font-size: 24px; 
    margin: 0;
    text-shadow: none;
    color: var(--text-color);
    white-space: nowrap;
}
.subtitle {
    margin-top: 4px;
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 2px;
    color: var(--primary-color);
    opacity: 0.9;
}

.share-btn {
    justify-self: end;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid rgba(215,192,138,0.25);
    background: linear-gradient(180deg, rgba(255,255,255,0.15), rgba(0,0,0,0.2)), var(--accent-color);
    color: rgba(243,231,207,0.95);
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
}

.rule {
    margin: 10px auto 0;
    width: 78%; height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-color), transparent);
    opacity: 0.3;
}

.stat-group {
    display: flex;
    gap: 4px;
}

.action-group {
    display: flex;
    gap: 8px;
    align-items: center;
    border-inline-start: 1px solid rgba(215,192,138,0.25);
    padding-inline-start: 10px;
    margin-inline-start: auto;
}

.action-icon-btn {
    width: 40px;
    padding: 0 !important;
    flex-shrink: 0;
}

/* Flow-based Instruction Message / Controls Wrapper */
.controls-wrapper {
    position: relative;
    margin: 12px auto 0;
    width: 100%;
    z-index: 50;
}

.controls-bar {
    position: relative;
    background: linear-gradient(180deg, rgba(255,255,255,0.4), rgba(0,0,0,0.05)), var(--surface-color);
    border-radius: 30px;
    padding: 6px 8px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(62, 39, 35, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

.controls-bar.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.95);
}

#status-bar {
    position: absolute;
    inset: 0; 
    margin: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(0.95);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 2000;
}

#status-bar.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: scale(1);
}

.instruction {
    padding: 8px 12px;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    border-radius: 30px;
    background: var(--surface-color);
    border: 1px solid var(--primary-color);
    color: var(--text-color);
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: var(--shadow);
}

.instruction-content-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 2px;
}
.instruction-text { flex-grow: 1; text-align: start; font-size: 14px; line-height: 1.2; }

.instruction-btn {
    padding: 4px 10px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    border: 1px solid var(--primary-color);
    background: transparent;
    color: var(--text-color);
}

.instruction.game-over .instruction-btn, 
.instruction.victory .instruction-btn,
.instruction.dozdi-offer .instruction-btn,
.instruction.dozdi-active .instruction-btn {
    border: 1px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.2);
    color: #fff;
}

.instruction-btn:hover { opacity: 0.8; }

.lang-active {
    background-color: var(--primary-color) !important;
    color: #fff !important;
    border-color: var(--primary-color) !important;
}

.instruction.error { color: #C62828; border-color: #C62828; background: #FFEBEE; }
.instruction.success { color: #2E7D32; border-color: #2E7D32; background: #E8F5E9; }
.instruction.game-over { 
    background: linear-gradient(90deg, #8D4024, #3E2723); 
    color: #fff; 
    border-color: #8D4024;
    border-radius: 30px;
}
.instruction.victory { 
    background: linear-gradient(90deg, #556B2F, #3E4E23); 
    color: #fff; 
    border-color: #fff;
    border-radius: 30px;
}
.instruction.dozdi-offer {
    background: linear-gradient(90deg, #A05230, #5d4037);
    color: #fff;
    border-color: #ffccbc;
    border-radius: 30px;
    padding: 4px 8px;
    animation: attention-pulse 1.5s infinite;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    border-width: 2px;
}
.instruction.dozdi-active {
    background: linear-gradient(90deg, #556B2F, #2E7D32);
    color: #fff;
    border-color: #fff;
    border-radius: 30px;
}

/* Rug area */
.rug {
    background-color: var(--primary-color);
    background-image: 
        radial-gradient(circle at 50% 50%, rgba(255,255,255,0.05) 0%, transparent 70%),
        repeating-linear-gradient(45deg, rgba(62, 39, 35, 0.1) 0px, rgba(62, 39, 35, 0.1) 2px, transparent 2px, transparent 8px),
        repeating-linear-gradient(-45deg, rgba(85, 107, 47, 0.1) 0px, rgba(85, 107, 47, 0.1) 2px, transparent 2px, transparent 8px);
    
    border-radius: var(--radius-xl);
    padding: 10px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255,255,255,.2);
    position: relative;
    flex-grow: 1; 
    min-height: 0; 
    display: flex;
    flex-direction: column;
    overflow: hidden;
    justify-content: center;
    align-items: center; 
}

.rug:before {
    content: ""; 
    position: absolute; 
    inset: 0;
    background: rgba(141, 64, 36, 0.15);
    pointer-events: none;
}

.rug:after {
    content: ""; 
    position: absolute; 
    inset: 8px;
    border-radius: calc(var(--radius-xl) - 8px);
    border: 2px solid var(--surface-color);
    pointer-events: none;
}

/* Absolute Aspect Ratio Lock prevents Persian Rug Cards from stretching vertically */
.grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: clamp(4px, 1.5vw, 8px);
    padding: clamp(4px, 1.5vw, 8px);
    background: rgba(62, 39, 35, 0.3);
    border-radius: calc(var(--radius-xl) - 8px);
    border: 1px solid rgba(255,255,255,.2);
    backdrop-filter: blur(2px);
    position: relative;
    z-index: 1;
    
    width: 100%;
    max-width: calc((100dvh - 180px) * 0.91); 
    height: auto;
    aspect-ratio: 4 / 4.45;
    margin: auto;
}

/* Cards */
.card {
    width: 100%;
    height: 100%; 
    border-radius: clamp(6px, 2vw, 12px);
    min-width: 0;
    min-height: 0;
    background-color: #F0E6D2;
    background-image: 
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E"),
        radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.5) 0%, transparent 50%),
        linear-gradient(135deg, #FDF7E8 0%, #E6D5B8 100%);
    border: 1px solid rgba(60, 30, 10, 0.4);
    box-shadow: inset 0 0 20px rgba(100, 50, 10, 0.15), 0 14px 26px rgba(0,0,0,0.35);
    position: relative;
    cursor: pointer;
    overflow: hidden;
    transition: transform .12s ease, box-shadow .12s ease, opacity 0.3s ease, filter 0.3s ease;
}

/* REMOVED: .card.t1, .card.t2, .card.t3, .card.t4 to ensure perfectly straight cards */

.card.selected {
    outline: 3px solid #FFD700;
    box-shadow: 0 0 15px #FFD700, 0 0 8px white inset;
    z-index: 2;
    transform: scale(1.05); 
}

.card.hint-glow {
    z-index: 10;
    animation: pulse-hint 2s ease-in-out infinite;
}

.card.dozdi-target {
    cursor: crosshair;
}
.card.dozdi-target:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px var(--accent-color);
}

.flying-card {
    position: fixed;
    z-index: 100;
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1),
                left 0.6s cubic-bezier(0.25, 1, 0.5, 1),
                top 0.6s cubic-bezier(0.25, 1, 0.5, 1),
                opacity 0.6s ease;
    pointer-events: none;
    box-shadow: 0 15px 35px rgba(62, 39, 35, 0.4);
    transform-origin: center center;
}

.sol-flying {
    transition: all 0.28s ease-out !important;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5) !important;
}

@keyframes pulse-hint {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.08); filter: brightness(1.2); }
    100% { transform: scale(1); filter: brightness(1); }
}

@keyframes attention-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(160, 82, 48, 0.7); }
    70% { transform: scale(1.03); box-shadow: 0 0 10px 10px rgba(160, 82, 48, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(160, 82, 48, 0); }
}

.card.disabled:not(.rug-face) {
    filter: grayscale(100%);
    opacity: 0.5;
    cursor: default;
    pointer-events: none;
}

.sol-card.disabled {
    opacity: 1 !important;
    filter: grayscale(100%) brightness(0.85) !important;
}

.card.disabled.rug-face {
    filter: brightness(0.6) sepia(0.5); 
    cursor: default;
    pointer-events: none;
}

.card.won-rug-face {
    filter: brightness(1.1) contrast(1.15) drop-shadow(0 0 15px rgba(255, 215, 0, 0.7));
    transform: scale(1.05);
    z-index: 10;
    opacity: 1 !important;
    transition: all 1.2s cubic-bezier(0.25, 1, 0.5, 1);
    cursor: default;
}

.corner {
    position: absolute;
    font-weight: 700;
    color: var(--ink);
    font-size: clamp(10px, 2.5vw, 13px); 
    line-height: 0.9;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.corner.top { inset: 6px auto auto 6px; }
.corner.bottom { inset: auto 6px 6px auto; transform: rotate(180deg); }

.pip {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: clamp(18px, 5vw, 24px); 
    color: var(--ink);
    opacity: 0.9;
    pointer-events: none;
}

.card.red .corner, .card.red .pip { color: #B23A22; }

.card-empty {
    width: 100%; height: 100%;
    border-radius: 12px;
    border: 2px dashed rgba(255,255,255,0.4);
    background: rgba(0,0,0,0.1);
}

/* ===== Simple Face for Pasur & Solitaire ===== */
.pasur-simple-face {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    line-height: 1;
}
.pasur-simple-val {
    font-size: clamp(14px, 3vh, 20px);
    font-weight: 900;
}
.pasur-simple-suit {
    font-size: clamp(16px, 3.5vh, 24px);
}
.card.red .pasur-simple-face {
    color: #B23A22;
}
.card.black .pasur-simple-face {
    color: var(--ink);
}

/* ===== Pasur Layout & Table ===== */
.pasur-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    justify-content: space-between;
    position: relative;
    z-index: 1;
    padding: 4px 0; 
}

.pasur-hand {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex: 0 0 auto;
    height: calc(var(--pasur-card-h) + 24px); 
    padding: 4px 10px;
    border-radius: 16px;
    margin: 2px 4px; 
    position: relative;
    border: 1px solid rgba(255,255,255,0.08); 
    gap: 12px;
}

.pasur-cards-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    height: 100%;
    flex: 1 1 auto;
    min-width: 0;
}

.pasur-scoreboard {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    z-index: 10;
    color: #FFFDF9; 
    opacity: 1;
    flex-shrink: 0;
}

.pasur-area-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.score-pill {
    background: transparent;
    border: none;
    padding: 0px 4px;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: none;
    min-width: 48px;
    justify-content: center;
    color: #ffffff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.pasur-table {
    flex: 1 1 auto; 
    margin: auto 6px; 
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    align-items: center;
    gap: 10px;
    padding: 14px;
    background: rgba(62, 39, 35, 0.25); 
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.15);
    position: relative;
    min-height: calc((var(--pasur-card-h) * 2) + 30px); 
    box-shadow: inset 0 0 20px rgba(62, 39, 35, 0.4); 
    overflow-y: auto;
    overflow-x: hidden;
}

.card.pasur-card {
    height: var(--pasur-card-h); 
    width: var(--pasur-card-w); 
    cursor: pointer;
    flex-shrink: 0;
    overflow: visible;
}

.card-pts-tag-container {
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    z-index: 10;
    pointer-events: none;
}

.pt-tag {
    font-size: 12px;
    font-weight: 900;
    padding: 2px 5px;
    border-radius: 6px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.6);
    font-family: Inter, sans-serif;
    border: 1px solid rgba(255,255,255,0.5);
    white-space: nowrap;
}
.tag-star {
    background: linear-gradient(135deg, #FFD700, #DAA520);
    color: #000;
}
.tag-clover {
    background: linear-gradient(135deg, #4CAF50, #2E7D32);
    color: #FFF;
}

.card-back {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    background-color: var(--primary-color);
    background-image: 
        repeating-linear-gradient(45deg, rgba(0,0,0,0.1) 0, rgba(0,0,0,0.1) 2px, transparent 2px, transparent 6px),
        repeating-linear-gradient(-45deg, rgba(0,0,0,0.1) 0, rgba(0,0,0,0.1) 2px, transparent 2px, transparent 6px);
    background-size: cover;
    background-position: center;
    border: 2px solid var(--brass-1);
    box-shadow: inset 0 0 15px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.3);
    position: relative;
}

.card-stack {
    display: flex;
    flex-direction: row;
    direction: ltr; 
    position: relative;
    gap: 0;
    align-items: center;
}

.stacked-card {
    margin-left: calc(var(--pasur-card-w) * -0.65); 
    position: relative;
    box-shadow: -4px 0 10px rgba(0,0,0,0.15);
    z-index: 1;
}

.captured-highlight {
    outline: 4px solid #FFD700 !important;
    box-shadow: 0 0 25px #FFD700, inset 0 0 10px #FFD700 !important;
    transform: scale(1.1) !important;
    z-index: 100 !important;
    transition: all 0.3s ease;
}

/* ===== Solitaire Layout ===== */
.solitaire-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    justify-content: flex-start;
    position: relative;
    z-index: 1;
    padding: 4px 6px;
    gap: 12px;
}

.sol-top-row, .sol-bottom-row {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    width: 100%;
    justify-items: center;
}

.sol-top-row {
    height: var(--sol-card-h);
}

.sol-bottom-row {
    flex: 1;
    position: relative;
    min-height: 0;
}

.sol-divider {
    width: 3px;
    background: rgba(243, 231, 207, 0.7);
    border-radius: 2px;
    height: 80%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.sol-col {
    position: relative;
    width: var(--sol-card-w);
    height: 100%;
}

.sol-card {
    position: absolute;
    width: var(--sol-card-w);
    height: var(--sol-card-h);
    border-radius: clamp(4px, 1.5vw, 8px);
}

.sol-slot {
    width: var(--sol-card-w);
    height: var(--sol-card-h);
    border-radius: clamp(4px, 1.5vw, 8px);
    border: 2px dashed rgba(255,255,255,0.2);
    background: rgba(0,0,0,0.1);
}

/* Adjusted Stat Styles for compactness */
.stat {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 6px;
    border-radius: 12px;
    background: rgba(62, 39, 35, 0.08);
    border: 1px solid rgba(62, 39, 35, 0.1);
    height: 38px;
    flex: 0 0 auto;
}
.badge {
    width: 20px; height: 20px;
    border-radius: 6px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,0.5);
    border: 1px solid rgba(62, 39, 35, 0.2);
    font-size: 12px;
    flex-shrink: 0;
}
.stat-val { 
    font-weight: 700; 
    font-size: 13px; 
    color: var(--text-color); 
    font-variant-numeric: tabular-nums; 
    min-width: 18px;
    text-align: center;
}

.primary-btn {
    padding: 0 12px;
    border-radius: 12px;
    border: 1px solid rgba(215,192,138,0.25);
    background: linear-gradient(180deg, rgba(255,255,255,0.15), rgba(0,0,0,0.2)), var(--accent-color);
    color: rgba(243,231,207,0.95);
    font-weight: 700;
    height: 38px;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 1;
    white-space: nowrap;
}
.primary-btn:active { transform: translateY(1px); }

.hint-btn {
    padding: 0 10px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.2);
    background: linear-gradient(180deg, #6B8E23, #556B2F);
    color: #fff;
    font-weight: 700;
    height: 38px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(85, 107, 47, 0.3);
    font-size: 12px;
    display: none; 
    align-items: center;
    justify-content: center;
    flex: 1;
}

/* Modals */
#modal-overlay {
    position: fixed; inset: 0;
    background: rgba(62, 39, 35, 0.85);
    display: flex; justify-content: center; align-items: flex-end; 
    padding-bottom: 20px; 
    z-index: 100; opacity: 0; pointer-events: none;
    transition: opacity 0.3s, background 0.3s;
    backdrop-filter: blur(5px);
}

#modal-overlay.visible { opacity: 1; pointer-events: auto; }

#modal-overlay.end-game {
    background: transparent;
    backdrop-filter: none;
    align-items: flex-start; 
    padding-top: 96px; 
}

#modal-overlay.end-game .modal-content {
    background: var(--paper);
    box-shadow: 0 10px 40px rgba(62, 39, 35, 0.4);
    animation: slideDown 0.4s ease-out;
    width: calc(100% - 24px); 
    max-width: 400px;
    padding: 10px 16px;
    border-radius: 16px;
}

@keyframes slideDown {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-content {
    background: var(--paper);
    color: var(--text-color);
    padding: 30px;
    border-radius: var(--radius-xl);
    text-align: center;
    width: min(340px, 96%); 
    box-shadow: var(--shadow);
    border: 2px solid var(--accent-color);
    margin-bottom: 20px; 
}
.modal-title { font-family: Georgia, 'Times New Roman', serif; font-size: 24px; margin-bottom: 15px; font-weight: 700; color: var(--primary-color); }
.modal-text { color: var(--text-color); }

.mode-selection {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mode-btn {
    padding: 16px;
    border-radius: 16px;
    border: 1px solid rgba(62, 39, 35, 0.1);
    background: var(--surface-color);
    color: var(--text-color);
    font-weight: 700;
    font-size: 18px; 
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.1s;
}
.mode-btn:active { transform: scale(0.98); }
.mode-btn span { 
    font-size: 14px; 
    opacity: 0.9; 
    font-weight: 400; 
    margin-top: 6px; 
}
.mode-btn.tutorial { border: 2px solid var(--accent-color); }
.mode-btn.hard { background: var(--primary-color); color: #fff; }

@media (max-height: 700px) {
    .app { padding: 8px 10px; }
    .topbar { padding: 10px; }
    .grid { gap: 8px; padding: 8px; }
    .title { font-size: 22px; }
    .pip { font-size: 26px; }
}

/* ===== Persian Rug Premium Skin (V2) ===== */
:root{
    --bg-color: #120A06;
    --surface-color: #1B120C;
    --text-color: #F3E7CF;
    --primary-color: #D7C08A; 
    --accent-color: #1C6B67;  

    --wood-1:#1B120C;
    --wood-2:#2A1710;
    --wood-3:#3B2419;
    --brass-1:#D7C08A;
    --brass-2:#B89F66;
    --ink:#120A06;
    --paper:#F3E7CF;
    --paper-2:#E7D8BD;
    --teal-1:#1C6B67;
    --teal-2:#14524F;

    --shadow: 0 18px 40px rgba(0,0,0,0.45);
    --shadow-soft: 0 10px 22px rgba(0,0,0,0.35);
}

body{
    background: radial-gradient(circle at 50% 18%, #2B1A12 0%, #120A06 72%);
    color: var(--text-color);
}

.topbar{
    background: linear-gradient(180deg, #2E1B12 0%, #1A0F0A 100%);
    border: 1px solid rgba(215,192,138,0.15);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    border-radius: 24px;
}

.icon-btn{
    background: #1C110C;
    border: 1px solid rgba(215,192,138,0.2);
    color: #D7C08A;
    box-shadow: inset 0 2px 4px rgba(255,255,255,0.05), 0 4px 10px rgba(0,0,0,0.3);
    border-radius: 14px;
}

.brand-label{
    color: #B09360;
    font-family: 'Cinzel', Georgia, serif;
    letter-spacing: 3px;
}
.title{
    font-family: 'Cinzel', Georgia, serif;
    color: #FDF4E0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.6);
    letter-spacing: 1px;
    font-size: clamp(20px, 6vw, 26px);
}
.subtitle{
    color: #B09360;
    font-family: 'Cinzel', Georgia, serif;
    text-transform: uppercase;
    letter-spacing: 3px;
}

.rule{
    background: linear-gradient(90deg, transparent, rgba(215,192,138,0.8), transparent);
    opacity: 0.35;
}

.controls-bar{
    position: relative;
    background: linear-gradient(180deg, rgba(255,255,255,0.4), rgba(0,0,0,0.05)), var(--surface-color);
    border-radius: 30px;
    padding: 6px 8px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(62, 39, 35, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

.stat{
    background: #252220;
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 16px;
    height: 40px;
    padding: 0 10px 0 6px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.4);
}

.badge {
    background: #353230;
    border: none;
    color: #A09890;
    border-radius: 10px;
    width: 26px;
    height: 26px;
}

.stat-val{ color: #FDF4E0; font-size: 13px; margin-left: 4px; }

.primary-btn.secondary{
    background: #3A3532;
    border: 1px solid rgba(215,192,138,0.3);
    border-radius: 16px;
    height: 40px;
    color: #FDF4E0;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: background 0.2s;
    padding: 0 18px;
}
.primary-btn.secondary:active { background: #2A2624; }

.instruction {
    background: rgba(30, 20, 15, 0.98);
    border: 1px solid rgba(215,192,138,0.3);
    color: rgba(243,231,207,0.95);
    box-shadow: 0 10px 25px rgba(0,0,0,0.6);
}

.rug{
    background-color: #2A1710;
    background-image: 
        radial-gradient(circle at 50% 30%, rgba(255,255,255,0.06), transparent 60%),
        linear-gradient(180deg, #6B3D27 0%, #2A1710 60%, #1B120C 100%);
    border: 1px solid rgba(215,192,138,0.18);
    box-shadow: var(--shadow);
}

.grid{
    background: rgba(0,0,0,0.12);
    border: 1px solid rgba(215,192,138,0.12);
}

.sol-divider {
    background: rgba(215, 192, 138, 0.6);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

#modal-overlay{
    background: rgba(10,6,4,0.82);
    backdrop-filter: blur(6px);
}
.modal-content{
    background:
        radial-gradient(circle at 50% 0%, rgba(255,255,255,0.08), transparent 55%),
        linear-gradient(180deg, #3B2419 0%, #24140F 55%, #1B120C 100%);
    border: 1px solid rgba(215,192,138,0.22);
    box-shadow: var(--shadow);
    color: #F3E7CF;
}
.modal-title{
    font-family: 'Cinzel', Georgia, serif;
    color: rgba(215,192,138,0.95);
}
.primary-btn{
    background: linear-gradient(180deg, rgba(255,255,255,0.15), rgba(0,0,0,0.2)), var(--teal-1);
    border: 1px solid rgba(215,192,138,0.25);
    box-shadow: var(--shadow-soft);
    color: rgba(243,231,207,0.95);
    height: 44px;
    font-size: 13px;
}
.primary-btn.secondary{
    background: linear-gradient(180deg, #3B2419, #1B120C);
    border: 1px solid rgba(215,192,138,0.18);
}

.mode-btn{
    background: rgba(0,0,0,0.18);
    border: 1px solid rgba(215,192,138,0.22);
    color: #F3E7CF;
}
.mode-btn.tutorial{ border: 2px solid rgba(215,192,138,0.55); }
.mode-btn.hard{
    background: linear-gradient(180deg, #4B1F1F, #2A0F0F);
    border: 1px solid rgba(215,192,138,0.18);
}
}