/**
 * Mind Tiles - Styles
 *
 * @author      Mike Fairbrother
 * @copyright   2024-2026 Mike Fairbrother. All rights reserved.
 */

/* ---- Color Tokens ---- */
:root {
    --mt-c1: #7ec8e3;   /* soft sky blue */
    --mt-c2: #c9a0dc;   /* soft lavender */
    --mt-c3: #82ddb0;   /* soft mint */
    --mt-c4: #f7b977;   /* soft peach */
    --mt-c5: #f291a3;   /* soft rose */
    --mt-c6: #a0c4ff;   /* soft periwinkle */
    --mt-empty: rgba(255, 255, 255, 0.06);
    --mt-given-opacity: 1;
    --mt-placed-opacity: 0.9;
    --mt-conflict: #ff4757;
    --mt-success: #2ed573;
    --mt-title-a: #0abde3;
    --mt-title-b: #60a5fa;
}

/* ---- Title ---- */
.mt-title {
    font-size: 48px;
    font-weight: 900;
    line-height: 1;
    background: linear-gradient(135deg, var(--mt-title-a), var(--mt-title-b));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.mt-subtitle {
    font-size: 15px;
    color: var(--gp-text-secondary);
    margin-bottom: 24px;
    letter-spacing: 0.5px;
}

/* ---- Logo ---- */
.mt-logo {
    margin-bottom: 16px;
}

.mt-logo-grid {
    display: grid;
    grid-template-columns: repeat(3, 28px);
    grid-template-rows: repeat(3, 28px);
    gap: 4px;
}

.mt-logo-tile {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--c);
    opacity: 0.85;
    animation: mt-logo-pulse 3s ease-in-out infinite;
}

.mt-logo-tile:nth-child(2) { animation-delay: 0.3s; }
.mt-logo-tile:nth-child(3) { animation-delay: 0.6s; }
.mt-logo-tile:nth-child(4) { animation-delay: 0.9s; }
.mt-logo-tile:nth-child(6) { animation-delay: 1.2s; }
.mt-logo-tile:nth-child(7) { animation-delay: 0.4s; }
.mt-logo-tile:nth-child(8) { animation-delay: 0.7s; }
.mt-logo-tile:nth-child(9) { animation-delay: 1.0s; }

.mt-logo-empty {
    background: var(--mt-empty);
    border: 2px dashed rgba(255, 255, 255, 0.15);
}

@keyframes mt-logo-pulse {
    0%, 100% { transform: scale(1); opacity: 0.85; }
    50% { transform: scale(1.08); opacity: 1; }
}

/* ---- Difficulty Selector ---- */
.mt-difficulty-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.mt-diff-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 18px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--gp-radius-sm);
    background: rgba(255, 255, 255, 0.04);
    color: var(--gp-text-secondary);
    font-size: 14px;
    font-weight: 700;
    font-family: var(--gp-font-stack);
    cursor: pointer;
    transition: all 0.2s ease;
}

.mt-diff-btn.active {
    border-color: var(--mt-title-a);
    background: rgba(10, 189, 227, 0.12);
    color: var(--mt-title-a);
}

.mt-diff-size {
    font-size: 11px;
    font-weight: 500;
    opacity: 0.7;
    margin-top: 2px;
}

/* ---- Menu Stats ---- */
.mt-menu-stats {
    display: flex;
    gap: 24px;
    margin-bottom: 28px;
}

.mt-menu-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mt-menu-stat-value {
    font-size: 24px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: #fff;
}

.mt-menu-stat-label {
    font-size: 11px;
    color: var(--gp-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

/* ---- Game Area ---- */
#game-area {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    gap: 16px;
}

#mt-grid-wrap {
    position: relative;
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
}

#mt-grid {
    display: grid;
    gap: 4px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--gp-radius-md);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

/* ---- Cells ---- */
.mt-cell {
    position: relative;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.mt-cell.mt-empty {
    background: var(--mt-empty);
    border: 2px dashed rgba(255, 255, 255, 0.08);
}

.mt-cell.mt-given {
    opacity: var(--mt-given-opacity);
    cursor: default;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.mt-cell.mt-given::after {
    content: '';
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
}

.mt-cell.mt-placed {
    opacity: var(--mt-placed-opacity);
    border: 2px solid transparent;
}

.mt-cell.mt-placed:active {
    transform: scale(0.92);
}

.mt-cell.mt-selected {
    box-shadow: 0 0 0 3px var(--mt-title-a), 0 0 16px rgba(10, 189, 227, 0.3);
}

/* Conflict flash */
.mt-cell.mt-conflict {
    animation: mt-conflict-flash 0.5s ease;
}

@keyframes mt-conflict-flash {
    0%, 100% { box-shadow: none; }
    25% { box-shadow: 0 0 0 3px var(--mt-conflict), 0 0 20px rgba(255, 71, 87, 0.4); }
    50% { box-shadow: 0 0 0 3px var(--mt-conflict), 0 0 20px rgba(255, 71, 87, 0.2); }
    75% { box-shadow: 0 0 0 2px var(--mt-conflict); }
}

/* Success glow */
.mt-cell.mt-valid {
    animation: mt-valid-glow 0.6s ease;
}

@keyframes mt-valid-glow {
    0% { box-shadow: none; }
    50% { box-shadow: 0 0 0 3px var(--mt-success), 0 0 16px rgba(46, 213, 115, 0.3); }
    100% { box-shadow: 0 0 0 2px rgba(46, 213, 115, 0.15); }
}

/* Celebration */
.mt-cell.mt-celebrate {
    animation: mt-celebrate 0.6s ease forwards;
}

@keyframes mt-celebrate {
    0% { transform: scale(1); }
    30% { transform: scale(1.15) rotate(3deg); }
    60% { transform: scale(0.95) rotate(-2deg); }
    100% { transform: scale(1) rotate(0); box-shadow: 0 0 12px rgba(46, 213, 115, 0.3); }
}

/* Hint pulse */
.mt-cell.mt-hint {
    animation: mt-hint-pulse 1s ease infinite;
}

@keyframes mt-hint-pulse {
    0%, 100% { box-shadow: 0 0 0 2px rgba(255, 217, 61, 0.3); }
    50% { box-shadow: 0 0 0 4px rgba(255, 217, 61, 0.6), 0 0 16px rgba(255, 217, 61, 0.2); }
}

/* ---- Color Palette ---- */
#mt-palette {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--gp-radius-md);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.mt-palette-swatch {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
    border: 3px solid transparent;
    -webkit-tap-highlight-color: transparent;
}

.mt-palette-swatch:active {
    transform: scale(0.9);
}

.mt-palette-swatch.active {
    border-color: #fff;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

.mt-palette-eraser {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    background: var(--mt-empty);
    border: 3px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    color: var(--gp-text-secondary);
}

.mt-palette-eraser:active {
    transform: scale(0.9);
}

.mt-palette-eraser.active {
    border-color: #fff;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

/* ---- Game Footer Actions ---- */
.mt-game-footer {
    display: flex;
    flex-shrink: 0;
    gap: 8px;
    padding: 8px 16px 16px;
    justify-content: center;
}

.mt-action-btn {
    padding: 10px 24px;
    border: none;
    border-radius: var(--gp-radius-sm);
    font-size: 15px;
    font-weight: 700;
    font-family: var(--gp-font-stack);
    cursor: pointer;
    background: linear-gradient(135deg, var(--mt-title-a), var(--mt-title-b));
    color: #fff;
    transition: transform 0.15s ease;
}

.mt-action-btn:active {
    transform: scale(0.95);
}

.mt-action-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--gp-text-secondary);
}

/* ---- Complete Screen ---- */
.mt-complete-title {
    font-size: 32px;
    font-weight: 900;
    background: linear-gradient(135deg, var(--mt-success), var(--mt-title-a));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.mt-new-best {
    display: inline-block;
    padding: 6px 16px;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--gp-accent), var(--gp-fire-b));
    color: #1a1640;
    font-size: 14px;
    font-weight: 800;
    margin-bottom: 16px;
    animation: gp-badge-pop 0.4s ease forwards;
}

.mt-complete-stats {
    display: flex;
    gap: 28px;
    margin: 20px 0 32px;
}

.mt-complete-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mt-complete-stat-value {
    font-size: 28px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: #fff;
}

.mt-complete-stat-label {
    font-size: 11px;
    color: var(--gp-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

/* ---- Help Modal ---- */
.mt-help-section {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.mt-help-icon {
    font-size: 22px;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

.mt-help-text {
    font-size: 14px;
    color: var(--gp-text-secondary);
    line-height: 1.5;
    text-align: left;
}

.mt-help-text strong {
    color: var(--gp-text-primary);
}

/* ---- Responsive Grid Sizing ---- */
#mt-grid.mt-size-4 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
}
#mt-grid.mt-size-5 {
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
}
#mt-grid.mt-size-6 {
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(6, 1fr);
}

/* Cell sizing based on grid */
#mt-grid.mt-size-4 .mt-cell { width: 68px; height: 68px; }
#mt-grid.mt-size-5 .mt-cell { width: 56px; height: 56px; }
#mt-grid.mt-size-6 .mt-cell { width: 46px; height: 46px; }

/* Smaller screens */
@media (max-width: 380px) {
    #mt-grid.mt-size-4 .mt-cell { width: 60px; height: 60px; }
    #mt-grid.mt-size-5 .mt-cell { width: 50px; height: 50px; }
    #mt-grid.mt-size-6 .mt-cell { width: 40px; height: 40px; }
    .mt-palette-swatch, .mt-palette-eraser { width: 34px; height: 34px; }
}

/* Taller screens: give more breathing room */
@media (min-height: 750px) {
    #game-area { gap: 24px; }
}

/* ---- Celebration Particles ---- */
.mt-particle {
    position: fixed;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 200;
    animation: mt-particle-fly 1s ease-out forwards;
}

@keyframes mt-particle-fly {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--dx), var(--dy)) scale(0.3);
    }
}

/* ---- Daily badge ---- */
.mt-daily-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--mt-title-a), var(--mt-title-b));
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

/* ---- Screen game layout ---- */
#screen-game {
    display: flex;
    flex-direction: column;
}

#screen-game.active {
    display: flex;
}

/* Android standalone/PWA: reserve space inside gameplay chrome itself. */
.pwa-standalone #screen-game {
    padding-top: calc(var(--safe-top) + var(--gameplay-top-inset, 0px));
    padding-bottom: calc(var(--safe-bottom) + var(--gameplay-bottom-inset, 0px));
}

.pwa-standalone #screen-game .gp-footer-gameplay {
    display: none;
}

#mt-debug-overlay {
    display: none;
    position: fixed;
    top: calc(var(--mt-debug-target-top, 0px) + 12px);
    left: 12px;
    right: 12px;
    z-index: 1000;
    max-width: min(360px, calc(100vw - 24px));
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    background: rgba(9, 11, 28, 0.84);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    pointer-events: none;
}

@media (min-width: 440px) {
    #mt-debug-overlay {
        left: auto;
    }
}

.mt-debug-title {
    margin-bottom: 6px;
    color: #ffe04a;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.1px;
    text-transform: uppercase;
}

#mt-debug-output {
    margin: 0;
    color: #fff;
    font-size: 11px;
    line-height: 1.45;
    white-space: pre-wrap;
    font-family: Consolas, Menlo, Monaco, monospace;
}

.mt-debug-guide {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    height: 0;
    border-top: 2px dashed transparent;
    pointer-events: none;
    z-index: 999;
    opacity: 0.95;
}

.mt-debug-guide::before {
    position: absolute;
    left: 12px;
    top: -10px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(9, 11, 28, 0.92);
    color: inherit;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

#mt-debug-guide-target-top {
    top: var(--mt-debug-target-top, 0px);
    border-top-color: #94ff72;
    color: #94ff72;
}

#mt-debug-guide-target-top::before {
    content: 'target top';
}

#mt-debug-guide-hud-top {
    top: var(--mt-debug-hud-top, 0px);
    border-top-color: #ff6b7a;
    color: #ff6b7a;
}

#mt-debug-guide-hud-top::before {
    content: 'hud top';
}

#mt-debug-guide-target-bottom {
    top: var(--mt-debug-target-bottom, 0px);
    border-top-color: #ffd85a;
    color: #ffd85a;
}

#mt-debug-guide-target-bottom::before {
    content: 'target bottom';
}

#mt-debug-guide-footer-bottom {
    top: var(--mt-debug-footer-bottom, 0px);
    border-top-color: #4de1ff;
    color: #4de1ff;
}

#mt-debug-guide-footer-bottom::before {
    content: 'footer bottom';
}

/* ---- Daily Leaderboard ---- */
.mt-lb-loading {
    text-align: center;
    color: rgba(255,255,255,0.4);
    padding: 16px;
    font-size: 0.85rem;
}

.mt-lb-entry {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(255,255,255,0.03);
    margin-bottom: 6px;
}

.mt-lb-entry.mt-lb-me {
    background: rgba(10, 189, 227, 0.1);
    border: 1px solid rgba(10, 189, 227, 0.25);
}

.mt-lb-rank {
    font-size: 0.85rem;
    font-weight: 700;
    color: rgba(255,255,255,0.4);
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.mt-lb-entry:nth-child(1) .mt-lb-rank { color: #ffe04a; }
.mt-lb-entry:nth-child(2) .mt-lb-rank { color: #c0c0c0; }
.mt-lb-entry:nth-child(3) .mt-lb-rank { color: #cd7f32; }

.mt-lb-name {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mt-lb-time {
    font-size: 0.8rem;
    color: var(--mt-title-a);
    font-weight: 600;
    flex-shrink: 0;
}

.mt-lb-hints {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    flex-shrink: 0;
}
