/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #52c234 0%, #a8d530 100%);
    color: #2d7a1f;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for better mobile support */
}

/* Container - Full height layout */
.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for better mobile support */
    max-width: 100%;
    margin: 0 auto;
}

/* Header Bar */
.header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.game-title {
    font-size: 20px;
    font-weight: 700;
    color: #2d7a1f;
    flex: 1;
    text-align: center;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.icon-btn:hover:not(:disabled) {
    background-color: #f0f0f0;
}

.icon-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.icon-btn sub {
    font-size: 12px;
    margin-left: -4px;
    color: #2d7a1f;
    font-weight: 700;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Tree Area - Endless canvas with touch navigation */
.tree-area {
    flex: 1;
    overflow: hidden;
    background: white;
    margin: 12px;
    border-radius: 16px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    cursor: grab;
    touch-action: none;
}

.tree-area.dragging {
    cursor: grabbing;
}

.empty-state {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    font-size: 18px;
    text-align: center;
    padding: 20px;
    z-index: 10;
    pointer-events: none;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

/* Tree Container - Viewport for panning */
.tree-viewport {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Tree Container */
.tree-container {
    position: absolute;
    top: 0;
    left: 0;
    padding: 0;
    transition: transform 0.1s ease-out;
    will-change: transform;
    min-width: 100%;
    min-height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.tree-container > * {
    pointer-events: auto;
}

.tree-connections {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

/* Tree Hierarchical Layout */
.tree-root {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    padding: 40px 0 0 0;
}

.tree-branch-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.tree-node-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
}

.tree-children {
    display: flex;
    gap: 40px;
    align-items: flex-start;
    margin-top: 30px;
}

.tree-node {
    text-align: center;
    font-weight: 600;
    font-size: 14px;
    position: relative;
    animation: fadeIn 0.3s ease-in;
    cursor: default;
    transition: transform 0.2s;
}

.tree-node:hover {
    transform: scale(1.05);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tree-node.mystery {
    min-width: 80px;
    max-width: 100px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 24px;
    color: #999;
    font-weight: 700;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 2px dashed #999;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.tree-node.target {
    min-width: 140px;
    max-width: 200px;
    padding: 12px 16px;
    border-radius: 12px;
    background: linear-gradient(135deg, #ffd43b 0%, #fab005 100%);
    box-shadow: 0 4px 16px rgba(250, 176, 5, 0.4);
}

.tree-node.target .node-name,
.tree-node.target .node-label {
    color: white;
}

.tree-node.taxonomy-node {
    min-width: 140px;
    max-width: 200px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.tree-node.animal-node {
    /* No background, just text */
    background: none;
    border: none;
    box-shadow: none;
}

.node-name {
    font-size: 15px;
    font-weight: 700;
    color: #2d7a1f;
}

.node-label {
    font-size: 12px;
    display: block;
    margin-top: 2px;
    opacity: 0.7;
    font-weight: 400;
    font-style: italic;
    color: #6c757d;
}

/* Taxonomy Level Colors */
.level-kingdom { background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%); color: white; }
.level-phylum { background: linear-gradient(135deg, #f06595 0%, #e64980 100%); color: white; }
.level-class { background: linear-gradient(135deg, #cc5de8 0%, #be4bdb 100%); color: white; }
.level-order { background: linear-gradient(135deg, #748ffc 0%, #5c7cfa 100%); color: white; }
.level-family { background: linear-gradient(135deg, #4dabf7 0%, #339af0 100%); color: white; }
.level-genus { background: linear-gradient(135deg, #38d9a9 0%, #20c997 100%); color: white; }
.level-species { background: linear-gradient(135deg, #82c91e 0%, #5c940d 100%); color: white; }

/* Input Bar */
.input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: white;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.autocomplete-wrapper {
    flex: 1;
    position: relative;
}

.guess-input {
    width: 100%;
    padding: 12px 20px;
    border: 2px solid #dee2e6;
    border-radius: 24px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

.guess-input:focus {
    border-color: #52c234;
}

.autocomplete-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 12px;
    margin-bottom: 8px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
    display: none;
}

.autocomplete-dropdown.show {
    display: block;
}

.autocomplete-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 1px solid #f0f0f0;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background-color: #f8f9fa;
}

.autocomplete-item.selected {
    background-color: #e7f5ff;
}

.autocomplete-common {
    font-weight: 600;
    font-size: 15px;
    color: #2d7a1f;
}

.autocomplete-scientific {
    font-style: italic;
    font-size: 13px;
    color: #6c757d;
    margin-top: 2px;
}

.submit-btn {
    min-width: 80px;
    min-height: 44px;
    padding: 12px 24px;
    background: linear-gradient(135deg, #52c234 0%, #2d7a1f 100%);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(82, 194, 52, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.submit-btn:hover {
    background: linear-gradient(135deg, #2d7a1f 0%, #1a4d12 100%);
    box-shadow: 0 4px 12px rgba(82, 194, 52, 0.4);
    transform: translateY(-1px);
}

.submit-btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 6px rgba(82, 194, 52, 0.3);
}

.submit-btn:disabled {
    background: #dee2e6;
    cursor: not-allowed;
    box-shadow: none;
}

.submit-btn-icon {
    font-size: 18px;
}

/* Slide-out Menu Panel */
.menu-panel {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100vh;
    background: white;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.2);
    transition: left 0.3s ease;
    z-index: 1000;
    overflow-y: auto;
    padding: 20px;
}

.menu-panel.open {
    left: 0;
}

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    z-index: 999;
}

.menu-overlay.show {
    display: block;
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 2px solid #e9ecef;
}

.menu-header h2 {
    font-size: 24px;
    color: #2d7a1f;
}

.close-menu-btn {
    background: none;
    border: none;
    font-size: 32px;
    cursor: pointer;
    color: #6c757d;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
}

.menu-section {
    margin-bottom: 24px;
}

.menu-section h3 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6c757d;
    margin-bottom: 12px;
}

.menu-btn {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 8px;
    transition: opacity 0.2s, transform 0.1s;
    min-height: 44px;
}

.menu-btn:hover:not(:disabled) {
    opacity: 0.9;
}

.menu-btn:active:not(:disabled) {
    transform: scale(0.98);
}

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

.btn-orange {
    background: #ffa500;
    color: white;
}

.btn-red {
    background: #dc3545;
    color: white;
}

.btn-gray {
    background: #6c757d;
    color: white;
}

.btn-hint {
    background: #ffd43b;
    color: #2d7a1f;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
    color: #495057;
}

.stat-item span:last-child {
    font-weight: 600;
    color: #2d7a1f;
}

.hints-display {
    margin-top: 12px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    font-size: 14px;
    display: none;
}

.hints-display.show {
    display: block;
}

.hint-item {
    margin-bottom: 8px;
    padding: 8px;
    background: white;
    border-radius: 6px;
}

.hint-item-new {
    animation: slideFromRight 0.5s ease-out;
}

@keyframes slideFromRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.hint-item strong {
    color: #2d7a1f;
}

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

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 16px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal.hint-closing {
    background: rgba(0, 0, 0, 0.3);
    transition: background 0.8s ease;
}

.modal-content.hint-slide-out {
    animation: hintSlideOut 0.8s ease forwards;
}

@keyframes hintSlideOut {
    0% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
    70% {
        opacity: 0.7;
        transform: translateX(-400px) scale(0.7);
    }
    100% {
        opacity: 0;
        transform: translateX(-500px) scale(0.5);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 2px solid #e9ecef;
}

.modal-header h2 {
    font-size: 24px;
    color: #2d7a1f;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 32px;
    cursor: pointer;
    color: #6c757d;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
}

.modal-body {
    padding: 24px;
}

.modal-body h3 {
    color: #2d7a1f;
    margin-top: 16px;
    margin-bottom: 8px;
    font-size: 18px;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body p {
    margin-bottom: 12px;
    line-height: 1.6;
    color: #495057;
}

.modal-body ul, .modal-body ol {
    margin-left: 20px;
    margin-bottom: 12px;
    line-height: 1.6;
    color: #495057;
}

.modal-body li {
    margin-bottom: 6px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    min-height: 44px;
}

.btn-primary {
    background: #52c234;
    color: white;
}

.btn-primary:hover {
    background: #2d7a1f;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: #6c757d;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-secondary:active {
    transform: scale(0.98);
}

/* Wikipedia Modal */
#wiki-images {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

#wiki-images img {
    width: 100%;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#wiki-content {
    color: #495057;
    line-height: 1.6;
}

#wiki-content p {
    margin-bottom: 12px;
}

.wiki-loading {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
}

.wiki-loading::after {
    content: '...';
    animation: ellipsis 1.5s infinite;
}

@keyframes ellipsis {
    0% { content: '.'; }
    33% { content: '..'; }
    66% { content: '...'; }
}

/* Taxonomy Filter */
.taxonomy-filter {
    margin: 20px 0;
}

.filter-group {
    margin-bottom: 16px;
}

.filter-item {
    padding: 10px;
    margin: 8px 0;
    background: #f8f9fa;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    user-select: none;
}

.filter-item:hover {
    background: #e9ecef;
}

.filter-item.disabled {
    opacity: 0.4;
    text-decoration: line-through;
}

.filter-item-main {
    font-weight: 600;
    color: #2d7a1f;
    font-size: 15px;
}

.filter-item-sub {
    margin-left: 20px;
    padding: 8px;
    margin-top: 4px;
    font-size: 14px;
    background: white;
}

/* Game Over Modal Styling */
#gameover-message {
    text-align: center;
    padding: 20px;
}

.gameover-emoji {
    font-size: 64px;
    margin-bottom: 16px;
}

.gameover-animal {
    font-size: 24px;
    font-weight: 700;
    color: #2d7a1f;
    margin-bottom: 8px;
}

.gameover-scientific {
    font-size: 18px;
    font-style: italic;
    color: #6c757d;
    margin-bottom: 16px;
}

.gameover-stats {
    font-size: 16px;
    color: #495057;
    margin-bottom: 20px;
}

/* Responsive Design */
@media (min-width: 768px) {
    .container {
        max-width: 900px;
    }

    .header-bar {
        padding: 16px 24px;
    }

    .game-title {
        font-size: 24px;
    }

    .tree-area {
        margin: 16px;
        padding: 32px;
    }

    .tree-node {
        min-width: 140px;
        max-width: 220px;
        padding: 14px 18px;
        font-size: 15px;
    }

    .input-bar {
        padding: 16px 24px;
    }
}

/* Scrollbar Styling */
.tree-area::-webkit-scrollbar {
    width: 8px;
}

.tree-area::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.tree-area::-webkit-scrollbar-thumb {
    background: #52c234;
    border-radius: 10px;
}

.tree-area::-webkit-scrollbar-thumb:hover {
    background: #2d7a1f;
}
