:root {
    --rpg-gold: #f1c40f;
    --rpg-green: #2ecc71;
    --rpg-green-dark: #27ae60;
    --rpg-blue: #3498db;
    --rpg-blue-dark: #2980b9;
    --rpg-brown: #3e2723;
    --ssr: #ff00ff;
    /* Pink/Rainbow for SSR in reference */
    --sr: #f39c12;
    --r: #bdc3c7;
}

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

.hidden {
    display: none !important;
}

body {
    font-family: 'Outfit', 'Noto Sans JP', sans-serif;
    background-color: #000;
    color: #fff;
    overflow: hidden;
}

#game-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: 100dvh;
    /* Use dynamic viewport height to prevent browser UI overlap */
    background: #111;
}

#game-container {
    width: 100%;
    max-width: 450px;
    height: 100%;
    max-height: 850px;
    background: url('bg.png') no-repeat center bottom;
    background-size: cover;
    position: relative;
    display: flex;
    flex-direction: column;
    border: 4px solid #4e342e;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
}

/* Header Improvements */
#rpg-header {
    background: transparent;
    padding: 1rem 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.gem-display {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    padding: 0 12px 0 0;
    border-radius: 20px;
    border: 2px solid rgba(141, 110, 99, 0.8);
    gap: 4px;
    backdrop-filter: blur(5px);
    height: 32px;
    /* Small frame height */
    margin-top: 10px;
}

.gem-icon-img {
    width: 55px;
    /* Icon is still large */
    height: 55px;
    object-fit: contain;
    filter: drop-shadow(0 0 8px rgba(0, 229, 255, 0.6));
    margin-left: -15px;
    /* Let it pop out to the left */
    margin-top: -2px;
}

#gem-count {
    font-weight: 900;
    color: #fff;
    font-size: 1.1rem;
    font-family: 'Outfit', sans-serif;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.add-gem-btn {
    background: #4caf50;
    border: none;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    margin-left: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s;
    line-height: 1;
}

.add-gem-btn:active {
    transform: scale(0.9);
}

.icon-btn {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.2);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
    backdrop-filter: blur(5px);
}

.icon-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.icon-mail {
    font-size: 1.2rem;
}

.notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #ff5252;
    border: 2px solid #fff;
    border-radius: 50%;
    animation: pulseBadge 2s infinite;
}

@keyframes pulseBadge {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(255, 82, 82, 0.7);
    }

    70% {
        transform: scale(1.2);
        box-shadow: 0 0 10px rgba(255, 82, 82, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(255, 82, 82, 0);
    }
}

/* Content Modals */
.content-modal .modal-content {
    background: #fdf5e6;
    /* Parchment color */
    background-image:
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.2) 0%, transparent 80%),
        linear-gradient(45deg, rgba(139, 69, 19, 0.05) 25%, transparent 25%, transparent 50%, rgba(139, 69, 19, 0.05) 50%, rgba(139, 69, 19, 0.05) 75%, transparent 75%, transparent);
    background-size: 100% 100%, 4px 4px;
    border: 8px double #8b4513;
    border-radius: 5px;
    width: 92%;
    max-height: 85%;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    color: #3e2723;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8), inset 0 0 100px rgba(139, 69, 19, 0.2);
}

.modal-title {
    color: #8b4513;
    text-align: center;
    margin-bottom: 1.2rem;
    font-size: 1.6rem;
    font-weight: 900;
    border-bottom: 3px double #8b4513;
    padding-bottom: 0.5rem;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.5);
}

.modal-body {
    flex-grow: 1;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.6;
}

.scrollable::-webkit-scrollbar {
    width: 8px;
}

.scrollable::-webkit-scrollbar-thumb {
    background: #8d6e63;
    border-radius: 4px;
}

.encyclopedia-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.ency-item {
    display: flex;
    gap: 1.2rem;
    align-items: center;
    background: rgba(139, 69, 19, 0.1);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid rgba(139, 69, 19, 0.2);
    transition: transform 0.2s;
}

.ency-item:hover {
    transform: translateX(5px);
    background: rgba(139, 69, 19, 0.15);
}

.ency-item img {
    width: 70px;
    height: 70px;
    object-fit: contain;
    filter: drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.3));
}

.ency-item strong {
    color: #5d4037;
    font-size: 1rem;
}

.ency-item div {
    font-size: 0.85rem;
    color: #4e342e;
}

.video-placeholder {
    height: 100px;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 2px dashed #8d6e63;
    border-radius: 10px;
    color: #ffeb3b;
    margin-top: 1rem;
    font-weight: bold;
}

.mail-list,
.trivia-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mail-item {
    background: rgba(139, 69, 19, 0.05);
    border: 1px solid rgba(139, 69, 19, 0.1);
    border-radius: 10px;
    padding: 12px;
    position: relative;
}

.mail-item.unread {
    background: rgba(255, 235, 59, 0.05);
    border-color: rgba(255, 235, 59, 0.3);
}

.mail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.mail-tag {
    background: #ff5252;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 900;
    padding: 2px 6px;
    border-radius: 4px;
}

.mail-date {
    font-size: 0.75rem;
    color: #8d6e63;
}

.mail-body {
    font-size: 0.85rem;
    line-height: 1.4;
    color: #3e2723;
}

.trivia-item {
    background: rgba(139, 69, 19, 0.08);
    padding: 14px;
    border-radius: 8px;
    border-left: 5px solid #8b4513;
}

.trivia-q {
    font-weight: 900;
    color: #8b4513;
    margin-bottom: 6px;
    font-size: 1rem;
}

.trivia-a {
    color: #4e342e;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Main Gacha */
#rpg-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 1.5rem;
    position: relative;
    width: 100%;
}

.logo-section {
    width: 80%;
    margin-top: -60px;
    margin-bottom: 0.5rem;
    z-index: 2;
    filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.5));
    animation: fadeInDown 0.8s ease-out;
}

.main-logo-img {
    width: 100%;
    height: auto;
    object-fit: contain;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.center-visual {
    flex-grow: 1;
    width: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

#center-character {
    width: 50%;
    max-height: 160px;
    object-fit: contain;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.6));
    animation: floatAnim 5s infinite ease-in-out;
}

@keyframes floatAnim {

    0%,
    100% {
        transform: scale(2.5) translateY(10px);
    }

    50% {
        transform: scale(2.5) translateY(15px);
    }
}

.slideshow-container {
    position: absolute;
    bottom: 5%;
    right: 5%;
    width: 45%;
    max-width: 200px;
    border: 2px solid var(--rpg-gold, #ffeb3b);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.6);
    background: rgba(0, 0, 0, 0.8);
}

#notification-slide {
    width: 100%;
    height: auto;
    display: block;
    animation: fadeIn 1s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Featured Bar */
.featured-bar {
    width: 90%;
    background: #fdf5e6;
    /* Parchment color */
    border: 3px solid #8b4513;
    border-radius: 15px;
    padding: 5px;
    margin-bottom: 1rem;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
}

.featured-label {
    background: #8b4513;
    color: #fff;
    font-size: 0.7rem;
    text-align: center;
    padding: 2px;
    border-radius: 5px;
    margin-bottom: 5px;
}

.featured-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.feat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.feat-item img {
    width: 45px;
    height: 45px;
    object-fit: contain;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.5));
}

.feat-item span {
    font-size: 0.6rem;
    font-weight: 900;
    padding: 1px 4px;
    border-radius: 3px;
    margin-top: 2px;
}

.ssr-text {
    background: #ff00ff;
    color: #fff;
}

.sr-text {
    background: #3498db;
    color: #fff;
}

.r-text {
    background: #2ecc71;
    color: #fff;
}

/* Action Buttons */
.action-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding-bottom: 1.5rem;
}

.rpg-btn-img {
    width: 75%;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), filter 0.2s;
    animation: pulse 2s infinite ease-in-out;
}

.rpg-btn-img img {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.6));
}

.rpg-btn-img:active {
    transform: scale(0.95) translateY(4px);
    filter: brightness(1.1);
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.03);
    }

    100% {
        transform: scale(1);
    }
}

.btn-top {
    font-size: 1.1rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.btn-bottom {
    font-size: 0.8rem;
    color: #fff;
    opacity: 0.9;
}

.gem-small {
    color: #00e5ff;
}

/* Footer */
#rpg-footer {
    background: #3e2723;
    border-top: 3px solid #5d4037;
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
}

.footer-nav {
    display: flex;
    justify-content: space-around;
}

.f-nav-item {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #d7ccc8;
    cursor: pointer;
    text-decoration: none;
    gap: 4px;
    /* Added gap between icon and text */
}

.f-nav-item.active {
    color: #ffeb3b;
}

.f-icon {
    font-size: 1.8rem;
    /* Increased size */
    display: flex;
    justify-content: center;
    align-items: center;
}

.f-icon-img {
    width: 40px;
    /* Increased size */
    height: 40px;
    object-fit: contain;
}

.f-label {
    font-size: 0.8rem;
    /* Increased size */
    font-weight: bold;
    /* Added bold */
}

/* Modal */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    transition: opacity 0.3s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal.hidden {
    display: none;
    opacity: 0;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    z-index: 1001;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    animation: modalScaleUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.content-modal .modal-content {
    width: 90%;
    max-width: 400px;
    height: auto;
    max-height: 85vh;
    background: #3e2723;
    border: 3px solid #8d6e63;
    border-radius: 15px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.9);
    padding: 1.5rem;
    justify-content: flex-start;
}

.modal-title {
    color: #ffeb3b;
    font-size: 1.2rem;
    margin-bottom: 1rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    width: 100%;
    text-align: center;
}

.modal-body {
    width: 100%;
    color: #ffffff;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-y: auto;
    overflow-x: hidden;
    margin-bottom: 1rem;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
}

.modal-body p {
    margin-bottom: 0.8rem;
}

@keyframes modalScaleUp {
    from {
        transform: scale(0.85);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

#reveal-animation {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

#reveal-animation.hidden {
    display: none;
}

#gacha-video {
    width: 40%;
    height: auto;
    /* 40% の安全なサイズで描画処理を行った後、見た目だけを1.875倍（=75%相当）に拡大する */
    transform: scale(1.875);
}

#result-display {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    padding: 4rem 0 2rem;
}

#result-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    width: 90%;
    max-width: 380px;
    margin: 0 auto 1rem;
}

.result-card {
    background: #4e342e;
    background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, transparent 100%);
    border: 3px solid #8d6e63;
    border-radius: 12px;
    padding: 6px;
    text-align: center;
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.2);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.5);
    aspect-ratio: 1 / 1.15;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.result-card img {
    width: 100%;
    height: auto;
    max-height: 90px;
    object-fit: contain;
    filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.5));
    transform: scale(1.2);
    /* Visually enlarge the character */
    margin-bottom: 5px;
    /* Adjust spacing for the scaled image */
}

.result-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.1), transparent);
    transform: skewX(-25deg);
    transition: 0.5s;
}

.result-card.show::before {
    left: 150%;
    transition: 1s 0.5s;
}

.result-card.show {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.result-card.ssr {
    border-color: #ff00ff;
    box-shadow: 0 0 25px rgba(255, 0, 255, 0.5), inset 0 0 20px rgba(255, 0, 255, 0.2);
    background: linear-gradient(135deg, #4e342e 0%, #2a1b19 100%);
}

.result-card.ssr::after {
    content: '★5';
    position: absolute;
    top: 5px;
    right: 5px;
    background: #ff00ff;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 900;
    padding: 2px 4px;
    border-radius: 4px;
    box-shadow: 0 0 10px #ff00ff;
}

.char-name {
    margin-top: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    color: #fdf5e6;
}

.rpg-btn-close {
    background: #5d4037;
    color: #fff;
    border: 2px solid #8d6e63;
    padding: 10px 40px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
}

/* Modal Content Details */
.info-list,
.encyclopedia-list,
.mail-list,
.trivia-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-row {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(141, 110, 99, 0.5);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.info-label {
    font-weight: 900;
    color: #ffeb3b !important;
    font-size: 0.85rem;
    border-bottom: 1px dashed rgba(255, 235, 59, 0.3);
    padding-bottom: 4px;
}

.info-value {
    color: #ffffff !important;
    font-size: 0.95rem;
    line-height: 1.5;
}

.ency-item,
.mail-item,
.trivia-item {
    background: rgba(0, 0, 0, 0.5);
    /* Background is a bit darker for better contrast */
    border-radius: 10px;
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid rgba(141, 110, 99, 0.3);
    color: #ffffff !important;
    /* Force white for all modal items */
}

.ency-item strong,
.mail-body strong,
.trivia-q,
.trivia-a,
.mail-date,
.ency-item div,
.mail-body {
    color: #ffffff !important;
    /* Ensure nested titles and text are white */
}

.ency-item img {
    width: 50px;
    height: 50px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.trivia-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.trivia-q {
    color: #ffeb3b !important;
    font-weight: bold;
    border-bottom: 1px dashed rgba(255, 235, 59, 0.3);
    padding-bottom: 4px;
    width: 100%;
}

.close-modal-btn {
    margin-top: 1rem;
    width: 100%;
}

.rpg-btn-video {
    display: block;
    background: #ffffff;
    color: #000000;
    text-align: center;
    padding: 12px;
    border-radius: 10px;
    text-decoration: none;
    font-weight: bold;
    margin-top: 1rem;
    transition: transform 0.2s;
    text-shadow: none;
}

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

.google-map {
    width: 100%;
    height: 200px;
    border: 2px solid rgba(141, 110, 99, 0.5);
    border-radius: 8px;
    margin-top: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.direction-btns {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
    margin-bottom: 10px;
}

.yt-btn {
    background: #5d4037;
    /* Softer, RPG-themed brown */
    color: #fff !important;
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 0.75rem;
    /* Smaller to fit side-by-side */
    display: block;
    border: 1px solid #8d6e63;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s, filter 0.1s;
    flex: 1 1 30%;
    /* Take up roughly a third of the row each */
    text-align: center;
}

.yt-btn:active {
    transform: scale(0.98);
    filter: brightness(1.2);
}