* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Courier New', monospace;
    background: linear-gradient(180deg, #0a0512 0%, #1a0a2e 50%, #0d1a0d 100%);
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #b8a9c9;
    overflow: hidden;
    overscroll-behavior: none;
    user-select: none;
    position: fixed;
    width: 100%;
    touch-action: manipulation;
}

.game-container {
    width: 100%;
    max-width: 400px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.title {
    font-size: 1.8em;
    color: #9b59b6;
    text-shadow: 0 0 10px #8e44ad, 0 0 20px #6b2d7b;
    margin: 10px 0;
    letter-spacing: 3px;
}

.crystal-ball-container {
    position: relative;
    margin: 10px 0;
}

#crystalBall {
    border-radius: 50%;
    box-shadow:
        0 0 30px rgba(155, 89, 182, 0.5),
        0 0 60px rgba(155, 89, 182, 0.3),
        inset 0 0 50px rgba(255, 255, 255, 0.1);
    cursor: pointer;
}

.ball-base {
    width: 200px;
    height: 40px;
    background: linear-gradient(180deg, #2d1f3d 0%, #1a1025 100%);
    border-radius: 0 0 100px 100px;
    margin: -10px auto 0;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.stats-container {
    width: 100%;
    background: rgba(26, 10, 46, 0.8);
    border: 1px solid #4a2c6a;
    border-radius: 10px;
    padding: 10px;
    margin: 10px 0;
}

.stat-row {
    display: flex;
    align-items: center;
    margin: 5px 0;
    font-size: 0.85em;
}

.stat-icon {
    width: 25px;
    text-align: center;
    margin-right: 8px;
}

.stat-label {
    width: 70px;
    color: #9b59b6;
}

.stat-bar {
    flex: 1;
    display: flex;
    align-items: center;
    font-family: monospace;
}

.stat-bar-container {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #4a2c6a;
    border-radius: 3px;
    padding: 2px 4px;
    width: 100%;
    height: 18px;
    position: relative;
    overflow: hidden;
}

.stat-bar-fill {
    display: flex;
    height: 100%;
    width: 100%;
    gap: 2px;
}

.stat-bar-segment {
    flex: 1;
    height: 100%;
    background: #27ae60;
    border-radius: 1px;
}

.stat-bar-empty {
    flex: 1;
    height: 100%;
    background: transparent;
}

.stat-bar.warning .stat-bar-segment {
    background: #f39c12;
}

.stat-bar.danger .stat-bar-segment {
    background: #e74c3c;
}

.asterisks {
    color: #e74c3c;
    margin-left: 5px;
    font-weight: bold;
}

.buttons-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
    margin: 10px 0;
}

.btn {
    background: linear-gradient(180deg, #4a2c6a 0%, #2d1f3d 100%);
    border: 1px solid #6b3d8a;
    color: #b8a9c9;
    padding: 12px 8px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
}

.btn:hover, .btn:active {
    background: linear-gradient(180deg, #6b3d8a 0%, #4a2c6a 100%);
    box-shadow: 0 0 10px rgba(155, 89, 182, 0.5);
}

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

.btn.active {
    background: linear-gradient(180deg, #27ae60 0%, #1e8449 100%);
    border-color: #2ecc71;
}

.btn.btn-danger {
    background: linear-gradient(180deg, #6b2d2d 0%, #4a1a1a 100%);
    border-color: #8b3d3d;
}

.btn.btn-danger:hover {
    background: linear-gradient(180deg, #8b3d3d 0%, #6b2d2d 100%);
    box-shadow: 0 0 10px rgba(180, 60, 60, 0.5);
}

.btn.btn-danger.active {
    background: linear-gradient(180deg, #c0392b 0%, #96281b 100%);
    border-color: #e74c3c;
    animation: pulse-danger 1s infinite;
}

@keyframes pulse-danger {
    0%, 100% { box-shadow: 0 0 10px rgba(231, 76, 60, 0.5); }
    50% { box-shadow: 0 0 20px rgba(231, 76, 60, 0.8); }
}

.menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 80;
}

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

.food-menu,
.game-menu {
    display: none;
    background: rgba(26, 10, 46, 0.95);
    border: 2px solid #6b3d8a;
    border-radius: 15px;
    padding: 20px 15px 15px;
    position: relative;
    min-width: 200px;
}

.food-menu.show,
.game-menu.show {
    display: block;
    text-align: center;
}

.menu-title {
    color: #9b59b6;
    font-size: 1.1em;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 15px;
}

.menu-options {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.menu-close {
    position: absolute;
    top: 5px;
    right: 10px;
    background: none;
    border: none;
    color: #b8a9c9;
    font-size: 1.5em;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: auto;
    height: auto;
}

.menu-close:hover {
    color: #e74c3c;
}

.food-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(74, 44, 106, 0.5);
    border: 1px solid #6b3d8a;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.food-btn:hover {
    background: rgba(107, 61, 138, 0.7);
}

.food-icon {
    font-size: 1.5em;
    margin-bottom: 5px;
}

.game-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(74, 44, 106, 0.5);
    border: 1px solid #6b3d8a;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    color: #b8a9c9;
    font-size: 0.85em;
}

.game-btn:hover {
    background: rgba(107, 61, 138, 0.7);
}

.game-icon {
    font-size: 1.5em;
    margin-bottom: 5px;
}

/* Pong game */
#pongCanvas {
    border-radius: 10px;
    background: rgba(10, 5, 18, 0.8);
    border: 2px solid #4a2c6a;
    touch-action: none;
}

.pong-score {
    display: flex;
    justify-content: space-around;
    width: 100%;
    margin-bottom: 10px;
    font-size: 1.2em;
    color: #b8a9c9;
}

.pong-score span {
    padding: 5px 15px;
    background: rgba(74, 44, 106, 0.5);
    border-radius: 5px;
}

.mute-btn {
    position: absolute;
    top: 10px;
    right: calc(50% - 200px);
    background: rgba(74, 44, 106, 0.8);
    border: 1px solid #6b3d8a;
    color: #b8a9c9;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.4em;
    z-index: 50;
}

@media (min-width: 420px) {
    .mute-btn {
        width: 40px;
        height: 40px;
        font-size: 1.2em;
    }
}

@media (max-width: 419px) {
    .mute-btn {
        right: 10px;
    }
}

.status-text {
    text-align: center;
    color: #9b59b6;
    font-size: 0.9em;
    min-height: 20px;
    margin: 5px 0;
}

/* Tic-tac-toe modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 5, 18, 0.95);
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: linear-gradient(180deg, #1a0a2e 0%, #0d1a0d 100%);
    border: 2px solid #6b3d8a;
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    max-width: 320px;
    width: 90%;
}

.ttt-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin: 15px auto;
    width: 240px;
}

.ttt-cell {
    width: 75px;
    height: 75px;
    background: rgba(74, 44, 106, 0.5);
    border: 1px solid #6b3d8a;
    border-radius: 8px;
    font-size: 2.5em;
    color: #b8a9c9;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ttt-cell:hover:not(.taken) {
    background: rgba(107, 61, 138, 0.7);
}

.ttt-cell.taken {
    cursor: not-allowed;
}

.ttt-cell.x {
    color: #9b59b6;
}

.ttt-cell.o {
    color: #27ae60;
}

.modal-title {
    color: #9b59b6;
    font-size: 1.3em;
    margin-bottom: 10px;
}

.modal-text {
    color: #b8a9c9;
    margin: 10px 0;
}

.streak-display {
    color: #f39c12;
    font-size: 0.9em;
    margin: 5px 0;
}

.close-btn {
    margin-top: 15px;
}

.death-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    z-index: 200;
    flex-direction: column;
}

.death-overlay.show {
    display: flex;
}

.death-text {
    color: #e74c3c;
    font-size: 1.5em;
    text-align: center;
    margin-bottom: 20px;
    text-shadow: 0 0 10px #c0392b;
}

.tap-prompt {
    color: #9b59b6;
    font-size: 1em;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.pet-name {
    color: #9b59b6;
    font-size: 1.1em;
    margin: 5px 0;
    text-transform: capitalize;
}

.grimoire-btn {
    position: absolute;
    top: 10px;
    left: calc(50% - 200px);
    background: rgba(74, 44, 106, 0.8);
    border: 1px solid #6b3d8a;
    color: #b8a9c9;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.4em;
    z-index: 50;
}

@media (min-width: 420px) {
    .grimoire-btn {
        width: 40px;
        height: 40px;
        font-size: 1.2em;
    }
}

@media (max-width: 419px) {
    .grimoire-btn {
        left: 10px;
    }
}

.grimoire-btn:hover {
    background: rgba(107, 61, 138, 0.9);
    box-shadow: 0 0 10px rgba(155, 89, 182, 0.5);
}

.grimoire-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 5, 18, 0.98);
    justify-content: center;
    align-items: flex-start;
    z-index: 150;
    overflow-y: auto;
    padding: 20px 10px;
}

.grimoire-modal.show {
    display: flex;
}

.grimoire-content {
    background: linear-gradient(180deg, #1a0a2e 0%, #0d1a0d 100%);
    border: 2px solid #6b3d8a;
    border-radius: 15px;
    padding: 20px;
    width: 100%;
    max-width: 380px;
}

.grimoire-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 1px solid #4a2c6a;
    padding-bottom: 10px;
}

.grimoire-title {
    color: #9b59b6;
    font-size: 1.4em;
    text-shadow: 0 0 10px #8e44ad;
}

.grimoire-close {
    background: none;
    border: none;
    color: #b8a9c9;
    font-size: 1.5em;
    cursor: pointer;
}

.grimoire-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.grimoire-entry {
    background: rgba(45, 31, 77, 0.5);
    border: 1px solid #4a2c6a;
    border-radius: 10px;
    padding: 10px;
    text-align: center;
}

.grimoire-entry.discovered {
    border-color: #6b3d8a;
}

.grimoire-entry.undiscovered {
    opacity: 0.6;
}

.grimoire-sprite {
    width: 80px;
    height: 80px;
    margin: 0 auto 8px;
}

.grimoire-name {
    color: #9b59b6;
    font-size: 0.85em;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.grimoire-name.unknown {
    color: #666;
}

.grimoire-count {
    color: #27ae60;
    font-size: 0.75em;
}

.grimoire-stats {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid #4a2c6a;
    text-align: center;
    color: #b8a9c9;
    font-size: 0.85em;
}

.grimoire-rare {
    color: #f1c40f;
    font-size: 0.7em;
    margin-top: 2px;
}
