/* DunceAI - Tangram Teasers Styles */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-orange: #FF6B35;
    --primary-yellow: #FFD23F;
    --primary-blue: #3D5A80;
    --primary-teal: #35A7A7;
    --success-green: #4CAF50;
    --error-red: #E74C3C;
    --bg-cream: #FFF8E7;
    --text-dark: #2C3E50;
    --shadow: 0 4px 15px rgba(0,0,0,0.1);

    /* Tangram colors */
    --shape-red: #E74C3C;
    --shape-blue: #3498DB;
    --shape-green: #2ECC71;
    --shape-yellow: #F39C12;
    --shape-purple: #9B59B6;
    --shape-teal: #1ABC9C;
    --shape-pink: #E91E63;
}

body {
    font-family: 'Segoe UI', 'Comic Sans MS', Tahoma, sans-serif;
    background: linear-gradient(135deg, var(--bg-cream) 0%, #E8E0D5 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.game-container {
    background: white;
    border-radius: 24px;
    box-shadow: var(--shadow), 0 0 0 4px var(--primary-orange);
    max-width: 950px;
    width: 100%;
    padding: 24px;
    position: relative;
    overflow: hidden;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
}

.logo-dunce {
    color: var(--primary-orange);
}

.logo-ai {
    color: var(--primary-blue);
}

.game-header h1 {
    color: var(--text-dark);
    font-size: 1.4rem;
}

/* Intro Screen */
.intro-screen {
    text-align: center;
    padding: 40px 20px;
}

.intro-content {
    max-width: 400px;
    margin: 0 auto;
}

.intro-tangram {
    animation: spin-slow 8s linear infinite;
}

@keyframes spin-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.intro-content h2 {
    color: var(--primary-blue);
    font-size: 1.4rem;
    margin: 20px 0 30px;
    line-height: 1.5;
}

.mode-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-mode {
    background: linear-gradient(135deg, var(--primary-blue) 0%, #2C4A6E 100%);
    color: white;
    box-shadow: 0 4px 0 #1E3A5F;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 120px;
}

.btn-mode:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #1E3A5F;
}

.mode-title {
    font-size: 1.3rem;
}

.mode-desc {
    font-size: 0.85rem;
    opacity: 0.8;
    margin-top: 4px;
}

.btn-back {
    background: #EEE;
    color: var(--text-dark);
    padding: 10px 20px;
}

.btn-back:hover {
    background: #DDD;
}

.btn-rotate {
    background: var(--primary-teal);
    color: white;
    padding: 12px;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-rotate:hover {
    background: #2D9090;
    transform: scale(1.1);
}

.btn-rotate:disabled {
    background: #CCC;
    cursor: not-allowed;
    transform: none;
}

.btn-next {
    background: linear-gradient(135deg, var(--success-green) 0%, #45A049 100%);
    color: white;
    box-shadow: 0 4px 0 #2E7D32;
}

.btn-next:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #2E7D32;
}

.btn-secondary {
    background: #EEE;
    color: var(--text-dark);
}

.btn-secondary:hover {
    background: #DDD;
}

/* Puzzle Select Screen */
.puzzle-screen {
    padding: 10px;
}

.puzzle-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.puzzle-header h2 {
    color: var(--primary-blue);
    font-size: 1.2rem;
}

.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
    padding: 10px;
}

.puzzle-thumb {
    aspect-ratio: 1;
    background: #F5F5F5;
    border: 3px solid var(--primary-blue);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.puzzle-thumb:hover {
    transform: scale(1.05);
    border-color: var(--primary-orange);
}

.puzzle-thumb.completed {
    border-color: var(--success-green);
}

.puzzle-thumb.completed::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: var(--success-green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.puzzle-thumb .puzzle-num {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-blue);
}

/* Game Screen */
.game-screen {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.game-controls-top {
    display: flex;
    align-items: center;
    gap: 20px;
}

.puzzle-label {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--primary-blue);
}

.game-layout {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

/* Shape Panel */
.shape-panel {
    width: 240px;
    flex-shrink: 0;
}

.shape-panel h3 {
    color: var(--primary-blue);
    font-size: 1rem;
    margin-bottom: 10px;
    text-align: center;
}

.shapes-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: #F5F5F5;
    border-radius: 12px;
    padding: 10px;
    min-height: 300px;
    max-height: 500px;
    overflow-y: auto;
    align-items: start;
    justify-items: center;
}

.shapes-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.shape-piece {
    cursor: grab;
    transition: transform 0.1s ease;
    position: relative;
}

.shape-piece:hover {
    transform: scale(1.05);
}

.shape-piece.selected {
    outline: 3px solid var(--primary-orange);
    outline-offset: 2px;
    border-radius: 4px;
}

.shape-piece.dragging {
    position: fixed;
    z-index: 1000;
    cursor: grabbing;
    opacity: 0.9;
    pointer-events: none;
}

.shape-piece.placed {
    display: none;
}

/* Play Area */
.play-area {
    flex: 1;
    display: flex;
    justify-content: center;
}

.grid-container {
    width: 400px;
    height: 400px;
    background: #FAFAFA;
    border: 3px solid var(--primary-blue);
    border-radius: 8px;
    position: relative;
    /* 8x8 grid (50px cells) matching original tangram grid */
    background-image:
        linear-gradient(to bottom, #BBB 1px, transparent 1px),
        linear-gradient(to right, #BBB 1px, transparent 1px);
    background-size: 50px 50px;
    background-position: -1px -1px;
}

.target-layer,
.shapes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.target-layer {
    z-index: 1;
    opacity: 0.5;
}

.shapes-layer {
    z-index: 2;
}

.placed-shape {
    cursor: grab;
    transition: opacity 0.2s;
}

.placed-shape:hover {
    opacity: 0.8;
}

.placed-shape.selected {
    filter: brightness(1.1);
}

/* Controls Panel */
.controls-panel {
    width: 150px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.rotation-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.control-hint {
    text-align: center;
    font-size: 0.85rem;
    color: #666;
}

/* Dunce Panel */
.dunce-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.dunce-character {
    width: 70px;
    transition: transform 0.3s ease;
}

.dunce-svg {
    width: 100%;
    height: auto;
}

.dunce-character.excited {
    animation: dunce-bounce 0.4s ease;
}

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

.speech-bubble {
    background: white;
    border: 2px solid var(--primary-orange);
    border-radius: 12px;
    padding: 10px;
    position: relative;
    box-shadow: var(--shadow);
}

.speech-bubble::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-bottom-color: var(--primary-orange);
}

.speech-bubble::after {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-bottom-color: white;
}

.speech-bubble p {
    color: var(--text-dark);
    line-height: 1.3;
    margin: 0;
    font-size: 0.85rem;
    text-align: center;
}

/* Win Overlay */
.win-overlay {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: rgba(255, 255, 255, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 24px 0 0 24px;
    z-index: 100;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2);
}

.win-overlay.show {
    display: flex;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.win-content {
    background: transparent;
    border-radius: 20px;
    padding: 20px;
    text-align: center;
    animation: popIn 0.4s ease;
}

@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.win-tangram {
    animation: celebrate 0.6s ease-in-out infinite alternate;
}

@keyframes celebrate {
    from { transform: rotate(-5deg); }
    to { transform: rotate(5deg); }
}

/* Master Badge */
.master-badge {
    display: none;
    margin-bottom: 10px;
}

.master-badge.show {
    display: block;
    animation: badgePop 0.6s ease;
}

@keyframes badgePop {
    0% { transform: scale(0) rotate(-180deg); opacity: 0; }
    50% { transform: scale(1.3) rotate(10deg); }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.master-badge svg {
    filter: drop-shadow(0 4px 8px rgba(255, 107, 53, 0.4));
}

.win-content h2 {
    color: var(--primary-blue);
    margin: 12px 0 8px;
    font-size: 1.3rem;
}

.win-content p {
    color: var(--text-dark);
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.win-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

/* Responsive */
@media (max-width: 750px) {
    .game-layout {
        flex-direction: column;
        align-items: center;
    }

    .shape-panel {
        width: 100%;
    }

    .shapes-container {
        grid-template-columns: 1fr 1fr;
        min-height: auto;
    }

    .shapes-column {
        flex-direction: column;
    }

    .controls-panel {
        width: 100%;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        flex-wrap: wrap;
    }

    .dunce-panel {
        flex-direction: row;
    }

    .grid-container {
        width: 300px;
        height: 300px;
        background-size: 37.5px 37.5px;
    }
}

@media (max-width: 400px) {
    .game-container {
        padding: 16px;
    }

    .grid-container {
        width: 250px;
        height: 250px;
        background-size: 31.25px 31.25px;
    }

    .puzzle-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}
