/* Reset & Base */
:root {
    --color-bg: #eff6ff; /* blue-50 */
    --color-primary: #3b82f6; /* blue-500 */
    --color-primary-dark: #2563eb;
    --color-text: #1f2937; /* gray-800 */
    --font-main: 'Fredoka', sans-serif;
}

* {
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-main);
    background-color: #111827; /* gray-900 */
    color: var(--color-text);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Responsive font size base: scales with the smaller screen dimension */
    font-size: clamp(12px, 2.2vmin, 24px); 
	
	 background-image: url("images/bg.png");
    background-size: cover;        /* растягивает красиво */
    background-position: center;   /* центр */
    background-repeat: no-repeat;  /* без тайлов */
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.15); /* лёгкое затемнение */
    z-index: -1;
}


#app {
    width: 100%;
    height: 100%;
    position: relative;
    background-color: var(--color-bg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

@media (min-width: 640px) {
    #app {
        width: auto;
        aspect-ratio: 9/16;
        max-height: 95vh;
        border-radius: 2rem;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    }
}

/* Screens */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    transition: opacity 0.3s ease;
}

.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Loading Screen */
#loading-screen {
    justify-content: center;
    align-items: center;
    z-index: 50;
}

.spinner {
    width: 4em;
    height: 4em;
    border: 0.5em solid #bfdbfe;
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1em;
}

#loading-text {
    color: var(--color-primary);
    font-size: 1.5em;
}

/* Start Screen */
#start-screen {
    justify-content: center;
    align-items: center;
    padding: 2em;
    text-align: center;
}

#game-title {
    font-size: 3em;
    font-weight: 700;
    background: linear-gradient(to right, #2563eb, #9333ea);
    -webkit-background-clip: text;
    color: transparent;
    margin-bottom: 2em;
    line-height: 1.2;
}

.btn-start {
    font-size: 2em;
    padding: 0.8em 2.5em;
    background: linear-gradient(to right, #4ade80, #3b82f6);
    color: white;
    border: none;
    border-radius: 2em;
    font-weight: 700;
    box-shadow: 0 0.2em 0.5em rgba(0,0,0,0.2);
    cursor: pointer;
    transition: transform 0.1s;
}
.btn-start:active { transform: scale(0.95); }

/* Game Screen */
.game-header {
    flex: 0 0 auto; /* Allow height to shrink to content */
    padding: 0.5em 1em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5em;
    background-color: rgba(239, 246, 255, 0.9);
    backdrop-filter: blur(4px);
    z-index: 10;
    min-height: 3.5em;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.stats-container {
    display: flex;
    flex-direction: column;
    gap: 0.2em;
}

.stat-badge {
    background: white;
    padding: 0.2em 0.6em;
    border-radius: 0.5em;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    font-weight: 700;
    font-size: 0.8em;
    color: #4b5563;
    border: 1px solid #f3f4f6;
    white-space: nowrap;
}

.star-badge {
    background: #fef9c3;
    border-color: #fef08a;
    color: #a16207;
    display: flex;
    align-items: center;
    gap: 0.2em;
}

.progress-container {
    flex: 1;
    height: 0.8em;
    background: #e5e7eb;
    border-radius: 9999px;
    overflow: hidden;
    border: 1px solid #d1d5db;
    max-width: 50%; /* Limit width on wide screens */
}

#progress-bar-fill {
    height: 100%;
    background: linear-gradient(to right, #4ade80, #3b82f6);
    width: 0%;
    transition: width 0.5s ease;
}

.btn-circle {
    width: 2.2em;
    height: 2.2em;
    border-radius: 50%;
    background: white;
    border: 0.15em solid #fef08a;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2em;
    box-shadow: 0 0.1em 0.2em rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.1s;
    flex-shrink: 0;
}

.btn-circle:active {
    transform: scale(0.95);
}

.btn-circle.active-hint {
    background: #fef2f2;
    border-color: #fca5a5;
}

/* Canvas Area */
.canvas-wrapper {
    flex: 1 1 auto; /* Grow to fill space, shrink if needed */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5em; /* Small padding to maximize board size */
    position: relative;
    overflow: hidden;
    min-height: 0; /* Crucial for flex child scrolling/shrinking */
}

#phase-title {
    margin: 0 0 0.3em 0;
    font-size: 1.2em;
    color: #1f2937;
    font-weight: 700;
    text-align: center;
    z-index: 5;
    flex-shrink: 0;
}

#board {
    position: relative;
    background: white;
    border-radius: 1em;
    box-shadow: 0 0.5em 1em -0.2em rgba(0, 0, 0, 0.1);
    border: 0.2em dashed #d1d5db;
    overflow: hidden;
    /* Scale logic */
    width: auto;
    height: auto;
    /* Ensure it doesn't overflow parent */
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 4/5;
    touch-action: none;
    flex-shrink: 1; /* Allow shrinking */
}

#game-svg {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
}

/* Footer */
.game-footer {
    flex: 0 0 auto; /* Size based on content */
    background: white;
    border-top-left-radius: 1.5em;
    border-top-right-radius: 1.5em;
    box-shadow: 0 -0.2em 0.5em rgba(0,0,0,0.05);
    padding: 0.5em;
    padding-bottom: 1.5em; /* Safe area for swipe bar */
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 4em; /* Ensure visible */
}

.instruction {
    font-size: 1.2em;
    color: #9ca3af;
    font-weight: 600;
    animation: pulse 2s infinite;
    text-align: center;
    width: 100%;
}

.palette {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4em;
    width: 100%;
    max-width: 30em; /* Prevent stretching too wide */
}

.color-btn {
    width: 2.6em; /* More compact buttons */
    height: 2.6em;
    border-radius: 50%;
    border: 0.2em solid white;
    box-shadow: 0 0.1em 0.2em rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
    flex-shrink: 0;
}

.color-btn.selected {
    transform: scale(1.15);
    border-color: #1f2937;
    z-index: 10;
}

.color-btn.selected::after {
    content: '✓';
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
    font-size: 1.4em;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* Marker - SCALED WITH EM */
.marker {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 50;
    width: 0;
    height: 0;
    font-size: 0.5em; /* Base scale for marker components */
}

.marker-pivot {
    position: relative;
    transform-origin: 0 0; 
    transition: transform 0.1s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.marker.dragging .marker-pivot {
    transform: rotate(-15deg) translateY(-2em);
}

.marker:not(.dragging) .marker-pivot {
    transform: rotate(-45deg);
}

.marker-body {
    position: absolute;
    bottom: 0;
    left: -2em; /* width 4em, so center is -2em */
    width: 4em;
    height: 20em;
}

.marker-top {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 12em;
    background: #1f2937;
    border-top-left-radius: 0.5em;
    border-top-right-radius: 0.5em;
    box-shadow: 0.2em 0.2em 0.5em rgba(0,0,0,0.2);
}

.marker-ring {
    position: absolute;
    top: 12em;
    left: 0;
    width: 100%;
    height: 3em;
    background: #374151;
}

.marker-color-ring {
    position: absolute;
    top: 12em;
    left: 0;
    width: 100%;
    height: 2em;
    opacity: 0.9;
}

.marker-grip {
    position: absolute;
    top: 15em;
    left: 0;
    width: 100%;
    height: 3em;
    background: #1f2937;
    clip-path: polygon(0 0, 100% 0, 80% 100%, 20% 100%);
}

.marker-tip {
    position: absolute;
    top: 18em;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 0.8em solid transparent;
    border-right: 0.8em solid transparent;
    border-top: 2em solid; 
}

.marker-shadow {
    position: absolute;
    top: 0;
    left: 0;
    transform: translate(-50%, -50%);
    width: 1em;
    height: 1em;
    background: rgba(0,0,0,0.2);
    border-radius: 50%;
    filter: blur(0.1em);
}
.marker.dragging .marker-shadow {
    display: none;
}

/* Modals */
.modal {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1em;
}

.modal-content {
    background: white;
    padding: 1.5em;
    border-radius: 1.5em;
    width: 85%;
    max-width: 30em; /* Limit width */
    max-height: 90vh; /* Prevent overflow on landscape */
    overflow-y: auto; /* Scroll if needed */
    text-align: center;
    box-shadow: 0 1em 2em rgba(0, 0, 0, 0.25);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-size: 1em;
}

.modal-emoji {
    font-size: 3.5em;
    margin-bottom: 0.1em;
}

.modal h2, .modal h3 {
    margin: 0.3em 0;
    font-size: 1.5em;
    color: #1f2937;
}

.points-plus {
    color: #ca8a04;
    font-weight: 700;
    font-size: 1.1em;
    margin-bottom: 0.8em;
}

.victory-preview {
    position: relative;
    width: 50%; /* Smaller preview */
    aspect-ratio: 1;
    margin: 0.5em auto;
    background: white;
    border: 0.2em solid #e5e7eb;
    border-radius: 0.5em;
    padding: 0.3em;
    display: flex;
    justify-content: center;
    align-items: center;
}

#victory-image {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.btn-download {
    position: absolute;
    bottom: -0.5em;
    right: -0.5em;
    background: #22c55e;
    color: white;
    border: 0.2em solid white;
    width: 2.2em;
    height: 2.2em;
    font-size: 1em;
}
.btn-download.saved {
    background: #e5e7eb;
    color: #16a34a;
}

.btn-primary {
    background: linear-gradient(to right, #22c55e, #3b82f6);
    color: white;
    font-weight: 700;
    font-size: 1.1em;
    padding: 0.7em 2em;
    border-radius: 2em;
    border: none;
    box-shadow: 0 0.3em 0.6em rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.1s;
    width: 100%;
    margin-top: 0.8em;
}

.btn-primary:active {
    transform: scale(0.95);
}

.btn-primary:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

.btn-green {
    background: linear-gradient(to right, #4ade80, #16a34a);
}

.btn-secondary {
    background: #f3f4f6;
    color: #6b7280;
    font-weight: 700;
    padding: 0.7em;
    border-radius: 0.8em;
    border: none;
    cursor: pointer;
    width: 100%;
    font-size: 0.9em;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.6em;
    margin-top: 1.2em;
}

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
}

.pause-box {
    background: white;
    padding: 1.5em 3em;
    border-radius: 1em;
    font-weight: 700;
    font-size: 1.5em;
    box-shadow: 0 0.5em 1em rgba(0,0,0,0.1);
    animation: pulse 2s infinite;
}

/* Animations */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

html, body {
    overscroll-behavior: none;
    overscroll-behavior-y: none;
    touch-action: none;
}


