/* DESIGN SYSTEM CUSTOM PROPERTIES */
:root {
    --bg-dark-start: #080811;
    --bg-dark-end: #121225;
    --accent: #ff6b8b;
    --accent-hover: #ff476f;
    --surface: rgba(22, 22, 45, 0.75);
    --card: rgba(35, 35, 68, 0.45);
    --card-active: rgba(255, 107, 139, 0.15);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.15);
    --text-primary: #f0f2f5;
    --text-secondary: #8e98b0;
    --success: #4ade80;
    --gold: #ffd700;
}

/* GENERAL STYLING */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: radial-gradient(circle at center, var(--bg-dark-end) 0%, var(--bg-dark-start) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

h1, h2, h3, .logo-text, .section-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
}

/* APP WRAPPER */
#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 600px; /* Target mobile-width layout matching the Android app */
    margin: 0 auto;
    background: rgba(10, 10, 20, 0.6);
    border-left: 1px solid var(--glass-border);
    border-right: 1px solid var(--glass-border);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    position: relative;
}

/* APP HEADER */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;
    padding: 0 20px;
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-emoji {
    font-size: 24px;
    filter: drop-shadow(0 0 6px var(--accent));
}

.logo-text {
    font-size: 20px;
    background: linear-gradient(135deg, #fff 30%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* SCREENS */
.screen {
    display: none;
    flex-direction: column;
    flex-grow: 1;
    padding: 16px 16px 80px 16px; /* Space at bottom for float bar */
    animation: fadeIn 0.3s ease-out;
}

.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* SECTIONS */
.panel-section {
    margin-bottom: 24px;
}

.section-title {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    letter-spacing: 0.5px;
}

/* DIFFICULTY TABS */
.difficulty-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.diff-btn {
    background: var(--card);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 10px 4px;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.diff-btn span {
    font-size: 9px;
    opacity: 0.6;
}

.diff-btn:hover {
    background: var(--glass-highlight);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.diff-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 0 15px rgba(255, 107, 139, 0.4);
}

/* CATEGORY SCROLL */
.category-scroll {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none; /* Hide standard Firefox scrollbar */
}

.category-scroll::-webkit-scrollbar {
    display: none; /* Hide Chrome/Safari scrollbar */
}

.category-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 80px;
    height: 94px;
    background: var(--card);
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.category-card:hover {
    background: var(--glass-highlight);
    transform: scale(1.04);
}

.category-card.active {
    background: var(--card-active);
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(255, 107, 139, 0.25);
}

.category-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 6px;
    border: 1px solid var(--glass-border);
}

.category-label {
    font-size: 10px;
    font-weight: 700;
    text-align: center;
    color: var(--text-secondary);
}

.category-card.active .category-label {
    color: var(--accent);
}

/* PUZZLES GRID */
.puzzles-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.puzzle-card {
    background: var(--card);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.puzzle-card:hover {
    transform: translateY(-4px) scale(1.02);
    border-color: var(--glass-highlight);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.puzzle-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 12px rgba(255, 107, 139, 0.3);
}

.puzzle-thumb-container {
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    background: #000;
    position: relative;
}

.puzzle-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

.puzzle-card:hover .puzzle-thumb {
    transform: scale(1.15);
}

.puzzle-info {
    padding: 8px;
    text-align: center;
}

.puzzle-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* FLOAT START BAR */
.start-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 16px 20px;
    background: linear-gradient(to top, rgba(8, 8, 17, 0.95) 75%, transparent);
    z-index: 5;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
}

.btn-primary {
    width: 100%;
    height: 52px;
    background: var(--accent);
    border: none;
    border-radius: 14px;
    color: #fff;
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(255, 107, 139, 0.35);
    transition: all 0.25s ease;
}

.btn-primary:not(:disabled):hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 107, 139, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    background: var(--card);
    color: var(--text-secondary);
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.6;
}

.btn-secondary {
    padding: 10px 18px;
    background: var(--card);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.btn-secondary:hover {
    background: var(--glass-highlight);
    transform: translateY(-1px);
}

.btn-accent {
    padding: 10px 18px;
    background: rgba(255, 215, 0, 0.1);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 12px;
    color: var(--gold);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.btn-accent:hover:not(:disabled) {
    background: rgba(255, 215, 0, 0.2);
    transform: translateY(-1px);
}

.btn-accent:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.icon-button {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--card);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-button:hover {
    background: var(--glass-highlight);
}

/* GAME SCREEN HEADER */
.game-control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.game-stats {
    display: flex;
    gap: 16px;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 16px;
}

#timerText {
    color: var(--accent);
}

/* CANVAS CONTAINER */
.canvas-container {
    width: 100%;
    aspect-ratio: 0.8; /* Height matches mobile gameplay space */
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}

#jigsawCanvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    cursor: grab;
}

#jigsawCanvas:active {
    cursor: grabbing;
}

/* LOADING OVERLAY */
.loading-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(8, 8, 17, 0.85);
    backdrop-filter: blur(8px);
    z-index: 8;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--card);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    filter: drop-shadow(0 0 6px var(--accent));
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* WIN MODAL OVERLAY */
.modal-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(4, 4, 8, 0.8);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 20;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeIn 0.3s ease-out;
}

.win-card {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 30px 24px;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    animation: slideUp 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

@keyframes slideUp {
    to { transform: translateY(0); }
}

.trophy-icon {
    font-size: 56px;
    margin-bottom: 8px;
    filter: drop-shadow(0 0 10px var(--gold));
    animation: float 2.5s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.win-title {
    font-size: 26px;
    margin-bottom: 6px;
    background: linear-gradient(to right, #fff, var(--gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.star-rating {
    font-size: 28px;
    letter-spacing: 4px;
    margin-bottom: 18px;
    filter: drop-shadow(0 0 4px var(--gold));
}

.win-stats-container {
    display: flex;
    gap: 16px;
    width: 100%;
    margin-bottom: 20px;
}

.win-stat-box {
    flex: 1;
    background: var(--card);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 12px;
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-value {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.win-preview-container {
    width: 140px;
    height: 140px;
    border-radius: 16px;
    overflow: hidden;
    border: 2px solid var(--glass-border);
    margin-bottom: 24px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

#winPreviewImage {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.win-actions {
    display: flex;
    gap: 12px;
    width: 100%;
}

.win-actions button {
    flex: 1;
}
