html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    box-sizing: border-box;
}
body {
    font-family: 'Fredoka', cursive, sans-serif;
    background-color: #18181b;
    color: #f4f4f5;
}
.page-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    padding: 0.75rem;
    gap: 0.75rem;
    box-sizing: border-box;
}
.hud-container { flex-shrink: 0; }
.game-wrapper {
    flex-grow: 1;
    min-height: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
}
.leaderboard-panel { display: none; }
.global-footer { flex-shrink: 0; }

/* HUD Styles */
.hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}
.hud-element {
    background-color: rgba(24, 24, 27, 0.75);
    padding: 0.45rem 0.9rem;
    border-radius: 0.65rem;
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    letter-spacing: 0.5px;
    white-space: nowrap;
    font-size: 0.95rem;
    font-weight: 600;
    transition: transform 0.1s ease-in-out;
}
.hud-left { text-align: left; min-width: 110px; }
.hud-right { text-align: right; min-width: 100px; }
.hud-center {
    flex-grow: 1;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}
.hud-combo {
    min-width: 120px;
    color: #facc15;
}
.hud-combo.combo-increase { animation: combo-pop 0.3s ease-out; }
.hud-combo.combo-break { animation: combo-shake 0.4s ease-in-out; }

@keyframes combo-pop {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); color: #facc15; border-color: #facc15; }
}
@keyframes combo-shake {
    10%, 90% { transform: translateX(-3px); }
    20%, 80% { transform: translateX(3px); }
    30%, 50%, 70% { transform: translateX(-3px); }
    40%, 60% { transform: translateX(3px); }
}

.hud-mute-button {
    cursor: pointer;
    background-color: rgba(24, 24, 27, 0.75);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.65rem;
    padding: 0.45rem 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #38bdf8;
    transition: background-color 0.2s, transform 0.15s;
}
.hud-mute-button:hover {
    background-color: rgba(56, 189, 248, 0.2);
    transform: scale(1.05);
}
.hud-icon {
    width: 1.25rem;
    height: 1.25rem;
}

.protein-chain-container { width: 100%; max-width: 360px; }
.hud-label {
    font-size: 0.8rem;
    display: block;
    margin-bottom: 0.2rem;
    font-weight: 600;
    color: #a1a1aa;
    letter-spacing: 0.5px;
}
.protein-chain-bar {
    width: 100%;
    height: 1.1rem;
    background-color: rgba(0, 0, 0, 0.5);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.5rem;
    padding: 2px;
    box-sizing: border-box;
}
.protein-chain-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #f87171, #facc15, #4ade80, #60a5fa, #c084fc);
    border-radius: 0.35rem;
    transition: width 0.3s ease-in-out;
}

/* Power Up Bar */
#power-up-bar {
    position: absolute;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    z-index: 50;
}
.power-up-status {
    background-color: rgba(24, 24, 27, 0.85);
    border-radius: 0.5rem;
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    border: 1.5px solid transparent;
}
.power-up-status.active {
    border-color: #facc15;
    animation: pulse-border 1s infinite;
}
@keyframes pulse-border {
    0%, 100% { border-color: #facc15; }
    50% { border-color: white; }
}

/* Game Area */
.game-area-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    aspect-ratio: 16 / 9;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 1rem;
    overflow: hidden;
    background: radial-gradient(circle at center, #27272a 0%, #18181b 100%);
    border: 2px solid rgba(255, 255, 255, 0.12);
    padding: 1rem;
    box-sizing: border-box;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.game-area-wrapper.shake { animation: screen-shake 0.15s ease-in-out; }
@keyframes screen-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-5px); }
}

#game-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}
.game-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

#mutation-display {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    background-color: rgba(239, 68, 68, 0.85);
    border: 2px solid #f87171;
    color: white;
    padding: 0.5rem 0.85rem;
    border-radius: 0.65rem;
    font-size: 0.85rem;
    font-weight: 600;
    animation: pulse-border-red 1.5s infinite;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}
@keyframes pulse-border-red {
    0%, 100% { border-color: #f87171; }
    50% { border-color: white; }
}
#mutation-display .mutation-title {
    font-weight: 700;
    display: block;
    text-align: center;
    margin-bottom: 0.2rem;
    letter-spacing: 0.5px;
}

#power-up-spawn-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
}
.power-up-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    animation: pop-in 0.3s ease-out, float 3s ease-in-out infinite;
    transition: transform 0.2s ease;
}
.power-up-icon:hover {
    transform: scale(1.12);
}
.power-up-2x {
    background: linear-gradient(135deg, #facc15 0%, #eab308 100%);
    color: #1e092b;
}
.power-up-slow {
    background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
    color: white;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* Controls */
.game-controls-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}
.game-controls-container {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    max-width: 42rem;
}
.control-btn {
    font-family: 'Fredoka', cursive, sans-serif;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 0.75rem;
    padding: 0.65rem 1.25rem;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.2s;
    min-width: 75px;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.control-btn:hover {
    transform: translateY(-2px) scale(1.04);
    border-color: white;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}
.control-btn:active {
    transform: translateY(1px) scale(0.97);
}
.amino-acid-btn {
    font-size: 1rem;
    padding: 0.55rem 1rem;
    min-width: 110px;
    color: #18181b;
}
.btn-small {
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
}
.btn-skip {
    background-color: #ef4444;
    border-color: #dc2626;
    min-width: 180px;
}
.btn-skip:hover {
    background-color: #dc2626;
}

/* Strands and Bases */
.strand-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #a1a1aa;
    align-self: flex-start;
    letter-spacing: 0.5px;
}
.strand-container {
    display: flex;
    gap: 0.35rem;
    padding: 0.6rem;
    background-color: rgba(0, 0, 0, 0.35);
    border: 1.5px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.65rem;
    width: 100%;
    min-height: 52px;
    box-sizing: border-box;
    overflow-x: auto;
    position: relative;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
    scroll-padding: 0 50%;
}
.strand-container::-webkit-scrollbar {
    display: none;
}
.base {
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 0.5rem;
    flex-shrink: 0;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
    color: white;
}
.dna-base.active {
    transform: scale(1.22);
    box-shadow: 0 0 16px rgba(255, 255, 255, 0.8);
    z-index: 10;
}
.base.insertion {
    outline: 3px dashed #f87171;
    animation: pulse-border-red 1.5s infinite;
}
.base-A { background-color: #22c55e; border-bottom: 3.5px solid #16a34a; }
.base-T { background-color: #ef4444; border-bottom: 3.5px solid #dc2626; }
.base-U { background-color: #ef4444; border-bottom: 3.5px solid #dc2626; }
.base-C { background-color: #3b82f6; border-bottom: 3.5px solid #2563eb; }
.base-G { background-color: #facc15; border-bottom: 3.5px solid #d97706; color: #18181b; }

/* Ribosome Phase */
#translation-area { gap: 1rem; }
.ribosome {
    background: linear-gradient(135deg, #a855f7 0%, #7e22ce 100%);
    border-radius: 1.25rem;
    padding: 0.85rem 1.25rem;
    border: 3px solid #c084fc;
    width: auto;
    max-width: 92%;
    display: inline-flex;
    justify-content: center;
    position: relative;
    box-shadow: 0 8px 24px rgba(168, 85, 247, 0.3);
}
.ribosome::before, .ribosome::after {
    content: '';
    position: absolute;
    background-color: #c084fc;
    border: 2px solid #7e22ce;
    width: 36px;
    height: 100%;
    border-radius: 1rem;
    top: 0;
}
.ribosome::before { left: -22px; }
.ribosome::after { right: -22px; }
.codon {
    outline: 3px dashed #fde047;
    transform: scale(1.08);
    box-shadow: 0 0 16px rgba(253, 224, 71, 0.6);
    border-radius: 0.5rem;
    display: flex;
    gap: 0.25rem;
    padding: 2px;
}
.protein-chain-display {
    display: flex;
    gap: 0.35rem;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}
.amino-acid {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: #18181b;
    border: 2px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    animation: pop-in 0.3s ease-out;
}
@keyframes pop-in {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

/* Codon Chart */
.codon-chart-container {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    background-color: rgba(24, 24, 27, 0.95);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.75rem;
    padding: 0.65rem;
    z-index: 110;
    font-size: 0.75rem;
    width: 280px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
}
.codon-chart-container h3 {
    text-align: center;
    font-size: 0.85rem;
    font-weight: 700;
    margin: 0 0 0.5rem 0;
    color: #facc15;
}
.codon-table {
    width: 100%;
    border-collapse: collapse;
}
.codon-table td {
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 3px 4px;
    text-align: center;
}
.codon-table td span {
    color: #94a3b8;
    font-size: 0.7rem;
}

/* Aspect-Ratio Preserving Sprite Container */
.icon-container, .card-portrait {
    width: 3.5rem;
    height: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 0.65rem;
    padding: 0.3rem;
    box-sizing: border-box;
    margin-bottom: 0.35rem;
    transition: transform 0.2s ease;
}
.icon-container img, .card-portrait img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

/* Compact Character Intro and Responsive Grid */
.intro-box {
    width: 100%;
    max-width: 58rem;
    margin: 0 auto 0.75rem auto;
    padding: 0.75rem;
    background-color: rgba(24, 24, 27, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-sizing: border-box;
}
.cards-hint {
    text-align: center;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    color: #94a3b8;
    letter-spacing: 0.3px;
}
.cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    width: 100%;
}
@media (min-width: 540px) {
    .cards-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 720px) {
    .cards-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 860px) {
    .cards-grid { grid-template-columns: repeat(5, 1fr); }
}
@media (min-width: 1024px) {
    .cards-grid { grid-template-columns: repeat(5, 1fr); }
}

/* Character Card */
.character-card {
    position: relative;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.85rem;
    padding: 0.65rem 0.5rem 0.6rem 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}
.character-card:hover {
    animation: wiggle 0.4s ease-in-out;
    transform: translateY(-4px) scale(1.03);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}
.character-card:active {
    transform: scale(0.96);
}
.character-card:hover .card-portrait,
.character-card:hover .icon-container {
    transform: scale(1.08);
}

/* Four-sided border color indicators */
.card-hero { border-color: rgba(34, 211, 238, 0.4); }
.card-hero:hover { border-color: #22d3ee; box-shadow: 0 8px 24px rgba(34, 211, 238, 0.25); }
.card-ally { border-color: rgba(56, 189, 248, 0.35); }
.card-ally:hover { border-color: #38bdf8; box-shadow: 0 8px 24px rgba(56, 189, 248, 0.2); }
.card-threat { border-color: rgba(248, 113, 113, 0.35); }
.card-threat:hover { border-color: #f87171; box-shadow: 0 8px 24px rgba(248, 113, 113, 0.2); }

.card-badge {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.55rem;
    border-radius: 9999px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 0.35rem;
    line-height: 1.2;
}
.badge-hero { background: rgba(34, 211, 238, 0.2); color: #67e8f9; border: 1px solid rgba(34, 211, 238, 0.4); }
.badge-ally { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.4); }
.badge-threat { background: rgba(239, 68, 68, 0.2); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.4); }

.card-name {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.2rem;
}
.card-ability {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.72rem;
    color: #d4d4d8;
    line-height: 1.25;
    font-weight: 500;
}

/* Modals */
.modal {
    position: absolute;
    inset: 0;
    background-color: rgba(10, 4, 20, 0.88);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    z-index: 100;
    box-sizing: border-box;
}
.modal-header {
    flex-shrink: 0;
    padding-bottom: 0.75rem;
    text-align: center;
}
.modal-body {
    flex-grow: 1;
    overflow-y: auto;
    width: 100%;
    min-height: 0;
}
.modal-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    padding-top: 0.75rem;
    width: 100%;
}
.modal-title {
    font-size: 2.25rem;
    font-weight: 700;
    color: white;
    margin-bottom: 0.35rem;
    letter-spacing: 0.5px;
}
.modal-subtitle {
    font-size: 1.15rem;
    font-weight: 600;
    color: #facc15;
    margin-bottom: 0.75rem;
}
.game-over-title { font-size: 2rem; color: #facc15; }
.final-score-text { font-size: 1.35rem; font-weight: 700; color: #f4f4f5; margin-bottom: 0.5rem; }
.leaderboard-rank-text { font-size: 1.1rem; font-weight: 600; color: #facc15; margin-bottom: 1rem; }

/* Modal Specificity & Visibility */
.hidden,
.modal.hidden,
#factModal.hidden,
#howToModal.hidden,
#mainLeaderboardModal.hidden,
#soundOffIcon.hidden {
    display: none !important;
}

/* Modal Scrollbar */
.modal-body::-webkit-scrollbar { width: 8px; }
.modal-body::-webkit-scrollbar-track { background: #1e293b; border-radius: 4px; }
.modal-body::-webkit-scrollbar-thumb { background-color: #facc15; border-radius: 6px; border: 2px solid #1e293b; }

/* Input & Buttons */
.player-name-input {
    background-color: #27272a;
    color: white;
    width: 100%;
    max-width: 24rem;
    text-align: center;
    padding: 0.65rem 1rem;
    border-radius: 0.65rem;
    border: 2px solid rgba(255, 255, 255, 0.15);
    margin-bottom: 0.75rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    font-weight: 600;
}
.player-name-input:focus {
    outline: none;
    border-color: #22c55e;
}
.player-name-input.shake-input { animation: input-shake 0.4s; }
@keyframes input-shake {
    10%, 90% { transform: translateX(-3px); }
    20%, 80% { transform: translateX(3px); }
    30%, 50%, 70% { transform: translateX(-3px); }
    40%, 60% { transform: translateX(3px); }
}

.btn-primary, .btn-secondary {
    font-family: 'Fredoka', cursive, sans-serif;
    color: white;
    font-weight: 700;
    padding: 0.7rem 1.5rem;
    border-radius: 0.65rem;
    font-size: 1.05rem;
    letter-spacing: 0.5px;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.2s;
}
.btn-primary { background-color: #22c55e; }
.btn-primary:hover {
    transform: translateY(-2px) scale(1.02);
    background-color: #16a34a;
    box-shadow: 0 6px 18px rgba(34, 197, 94, 0.4);
}
.btn-primary:active {
    transform: translateY(1px) scale(0.98);
}
.btn-secondary { background-color: #3b82f6; }
.btn-secondary:hover {
    transform: translateY(-2px) scale(1.02);
    background-color: #2563eb;
    box-shadow: 0 6px 18px rgba(59, 130, 246, 0.4);
}
.btn-secondary:active {
    transform: translateY(1px) scale(0.98);
}
.modal-footer-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    max-width: 28rem;
    margin: 0 auto;
}

/* Animations */
@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-3deg) scale(1.03); }
    75% { transform: rotate(3deg) scale(1.03); }
}
@keyframes pulse-wiggle {
    0%, 100% { transform: scale(1) rotate(0deg); }
    20% { transform: scale(1.04) rotate(-2deg); }
    40% { transform: scale(1.04) rotate(2deg); }
    60% { transform: scale(1.02) rotate(-1deg); }
    80% { transform: scale(1.02) rotate(1deg); }
}

/* How to Play Corner Button */
.tutorial-corner-btn {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1.5px solid rgba(6, 182, 212, 0.4);
    border-radius: 9999px;
    padding: 0.4rem 0.85rem;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
    color: #a5f3fc;
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: all 0.2s ease;
}
.tutorial-corner-btn:hover {
    background: rgba(6, 182, 212, 0.2);
    border-color: rgba(6, 182, 212, 0.8);
    transform: translateY(-2px) scale(1.03);
}

/* How to Play Modal Card */
.how-to-card {
    position: relative;
    width: 100%;
    max-width: 48rem;
    max-height: 90vh;
    margin: auto;
    overflow-y: auto;
    background: linear-gradient(135deg, rgba(30, 10, 48, 0.96) 0%, rgba(15, 6, 26, 0.98) 100%);
    border: 2px solid rgba(6, 182, 212, 0.45);
    border-radius: 1.25rem;
    padding: 1.5rem 1.75rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 30px rgba(6, 182, 212, 0.25);
    text-align: center;
    box-sizing: border-box;
}
.how-to-header-badge {
    font-family: 'Fredoka', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.2rem 0.75rem;
    border-radius: 9999px;
    background: rgba(6, 182, 212, 0.2);
    color: #67e8f9;
    border: 1px solid rgba(6, 182, 212, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.how-to-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: white;
    margin: 0.5rem 0 0.25rem 0;
}
.how-to-subtitle {
    font-size: 0.95rem;
    color: #94a3b8;
    margin-bottom: 1.25rem;
}
.tutorial-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
@media (min-width: 640px) {
    .tutorial-grid { grid-template-columns: repeat(3, 1fr); }
}
.tutorial-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.85rem;
    padding: 0.85rem 0.65rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}
.tutorial-icon-box {
    width: 3.5rem;
    height: 3.5rem;
    margin-bottom: 0.5rem;
}
.tutorial-step-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #38bdf8;
    margin-bottom: 0.25rem;
}
.tutorial-step-desc {
    font-size: 0.8rem;
    color: #cbd5e1;
    line-height: 1.35;
}

/* Science Fact Modal */
.fact-card {
    position: relative;
    width: 100%;
    max-width: 28rem;
    margin: auto;
    background: linear-gradient(135deg, rgba(24, 24, 27, 0.98) 0%, rgba(15, 6, 26, 0.98) 100%);
    border: 2px solid rgba(34, 211, 238, 0.45);
    border-radius: 1.25rem;
    padding: 1.5rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 25px rgba(34, 211, 238, 0.2);
    text-align: center;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.fact-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 0.75rem;
}
.fact-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #94a3b8;
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s;
}
.fact-close-btn:hover { color: white; }
.fact-portrait {
    width: 4.5rem;
    height: 4.5rem;
    margin-bottom: 0.75rem;
}
.fact-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: white;
    margin: 0 0 0.5rem 0;
}
.fact-text {
    font-size: 0.92rem;
    color: #cbd5e1;
    line-height: 1.45;
    margin-bottom: 1.25rem;
}
.fact-btn {
    width: 100%;
    max-width: 12rem;
}

/* Leaderboard Sidebar & Podium */
.leaderboard-panel-title {
    font-size: 1.35rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.65rem;
    color: #facc15;
}
.leaderboard-tip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(6, 182, 212, 0.1);
    border: 1px dashed rgba(6, 182, 212, 0.35);
    border-radius: 0.65rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.8rem;
    color: #67e8f9;
}
.leaderboard-box {
    background: #18181b;
    padding: 0.75rem;
    border-radius: 0.65rem;
    font-size: 0.85rem;
}
.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.leaderboard-podium-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.4rem;
    border-radius: 0.65rem;
    background: rgba(255, 255, 255, 0.04);
}
.podium-rank-1 {
    background: linear-gradient(90deg, rgba(250, 204, 21, 0.2) 0%, rgba(35, 12, 50, 0.7) 100%);
    border: 1.5px solid rgba(250, 204, 21, 0.6);
}
.podium-rank-2 {
    background: linear-gradient(90deg, rgba(203, 213, 225, 0.2) 0%, rgba(35, 12, 50, 0.7) 100%);
    border: 1.5px solid rgba(203, 213, 225, 0.6);
}
.podium-rank-3 {
    background: linear-gradient(90deg, rgba(251, 146, 60, 0.2) 0%, rgba(35, 12, 50, 0.7) 100%);
    border: 1.5px solid rgba(251, 146, 60, 0.6);
}
.podium-badge {
    font-size: 0.75rem;
    font-weight: 700;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.4rem;
}
.podium-badge.rank-1 { background: #facc15; color: #1e092b; }
.podium-badge.rank-2 { background: #cbd5e1; color: #1e092b; }
.podium-badge.rank-3 { background: #fb923c; color: #1e092b; }

/* Notifications */
#notification-container {
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    z-index: 100;
}
.notification-item {
    font-size: 1.4rem;
    font-weight: 700;
    text-shadow: 0 0 10px black, 0 0 20px black;
    animation: ready-pulse 0.5s ease-out, fade-in 0.3s ease-out;
    opacity: 1;
    transition: opacity 0.5s ease-out;
    white-space: nowrap;
}
.notification-item.fade-out { opacity: 0; }
@keyframes ready-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
@keyframes fade-in {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Footer */
.global-footer { flex-shrink: 0; padding-top: 0.5rem; }
.footer-content { display: flex; align-items: center; justify-content: center; gap: 1rem; }
.footer-logo { height: 2.5rem; transition: transform 0.2s ease-in-out; }
.footer-logo.large { height: 3rem; }
.footer-link { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; color: #a1a1aa; transition: color 0.2s; }
.footer-link:hover { color: #f4f4f5; }
.footer-link:hover .footer-logo { transform: scale(1.1); }

/* Responsive Layout */
@media (min-width: 768px) {
    .modal-footer-buttons { flex-direction: row; justify-content: center; }
}
@media (min-width: 1024px) {
    body {
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .page-container {
        display: grid;
        grid-template-columns: minmax(0, 3fr) minmax(0, 1fr);
        grid-template-rows: auto 1fr auto;
        grid-template-areas:
            "header header"
            "main   leaderboard"
            "footer footer";
        height: 95vh;
        max-height: 900px;
        max-width: 82rem;
        gap: 1rem;
        align-content: center;
    }
    .hud-container { grid-area: header; }
    .game-wrapper {
        grid-area: main;
        min-height: 0;
    }
    .leaderboard-panel {
        grid-area: leaderboard;
        display: flex;
        flex-direction: column;
        background-color: #27272a;
        border-radius: 0.85rem;
        padding: 1rem;
        border: 2px solid rgba(255, 255, 255, 0.12);
        min-height: 0;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    }
    .leaderboard-box { overflow-y: auto; flex-grow: 1; min-height: 0; }
    #leaderboardBtn,
    #leaderboardGameOverBtn {
        display: none !important;
    }
    .global-footer { grid-area: footer; }

    .modal-footer-buttons {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
    }
    #start-game-btn, #start-challenge-btn {
        margin: 0 auto;
    }
}
@media (max-width: 640px) {
    .modal-title { font-size: 1.75rem; }
    .control-btn { font-size: 1.05rem; padding: 0.5rem; min-width: 60px; }
    .amino-acid-btn { font-size: 0.85rem; min-width: 85px; }
    .hud-center { flex-direction: column-reverse; }
}

.hud-mute-button {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    transition: transform 0.15s ease, background-color 0.2s, border-color 0.2s;
}

.hud-mute-button:hover {
    transform: scale(1.06);
    background: rgba(39, 39, 42, 0.95);
    border-color: #a1a1aa;
}

.hud-mute-button:active {
    transform: scale(0.95);
}

.hud-mute-button svg {
    width: 1.25rem;
    height: 1.25rem;
    display: block;
}

#rotate-warning {
    display: none;
    position: fixed;
    inset: 0;
    background-color: #18181b;
    color: #f4f4f5;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 200;
    padding: 1.5rem;
    font-family: 'Fredoka', sans-serif;
}

.rotate-icon {
    width: 4.5rem;
    height: 4.5rem;
    margin-bottom: 1.25rem;
    color: #38bdf8;
    animation: rotate-pulse 2s infinite ease-in-out;
}

@keyframes rotate-pulse {
    0%, 100% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(90deg) scale(1.08); }
}

@media screen and (max-width: 1023px) and (orientation: portrait) {
    .page-container, footer {
        display: none !important;
    }
    #rotate-warning {
        display: flex !important;
    }
}

@media screen and (max-height: 540px) and (orientation: landscape) {
    footer {
        display: none !important;
    }
    .page-container {
        padding: 0.25rem 0.5rem;
    }
    .game-wrapper {
        max-width: 100%;
        height: 100%;
    }
    .leaderboard-panel {
        display: none !important;
    }
    .hud {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        margin-bottom: 0.25rem !important;
        gap: 0.35rem !important;
    }
    .hud-element {
        font-size: 0.78rem;
        padding: 0.2rem 0.5rem;
        border-radius: 0.5rem;
    }
    .hud-label {
        display: none !important;
    }
    .integrity-container {
        min-width: 70px;
        max-width: 180px;
        flex-grow: 1;
    }
    .integrity-bar {
        height: 0.95rem;
        border-radius: 0.35rem;
    }
    .hud-mute-button {
        display: flex !important;
        padding: 0.2rem 0.4rem;
    }
    .canvas-container,
    .game-area-wrapper,
    #game-container {
        min-height: 0;
        flex: 1 1 auto;
    }
    canvas {
        max-height: 100%;
        max-width: 100%;
    }
    .modal {
        padding: 0.35rem 0.6rem;
    }
    .modal-header {
        padding-bottom: 0.15rem;
    }
    .modal-title {
        font-size: 1.3rem;
        line-height: 1.1;
    }
    .modal-subtitle {
        font-size: 0.7rem;
        margin: 0;
    }
    .tutorial-corner-btn {
        top: 0.35rem;
        left: 0.35rem;
        right: auto !important;
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
    }
    .intro-box {
        padding: 0.3rem 0.4rem;
        margin-bottom: 0.25rem;
    }
    .cards-hint {
        font-size: 0.65rem;
        margin-bottom: 0.15rem;
    }
    .cards-grid {
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 0.25rem;
    }
    .character-card {
        padding: 0.25rem 0.2rem;
        border-radius: 0.5rem;
    }
    .card-badge {
        font-size: 0.5rem;
        padding: 0.05rem 0.25rem;
        margin-bottom: 0.15rem;
    }
    .card-portrait, .icon-container {
        width: 2rem;
        height: 2rem;
        padding: 0.15rem;
        margin-bottom: 0.15rem;
    }
    .card-name {
        font-size: 0.65rem;
        margin-bottom: 0.05rem;
    }
    .card-ability {
        font-size: 0.56rem;
        line-height: 1.1;
    }
    .modal-footer {
        padding-top: 0.25rem;
    }
    .player-name-input {
        padding: 0.3rem 0.6rem;
        font-size: 0.85rem;
        max-width: 16rem;
        border-radius: 0.5rem;
    }
    .modal-footer-buttons {
        margin-top: 0.25rem;
        gap: 0.5rem;
    }
    .btn-primary, .btn-secondary {
        padding: 0.35rem 1rem;
        font-size: 0.88rem;
        border-radius: 0.5rem;
    }
    .game-over-title {
        font-size: 1.3rem;
    }
    .game-over-fact-card {
        padding: 0.35rem 0.6rem;
        max-width: 22rem;
        margin: 0.2rem auto;
    }
    .game-over-fact-portrait {
        width: 2.75rem;
        height: 2.75rem;
        margin-bottom: 0.2rem;
    }
    .game-over-fact-title {
        font-size: 0.95rem;
        margin-bottom: 0.15rem;
    }
    .game-over-fact-text {
        font-size: 0.72rem;
        line-height: 1.25;
    }
    #mainLeaderboardModal .modal-body,
    .how-to-card,
    .fact-card {
        max-height: 85vh;
        overflow-y: auto;
    }
    .tutorial-cards {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.35rem;
    }
    .tutorial-card {
        padding: 0.4rem;
    }
    .tutorial-step-img {
        width: 2rem;
        height: 2rem;
    }
}

.science-corner-btn {
    position: absolute;
    top: 1rem;
    left: auto;
    right: 1rem;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #f4f4f5;
    background: rgba(5, 150, 105, 0.35);
    border: 1.5px solid #34d399;
    border-radius: 9999px;
    padding: 0.35rem 1rem;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}
.science-corner-btn:hover {
    background: #059669;
    color: #ffffff;
    box-shadow: 0 0 15px rgba(52, 211, 153, 0.6);
    transform: translateY(-1px);
}
#scienceInfoModal {
    position: fixed;
    inset: 0;
    z-index: 110;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    box-sizing: border-box;
}
#scienceInfoModal.hidden {
    display: none !important;
}
.science-info-card {
    position: relative;
    background: #18181b;
    border: 2px solid #34d399;
    border-radius: 1.25rem;
    padding: 1.5rem;
    max-width: 48rem;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.65);
    margin: auto;
}
.science-info-body {
    text-align: left;
    color: #d4d4d8;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.85rem;
    line-height: 1.55;
    width: 100%;
}
.science-info-body h3 {
    color: #6ee7b7;
    font-size: 0.95rem;
    font-weight: 700;
    margin: 1rem 0 0.4rem 0;
}
.science-info-body p { margin: 0.5rem 0; }
.science-info-body ul {
    margin: 0.3rem 0 0.6rem 1.1rem;
    list-style: disc;
}
.science-info-body li { margin: 0.2rem 0; }
.science-info-body a {
    color: #38bdf8;
    text-decoration: underline;
}
.science-info-body a:hover { color: #7dd3fc; }
.science-grade { font-size: 0.8rem; color: #a1a1aa; }
@media (max-width: 1024px) {
    .science-corner-btn {
        top: 0.35rem;
        right: 0.35rem;
        left: auto !important;
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
    }
}

.footer-legal {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    margin-top: 0.4rem;
    font-family: 'Fredoka', sans-serif;
    font-size: 0.7rem;
}
.footer-legal a, .footer-legal-btn {
    color: #71717a;
    text-decoration: none;
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    cursor: pointer;
}
.footer-legal a:hover, .footer-legal-btn:hover { color: #34d399; }
