/* Base Variables */
:root {
    --color-primary: #e6322e; /* Vermilion (Shu-iro) */
    --color-primary-dark: #b01e1a;
    --color-bg: #fcfaf2; /* Cream/Washi paper color */
    --color-text: #333333; /* Sumi ink */
    --color-gold: #d4af37;
    --color-shadow: rgba(0, 0, 0, 0.1);
    --font-main: 'Noto Serif JP', serif;
    --ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
}

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

body {
    font-family: var(--font-main);
    background-color: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Prevent scrolling during animation if possible */
    background-image:
        radial-gradient(var(--color-shadow) 1px, transparent 1px),
        radial-gradient(var(--color-shadow) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
}

.app-container {
    width: 100%;
    max-width: 480px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh; /* Full screen on mobile */
    justify-content: space-between;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
    z-index: 10;
}

.title {
    font-size: 2.5rem;
    letter-spacing: 0.2em;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 0px rgba(230, 50, 46, 0.1);
}

.subtitle {
    font-size: 0.9rem;
    color: var(--color-primary);
    letter-spacing: 0.1em;
    opacity: 0.8;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    position: relative;
}

.omikuji-container {
    pointer-events: none;
    position: absolute;
    z-index: 99;
    width: 370px; /* Slightly wider */
    min-height: 60vh; /* Taller to fit more text */
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 3rem;
    perspective: 1000px;
}

/* Omikuji Box (Hexagonal Prism representation roughly) */
.omikuji-box {
    width: 120px;
    height: 200px;
    background: linear-gradient(135deg, #e6322e 0%, #b01e1a 100%);
    position: relative;
    border-radius: 4px; /* Slightly rounded */
    box-shadow:
        10px 10px 20px rgba(0,0,0,0.2),
        inset 2px 2px 5px rgba(255,255,255,0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    transform-origin: bottom center;
    transition: transform 0.5s var(--ease-out-quint);
    z-index: 5;
}

/* Decorative hole on top */
.omikuji-box::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 20px;
    background-color: #330000;
    border-radius: 50%;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
}

.box-body {
    writing-mode: vertical-rl;
    text-orientation: upright;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    letter-spacing: 0.5em;
    border: 2px solid rgba(255,255,255,0.3);
    padding: 1rem 0.5rem;
}

/* Shake Animation */
@keyframes shake {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(15deg); }
    50% { transform: rotate(-15deg); }
    75% { transform: rotate(10deg); }
    100% { transform: rotate(0deg); }
}

.omikuji-box.shaking {
    animation: shake 0.5s infinite;
}

/* Stick (The Omikuji stick popping out) */
.stick {
    position: absolute;
    top: 10px; /* Hidden inside */
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 80px;
    background-color: #f0e68c;
    border-radius: 2px;
    z-index: 1; /* Behind box front but visible when popping */
    transition: top 0.5s ease-out;
    opacity: 0;
}

.stick.popping {
    opacity: 1;
    top: -60px; /* Pop out */
}

/* Result Card */
.result-card {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--color-primary);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Start from top */
    align-items: center;
    padding: 2rem 1.5rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    z-index: 20;
    text-align: center;

    /* Animation initial state */
    opacity: 0;
    transform: scale(0.8) translateY(20px);
    pointer-events: none;
    transition: all 0.6s var(--ease-out-quint);
    overflow-y: auto; /* Scroll if text is really long */
}

.result-card.visible {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.result-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem; /* Reduced space */
    color: var(--color-gold);
    flex-shrink: 0;
}

.decorative-icon {
    font-size: 0.8rem;
}

.result-header h2 {
    font-size: 1rem;
    color: var(--color-text);
    font-weight: normal;
}

.result-image-container {
    flex-shrink: 0;
    width: 100%;
        max-width: 200px;
    height: auto; /* Fixed height for image area */
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
    overflow: hidden;
    border-radius: 4px;
    background-color: #f0f0f0;
}

.result-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.result-card:hover .result-image {
    transform: scale(1.05); /* Subtle zoom on hover */
}

.result-value {
    font-size: 2.6rem; /* Slightly smaller to fit long names */
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 1rem;
    line-height: 1.2;
    border-top: 1px solid var(--color-bg);
    border-bottom: 1px solid var(--color-bg);
    padding: 0.5rem 0;
    width: 100%;
    background-image: linear-gradient(to right, transparent, rgba(230, 50, 46, 0.05), transparent);
    flex-shrink: 0;
}

.result-message {
    font-size: 0.95rem; /* Improved readable size */
    margin-bottom: auto; /* Push button to bottom */
    line-height: 1.8;
    text-align: left;
    width: 100%;
}

.retry-button {
    margin-top: 20px;
    background: transparent;
    border: 1px solid var(--color-text);
    color: var(--color-text);
    padding: 0.5rem 1.5rem;
    font-family: var(--font-main);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
    border-radius: 50px;
}

.retry-button:hover {
    background: var(--color-text);
    color: white;
}

/* Draw Button */
.draw-button {
    margin-top: 50px;
    position: relative;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 1rem 3rem;
    font-family: var(--font-main);
    font-size: 1.2rem;
    font-weight: bold;
    color: white;
    overflow: hidden;
    border-radius: 50px;
    box-shadow: 0 4px 15px rgba(230, 50, 46, 0.4);
    transition: transform 0.2s;
    z-index: 10;
}

.draw-button .button-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #e6322e, #b01e1a);
    z-index: -1;
    transition: transform 0.3s;
}

.draw-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(230, 50, 46, 0.5);
}

.draw-button:active {
    transform: translateY(1px);
}

.draw-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Hidden utility */
.hidden {
    display: none; /* Only use if avoiding layout shift isn't needed, otherwise toggle classes */
    /* We are using opacity/pointer-events for result-card, but 'display: none' might be safer for accessibility if completely hidden */
    /* Let's override the result-card hidden logic with simpler class toggling in JS for display if needed,
       but for smooth animation, opacity is better.
       Let's say .hidden just applies pointer-events:none and opacity:0 which we already did.
       Wait, let's strictly use .hidden for display:none if we want it out of flow,
       but for the card overlay we want it IN flow or absolute over.
    */
}

/* Footer */
.footer {
    margin-top: 2rem;
    opacity: 0.5;
    font-size: 0.7rem;
}

/* Share Section */
.share-area {
    margin-top: 1.5rem;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.share-label {
    font-size: 0.8rem;
    color: var(--color-text);
    opacity: 0.6;
}

.share-buttons {
    display: flex;
    gap: 1rem;
}

.share-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: white;
    text-decoration: none;
    transition: transform 0.3s var(--ease-out-quint), box-shadow 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.share-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}

.share-x {
    background-color: #000;
}

.share-line {
    background-color: #06C755;
}

.share-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Image Filters for Variations */
.filter-hue-90 { filter: hue-rotate(90deg); }
.filter-hue-180 { filter: hue-rotate(180deg); }
.filter-hue-270 { filter: hue-rotate(270deg); }
.filter-grayscale { filter: grayscale(100%); }
.filter-sepia { filter: sepia(100%); }
.filter-invert { filter: invert(100%); }
.filter-saturate { filter: saturate(300%); }
.filter-contrast { filter: contrast(150%); }
.filter-glitch {
    filter: contrast(150%) hue-rotate(90deg);
}
.filter-toxic {
    filter: hue-rotate(120deg) saturate(200%);
}
.filter-frozen {
    filter: hue-rotate(200deg) brightness(120%);
}
.filter-dark {
    filter: brightness(60%) contrast(150%);
}

/* Responsive adjustments */
@media (max-width: 400px) {
    .title {
        font-size: 2rem;
    }
    .omikuji-container {
        height: 80vh;
    }
}
