@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@500;800&display=swap');

/* --- GLOBAL STYLES --- */
html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background-color: #6bc04b;
    background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0px, rgba(255, 255, 255, 0.1) 20px, transparent 20px, transparent 40px);
}

body {
    font-family: 'M PLUS Rounded 1c', sans-serif;
    color: #333333;
    display: flex;
    justify-content: center;
    padding: 40px 20px;
    box-sizing: border-box;
}

.gacha-container {
    background-color: #f7f9fc;
    padding: 30px;
    border-radius: 20px;
    border: 4px solid #ffffff;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    max-width: 900px;
    width: 100%;
    text-align: center;
}

h1 {
    color: #e04a73;
    margin-top: 0;
    font-weight: 800;
}

.rates p {
    font-weight: 500;
    color: #555555;
}

/* --- PULL & CARROT COUNTER --- */
.counter-display {
    background-color: #ffffff;
    border: 2px solid #e2e8f0;
    border-radius: 20px;
    padding: 8px 15px;
    display: inline-block;
    margin-top: 15px;
    font-weight: 800;
    color: #f69c00;
    box-shadow: 0 4px 0 #e2e8f0;
}

.carrot-icon {
    font-size: 18px;
}

/* --- BUTTONS --- */
.controls button {
    background: linear-gradient(180deg, #38c8ff 0%, #1da0f2 100%);
    color: white;
    border: 2px solid #1a8ccf;
    padding: 12px 25px;
    margin: 5px;
    font-size: 16px;
    border-radius: 30px;
    cursor: pointer;
    font-weight: 800;
    box-shadow: 0 4px 0 #1579b5;
    transition: transform 0.1s, box-shadow 0.1s;
}

.controls button:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #1579b5;
}

.controls .clear-btn {
    background: linear-gradient(180deg, #ff7b7b 0%, #ed4245 100%);
    border-color: #c03537;
    box-shadow: 0 4px 0 #c03537;
}

.controls .clear-btn:active {
    box-shadow: 0 0 0 #c03537;
}

/* --- RESULTS GRID --- */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); /* Increased from 120px */
    gap: 15px;
    margin-top: 20px;
    min-height: 150px;
}

/* --- 3D CARD LAYOUT --- */
.character-card {
    background-color: transparent;
    perspective: 1000px;
    cursor: pointer;
    min-height: 190px; /* Increased from 160px to fit longer names */
    animation: popIn 0.3s ease-out;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}

.character-card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front, .card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.card-front {
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    z-index: 2;
    transform: rotateY(0deg);
    -webkit-transform: rotateY(0deg);
}

.tap-text {
    font-weight: 800;
    color: #333333;
    font-size: 16px;
    text-shadow: 0 2px 4px rgba(255,255,255,0.8);
}

/* --- FRONT COLOURS (SEALED) --- */
.star-1 .card-front {
    background: linear-gradient(135deg, #f7f9fc, #a0aec0);
    border: 3px solid #718096;
}

.star-2 .card-front {
    background: linear-gradient(135deg, #fffbeb, #ffd700);
    border: 3px solid #d4af37;
}

.star-3 .card-front {
    background-color: #ffffff;
    border: 3px solid #ff00ff; /* Solid fallback colour */
    animation: rainbowGlow 3s linear infinite;
}

/* --- BACK COLOURS (REVEALED) --- */
.card-back {
    background-color: #ffffff;
    transform: rotateY(180deg);
    -webkit-transform: rotateY(180deg);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    z-index: 1;
}

.star-1 .card-back {
    border: 3px solid #a0aec0;
}

.star-2 .card-back {
    border: 3px solid #ffd700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}

/* --- COLOURS (REVEALED) --- */
.star-3 .card-back {
    background-color: #ffffff;
    border: 3px solid #ff00ff;
    position: relative;
    
    /* Removed overflow: hidden; to stop the card disappearing */
    /* Added clip-path to keep the shimmer neatly inside the rounded corners */
    clip-path: inset(0 round 12px); 
    
    animation: rainbowGlow 3s linear infinite, pulse 2s ease-in-out infinite;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
}

.star-3 .card-back::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.8) 50%, rgba(255,255,255,0) 100%);
    transform: rotate(30deg);
    animation: shimmer 2.5s infinite;
    pointer-events: none;
}

/* --- CARD CONTENTS --- */
.char-img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 10px;
    margin: 10px 0;
    background-color: #f1f5f9;
    position: relative;
    z-index: 1;
    border: none;
}

.char-name {
    font-weight: 800;
    margin-top: 8px; /* Slightly more vertical gap */
    font-size: 14px;
    position: relative;
    z-index: 1;
    text-align: center; /* Centres the text */
    padding: 0 5px; /* Adds a buffer so text doesn't hit the edges */
    line-height: 1.2;
}

.char-stars {
    margin-top: 5px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    position: relative;
    z-index: 1;
}

/* --- INVENTORY --- */
.divider {
    border: 0;
    height: 2px;
    background: #e2e8f0;
    margin: 30px 0;
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.inventory-item {
    background-color: #ffffff;
    padding: 10px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 800;
    border: 2px solid #e2e8f0;
    border-left: 6px solid #1da0f2;
}

.inventory-item.inv-star-3 { border-left-color: #ff00ff; }
.inventory-item.inv-star-2 { border-left-color: #ffd700; }
.inventory-item.inv-star-1 { border-left-color: #a0aec0; }

.item-count {
    background-color: #e2e8f0;
    color: #333333;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 12px;
}

.empty-msg {
    grid-column: 1 / -1;
    color: #a0aec0;
    font-style: italic;
}

/* --- WIPE BUTTON --- */
.wipe-container {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px dashed #e2e8f0;
}

.wipe-btn {
    background: linear-gradient(180deg, #ff7b7b 0%, #ed4245 100%);
    color: white;
    border: 2px solid #c03537;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 30px;
    cursor: pointer;
    font-weight: 800;
    box-shadow: 0 4px 0 #c03537;
    transition: transform 0.1s, box-shadow 0.1s;
}

.wipe-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #c03537;
}

/* --- CHAT SIDEBAR --- */
#chat-toggle-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 900;
    background: linear-gradient(180deg, #38c8ff 0%, #1da0f2 100%);
    color: white;
    border: 2px solid #1a8ccf;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 800;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 4px 0 #1579b5, 0 10px 20px rgba(0,0,0,0.2);
    transition: transform 0.1s, box-shadow 0.1s;
}

#chat-toggle-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #1579b5;
}

.chat-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 350px;
    height: 100vh;
    background-color: #f7f9fc;
    border-left: 4px solid #1da0f2;
    box-shadow: -10px 0 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-sidebar.hidden {
    transform: translateX(110%);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: #ffffff;
    border-bottom: 2px solid #e2e8f0;
}

.chat-header h3 {
    margin: 0;
    color: #e04a73;
    font-weight: 800;
}

.close-chat-btn {
    background: none;
    border: none;
    color: #a0aec0;
    font-size: 20px;
    cursor: pointer;
    font-weight: bold;
    transition: color 0.2s;
}

.close-chat-btn:hover {
    color: #ed4245;
}

/* --- ANIMATIONS --- */
@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes rainbowGlow {
    0% { border-color: #ff0000; box-shadow: 0 0 15px rgba(255,0,0,0.5); }
    16% { border-color: #ff7f00; box-shadow: 0 0 15px rgba(255,127,0,0.5); }
    33% { border-color: #ffff00; box-shadow: 0 0 15px rgba(255,255,0,0.5); }
    50% { border-color: #00ff00; box-shadow: 0 0 15px rgba(0,255,0,0.5); }
    66% { border-color: #0000ff; box-shadow: 0 0 15px rgba(0,0,255,0.5); }
    83% { border-color: #4b0082; box-shadow: 0 0 15px rgba(75,0,130,0.5); }
    100% { border-color: #ff0000; box-shadow: 0 0 15px rgba(255,0,0,0.5); }
}

@keyframes shimmer {
    0% { transform: translateX(-100%) rotate(30deg); }
    100% { transform: translateX(100%) rotate(30deg); }
}

@keyframes pulse {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.03); }
    100% { transform: rotateY(180deg) scale(1); }
}


/* --- EXTRA CONTENT & CUSTOM BUTTON --- */
.extra-content-container {
    margin-top: 20px;
    padding-bottom: 10px;
}

.custom-link-btn {
    background: linear-gradient(180deg, #4a4d53 0%, #2b2b2e 100%);
    color: white;
    border: 2px solid #1a1a1c;
    padding: 12px 25px;
    margin: 5px;
    font-size: 16px;
    border-radius: 30px;
    cursor: pointer;
    font-weight: 800;
    box-shadow: 0 4px 0 #1a1a1c;
    text-decoration: none;
    display: inline-block;
    transition: transform 0.1s, box-shadow 0.1s;
}

.custom-link-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #1a1a1c;
}