/* ── Page Layout ─────────────────────────────────────────────────────────── */
body:has(.ts-page) {
    background: #111827;
    margin: 0;
    padding: 0;
}
body:has(.ts-page) footer {
    display: none;
}
body:has(.ts-page) > .container {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
}

.ts-page {
    min-height: 100dvh;
    background: #111827;
    color: #f0f0f0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 2rem;
    box-sizing: border-box;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.ts-header {
    width: 100%;
    max-width: 520px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    box-sizing: border-box;
}

.ts-home-btn {
    color: #9ca3af;
    text-decoration: none;
    padding: 0.25rem;
    display: flex;
    align-items: center;
}
.ts-home-btn:hover { color: #f0f0f0; }

.ts-header-center {
    text-align: center;
    flex: 1;
}

.ts-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: #D4AF37;
    letter-spacing: 0.03em;
}

.ts-date {
    font-size: 0.75rem;
    color: #9ca3af;
    margin: 0;
}

.ts-header-right {
    display: flex;
    align-items: center;
    min-width: 80px;
    justify-content: flex-end;
}

.ts-auth-btn {
    background: none;
    border: 1px solid #374151;
    color: #d1d5db;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    white-space: nowrap;
}
.ts-auth-btn:hover { border-color: #6b7280; color: #f0f0f0; }

.ts-auth-menu { position: relative; }
.ts-auth-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 110%;
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 6px;
    min-width: 120px;
    z-index: 100;
}
.ts-auth-dropdown.open { display: block; }
.ts-auth-dropdown a {
    display: block;
    padding: 0.5rem 0.75rem;
    color: #d1d5db;
    text-decoration: none;
    font-size: 0.85rem;
}
.ts-auth-dropdown a:hover { background: #374151; }

/* ── Game Container ───────────────────────────────────────────────────────── */
#ts-game {
    width: 100%;
    max-width: 520px;
    padding: 0 0.5rem;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.ts-score-row {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: #9ca3af;
}
.ts-score-row strong { color: #D4AF37; }

/* ── Board Grid ──────────────────────────────────────────────────────────── */
.ts-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    /* gap: 3px; */
    width: 100%;
    max-width: 480px;
    aspect-ratio: 1;
    background: #1f2937;
    border: 2px solid #374151;
    border-radius: 8px;
    padding: 4px;
    box-sizing: border-box;
    position: relative;
}

/* ── Tiles ───────────────────────────────────────────────────────────────── */
.ts-cell {
    border-radius: 4px;
    padding: 5px;
    position: relative;
    isolation: isolate;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.8rem, 2.5vw, 1.2rem);
    font-weight: bold;
    color: rgba(255, 255, 255, 0.7);
    transition: transform 0.1s, opacity 0.3s, box-shadow 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.ts-cell:active { transform: scale(0.92); }

/* Inset coloured background — 5px from the grid cell edge */
.ts-cell[data-type]::before {
    content: '';
    position: absolute;
    inset: 5px;
    border-radius: 3px;
    z-index: -1;
}

/* Tile type colours */
/*.ts-cell[data-type="0"]::before { background: #C53030; } /* Red */
.ts-cell[data-type="0"]::before { 
    background-image: url('/post_renders/orange_tile.png'); background-size: cover; background-color: transparent; 
} /* Orange */
.ts-cell[data-type="1"]::before { 
    background-image: url('/post_renders/silver_tile.png'); background-size: cover; background-color: transparent; 
} /* Silver */
.ts-cell[data-type="2"]::before { 
    background-image: url('/post_renders/red_tile.png'); background-size: cover; background-color: transparent; 
} /* Red */
.ts-cell[data-type="3"]::before { 
    background-image: url('/post_renders/pink_tile.png'); background-size: cover; background-color: transparent; 
} /* Pink */
.ts-cell[data-type="4"]::before { 
    background-image: url('/post_renders/green_tile.png'); background-size: cover; background-color: transparent; 
} /* Green */
.ts-cell[data-type="5"]::before { 
    background-image: url('/post_renders/gold_tile.png'); background-size: cover; background-color: transparent; 
} /* Gold */
.ts-cell[data-type="6"]::before { 
    background-image: url('/post_renders/cyan_tile.png'); background-size: cover; background-color: transparent; 
} /* Teal/Cyan */

/* Tile being dragged — floats above the board */
.ts-cell.dragging {
    z-index: 10;
    opacity: 0.92;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65);
    transition: none !important;
    cursor: grabbing;
}

/* Swap target tile — glows to indicate it will be swapped */
.ts-cell.drag-target {
    box-shadow: 0 0 0 3px #fff, 0 0 0 5px rgba(212, 175, 55, 0.6);
    transition: box-shadow 0.08s;
}

/* Selected tile */
.ts-cell.selected {
    box-shadow: 0 0 0 3px #fff, 0 0 0 5px rgba(212, 175, 55, 0.8);
    transform: scale(1.08);
    z-index: 1;
}

/* Match flash border overlay — injected via JS, fades out during gravity */
.ts-match-flash-border {
    position: absolute;
    border-radius: 8px;
    pointer-events: none;
    z-index: 10;
    box-sizing: border-box;
    border-width: 3px;
    border-style: solid;
    transition: opacity 800ms ease;
}

/* Removing animation — targets only the tile image, not the flash overlay */
.ts-cell.removing::before {
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 1s, transform 1s;
}

/* Invalid swap feedback */
@keyframes ts-invalid {
    0%, 100% { transform: translateX(0); }
    25%       { transform: translateX(-6px); }
    75%       { transform: translateX(6px); }
}

.ts-cell.invalid-swap {
    animation: ts-invalid 0.25s ease-in-out;
    transition: none;
}

/* ── Progress Counters ───────────────────────────────────────────────────── */
.ts-progress-row {
    display: flex;
    gap: 4px;
    margin-top: 0.75rem;
    width: 100%;
    max-width: 480px;
    box-sizing: border-box;
}

.ts-progress-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
}

.ts-tile-dot {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}
.ts-tile-dot[data-type="2"] { background-image: url('/post_renders/red_tile.png'); }
.ts-tile-dot[data-type="1"] { background-image: url('/post_renders/silver_tile.png'); }
.ts-tile-dot[data-type="4"] { background-image: url('/post_renders/green_tile.png'); }
.ts-tile-dot[data-type="5"] { background-image: url('/post_renders/gold_tile.png'); }
.ts-tile-dot[data-type="3"] { background-image: url('/post_renders/pink_tile.png'); }
.ts-tile-dot[data-type="0"] { background-image: url('/post_renders/orange_tile.png'); }
.ts-tile-dot[data-type="6"] { background-image: url('/post_renders/cyan_tile.png'); }

.ts-bar-track {
    width: 70%;
    height: 4px;
    background: #374151;
    border-radius: 2px;
    overflow: hidden;
}

.ts-bar-fill {
    height: 100%;
    background: #D4AF37;
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s;
}

.ts-count {
    font-size: 0.6rem;
    color: #6b7280;
    text-align: center;
}

.ts-progress-item.complete .ts-bar-fill { background: #48BB78; }
.ts-progress-item.complete .ts-count { color: #48BB78; }
.ts-progress-item.complete .ts-tile-dot { opacity: 0.5; }

/* ── Guest note ──────────────────────────────────────────────────────────── */
.ts-guest-note {
    font-size: 0.75rem;
    color: #6b7280;
    text-align: center;
    margin-top: 0.75rem;
    padding: 0 1rem;
}
.ts-guest-note a { color: #9ca3af; }

/* ── Shuffle / Status Message ────────────────────────────────────────────── */
.ts-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(31, 41, 55, 0.95);
    color: #D4AF37;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    border: 1px solid #374151;
    font-size: 1rem;
    font-weight: 600;
    z-index: 50;
    pointer-events: none;
}

/* ── Complete Screen ─────────────────────────────────────────────────────── */
.ts-complete-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #3d1a78 0%, #1a0a3d 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
    box-sizing: border-box;
    overflow-y: auto;
}

.ts-complete-inner {
    width: 100%;
    max-width: 420px;
    text-align: center;
    padding: 1.5rem 1rem;
}

.ts-complete-banner {
    font-size: 2rem;
    font-weight: 800;
    color: #D4AF37;
    margin-bottom: 1rem;
    text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.ts-complete-score, .ts-complete-swaps {
    font-size: 1.1rem;
    color: #d1d5db;
    margin: 0.25rem 0;
}
.ts-complete-score strong, .ts-complete-swaps strong { color: #D4AF37; }

.ts-rank-text { font-size: 1rem; color: #d1d5db; margin: 0.5rem 0; }
.ts-rank-text strong { color: #D4AF37; font-size: 1.25rem; }

/* Leaderboard */
.ts-lb-title {
    font-size: 1rem;
    color: #9ca3af;
    margin: 1rem 0 0.5rem;
}

.ts-lb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.ts-lb-table th {
    color: #6b7280;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid #374151;
}
.ts-lb-table td {
    padding: 0.25rem 0.5rem;
    color: #d1d5db;
    border-bottom: 1px solid #1f2937;
}
.ts-lb-table tr:first-child td { color: #D4AF37; }

/* Next puzzle button */
.ts-next-btn {
    display: inline-block;
    margin: 0.75rem 0;
    color: #D4AF37;
    text-decoration: none;
    font-size: 0.9rem;
    border: 1px solid #D4AF37;
    padding: 0.4rem 1rem;
    border-radius: 6px;
}
.ts-next-btn:hover { background: rgba(212, 175, 55, 0.1); }

/* Action buttons */
.ts-complete-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1rem;
}

.ts-btn {
    padding: 0.6rem 1.25rem;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: none;
}
.ts-btn-primary { background: #D4AF37; color: #1a0a3d; }
.ts-btn-primary:hover { background: #e4c047; }
.ts-btn-secondary { background: transparent; color: #d1d5db; border: 1px solid #374151; }
.ts-btn-secondary:hover { border-color: #6b7280; }

/* ── Small phone adjustments (≤430px) ───────────────────────────────────── */
@media (max-width: 430px) {
    .ts-score-row { gap: 0.75rem; font-size: 0.8rem; }
    .ts-cell { padding: 3px; }
    .ts-cell[data-type]::before { inset: 3px; }
    .ts-tile-dot { width: 35px; height: 35px; }
    .ts-progress-row { gap: 2px; flex-wrap: wrap; justify-content: center; }
    .ts-progress-item { flex: 0 0 calc(25% - 2px); }
    .ts-count { font-size: 0.55rem; }
}
