/* DunceAI – Snail Sums */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --orange: #FF6B35;
    --blue:   #3D5A80;
    --cream:  #FFF8E7;
    --green:  #4CAF50;
    --red:    #E74C3C;
    --shadow: 0 4px 15px rgba(0,0,0,0.1);
}

body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: linear-gradient(135deg, var(--cream) 0%, #FFE4C4 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
}

.game-container {
    background: white;
    border-radius: 24px;
    box-shadow: var(--shadow), 0 0 0 4px var(--orange);
    width: 100%;
    max-width: 680px;
    padding: 20px 24px 28px;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}
.logo { font-size: 1.4rem; font-weight: bold; }
.logo-dunce { color: var(--orange); }
.logo-ai    { color: var(--blue); }
.game-header h1 { color: #2C3E50; font-size: 1.3rem; }
.back-link { color: var(--blue); text-decoration: none; font-size: 0.9rem; font-weight: bold; }
.back-link:hover { text-decoration: underline; }

/* ── Intro ── */
#introScreen { text-align: center; padding: 20px 10px 10px; }
.intro-content h2 { color: var(--blue); font-size: 1.5rem; margin: 18px 0 8px; line-height: 1.4; }
.intro-hint { color: #666; font-size: 1rem; margin-bottom: 28px; }
.intro-snails {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

/* ── Score bar ── */
.score-bar {
    display: flex;
    justify-content: space-between;
    background: linear-gradient(135deg, #E8F4FD 0%, #D0E8F8 100%);
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 1rem;
    color: #2C3E50;
    margin-bottom: 14px;
}
.score-item strong { color: var(--blue); font-size: 1.15rem; }

/* ── Field wrapper (green panel) ── */
.field-wrapper {
    border-radius: 16px;
    overflow: hidden;
    border: 3px solid #5a9e2f;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    margin-bottom: 14px;
}
.snail-count, .sum-display {
    text-align: center;
    font-size: 1.1rem;
    font-weight: bold;
    color: #1a4a00;
    background: rgba(255,255,255,0.55);
    padding: 6px 12px;
}
.sum-display:empty { display: none; }

/* ── Field (holds the pens) ── */
.field {
    background: linear-gradient(180deg, #a8d96c 0%, #7bc843 60%, #5a9e2f 100%);
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 16px;
    gap: 0;
    position: relative;
}

/* ── Fenced pens ── */
.pen {
    border: 4px solid #8B4513;
    border-radius: 14px;
    background: rgba(255,255,255,0.28);
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: center;
    align-content: flex-start;
    max-width: 190px;
    min-width: 80px;
    /* Fence post effect at corners via box shadow */
    box-shadow:
        -6px -6px 0 2px #6B3410,
         6px -6px 0 2px #6B3410,
        -6px  6px 0 2px #6B3410,
         6px  6px 0 2px #6B3410,
        0 2px 8px rgba(0,0,0,0.15);
}

.pen-divider {
    font-size: 2.4rem;
    font-weight: bold;
    color: #1a5a00;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    padding: 0 14px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.pen-merged {
    border: 4px solid #8B4513;
    border-radius: 14px;
    background: rgba(255,255,255,0.28);
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: center;
    align-content: flex-start;
    max-width: 340px;
    box-shadow:
        -6px -6px 0 2px #6B3410,
         6px -6px 0 2px #6B3410,
        -6px  6px 0 2px #6B3410,
         6px  6px 0 2px #6B3410,
        0 2px 8px rgba(0,0,0,0.15);
}

/* ── Pen merge animation ── */
@keyframes mergePenLeft {
    from { transform: translateX(0);   opacity: 1; }
    to   { transform: translateX(28px); opacity: 0; }
}
@keyframes mergePenRight {
    from { transform: translateX(0);    opacity: 1; }
    to   { transform: translateX(-28px); opacity: 0; }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}
.pen.merging-a   { animation: mergePenLeft  0.45s ease forwards; }
.pen.merging-b   { animation: mergePenRight 0.45s ease forwards; }
.pen-divider.merging { animation: fadeOut   0.3s ease forwards; }

@keyframes penAppear {
    from { transform: scale(0.82); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}
.pen-merged.appearing { animation: penAppear 0.45s ease forwards; }

/* Snails slide in to merged pen */
@keyframes snailSlide {
    from { transform: translateX(var(--slide)); opacity: 0; }
    to   { transform: translateX(0);            opacity: 1; }
}
.snail.slide-in {
    animation: snailSlide 0.38s ease forwards;
    animation-delay: var(--delay, 0ms);
    opacity: 0;
}

/* ── Grass strip ── */
.field-grass {
    background: #4a8a22;
    height: 14px;
    position: relative;
    overflow: hidden;
}
.field-grass::before {
    content: '';
    position: absolute;
    top: -8px; left: 0; right: 0;
    height: 16px;
    background: repeating-linear-gradient(
        90deg,
        transparent 0px, transparent 10px,
        #4a8a22 10px, #4a8a22 11px,
        transparent 11px, transparent 14px,
        #3d7518 14px, #3d7518 15px
    );
}

/* ── Question box ── */
.question-box {
    background: #ffff99;
    border: 2px solid #000;
    border-radius: 10px;
    padding: 10px 20px;
    text-align: center;
    font-size: 1.2rem;
    color: #330000;
    margin-bottom: 14px;
}

/* ── Answer buttons ── */
.answer-section { margin-bottom: 14px; text-align: center; }
.answer-label { font-size: 1rem; font-weight: bold; color: #444; margin-bottom: 10px; }
.answer-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}
.ans-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 3px solid var(--blue);
    background: white;
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--blue);
    cursor: pointer;
    transition: all 0.15s ease;
}
.ans-btn:hover:not(:disabled) {
    background: var(--blue);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(61,90,128,0.35);
}
.ans-btn:disabled { cursor: not-allowed; }
.ans-btn.correct { background: var(--green);  border-color: #388E3C; color: white; transform: scale(1.15); }
.ans-btn.wrong   { background: var(--red);    border-color: #C0392B; color: white; }
.ans-btn.reveal  { background: var(--green);  border-color: #388E3C; color: white; transform: scale(1.12); }

/* ── Feedback ── */
.feedback-row {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 14px;
}
.result-badge { font-size: 2.2rem; min-width: 48px; text-align: center; padding-top: 6px; }
.dunce-panel  { display: flex; align-items: flex-start; gap: 10px; flex: 1; }
.dunce-character { flex-shrink: 0; }
.speech-bubble {
    background: white;
    border: 2px solid var(--orange);
    border-radius: 12px;
    padding: 10px 14px;
    position: relative;
    font-size: 0.95rem;
    color: #2C3E50;
    flex: 1;
    line-height: 1.4;
}
.speech-bubble::before {
    content: '';
    position: absolute;
    left: -8px; top: 14px;
    border: 6px solid transparent;
    border-right-color: var(--orange);
}
.speech-bubble::after {
    content: '';
    position: absolute;
    left: -5px; top: 15px;
    border: 5px solid transparent;
    border-right-color: white;
}

/* ── Buttons ── */
.btn {
    display: inline-block;
    padding: 12px 28px;
    font-size: 1.1rem;
    font-weight: bold;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    text-align: center;
}
.btn-start {
    background: linear-gradient(135deg, var(--green), #388E3C);
    color: white;
    box-shadow: 0 4px 0 #2E7D32;
}
.btn-start:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #2E7D32; }
.btn-next {
    background: linear-gradient(135deg, var(--blue), #2C4A6E);
    color: white;
    box-shadow: 0 4px 0 #1E3A5F;
    display: block;
    width: 100%;
    text-align: center;
}
.btn-next:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #1E3A5F; }
.btn-back-home {
    background: linear-gradient(135deg, #888, #555);
    color: white;
    box-shadow: 0 4px 0 #333;
    margin-left: 12px;
}
.btn-back-home:hover { transform: translateY(-2px); box-shadow: 0 6px 0 #333; }

/* ── End screen ── */
#endScreen { text-align: center; padding: 16px 10px 10px; }
.end-content h2   { color: var(--blue); font-size: 1.6rem; margin-bottom: 10px; }
.end-score        { font-size: 1.2rem; margin-bottom: 8px; color: #2C3E50; }
.end-score strong { font-size: 1.5rem; color: var(--orange); }
.end-comment      { font-size: 1rem; color: #555; margin-bottom: 24px; font-style: italic; line-height: 1.5; }
.end-snails {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
