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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #000;
    color: #fff;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: clamp(8px, 2vw, 16px);
    overflow-x: hidden;
}

.game-wrapper {
    width: 100%;
    max-width: min(800px, 95vw);
}

.container {
    background: #111;
    border-radius: clamp(12px, 2vw, 16px);
    padding: clamp(16px, 3vw, 24px);
    border: 1px solid #333;
    display: flex;
    flex-direction: column;
    gap: clamp(16px, 2.5vw, 24px);
}

.header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    padding-bottom: clamp(12px, 2vw, 20px);
    border-bottom: 1px solid #333;
    gap: clamp(8px, 1.5vw, 16px);
    min-width: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: clamp(8px, 1vw, 12px);
    min-width: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: clamp(4px, 0.8vw, 8px);
    flex-wrap: wrap;
    min-width: 0;
}

.header h1 {
    font-size: clamp(1.4rem, 4vw, 1.8rem);
    color: #fff;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn {
    background: #222;
    color: #fff;
    border: 1px solid #444;
    padding: clamp(8px, 1.5vw, 12px) clamp(12px, 2vw, 16px);
    border-radius: clamp(6px, 1vw, 8px);
    font-size: clamp(0.9rem, 2vw, 1rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: clamp(40px, 6vw, 48px);
    min-width: clamp(50px, 8vw, 60px);
    text-decoration: none;
    outline: none;
    flex-shrink: 0;
    overflow: hidden;
    white-space: nowrap;
}

.btn:hover {
    background: #333;
    transform: translateY(-2px);
}

.btn:active {
    transform: translateY(0);
}

.setup-btn {
    background: #10b981;
    color: white;
    border: 1px solid #10b981;
}

.load-btn {
    background: #8b5cf6;
    color: white;
    border: 1px solid #8b5cf6;
}

.cancel-reset-btn {
    background: #444;
    color: white;
    border: 1px solid #555;
}

.copy-btn {
    background: #0a3a2a;
    color: #10b981;
    border: 1px solid #1a4a3a;
    min-height: clamp(32px, 5vw, 40px);
    padding: clamp(6px, 1vw, 8px) clamp(12px, 2vw, 16px);
}

.header-btn {
    background: #222;
    color: #fff;
    border: 1px solid #444;
    padding: clamp(6px, 1vw, 8px) clamp(8px, 1.5vw, 12px);
    border-radius: clamp(4px, 0.8vw, 6px);
    font-size: clamp(0.8rem, 1.8vw, 0.9rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: clamp(32px, 5vw, 36px);
    min-width: clamp(50px, 8vw, 60px);
    flex-shrink: 0;
    overflow: hidden;
    white-space: nowrap;
}

.header-btn:hover {
    background: #333;
    transform: translateY(-2px);
}

.feed-btn {
    background: #1a3a0a;
    color: #84cc16;
    border-color: #2a4a1a;
}

.play-btn {
    background: #3a2a0a;
    color: #fbbf24;
    border-color: #4a3a1a;
}

.heal-btn {
    background: #3a0a1a;
    color: #ec4899;
    border-color: #4a0a2a;
}

.sleep-btn {
    background: #0a2a3a;
    color: #3b82f6;
    border-color: #1a3a4a;
}

.coins {
    background: #222;
    padding: clamp(6px, 1vw, 8px) clamp(12px, 2vw, 16px);
    border-radius: clamp(25px, 4vw, 50px);
    font-weight: 700;
    color: #fbbf24;
    border: 1px solid #444;
    font-size: clamp(0.9rem, 2vw, 1rem);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: clamp(4px, 0.8vw, 6px);
    min-height: clamp(32px, 5vw, 36px);
    flex-shrink: 0;
    white-space: nowrap;
}

.pet-area {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: clamp(16px, 2.5vw, 24px);
    background: #0a0a0a;
    padding: clamp(16px, 2.5vw, 20px);
    border-radius: clamp(8px, 1.5vw, 12px);
    border: 1px solid #222;
    align-items: center;
    min-width: 0;
}

@media (max-width: 768px) {
    .pet-area {
        grid-template-columns: 1fr;
        text-align: center;
    }
}

.pet-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(8px, 1.2vw, 12px);
    min-width: 0;
}

#pet {
    font-size: clamp(60px, 15vw, 80px);
    line-height: 1;
    cursor: pointer;
    transition: transform 0.2s;
    user-select: none;
    flex-shrink: 0;
}

#pet:hover {
    transform: scale(1.05);
}

.pet-name {
    font-size: clamp(1.2rem, 3.5vw, 1.5rem);
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.pet-info {
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 2vw, 16px);
    width: 100%;
    min-width: 0;
}

#status {
    color: #888;
    font-size: clamp(0.9rem, 2vw, 1rem);
    font-style: italic;
    margin-bottom: clamp(2px, 0.5vw, 4px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: clamp(8px, 1.5vw, 12px);
    min-width: 0;
}

@media (max-width: 480px) {
    .stats {
        grid-template-columns: 1fr;
    }
}

.stat {
    background: #0a0a0a;
    padding: clamp(8px, 1.5vw, 12px);
    border-radius: clamp(6px, 1vw, 8px);
    border: 1px solid #222;
    min-width: 0;
    overflow: hidden;
}

.stat-name {
    font-size: clamp(0.8rem, 1.8vw, 0.9rem);
    color: #aaa;
    margin-bottom: clamp(6px, 1vw, 8px);
    display: flex;
    align-items: center;
    gap: clamp(4px, 0.8vw, 6px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bar {
    height: clamp(8px, 1.5vw, 10px);
    background: #222;
    border-radius: clamp(4px, 0.8vw, 5px);
    overflow: hidden;
    width: 100%;
    min-width: 0;
}

.fill {
    height: 100%;
    border-radius: clamp(4px, 0.8vw, 5px);
    transition: width 0.3s ease;
    min-width: 3px;
}

.section-title {
    font-size: clamp(1.2rem, 3.5vw, 1.5rem);
    margin-bottom: clamp(12px, 2vw, 16px);
    color: #fff;
    display: flex;
    align-items: center;
    gap: clamp(6px, 1vw, 8px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shop,
.games,
.save-code-section {
    margin-top: clamp(16px, 2.5vw, 20px);
    padding-top: clamp(16px, 2.5vw, 20px);
    border-top: 1px solid #333;
    min-width: 0;
}

.shop-items,
.game-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(160px, 45vw), 1fr));
    gap: clamp(12px, 2vw, 16px);
    min-width: 0;
}

@media (max-width: 480px) {
    .shop-items,
    .game-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 360px) {
    .shop-items,
    .game-cards {
        grid-template-columns: 1fr;
    }
}

.item,
.game {
    background: #0a0a0a;
    padding: clamp(12px, 2vw, 16px);
    border-radius: clamp(8px, 1.2vw, 10px);
    border: 1px solid #222;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: clamp(100px, 20vw, 120px);
    min-width: 0;
    overflow: hidden;
}

.item:hover,
.game:hover {
    border-color: #444;
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.item.purchased {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #333;
}

.item.purchased:hover {
    transform: none;
    border-color: #333;
    box-shadow: none;
}

.item-emoji,
.game-emoji {
    font-size: clamp(32px, 8vw, 40px);
    margin-bottom: clamp(6px, 1vw, 8px);
    flex-shrink: 0;
}

.item-name,
.game-name {
    font-size: clamp(0.9rem, 2vw, 1rem);
    font-weight: 600;
    margin: clamp(2px, 0.5vw, 4px) 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.item-price {
    color: #fbbf24;
    font-size: clamp(0.8rem, 1.8vw, 0.9rem);
    margin: clamp(2px, 0.5vw, 4px) 0;
    font-weight: 700;
    white-space: nowrap;
}

.item-count {
    color: #10b981;
    font-size: clamp(0.75rem, 1.6vw, 0.8rem);
    margin-top: clamp(1px, 0.3vw, 2px);
    font-weight: 700;
    white-space: nowrap;
}

.game-desc {
    color: #888;
    font-size: clamp(0.75rem, 1.6vw, 0.85rem);
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: clamp(12px, 3vw, 20px);
    overflow-y: auto;
}

.modal-content {
    background: #111;
    padding: clamp(20px, 4vw, 32px);
    border-radius: clamp(12px, 2.5vw, 16px);
    max-width: min(500px, 90vw);
    width: 100%;
    border: 1px solid #333;
    text-align: center;
    position: relative;
    max-height: min(90vh, 800px);
    overflow-y: auto;
    overflow-x: hidden;
}

.modal-content h2 {
    font-size: clamp(1.4rem, 4vw, 1.8rem);
    margin-bottom: clamp(16px, 2.5vw, 20px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-content h3 {
    color: #aaa;
    font-size: clamp(1rem, 2.2vw, 1.1rem);
    margin-bottom: clamp(10px, 1.5vw, 12px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-content p {
    color: #aaa;
    font-size: clamp(0.9rem, 2vw, 1rem);
    margin: clamp(12px, 2vw, 16px) 0;
    line-height: 1.5;
    word-break: break-word;
}

.close {
    position: absolute;
    top: clamp(12px, 2vw, 16px);
    right: clamp(16px, 2.5vw, 20px);
    font-size: clamp(1.8rem, 4vw, 2rem);
    color: #888;
    cursor: pointer;
    line-height: 1;
    width: clamp(28px, 5vw, 32px);
    height: clamp(28px, 5vw, 32px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.close:hover {
    color: #fff;
}

.species-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: clamp(8px, 1.5vw, 12px);
    margin: clamp(16px, 2.5vw, 20px) 0;
    min-width: 0;
}

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

@media (max-width: 360px) {
    .species-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.species {
    padding: clamp(12px, 2vw, 16px);
    border: 1px solid #333;
    border-radius: clamp(8px, 1.2vw, 10px);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    min-width: 0;
    overflow: hidden;
}

.species:hover {
    border-color: #555;
    background: #1a1a1a;
}

.species.selected {
    border-color: #10b981;
    background: #0a2a1a;
    transform: scale(1.05);
}

.species-emoji {
    font-size: clamp(32px, 8vw, 40px);
    margin-bottom: clamp(6px, 1vw, 8px);
    flex-shrink: 0;
}

.species-name {
    font-size: clamp(0.75rem, 1.8vw, 0.85rem);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.input {
    width: 100%;
    padding: clamp(12px, 2vw, 16px);
    background: #0a0a0a;
    border: 1px solid #333;
    border-radius: clamp(8px, 1.2vw, 10px);
    color: #fff;
    margin: clamp(12px, 2vw, 16px) 0;
    font-size: clamp(0.9rem, 2vw, 1rem);
    text-align: center;
    outline: none;
    min-width: 0;
}

.input:focus {
    border-color: #10b981;
}

.save-code-input {
    width: 100%;
    padding: clamp(12px, 2vw, 16px);
    background: #0a0a0a;
    border: 1px solid #333;
    border-radius: clamp(8px, 1.2vw, 10px);
    color: #fff;
    margin: clamp(12px, 2vw, 16px) 0;
    font-size: clamp(0.8rem, 1.8vw, 0.9rem);
    font-family: monospace;
    resize: vertical;
    min-height: clamp(100px, 20vw, 120px);
    outline: none;
    min-width: 0;
}

.save-code-input:focus {
    border-color: #10b981;
}

.modal-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(12px, 2vw, 16px);
    margin-top: clamp(16px, 3vw, 24px);
    min-width: 0;
}

@media (max-width: 480px) {
    .modal-buttons {
        grid-template-columns: 1fr;
    }
}

.notification {
    position: fixed;
    top: clamp(12px, 3vw, 20px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.95);
    color: #fff;
    padding: clamp(8px, 1.5vw, 12px) clamp(16px, 2.5vw, 24px);
    border-radius: clamp(8px, 1.2vw, 10px);
    border: 1px solid #333;
    z-index: 1001;
    max-width: min(500px, 90vw);
    text-align: center;
    animation: fadeInOut 2s ease;
    display: none;
    font-size: clamp(0.85rem, 2vw, 0.95rem);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    word-break: break-word;
    white-space: normal;
}

@keyframes fadeInOut {
    0%, 100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    10%, 90% {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

#puzzle-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(6px, 1.2vw, 8px);
    margin: clamp(16px, 3vw, 24px) auto;
    width: min(300px, 80vw);
    min-width: 0;
}

.puzzle-cell {
    aspect-ratio: 1;
    background: #222;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: clamp(6px, 1vw, 8px);
    cursor: pointer;
    font-size: clamp(1.4rem, 4vw, 1.8rem);
    border: 1px solid #333;
    transition: transform 0.2s;
    min-width: 0;
}

.puzzle-cell:hover {
    transform: scale(1.05);
}

.puzzle-cell.empty {
    background: transparent;
    border-color: transparent;
    cursor: default;
}

.puzzle-cell.empty:hover {
    transform: none;
}

#fishing-area {
    width: 100%;
    height: min(250px, 50vw);
    background: #0a1a2a;
    border-radius: clamp(10px, 1.5vw, 12px);
    margin: clamp(16px, 2.5vw, 20px) 0;
    position: relative;
    overflow: hidden;
    border: 2px solid #334;
    min-width: 0;
}

.fish {
    position: absolute;
    font-size: clamp(24px, 6vw, 32px);
    cursor: pointer;
    transition: transform 0.1s;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
    user-select: none;
}

.fish.caught {
    transform: scale(0);
    opacity: 0.5;
}

.game-stats {
    display: flex;
    justify-content: space-between;
    margin: clamp(12px, 2vw, 16px) 0;
    font-size: clamp(0.85rem, 2vw, 0.95rem);
    color: #aaa;
    padding: 0 clamp(8px, 1.5vw, 12px);
    min-width: 0;
    flex-wrap: wrap;
    gap: 8px;
}

.save-code-display {
    background: #0a0a0a;
    padding: clamp(12px, 2vw, 16px);
    border-radius: clamp(8px, 1.2vw, 10px);
    border: 1px solid #333;
    margin: clamp(12px, 2vw, 16px) 0;
    display: flex;
    align-items: center;
    gap: clamp(8px, 1.5vw, 12px);
    min-width: 0;
}

.save-code-text {
    flex: 1;
    word-break: break-all;
    font-family: monospace;
    font-size: clamp(0.75rem, 1.8vw, 0.85rem);
    color: #aaa;
    text-align: left;
    padding: clamp(8px, 1.5vw, 12px);
    background: #111;
    border-radius: clamp(4px, 0.8vw, 6px);
    max-height: clamp(60px, 15vw, 80px);
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
}

.save-code-help {
    color: #888;
    font-size: clamp(0.75rem, 1.8vw, 0.85rem);
    margin-top: clamp(6px, 1vw, 8px);
    text-align: center;
    word-break: break-word;
}

.hidden {
    display: none !important;
}

.disabled {
    opacity: 0.5;
    cursor: not-allowed !important;
    pointer-events: none;
}

.btn:focus,
.header-btn:focus,
.input:focus,
.save-code-input:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.btn:active,
.header-btn:active {
    transform: translateY(0);
}

@media (hover: none) {
    .btn:hover,
    .header-btn:hover,
    .item:hover,
    .game:hover,
    .species:hover,
    #pet:hover,
    .puzzle-cell:hover {
        transform: none;
    }
    
    .btn:active,
    .header-btn:active {
        background: #444;
    }
}

@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    .bar {
        height: max(2px, clamp(8px, 1.5vw, 10px));
    }
}

.modal-content::-webkit-scrollbar {
    width: 8px;
}

.modal-content::-webkit-scrollbar-track {
    background: #0a0a0a;
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: #444;
}

.save-code-text::-webkit-scrollbar {
    width: 6px;
}

.save-code-text::-webkit-scrollbar-track {
    background: #0a0a0a;
    border-radius: 3px;
}

.save-code-text::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

.save-code-text::-webkit-scrollbar-thumb:hover {
    background: #444;
}