:root {
    --bg-color: #2E3D2F;
    --card-color: #1e1e1e;
    --text-color: #ffffff;
    --text-muted-color: #b3b3b3;
    --correct-color: #1db954;
    --family-color: #57c481;
    --order-color: #f5b123;
    --class-color: #f59b23;
    --phylum-color: #f57d23;
    --incorrect-color: #C75656;
    --grey-node-color: #777777;
    --grey-text-color: #cccccc;
    --font-family: 'Poppins', sans-serif;
}

body[data-theme="colorblind"] {
    --correct-color: #0077b6;
    --family-color: #0096c7;
    --order-color: #90e0ef;
    --class-color: #adb5bd;
    --phylum-color: #6c757d;
    --incorrect-color: #495057;
    --node-check-color: #00b4d8;
    --node-cross-color: #e9ecef;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    min-height: 100vh;
}

#loader {
    position: fixed; left: 50%; top: 50%; z-index: 200;
    width: 50px; height: 50px; border: 5px solid var(--grey-node-color);
    border-top-color: var(--text-color); border-radius: 50%;
    animation: spin 1s linear infinite;
    transform: translate(-50%, -50%);
}
#loader.hidden { display: none; }
@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }

header {
    text-align: center; margin-bottom: 20px;
    position: relative; width: 100%; max-width: 500px;
}
.header-top-row { display: flex; justify-content: space-between; align-items: center; height: 30px; margin-bottom: 10px; }
.header-icons-right { display: flex; align-items: center; gap: 10px; }

#mode-switcher, #help-icon, #stats-icon, #color-theme-switcher, #language-button {
    background: var(--card-color); border: none; padding: 0; font: inherit;
    color: var(--text-muted-color); cursor: pointer; width: 30px; height: 30px;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s, background-color 0.2s;
}
#mode-switcher:hover, #help-icon:hover, #stats-icon:hover, #color-theme-switcher:hover, #language-button:hover {
    transform: scale(1.1); background-color: #3a3a3a;
}
#help-icon { font-weight: 700; color: var(--text-color); }
#stats-icon svg, #mode-switcher svg, #color-theme-switcher svg { width: 18px; height: 18px; }

#language-switcher { position: relative; }
#language-button { font-weight: 700; font-size: 0.8rem; }
#language-button.active { background-color: #555; }
#language-dropdown {
    position: absolute; top: 35px; right: 0; background-color: #1c2a3a;
    border-radius: 8px; padding: 5px; z-index: 20; display: flex;
    flex-direction: column; gap: 5px;
}
#language-dropdown a {
    color: var(--text-color); text-decoration: none; padding: 5px 10px;
    border-radius: 4px; font-weight: 700; font-size: 0.8rem;
}
#language-dropdown a:hover { background-color: #3a4a5a; }

#logo-container { 
    position: relative;
    width: 100%; 
    max-width: 350px; 
    margin: 0 auto 10px auto; 
}
#logo-container img { width: 100%; height: auto; }
#expert-stamp {
    position: absolute;
    bottom: 5px;
    right: -15px;
    width: 110px;
    height: auto;
    transform: rotate(-10deg);
    pointer-events: none;
}
#expert-stamp.hidden { display: none; }
#expert-stamp text {
    font-family: 'Poppins', 'Impact', sans-serif;
    font-weight: 900;
    font-size: 24px;
    fill: white;
    stroke: #1e1e1e;
    stroke-width: 1.5px;
    paint-order: stroke;
}

#subtitle { 
    color: var(--text-muted-color); 
    padding: 0 10px; 
    transition: all 0.5s ease-in-out;
    max-height: 100px;
    overflow: hidden;
}
#subtitle strong em { color: var(--text-color); font-style: italic; }

header.shrunk #subtitle {
    opacity: 0;
    max-height: 0;
    margin: 0;
    padding: 0;
}

main#game-container { 
    width: 100%; 
    max-width: 500px; 
    flex-grow: 1; 
}
#guess-counter-wrapper { height: 20px; margin-bottom: 10px; }
#guess-counter { text-align: right; color: var(--text-muted-color); padding-right: 15px; font-size: 0.9rem; }
#search-section { position: relative; margin-bottom: 15px; }
#guess-input {
    width: 100%; padding: 15px; border-radius: 25px; border: none;
    background-color: var(--card-color); color: var(--text-color);
    font-size: 1rem; font-family: var(--font-family);
}
#guess-input:focus { outline: 2px solid #888; }
.shake { animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake {
    10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); }
    30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); }
}

#search-results {
    position: absolute; width: 100%; background-color: #1c2a3a;
    border-radius: 15px; margin-top: 5px; z-index: 10;
    max-height: 220px; overflow-y: auto; 
}
.search-result-item { padding: 10px 15px; cursor: pointer; }
.search-result-item.highlighted, .search-result-item:hover { background-color: #3a4a5a; }
.search-result-item em { color: var(--text-muted-color); font-size: 0.9rem; }

#color-guide-container {
    display: flex; justify-content: center; gap: 20px; margin-top: 20px;
    margin-bottom: 15px; transition: opacity 0.3s ease-in-out;
    width: 100%; max-width: 500px;
}
.guide-item { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.guide-color-box { width: 25px; height: 25px; border-radius: 5px; transition: background-color 0.3s; }
.guide-item span { font-size: 0.75rem; color: var(--text-muted-color); font-weight: 600; }
.guide-color-box.correct { background-color: var(--correct-color); }
.guide-color-box.close { background-color: var(--order-color); }
.guide-color-box.incorrect { background-color: var(--incorrect-color); }

#guesses-container { display: flex; flex-direction: column; gap: 15px; }
.guess-card { background-color: var(--card-color); border-radius: 15px; padding: 12px; animation: slideIn 0.5s ease-out forwards; }
.guess-header { display: flex; align-items: center; gap: 15px; margin-bottom: 12px; }
.guess-number { margin-left: auto; color: var(--text-muted-color); font-size: 0.9rem; }
.animal-image { width: 100px; height: 100px; border-radius: 12px; object-fit: cover; background-color: #333; }
.animal-name { font-size: 1.5rem; font-weight: 600; }

.attributes-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.attribute-tile {
    background-color: #3a3a3a; border-radius: 10px; padding: 6px;
    color: var(--text-color); transform: rotateY(90deg); opacity: 0;
    display: flex; flex-direction: column; justify-content: center;
    text-align: center; min-width: 0; transition: background-color 0.3s;
}
.taxonomy-tile { grid-column: span 6; padding: 8px; }
[data-attribute="conservation_status"], [data-attribute="lifestyle"] { grid-column: span 3; }
[data-attribute="habitat"], [data-attribute="length"], [data-attribute="weight"] { grid-column: span 2; }
.attribute-tile .label { display: block; margin-bottom: 2px; color: var(--text-color); font-size: 0.75rem; font-weight: 600; }
.attribute-tile .value { font-weight: 600; display: inline-flex; justify-content: center; align-items: center; gap: 0.25em; font-size: 0.85rem; }

.node-container { position: relative; display: flex; flex-direction: column; gap: 4px; padding-top: 2px; }
.node-row { position: relative; display: flex; align-items: center; gap: 10px; opacity: 0; transform: scale(0.9); }
.node-connector {
    position: absolute; top: 12px; left: 11px; width: 2px; height: calc(100% + 4px);
    background-color: var(--grey-node-color); z-index: 1; transform: scaleY(0);
    transform-origin: top; transition: transform 0.2s ease-out, background-color 0.3s ease-out;
}
.node-connector.match { background-color: #ffffff; }
.node-connector.animated { transform: scaleY(1); }
.node-row.visible { animation: popInNode 0.15s ease-out forwards; }
.node { width: 24px; height: 24px; flex-shrink: 0; position: relative; z-index: 2; }
.node-bg { fill: var(--grey-node-color); transition: fill 0.3s; }
.node-icon { fill: none; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 100; stroke-dashoffset: 100; }
.node.match .node-bg { fill: #ffffff; }
.node.match .check { stroke: var(--node-check-color, var(--correct-color)); animation: draw 0.4s 0.1s ease-out forwards; }
.node.mismatch .cross { stroke: var(--node-cross-color, var(--incorrect-color)); animation: draw 0.4s 0.1s ease-out forwards; }
.node-text { font-size: 0.85rem; text-align: left; color: var(--grey-text-color); font-weight: 600; line-height: 1.2; }
.node-text.match { color: var(--text-color); }

.taxonomy-tile.correct { background-color: var(--correct-color); }
.taxonomy-tile.family { background-color: var(--family-color); }
.taxonomy-tile.order { background-color: var(--order-color); }
.taxonomy-tile.class { background-color: var(--class-color); }
.taxonomy-tile.phylum { background-color: var(--phylum-color); }
.taxonomy-tile.incorrect { background-color: var(--incorrect-color); }
.attribute-tile.correct { background-color: var(--correct-color); }
.attribute-tile.close { background-color: var(--order-color); }
.attribute-tile.incorrect { background-color: var(--incorrect-color); }
.value::after { content: ''; font-weight: 700; }
.value.up-1::after { content: '↑'; }
.value.down-1::after { content: '↓'; }

@keyframes slideIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes flipIn { from { transform: rotateY(90deg); opacity: 0; } to { transform: rotateY(0deg); opacity: 1; } }
@keyframes popInNode { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
@keyframes draw { to { stroke-dashoffset: 0; } }

.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.7); display: flex;
    justify-content: center; align-items: center; z-index: 100; padding: 20px;
}
.modal.hidden { display: none; }
.modal-content {
    background-color: var(--card-color); padding: 20px 30px; border-radius: 15px;
    text-align: center; animation: slideIn 0.3s ease-out; display: flex;
    flex-direction: column; align-items: center; max-width: 90%;
    width: 500px; position: relative;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-close-button {
    position: absolute; top: 10px; right: 10px; width: 30px; height: 30px;
    background: #3a3a3a; color: var(--text-muted-color); border: none;
    border-radius: 50%; font-size: 1.5rem; line-height: 1; display: flex;
    align-items: center; justify-content: center; cursor: pointer; padding: 0; margin: 0;
    transition: background-color 0.2s;
}
.modal-close-button:hover { background-color: #555; }
#share-encouragement {
    color: var(--text-muted-color);
    font-size: 0.9rem;
    margin-bottom: 15px;
}
.modal-button-group { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 280px; margin-bottom: 15px; }
#modal-switch-mode-button {
    padding: 10px 20px; border: none; border-radius: 20px; color: var(--card-color);
    font-weight: 700; cursor: pointer; transition: transform 0.2s, background-color 0.2s;
}
#modal-switch-mode-button:hover { transform: scale(1.05); }
#modal-share-button {
    padding: 10px 20px; border: none; border-radius: 20px; font-weight: 700;
    cursor: pointer; transition: transform 0.2s, background-color 0.2s;
    background-color: var(--correct-color); color: #ffffff; display: flex;
    align-items: center; justify-content: center; gap: 8px;
}
#modal-share-button:hover { transform: scale(1.05); }
#modal-share-button svg { stroke: #ffffff; width: 18px; height: 18px; }

#modal-title { font-size: 1.8rem; margin-bottom: 5px; transition: font-size 0.3s, color 0.3s; padding-right: 30px; }
#modal-animal-reveal { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 15px; transition: gap 0.3s, margin-bottom 0.3s; }
#modal-animal-image { width: 160px; height: 160px; border-radius: 16px; object-fit: cover; transition: width 0.3s, height 0.3s; }
.modal-animal-header { display: flex; align-items: center; justify-content: center; gap: 10px; }
#modal-animal-name { font-size: 1.8rem; font-weight: 700; transition: font-size 0.3s; }

#modal-wiki-link {
    background-color: #f9f9f9;
    border-radius: 5px;
    padding: 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}
#modal-wiki-link:hover {
    transform: scale(1.1);
}
#modal-wiki-link svg {
    width: 24px;
    height: 24px;
    display: block;
}
#modal-wiki-link svg path {
    fill: #000000;
}

#modal-text, #modal-streak-text, #play-again-text { color: var(--text-muted-color); font-size: 0.9rem; font-style: normal; font-weight: 400; transition: font-size 0.3s; }
#modal-text { margin-bottom: 15px; }
#modal-streak-text { margin-top: -5px; margin-bottom: 15px; }
#play-again-text { margin-bottom: 15px; }

.modal-streaks-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    margin-bottom: 20px;
    color: var(--text-muted-color);
    font-size: 1.1rem;
    line-height: 1.4;
}
.modal-streaks-container span {
    font-weight: 700;
    color: var(--text-color);
}

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; width: 100%; margin-bottom: 25px; }
.stat-item { text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; }
.stat-label { font-size: 0.8rem; color: var(--text-muted-color); }
.distribution-title { font-size: 1.2rem; margin-bottom: 15px; }
#stats-distribution-container { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.dist-row { display: flex; align-items: center; gap: 10px; }
.dist-label { font-weight: 600; width: 20px; text-align: right; }
.dist-bar-wrapper { flex-grow: 1; background-color: #3a3a3a; border-radius: 4px; }
.dist-bar { background-color: var(--grey-node-color); height: 20px; border-radius: 4px; text-align: right; padding-right: 5px; color: var(--text-color); font-weight: 600; font-size: 0.8rem; white-space: nowrap; }

#help-modal .modal-content { text-align: left; }
#help-modal .modal-title-help { width: 100%; text-align: center; }
#help-modal .help-section { margin-bottom: 20px; }
#help-modal .help-section p { margin-bottom: 5px; }
#help-modal .help-list { list-style-position: inside; padding-left: 10px; margin-top: 5px; }
#help-modal .help-list li { margin-bottom: 2px; line-height: 1.2; }
#help-modal .legend-grid {
    display: grid;
    grid-template-columns: 30px 1fr;
    gap: 10px;
    align-items: center;
    max-width: 250px;
    margin: 15px 0;
}
#help-modal .legend-item {
    width: 25px;
    height: 25px;
    border-radius: 5px;
}
#help-modal .legend-item.correct { background-color: var(--correct-color); }
#help-modal .legend-item.order { background-color: var(--order-color); }
#help-modal .legend-item.incorrect-legend { background-color: var(--incorrect-color); }
#help-modal .legend-grid span { font-weight: 600; }

footer { 
    width: 100%; 
    max-width: 500px; 
    text-align: center; 
    padding: 20px 0 10px 0; 
    color: var(--text-muted-color); 
    font-size: 0.8rem; 
}
footer p {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}
.footer-icon-link {
    color: var(--text-muted-color);
    display: inline-flex;
    align-items: center;
    transition: color 0.2s, transform 0.2s;
}
.footer-icon-link:hover {
    color: var(--text-color);
    transform: scale(1.1);
}
.footer-icon-link svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

.hidden { display: none !important; }

@media (max-width: 480px) {
    .animal-name { font-size: 1.2rem; }
    .animal-image { width: 80px; height: 80px; }
    .node-text, .attribute-tile .value { font-size: 0.8rem; }
    .stat-value { font-size: 1.5rem; }
}
