:root {
    --primary-color: #FF6B6B;
    --secondary-color: #4ECDC4;
    --accent-color: #FFE66D;
    --dark-color: #2C3E50;
    --light-color: #F7F9FC;
    --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-hover: 0 8px 15px rgba(0,0,0,0.2);
    --border-radius: 16px;
    --font-heading: 'Fredoka One', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-body: 'Nunito', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: var(--font-body);
    background: var(--bg-gradient);
    color: var(--dark-color);
}

/* Prevent scrolling on game page, but allow on menu/landing pages */
body[data-screen="game"] {
    overflow: hidden;
}

body[data-screen="menu"],
body[data-screen="landing"],
body[data-screen="register"] {
    overflow: auto;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 0;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    z-index: 10;
}

/* Landing, Register, Menu Page Styles */
#landing-page, #register-page, #menu-page {
    justify-content: center;
    align-items: center;
    text-align: center;
    background: linear-gradient(135deg, #FF9A9E 0%, #FECFEF 99%, #FECFEF 100%);
}

.menu-header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.menu-header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.menu-legal-links {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    font-weight: 800;
    opacity: 0.72;
}

.menu-legal-links a {
    color: #fff;
    text-decoration: none;
    text-shadow: 0 2px 10px rgba(0,0,0,0.22);
}

.menu-legal-links a:hover {
    text-decoration: underline;
}

.global-legal-links {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.80);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 12px 25px rgba(0,0,0,0.10);
    font-size: 0.86rem;
    font-weight: 800;
    opacity: 0.85;
    pointer-events: auto;
}

.global-legal-links a {
    color: var(--dark-color);
    text-decoration: none;
}

.global-legal-links a:hover {
    text-decoration: underline;
}


/* Main pages (menu/game): smaller + no border */
body[data-screen="menu"] .global-legal-links,
body[data-screen="game"] .global-legal-links {
    right: 12px;
    bottom: 12px;
    padding: 5px 7px;
    font-size: 0.74rem;
    opacity: 0.65;
    background: rgba(255,255,255,0.30);
    border: none;
    box-shadow: none;
    backdrop-filter: blur(6px);
}

/* Never show legal links on the drawing board (avoid covering the canvas) */
body[data-screen="game"] .global-legal-links {
    display: none !important;
}

.landing-content {
    z-index: 2;
    padding: 2rem;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    animation: float 6s ease-in-out infinite;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    max-width: 90%;
}

#landing-page .landing-content {
    padding: 1rem;
    gap: 0.5rem;
    max-width: 400px;
    width: 80%;
}

.login-logo {
    width: 100%;
    max-width: 300px;
    height: auto;
    display: block;
    margin: 0;
    padding: 0 1.5rem;
    box-sizing: border-box;
}

.landing-content.menu-scroll {
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    width: min(720px, 92vw);
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    overscroll-behavior: contain; /* Prevent scroll chaining */
}

.game-title {
    font-family: var(--font-heading);
    font-size: 4rem;
    margin: 0;
    color: var(--primary-color);
    text-shadow: 2px 2px 0px #fff, 4px 4px 0px rgba(0,0,0,0.1);
    letter-spacing: 2px;
    display: inline-flex;
    align-items: flex-end;
    gap: 8px;
}

.title-icon {
    font-size: 1.8rem;
    line-height: 1;
    vertical-align: bottom;
    display: inline-flex;
    align-items: flex-end;
}

.subtitle {
    font-size: 1.5rem;
    margin: 0.5rem 0 1.5rem;
    color: var(--dark-color);
}

.big-button {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 1rem 3rem;
    font-size: 1.5rem;
    font-family: var(--font-heading);
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 6px 0 #3dbbb3, 0 10px 10px rgba(0,0,0,0.2);
    transition: transform 0.1s, box-shadow 0.1s;
    min-width: 200px;
}

.big-button.secondary {
    background: #95a5a6;
    box-shadow: 0 6px 0 #7f8c8d, 0 10px 10px rgba(0,0,0,0.2);
}

.landing-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    align-items: center;
}

.big-button.secondary:active {
    box-shadow: 0 2px 0 #7f8c8d, 0 4px 4px rgba(0,0,0,0.2);
}

.big-button.google-btn {
    background: #DB4437;
    box-shadow: 0 6px 0 #C1351D, 0 10px 10px rgba(0,0,0,0.2);
}

.big-button.google-btn:active {
    box-shadow: 0 2px 0 #C1351D, 0 4px 4px rgba(0,0,0,0.2);
}

.big-button.small-text {
    font-size: 1.2rem;
    padding: 0.8rem 2rem;
    min-width: auto;
}

.big-button:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #3dbbb3, 0 4px 4px rgba(0,0,0,0.2);
}

/* Auth Styles */
.email-auth-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 300px;
}

.auth-input {
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 25px;
    font-size: 1rem;
    font-family: var(--font-body);
    outline: none;
    transition: border-color 0.2s;
    text-align: center;
}

.auth-input:focus {
    border-color: var(--secondary-color);
}

.avatar-picker-section {
    margin: 20px 0;
    width: 100%;
}

.avatar-picker-label {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--dark-color);
    margin-bottom: 12px;
    text-align: center;
    opacity: 0.85;
}

.avatar-picker-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 100%;
    margin: 0 auto;
    padding: 8px;
}

.avatar-picker-item {
    aspect-ratio: 1;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    border: 3px solid transparent;
    background: rgba(255, 255, 255, 0.5);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

.avatar-picker-item:hover {
    transform: scale(1.05);
    border-color: rgba(255, 107, 107, 0.5);
    background: rgba(255, 255, 255, 0.7);
}

.avatar-picker-item.selected {
    border-color: var(--primary-color);
    background: rgba(255, 107, 107, 0.1);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
    transform: scale(1.08);
}

.avatar-picker-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.avatar-picker-custom {
    border-style: dashed;
    border-width: 2px;
}

.avatar-custom-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: rgba(0, 0, 0, 0.3);
    font-weight: 300;
}

.avatar-picker-custom.selected .avatar-custom-placeholder {
    color: var(--primary-color);
}

.avatar-picker-custom img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

@media (max-width: 480px) {
    .avatar-picker-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
}

.auth-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.avatar-picker-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

/* Avatar Drawing Modal */
.avatar-draw-content {
    max-width: 600px;
    padding: 24px;
}

.avatar-draw-toolbar {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 12px;
}

.avatar-draw-colors {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.avatar-color-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.avatar-color-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.avatar-color-btn.active {
    border-color: var(--dark-color);
    box-shadow: 0 0 0 3px rgba(44, 62, 80, 0.3);
    transform: scale(1.15);
}

.avatar-draw-size {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
}

.avatar-draw-size label {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--dark-color);
}

.avatar-draw-size input[type="range"] {
    flex: 1;
    max-width: 200px;
    height: 6px;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.1);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.avatar-draw-size input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.avatar-draw-size input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#avatar-draw-canvas {
    width: 100%;
    max-width: 400px;
    height: 400px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    background: #ffffff;
    cursor: crosshair;
    display: block;
    margin: 0 auto;
    touch-action: none;
}

.avatar-draw-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

@media (max-width: 480px) {
    .avatar-draw-content {
        padding: 16px;
    }
    
    #avatar-draw-canvas {
        max-width: 100%;
        height: 300px;
    }
    
    .avatar-draw-toolbar {
        padding: 12px;
    }
    
    .avatar-color-btn {
        width: 36px;
        height: 36px;
    }
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.8);
    padding: 5px 15px;
    border-radius: 30px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

#menu-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    background: white;
}

#menu-user-name {
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--dark-color);
}

/* Floating Shapes Background */
.floating-shapes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 1;
}

.shape {
    position: absolute;
    opacity: 0.6;
    animation: floatShape 20s infinite linear;
}

.circle {
    width: 100px; height: 100px; background: #FFE66D; border-radius: 50%;
    top: 10%; left: 10%; animation-duration: 25s;
}
.square {
    width: 80px; height: 80px; background: #FF6B6B; border-radius: 10px;
    top: 80%; left: 20%; animation-duration: 30s; transform: rotate(45deg);
}
.triangle {
    width: 0; height: 0; 
    border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 86px solid #4ECDC4;
    top: 30%; left: 80%; animation-duration: 20s;
}
.star {
    width: 60px; height: 60px; background: #C7F464;
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    top: 70%; left: 70%; animation-duration: 28s;
}

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

@keyframes floatShape {
    0% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(20px, 40px) rotate(180deg); }
    100% { transform: translate(0, 0) rotate(360deg); }
}

/* Game Page Styles */
#game-page {
    background: #f0f3f6;
    display: flex;
    flex-direction: column;
}

.game-header {
    height: 80px;
    background: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    z-index: 20;
}

.prompt-container {
    background: var(--accent-color);
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 1.5rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 4px 4px 0 rgba(0,0,0,0.1);
}

.highlight-word {
    color: #D35400;
    text-transform: uppercase;
    font-family: var(--font-heading);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    justify-content: flex-end;
}

.pill-button {
    border: none;
    background: var(--secondary-color);
    color: white;
    font-weight: 900;
    padding: 10px 16px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.12);
}

.pill-button.result {
    background: #3b82f6; /* blue */
}

.pill-button:active {
    transform: translateY(1px);
}

.board-time {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255,255,255,0.9);
    color: #5a3b00;
    font-weight: 900;
    padding: 6px 10px;
    border-radius: 999px;
    box-shadow: 0 6px 14px rgba(0,0,0,0.12);
    font-size: 0.85rem;
    z-index: 6;
}

.board-loading {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.75);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    color: var(--dark-color);
    z-index: 7;
}

.menu-section {
    width: 100%;
    max-width: 520px;
    margin-top: 12px;
}

.menu-section.gallery-section {
    margin-top: 26px; /* push Gallery (My Wall / Match history) a bit lower */
}

.menu-section-title {
    display: none;
}

.legal-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 14px 0 4px;
    font-size: 0.86rem;
    font-weight: 800;
    opacity: 0.72;
}

.legal-links a {
    color: var(--dark-color);
    text-decoration: none;
}

.legal-links a:hover {
    text-decoration: underline;
}

.legal-dot {
    opacity: 0.7;
}

.legal-note {
    opacity: 0.7;
}

.tab-row {
    /* Center "My Wall" in the row */
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    width: 100%;
    align-items: center;
    margin-bottom: 10px;
}

#tab-explore.tab-btn {
    grid-column: 3;
    justify-self: end;
}

.explore-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0,0,0,0.72);
    color: #fff;
    font-weight: 1000;
    font-size: 0.74rem;
    padding: 4px 8px;
    border-radius: 999px;
    box-shadow: 0 8px 18px rgba(0,0,0,0.18);
    border: 1px solid rgba(255,255,255,0.25);
    pointer-events: none;
}

.explore-avatar {
    width: 30px !important;
    height: 30px !important;
    border-radius: 50%;
    background: #fff;
    object-fit: cover;
    box-shadow: 0 10px 22px rgba(0,0,0,0.18);
    border: 2px solid rgba(255,255,255,0.95);
}

.explore-userchip {
    position: static;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    border-radius: 999px;
    background: transparent;
    border: none;
    box-shadow: none;
    pointer-events: none;
    max-width: 70%;
}

.explore-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 6px;
}

.explore-name {
    color: rgba(0,0,0,0.72);
    font-weight: 1000;
    font-size: 0.78rem;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.heart-btn {
    position: static;
    border: none;
    border-radius: 999px;
    padding: 5px 9px;
    font-weight: 1000;
    font-size: 0.8rem;
    color: #fff;
    background: rgba(0,0,0,0.60);
    border: 1px solid rgba(255,255,255,0.20);
    box-shadow: 0 10px 22px rgba(0,0,0,0.18);
    cursor: pointer;
    pointer-events: auto;
}

.heart-btn.active {
    background: rgba(255, 64, 129, 0.92);
    border-color: rgba(255,255,255,0.35);
}

.like-count-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 64, 129, 0.92);
    color: #fff;
    font-weight: 1000;
    font-size: 0.72rem;
    padding: 4px 8px;
    border-radius: 999px;
    box-shadow: 0 8px 18px rgba(0,0,0,0.18);
    border: 1px solid rgba(255,255,255,0.35);
    pointer-events: none;
}

.wall-stats-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
}

.wall-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 3px 7px;
    font-weight: 1000;
    font-size: 0.72rem;
    line-height: 1;
    border: 1px solid rgba(255,255,255,0.30);
    box-shadow: 0 8px 18px rgba(0,0,0,0.10);
}

.wall-score-chip {
    background: rgba(0,0,0,0.62);
    color: #fff;
}

.wall-like-chip {
    background: rgba(255, 64, 129, 0.92);
    color: #fff;
}

.history-item {
    position: relative;
}

.wall-sort-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0 10px;
    justify-content: flex-end;
}

.wall-sort-label {
    display: none;
}

.wall-sort-btn {
    border: none;
    background: rgba(255,255,255,0.82);
    color: var(--dark-color);
    font-weight: 900;
    padding: 7px 12px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 6px 12px rgba(0,0,0,0.08);
    transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
    opacity: 0.9;
}

.wall-sort-btn:active {
    transform: translateY(1px);
}

.wall-sort-btn.active {
    background: var(--secondary-color);
    color: #fff;
    opacity: 1;
}

.wall-sort-select {
    border: none;
    background: rgba(255,255,255,0.82);
    color: var(--dark-color);
    font-weight: 900;
    padding: 7px 12px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 6px 12px rgba(0,0,0,0.08);
    opacity: 0.95;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding-right: 34px;
    background-image:
        linear-gradient(45deg, transparent 50%, rgba(0,0,0,0.55) 50%),
        linear-gradient(135deg, rgba(0,0,0,0.55) 50%, transparent 50%);
    background-position:
        calc(100% - 18px) 52%,
        calc(100% - 12px) 52%;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
}

.tab-btn {
    border: none;
    background: rgba(255,255,255,0.8);
    color: var(--dark-color);
    font-weight: 900;
    padding: 8px 14px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 6px 12px rgba(0,0,0,0.08);
    transform: scale(0.92);
    transition: transform 0.2s ease, background 0.2s ease, opacity 0.2s ease;
    opacity: 0.9;
}

#tab-wall.tab-btn {
    padding: 10px 18px;
    font-size: 1.05rem;
    grid-column: 2;
    justify-self: center;
}

#tab-history.tab-btn {
    grid-column: 1;
    justify-self: start;
}

.tab-btn.active {
    background: var(--secondary-color);
    color: white;
    transform: scale(1.08);
    opacity: 1;
}

.games-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.games-empty {
    opacity: 0.7;
    font-weight: 700;
    padding: 12px;
    background: rgba(255,255,255,0.7);
    border-radius: 16px;
}

.game-card {
    background: rgba(255,255,255,0.92);
    border-radius: 18px;
    padding: 12px 14px;
    box-shadow: 0 6px 12px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.game-card-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
}

.game-card-title {
    font-weight: 900;
    color: var(--dark-color);
}

.game-card-meta {
    opacity: 0.75;
    font-weight: 700;
    font-size: 0.9rem;
}

.game-card-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.mini-btn {
    border: none;
    background: var(--secondary-color);
    color: white;
    padding: 8px 12px;
    border-radius: 14px;
    font-weight: 900;
    cursor: pointer;
}

.mini-btn.result {
    background: #3b82f6; /* blue */
}

.mini-btn.secondary {
    background: #95a5a6;
}

.mini-btn.submitted {
    background: #16a34a; /* green */
}

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

/* Results modal */
#results-modal .modal-content.results-content {
    /* Override generic .modal-content (max-width: 500px) so results can actually be wide */
    width: min(90vw, 1040px) !important;
    max-width: 1040px !important;
    padding: 16px !important;
    position: relative;
    overflow: hidden;
    max-height: 85vh;
    overflow-y: auto; /* allow scrolling if results are tall */
}

.confetti-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.results-stage {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 12px;
    align-items: center;
    margin: 16px 0;
}

/* Single-image mode (My Wall) */
#results-modal.single .results-stage {
    grid-template-columns: 1fr;
}

#results-modal.single h2 {
    display: none; /* hide "Result" title */
}

#results-modal.single .vs-badge {
    display: none;
}

#results-modal.single #result-right {
    display: none;
}

#results-modal.single .result-card {
    border: none !important;
    box-shadow: none !important;
    transform: none !important;
    padding: 6px !important;
    max-width: 1280px;
    margin: 0 auto;
}

#results-modal.single #result-left img {
    aspect-ratio: 16 / 10;
    height: auto;
    max-height: 78vh;
}

.result-card {
    background: #fff;
    border-radius: 16px;
    padding: 10px;
    box-shadow: 0 6px 12px rgba(0,0,0,0.1);
    transform: translateY(8px);
    opacity: 0;
    transition: transform 0.35s ease, opacity 0.35s ease;
    border: 3px solid transparent;
    max-width: 380px;
    justify-self: center;
    text-align: center;
}

.result-card.you {
    box-shadow: 0 10px 18px rgba(0,0,0,0.16);
    transform: translateY(0) scale(1.03);
}

.result-card.you .result-name {
    font-weight: 1000;
    font-size: 1.05rem;
    letter-spacing: 0.2px;
}

.result-card.outcome-win {
    border-color: #16a34a; /* green */
    background: rgba(22, 163, 74, 0.06);
}

.result-card.outcome-lose {
    border-color: #dc2626; /* red */
    background: rgba(220, 38, 38, 0.06);
}

.results-modal-show .result-card {
    transform: translateY(0);
    opacity: 1;
}

.result-player {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 6px;
}

.result-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 3px solid var(--primary-color);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.result-name {
    font-weight: 900;
    text-align: center;
}

.result-judge {
    font-size: 0.9rem;
    font-weight: 800;
    opacity: 0.85;
    margin-bottom: 8px;
    text-align: center;
}

.result-card img:not(.result-avatar) {
    width: 100%;
    /* Prefer width for most drawings (they're usually landscape). */
    aspect-ratio: 16 / 10;
    height: auto;
    max-height: 40vh;
    object-fit: contain; /* keep perspective, don't crop */
    border-radius: 12px;
    background: #fafafa;
    cursor: zoom-in;
}

/* Lightbox */
#image-lightbox .image-lightbox-content {
    max-width: min(92vw, 1100px);
    max-height: 90vh;
    width: min(92vw, 1100px);
    padding: 12px;
    background: rgba(255,255,255,0.96);
    overflow: hidden; /* prevent image from overflowing the modal */
    display: flex;
    flex-direction: column;
    align-items: center;
}

#image-lightbox #lightbox-img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: calc(90vh - 52px); /* leave room for hint */
    object-fit: contain;
    border-radius: 14px;
    background: #fff;
}

#image-lightbox .lightbox-hint {
    margin-top: 8px;
    font-weight: 800;
    opacity: 0.7;
    font-size: 0.9rem;
    text-align: center;
}

.vs-badge {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    background: var(--primary-color);
    color: white;
    padding: 10px 14px;
    border-radius: 999px;
    box-shadow: 2px 2px 0 rgba(0,0,0,0.12);
}

.winner-text {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    margin: 8px 0 14px;
    color: var(--primary-color);
}

.winner-text.win {
    color: #16a34a; /* green */
}

.winner-text.lose {
    color: #dc2626; /* red */
}

.judge-review {
    width: 100%;
    background: rgba(255,255,255,0.92);
    border-radius: 16px;
    padding: 12px 14px;
    box-shadow: 0 6px 12px rgba(0,0,0,0.08);
    margin: 8px 0 6px;
}

.judge-review-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    text-align: center;
}

.judge-review-col {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.judge-review-line {
    font-weight: 800;
    opacity: 0.9;
    margin: 4px 0;
}

.judge-review-label {
    font-weight: 1000;
    opacity: 0.9;
}

.judge-review-overall {
    margin-top: auto; /* keep both "Overall" lines aligned */
    padding-top: 8px;
    font-weight: 1000;
}

.judge-bullets {
    margin: 6px 0 8px 0;
    padding: 0;
    list-style-position: inside;
}

.judge-bullets li {
    margin: 4px 0;
    font-weight: 850;
    opacity: 0.92;
}

.judge-reveal-hidden {
    opacity: 0 !important;
    transform: translateY(6px);
}

.judge-reveal-item {
    transition: opacity 320ms ease, transform 320ms ease;
}

.winner-text.judge-reveal-item {
    transition: opacity 260ms ease, transform 260ms ease;
}

.judge-crit-good {
    color: #16a34a; /* green */
}

.judge-crit-ok {
    color: #ca8a04; /* yellow/amber */
}

.judge-crit-bad {
    color: #dc2626; /* red */
}

.zoom-controls {
    display: flex;
    align-items: center;
    background: #f0f0f0;
    border-radius: 25px;
    padding: 2px;
}

.board-zoom-controls {
    position: absolute;
    left: 12px;
    bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.85);
    border-radius: 16px;
    padding: 8px 10px;
    box-shadow: 0 6px 14px rgba(0,0,0,0.12);
    z-index: 5;
}

.board-zoom-controls #zoom-level {
    margin: 0 6px;
    min-width: 52px;
}

.history-grid {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
}

/* Match history: list rows (no pictures) */
#history-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#history-grid .history-item {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-color: transparent !important; /* no red/green borders in Match history */
}

#history-grid .history-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
    min-width: 0;
}

#history-grid .history-row-title {
    font-weight: 1000;
    color: var(--dark-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#history-grid .history-row-sub {
    font-size: 0.9rem;
    font-weight: 800;
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#history-grid .history-row-outcome {
    font-weight: 1000;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(0,0,0,0.06);
    flex: 0 0 auto;
}

#history-grid .history-row-outcome.won {
    background: rgba(22, 163, 74, 0.12);
    color: #166534;
}

#history-grid .history-row-outcome.lost {
    background: rgba(220, 38, 38, 0.12);
    color: #991b1b;
}

.history-item {
    background: rgba(255,255,255,0.92);
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 6px 12px rgba(0,0,0,0.08);
    cursor: pointer;
    border: 3px solid transparent;
}

.history-item.won {
    border-color: #16a34a; /* green */
}

.history-item.lost {
    border-color: #dc2626; /* red */
}

.history-item img.tile-img {
    width: 100%;
    height: 120px;
    object-fit: contain;
    border-radius: 10px;
    background: #fafafa;
}

.history-item .history-meta {
    margin-top: 6px;
    font-size: 0.85rem;
    font-weight: 800;
    opacity: 0.8;
}

.you-tag {
    font-weight: 900;
}

#zoom-level {
    font-weight: bold;
    margin: 0 10px;
    min-width: 45px;
    text-align: center;
}

.icon-button {
    background: white;
    border: 2px solid #eee;
    font-size: 1.5rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-button:hover {
    background: #f9f9f9;
    transform: scale(1.1);
}

.icon-button.small {
    width: 30px;
    height: 30px;
    font-size: 1rem;
    border: none;
    background: rgba(255,255,255,0.5);
}

.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    margin: 0 20px;
    background: white;
    border-radius: 20px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
    cursor: crosshair;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brush-preview {
    position: absolute;
    left: 0;
    top: 0;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,0.5);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 8;
    display: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

#drawing-board {
    display: block;
    /* Canvas is now sized via JS to fit, but we might transform it */
    transform-origin: 0 0; /* Changed from center for easier panning/zooming calculations */
    transition: transform 0.05s linear; /* Faster/smoother for panning */
    box-shadow: 0 0 10px rgba(0,0,0,0.1); /* To see edges when zoomed out */
}

/* Cursor states */
.canvas-container.tool-hand {
    cursor: grab;
}
.canvas-container.tool-hand.grabbing,
.canvas-container.tool-hand:active {
    cursor: grabbing;
}
.canvas-container.tool-pen {
    cursor: crosshair;
}

/* Tools Panel */
.tools-panel {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.08) 100%);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    height: 70px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 20px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1), inset 0 1px 0 rgba(255,255,255,0.4), inset 0 -1px 0 rgba(255,255,255,0.1);
    z-index: 60; /* above board */
    overflow: visible; /* don't clip hover menus */
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 14px 14px 0 0;
    border: 1px solid rgba(255,255,255,0.3);
    border-bottom: none;
    min-width: fit-content;
}

/* Bottom Right Actions Panel (Settings, Undo, Redo, Clear) */
.bottom-actions-panel {
    position: fixed;
    bottom: 14px;
    right: 14px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    padding: 5px 6px;
    box-shadow: 0 3px 12px rgba(0,0,0,0.12);
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 2px;
    border: 1px solid rgba(0,0,0,0.08);
}

.bottom-actions-panel .tool-btn {
    width: 30px;
    height: 30px;
    padding: 5px;
}

.bottom-actions-panel .tool-btn svg {
    width: 16px;
    height: 16px;
}

/* Pen Properties Panel */
.pen-properties-panel {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px 0 0 12px;
    padding: 0;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    z-index: 50;
    min-width: 160px;
    width: 160px;
    display: flex;
    flex-direction: column;
    transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.pen-properties-panel.collapsed {
    min-width: 40px;
    width: 40px;
    cursor: pointer;
}

.properties-content {
    padding: 15px 12px 15px 12px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1) 0.05s, transform 0.25s cubic-bezier(0.4, 0, 0.2, 1) 0.05s, visibility 0s 0.3s;
    visibility: visible;
    will-change: opacity, transform;
}

.pen-properties-panel.collapsed .properties-content {
    opacity: 0;
    transform: translateX(8px);
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s 0.2s;
}

/* Ensure content is visible when not collapsed, preventing flash */
.pen-properties-panel:not(.collapsed) .properties-content {
    opacity: 1 !important;
    transform: translateX(0) !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

/* Prevent content from being hidden during transition */
.pen-properties-panel .properties-content {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.properties-collapse-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    flex-shrink: 0;
}

.pen-properties-panel.collapsed .properties-collapse-btn {
    transform: translateX(0);
}

.properties-collapse-btn:hover {
    background: rgba(0, 0, 0, 0.2);
}

.properties-content {
    padding: 15px 12px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.properties-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.properties-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--dark-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.properties-colors {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding-right: 0;
    margin-right: 0;
}

.properties-color-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 2px solid rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.properties-color-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.properties-color-btn.active {
    border-color: #000000;
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.3);
}

.properties-size-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(0,0,0,0.1);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.properties-size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

.properties-size-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.4);
}

.properties-size-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

.properties-size-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 2px 8px rgba(255, 107, 107, 0.4);
}

.properties-fill-options {
    display: flex;
    gap: 8px;
}

.properties-fill-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid rgba(0,0,0,0.1);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.properties-fill-btn svg {
    width: 24px;
    height: 24px;
    color: var(--dark-color);
}

.properties-fill-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.properties-fill-btn.active {
    border-color: var(--primary-color);
    background: rgba(255, 107, 107, 0.1);
    box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.3);
}

.properties-density-options {
    display: flex;
    gap: 6px;
    padding: 0;
    margin: 4px 0;
    padding-right: 0;
    margin-right: 0;
}

.properties-density-btn {
    flex: 1;
    padding: 6px 8px;
    border: 2px solid rgba(0,0,0,0.1);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.properties-density-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.properties-density-btn.active {
    border-color: var(--primary-color);
    background: rgba(255, 107, 107, 0.1);
    box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.3);
    color: var(--primary-color);
}

.properties-pen-types {
    display: flex;
    gap: 6px;
    padding-right: 0;
    margin-right: 0;
}

.properties-layer-controls {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid rgba(0,0,0,0.1);
}

.properties-layer-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.properties-layer-btn {
    flex: 1;
    padding: 6px;
    border: 2px solid rgba(0,0,0,0.1);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.properties-layer-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    color: var(--dark-color);
}

.properties-layer-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    border-color: var(--primary-color);
}

.properties-head-options {
    display: flex;
    gap: 8px;
}

.properties-head-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid rgba(0,0,0,0.1);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.properties-head-btn svg {
    width: 24px;
    height: 24px;
    color: var(--dark-color);
}

.properties-head-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.properties-head-btn.active {
    border-color: var(--primary-color);
    background: rgba(255, 107, 107, 0.1);
    box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.3);
}

.properties-pen-type-btn {
    flex: 1;
    min-width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 2px solid rgba(0,0,0,0.1);
    background: rgba(0,0,0,0.05);
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.properties-pen-type-btn:hover {
    background: rgba(0,0,0,0.1);
    transform: scale(1.05);
}

.properties-pen-type-btn.active {
    border-color: var(--primary-color);
    background: rgba(255, 107, 107, 0.1);
    box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.3);
}

.properties-add-color-btn {
    width: 100%;
    height: 32px;
    border-radius: 6px;
    border: 2px dashed rgba(0,0,0,0.2);
    background: rgba(0,0,0,0.05);
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    color: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-top: 4px;
}

.properties-add-color-btn:hover {
    background: rgba(0,0,0,0.1);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: scale(1.02);
}

.properties-opacity-value {
    text-align: center;
    font-size: 11px;
    color: rgba(0,0,0,0.6);
    margin-top: 4px;
    font-weight: 600;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Color Palette */
.colors {
    display: none; /* Hidden from toolbar */
}

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

.color-btn {
    width: 32px;
    height: 32px;
    min-width: 32px; /* Prevent shrinking */
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    cursor: pointer;
    transition: transform 0.2s;
    position: relative;
}

.color-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: none;
    background: rgba(0,0,0,0.65);
    color: white;
    font-weight: 1000;
    line-height: 18px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}

.color-btn:hover .color-remove {
    display: flex;
}
.color-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 12px;
}

.color-btn::after {
    /* content: attr(data-key); */ /* Shortcuts hidden */
    position: absolute;
    left: 50%;
    bottom: -14px;
    transform: translateX(-50%);
    font-size: 0.6rem;
    font-weight: 1000;
    color: rgba(0,0,0,0.6);
    opacity: 0.8;
    pointer-events: none;
    line-height: 1;
}


.color-btn:hover {
    transform: scale(1.1);
}

.color-btn.active {
    transform: scale(1.2);
    border-color: #333;
}

.add-btn {
    background: #fff;
    border: 2px dashed #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #888;
}

.add-btn:hover {
    border-color: var(--secondary-color);
    color: var(--secondary-color);
}

/* Size Slider */
.sizes {
    display: none; /* Hidden from toolbar */
}

/* (removed toolbar brush-size preview; preview is shown centered on board while holding slider) */

#size-slider {
    appearance: none;
    -webkit-appearance: none;
    width: 80%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
}

#size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--dark-color);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: transform 0.1s;
}

#size-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

#size-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--dark-color);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Action Tools */
.actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

.tool-btn {
    background: #f5f5f5;
    border: none;
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    stroke: currentColor;
}

.tool-btn::after {
    /* content: attr(data-key); */ /* Shortcuts hidden */
    position: absolute;
    left: 50%;
    bottom: -14px;
    transform: translateX(-50%);
    font-size: 0.6rem;
    font-weight: 1000;
    color: rgba(0,0,0,0.6);
    opacity: 0.8;
    pointer-events: none;
    line-height: 1;
}

.canvas-container.tool-finger {
    cursor: default;
}

.canvas-container.tool-finger.grabbing {
    cursor: grabbing;
}


.canvas-container.tool-shape {
    cursor: crosshair;
}

.finger-selection {
    position: absolute;
    border: 2px dashed rgba(59, 130, 246, 0.95);
    border-radius: 8px;
    background: rgba(59, 130, 246, 0.06);
    box-shadow: 0 10px 18px rgba(0,0,0,0.12);
    /* Let drag-to-move pass through to the canvas; only handles/buttons should be interactive */
    pointer-events: none;
    touch-action: none;
    z-index: 8;
}

.finger-toolbar {
    position: absolute;
    top: -34px;
    right: 0;
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

.finger-toolbar.stack {
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    top: -72px; /* room for two rows above selection */
}

.finger-toolbar-row {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.finger-toolbtn {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: none;
    background: rgba(255,255,255,0.95);
    box-shadow: 0 8px 16px rgba(0,0,0,0.16);
    cursor: pointer;
    font-weight: 1000;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.finger-toolbtn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    color: var(--dark-color);
}

.finger-toolbtn-danger {
    background: rgba(255, 240, 240, 0.98);
}

.help-btn {
    position: absolute;
    left: 12px;
    bottom: 12px;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: none;
    background: rgba(255,255,255,0.92);
    box-shadow: 0 10px 18px rgba(0,0,0,0.14);
    cursor: pointer;
    font-weight: 1000;
    z-index: 12; /* above canvas + board overlays */
}

.help-modal-content {
    max-width: 520px;
    max-height: 80vh;
    overflow-y: scroll !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    pointer-events: auto;
}

.help-section {
    width: 100%;
    margin: 10px 0 14px;
}

.help-section-title {
    font-weight: 1000;
    opacity: 0.85;
    margin: 4px 0 8px;
    text-align: left;
}

.help-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

@media (min-width: 520px) {
    .help-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
}

.help-item {
    display: grid;
    grid-template-columns: 28px auto 1fr;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.75);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 14px;
    padding: 10px 12px;
    text-align: left;
}

.help-icon {
    font-size: 1.15rem;
    line-height: 1;
}

.help-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 1000;
    font-size: 0.82rem;
    padding: 4px 8px;
    border-radius: 10px;
    background: rgba(0,0,0,0.08);
    color: rgba(0,0,0,0.82);
    white-space: nowrap;
}

.help-text {
    font-weight: 800;
    opacity: 0.9;
}

.finger-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    background: rgba(59, 130, 246, 0.95);
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    pointer-events: auto;
}
.finger-handle.nw { left: -5px; top: -5px; cursor: nwse-resize; }
.finger-handle.ne { right: -5px; top: -5px; cursor: nesw-resize; }
.finger-handle.sw { left: -5px; bottom: -5px; cursor: nesw-resize; }
.finger-handle.se { right: -5px; bottom: -5px; cursor: nwse-resize; }
.finger-handle.n { left: 50%; top: -5px; transform: translateX(-50%); cursor: ns-resize; }
.finger-handle.s { left: 50%; bottom: -5px; transform: translateX(-50%); cursor: ns-resize; }
.finger-handle.w { left: -5px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.finger-handle.e { right: -5px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

/* Pen wrapper removed - pen type menu removed */

.shape-wrapper {
    position: relative;
    display: inline-flex;
}

.shape-menu {
    position: absolute;
    left: 50%;
    bottom: 56px;
    transform: translateX(-50%);
    display: none;
    flex-direction: row;
    gap: 8px;
    padding: 8px;
    background: rgba(255,255,255,0.95);
    border-radius: 14px;
    box-shadow: 0 10px 22px rgba(0,0,0,0.18);
    z-index: 2000;
}

.shape-wrapper:hover .shape-menu,
.shape-wrapper.open .shape-menu {
    display: flex;
}

.shape-menu::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -10px;
    height: 12px;
}

.shape-option {
    position: relative;
    border: none;
    background: rgba(0,0,0,0.06);
    width: 74px;
    height: 56px;
    padding: 6px 8px;
    border-radius: 12px;
    font-weight: 900;
    cursor: pointer;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
}

.shape-option.active {
    background: var(--secondary-color);
    color: white;
}

.shape-icon { font-size: 1.15rem; line-height: 1; }
.shape-name { font-size: 0.72rem; font-weight: 1000; opacity: 0.85; line-height: 1; }
/* Pen type menu removed */

.pen-type-option {
    border: none;
    background: rgba(0,0,0,0.06);
    width: 74px;
    height: 56px;
    padding: 6px 8px;
    border-radius: 12px;
    font-weight: 900;
    cursor: pointer;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    position: relative; /* anchor ::after shortcut badge to each option */
}

.pen-type-option.active {
    background: var(--secondary-color);
    color: white;
}

.pen-type-icon {
    font-size: 1.15rem;
    line-height: 1;
}

.pen-type-name {
    font-size: 0.72rem;
    font-weight: 1000;
    opacity: 0.85;
    line-height: 1;
}

.tool-btn:hover {
    background: #e0e0e0;
}

.tool-btn.active {
    background: var(--secondary-color);
    color: white;
}

.tool-btn.delete {
    color: #e74c3c;
}

.divider {
    width: 2px;
    height: 30px;
    background: #eee;
    margin: 0 5px;
}

/* (removed bottom-toolbar item actions; actions live near the selection overlay) */

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: 20px 0;
}

/* Front loading overlay */
.front-loading {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #FF9A9E 0%, #FECFEF 99%, #FECFEF 100%);
    overflow: hidden;
}

.front-loading-floats {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.front-loading-sparkles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.sparkle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    box-shadow: 
        0 0 8px rgba(255, 255, 255, 0.8),
        0 0 16px rgba(255, 154, 158, 0.6);
    animation: sparkleFloat 4s ease-in-out infinite;
}

.sparkle-1 { left: 15%; top: 25%; animation-delay: 0s; }
.sparkle-2 { left: 85%; top: 30%; animation-delay: 0.7s; }
.sparkle-3 { left: 20%; top: 70%; animation-delay: 1.4s; }
.sparkle-4 { left: 75%; top: 65%; animation-delay: 2.1s; }
.sparkle-5 { left: 50%; top: 15%; animation-delay: 0.3s; }
.sparkle-6 { left: 45%; top: 85%; animation-delay: 1.8s; }

@keyframes sparkleFloat {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.3;
    }
    25% {
        transform: translate(15px, -20px) scale(1.3);
        opacity: 1;
    }
    50% {
        transform: translate(-10px, -35px) scale(0.8);
        opacity: 0.6;
    }
    75% {
        transform: translate(20px, -15px) scale(1.2);
        opacity: 0.9;
    }
}

.front-float {
    position: absolute;
    opacity: 0.4;
    filter: blur(1px);
    animation: frontFloatShape 8s ease-in-out infinite;
}

.front-float.circle {
    width: 80px; height: 80px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.6);
    left: 8%;
    top: 15%;
    animation-duration: 9s;
    animation-delay: 0s;
    box-shadow: 0 8px 24px rgba(255, 255, 255, 0.3);
}

.front-float.square {
    width: 70px; height: 70px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.5);
    right: 10%;
    top: 20%;
    animation-duration: 10s;
    animation-delay: 1s;
    box-shadow: 0 8px 24px rgba(255, 255, 255, 0.25);
}

.front-float.triangle {
    width: 0; height: 0;
    border-left: 40px solid transparent;
    border-right: 40px solid transparent;
    border-bottom: 70px solid rgba(255, 255, 255, 0.55);
    left: 12%;
    bottom: 15%;
    animation-duration: 11s;
    animation-delay: 2s;
    filter: drop-shadow(0 8px 16px rgba(255, 255, 255, 0.3));
}

.front-float.star {
    width: 72px; height: 72px;
    background: rgba(255, 255, 255, 0.5);
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    right: 15%;
    bottom: 12%;
    animation-duration: 12s;
    animation-delay: 0.5s;
    box-shadow: 0 8px 24px rgba(255, 255, 255, 0.3);
}

@keyframes frontFloatShape {
    0%, 100% { 
        transform: translate(0, 0) rotate(0deg) scale(1);
        opacity: 0.4;
    }
    25% { 
        transform: translate(20px, -25px) rotate(15deg) scale(1.1);
        opacity: 0.6;
    }
    50% { 
        transform: translate(-15px, -40px) rotate(-10deg) scale(0.95);
        opacity: 0.5;
    }
    75% { 
        transform: translate(25px, -20px) rotate(20deg) scale(1.05);
        opacity: 0.55;
    }
}

.front-loading-card {
    width: min(92vw, 520px);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px) saturate(180%);
    border-radius: 28px;
    padding: 32px 28px 28px;
    box-shadow: 
        0 20px 60px rgba(255, 154, 158, 0.25),
        0 8px 24px rgba(0, 0, 0, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.6);
    animation: frontCardFadeIn 0.6s ease-out;
}

@keyframes frontCardFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.front-loading-card::before {
    content: "";
    position: absolute;
    inset: -60px;
    background:
        radial-gradient(120px 120px at 20% 25%, rgba(255, 255, 255, 0.4), transparent 60%),
        radial-gradient(100px 100px at 80% 30%, rgba(255, 200, 220, 0.5), transparent 60%),
        radial-gradient(90px 90px at 50% 75%, rgba(255, 180, 200, 0.35), transparent 60%);
    filter: blur(40px);
    opacity: 0.8;
    animation: frontFloatBg 8s ease-in-out infinite;
    pointer-events: none;
}

.front-loading-card::after {
    content: "";
    position: absolute;
    inset: 0;
    background: 
        radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 70% 80%, rgba(255, 200, 220, 0.2) 0%, transparent 50%);
    border-radius: 28px;
    pointer-events: none;
    animation: frontShimmer 4s ease-in-out infinite;
}

@keyframes frontFloatBg {
    0%, 100% { 
        transform: translate(0, 0) scale(1);
        opacity: 0.8;
    }
    50% { 
        transform: translate(15px, -20px) scale(1.1);
        opacity: 1;
    }
}

@keyframes frontShimmer {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

.front-loading-brand {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    margin-bottom: 2px;
    z-index: 1;
}

.front-loading-logo {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: 1.8rem;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 240, 250, 0.9));
    box-shadow: 
        0 12px 32px rgba(255, 154, 158, 0.3),
        0 4px 12px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.8);
    animation: frontLogoPulse 2s ease-in-out infinite;
    z-index: 2;
}

@keyframes frontLogoPulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 
            0 12px 32px rgba(255, 154, 158, 0.3),
            0 4px 12px rgba(0, 0, 0, 0.1),
            inset 0 1px 0 rgba(255, 255, 255, 0.9);
    }
    50% { 
        transform: scale(1.08);
        box-shadow: 
            0 16px 40px rgba(255, 154, 158, 0.4),
            0 6px 16px rgba(0, 0, 0, 0.12),
            inset 0 1px 0 rgba(255, 255, 255, 0.9);
    }
}

.front-loading-brand-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

.front-loading-app {
    font-family: var(--font-heading);
    font-size: 1.6rem;
    color: var(--dark-color);
    letter-spacing: 0.4px;
    line-height: 1.05;
    text-shadow: 0 2px 8px rgba(255, 255, 255, 0.8);
    animation: frontTitleGlow 3s ease-in-out infinite;
    display: inline-flex;
    align-items: flex-end;
    gap: 6px;
}

.front-loading-app .title-icon {
    font-size: 0.9rem;
    line-height: 1;
    vertical-align: bottom;
    display: inline-flex;
    align-items: flex-end;
}

@keyframes frontTitleGlow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

.front-loading-tagline {
    font-weight: 900;
    font-size: 0.92rem;
    opacity: 0.75;
}

.front-spinner {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 4px solid rgba(255, 154, 158, 0.2);
    border-top-color: rgba(255, 154, 158, 0.9);
    border-right-color: rgba(254, 207, 239, 0.7);
    animation: frontSpin 1s cubic-bezier(0.68, -0.55, 0.265, 1.55) infinite;
    z-index: 2;
    box-shadow: 0 4px 12px rgba(255, 154, 158, 0.2);
}

@keyframes frontSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.front-loading-title {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    color: var(--dark-color);
    z-index: 2;
    text-shadow: 0 2px 6px rgba(255, 255, 255, 0.6);
}

.front-loading-dots::after {
    content: "";
    display: inline-block;
    width: 22px;
    text-align: left;
    margin-left: 2px;
    animation: frontDots 1.1s steps(4, end) infinite;
}

@keyframes frontDots {
    0% { content: ""; }
    25% { content: "."; }
    50% { content: ".."; }
    75% { content: "..."; }
    100% { content: ""; }
}

.front-loading-sub {
    font-weight: 800;
    opacity: 0.75;
    font-size: 0.95rem;
    z-index: 1;
}

.front-loading-bar {
    width: 100%;
    height: 8px;
    background: rgba(255, 154, 158, 0.15);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 8px;
    z-index: 2;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.front-loading-bar-fill {
    height: 100%;
    width: 50%;
    background: linear-gradient(
        90deg,
        rgba(255, 154, 158, 0.0),
        rgba(255, 154, 158, 0.8),
        rgba(254, 207, 239, 0.9),
        rgba(255, 154, 158, 0.7),
        rgba(255, 154, 158, 0.0)
    );
    border-radius: 999px;
    animation: frontBar 1.4s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    box-shadow: 0 0 12px rgba(255, 154, 158, 0.4);
}

@keyframes frontBar {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
}

@media (prefers-reduced-motion: reduce) {
    .front-spinner,
    .front-loading-bar-fill,
    .front-loading-card::before,
    .front-float {
        animation: none !important;
    }
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: #fefefe;
    padding: 20px;
    border-radius: 20px;
    width: 80%;
    max-width: 500px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.prompt-modal-content {
    max-width: 520px;
}

.prompt-modal-text {
    font-family: var(--font-heading);
    font-size: 1.9rem;
    line-height: 1.1;
    margin: 10px 0 6px;
    color: var(--dark-color);
}

.prompt-modal-sub {
    font-size: 0.95rem;
    font-weight: 800;
    opacity: 0.72;
    margin-bottom: 12px;
}

.prompt-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.prompt-modal-actions .big-button.secondary {
    background: rgba(255,255,255,0.95);
    color: var(--dark-color);
    box-shadow: 0 6px 0 rgba(0,0,0,0.10), 0 10px 10px rgba(0,0,0,0.12);
}

@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal h2 {
    font-family: var(--font-heading);
    color: var(--dark-color);
    margin-top: 0;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 10px;
    margin: 20px 0;
    max-height: 300px;
    overflow-y: auto;
    padding: 5px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .game-title { font-size: 3rem; }
    .landing-buttons { flex-direction: column; }
    .tools-panel { 
        height: auto; 
        padding: 10px; 
        flex-direction: column; 
        gap: 10px;
    }
    .tool-group { width: 100%; justify-content: center; }
    .bottom-actions-panel {
        bottom: 10px;
        right: 10px;
        padding: 4px 5px;
    }
    .bottom-actions-panel .tool-btn {
        width: 26px;
        height: 26px;
        padding: 4px;
    }
    .bottom-actions-panel .tool-btn svg {
        width: 14px;
        height: 14px;
    }
    .sizes { border: none; border-top: 1px solid #eee; border-bottom: 1px solid #eee; padding: 10px 0; }
    .canvas-container { margin: 0 10px; }
    .game-header { height: auto; padding: 10px; flex-wrap: wrap; gap: 10px; justify-content: center; }
    .prompt-container { font-size: 1.2rem; order: 3; width: 100%; justify-content: center; }
    .colors { justify-content: flex-start; }
    .header-controls { order: 2; width: 100%; justify-content: space-between; }
    #back-btn { order: 1; }
    
    .menu-header { padding: 10px; }
}
