/* style.css */
@import url('https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400&family=Noto+Sans+Symbols+2&family=Cairo:wght@400;700&family=Aref+Ruqaa:wght@400;700&display=swap');

:root {
    --parchment: #f2e8cf;
    --ink: #386641;
    --accent: #bc4749;
    --ancient-font: 'Noto Sans Symbols 2', sans-serif;
    --bg-dark: #121212;
}

body {
    background: 
        radial-gradient(circle, transparent 40%, rgba(0,0,0,0.8) 150%),
        url('resource/BG.jpg');
    background-repeat: repeat;
    background-size: auto;
    background-attachment: fixed;
    font-family: 'Amiri', serif;
    color: #f2e8cf;
    margin: 0;
    overflow: hidden;
}
body::after {
    content: "";
    position: fixed;

    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Radial gradient from transparent center to black edges */
    background: radial-gradient(circle, transparent 40%, rgba(0,0,0,0.8) 100%);
    pointer-events: none; /* Allows you to click buttons underneath */
    z-index: 10;
}

.paper-texture {
    background-color: transparent;
    background-image: url('resource/paper.png');
    background-size: contain;      /* Fits the image inside the area without cropping */
    background-position: center;   /* Keeps it centered */
    background-repeat: no-repeat;  /* Prevents repeating */

    /* Layout: Ensuring text sits inside the paper's "safe zone" */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10%; /* Percentage padding helps keep text inside the paper bounds */
    
    /* Optional: Add a drop shadow to the image itself if it doesn't have one */
    filter: drop-shadow(0 15px 25px rgba(0,0,0,0.6));
    color: #2b2d42;
}

/* Add a "torn edge" effect using a pseudo-element */
.paper-texture::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border: 20px solid transparent;
    border-image: url('https://www.transparenttextures.com/patterns/pinstriped-suit.png') 30 round;
    pointer-events: none;
    opacity: 0.2;
}

#paper-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Vertical centering */
    min-height: 60vh;
}

/* Success Button Animation and Style */
.success-textured-btn {
    background-color: #5c4033; /* Dark wood/leather color */
    background-image: url('https://www.transparenttextures.com/patterns/leather.png');
    border: 2px solid #3e2723;
    color: #d4c391;
    box-shadow: 0 4px 0 #2a1b15;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    cursor: pointer;
}

.success-textured-btn:hover {
    filter: brightness(1.1);
}

/* Ensure the container doesn't push other elements out */
#success-nav.hidden {
    display: none !important;
}

#success-nav {
    display: block !important;
    margin-top: 10px;
}
.animate-fadeIn {
    animation: fadeIn 0.8s forwards;
}

@keyframes win-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.solved-ink {
    color: #1d5339; /* Deep forest green ink */
    text-shadow: 0.5px 0.5px 1px rgba(0,0,0,0.2);
    filter: sepia(0.2) saturate(1.2); /* Makes it look absorbed by paper */
    animation: win-pop 0.6s ease-out;
    transition: color 1s ease-in-out;
}

/* Ensure the container can scale without clipping */
#text-display {
    display: inline-block;
    transition: all 0.3s ease;
}

.controls-hidden {
    opacity: 0;
    pointer-events: none; /* Prevents clicking after win */
    transform: scale(0.9);
    transition: all 0.5s ease;
}
.hide-arrows .control-btn,
.hide-arrows .rest{
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px); /* Adds a slight downward slide as they fade */
    transition: all 0.4s ease;
    display: none;
}

/* Optional: Make the grid look "locked" when won */
.hide-arrows #cipher-grid {
    border-color: #22c55e; /* Green border */
    transition: border-color 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Sidebar transition to full screen on win */
#sidebar {
    background: #1a1a1a; /* Dark stone base */
    border: 8px solid #333;
    border-image: linear-gradient(to bottom, #444, #222) 1;
    box-shadow: inset 0 0 20px #000, 0 10px 30px rgba(0,0,0,0.8);
    padding: 24px;
}
.sidebar-hidden {
    display: none !important;
}

.archive-full-width {
    width: 100% !important;
    max-width: 100% !important;
}
/* Signs Game Styles */
.word-wrapper { display: inline-block; margin-left: 0.4em; cursor: pointer; }
.glyph { padding: 0 4px; border-radius: 2px; }
.word-wrapper.selected .glyph { background-color: var(--accent); color: white; border-bottom: none; }
.translated-text { font-weight: 700; color: #2a9d8f; }
.ancient-script { font-family: var(--ancient-font); font-size: 1.8rem; }

/* Sliding Game Matrix Styles */
.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 64px);
    grid-template-rows: repeat(3, 64px);
    gap: 12px;
    position: relative;
    padding: 12px;
    background: #1a1a1a;
    border-radius: 8px;
    border: 2px solid #333;
    overflow: hidden;
}

.grid-cell {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    
    font-family: sans-serif; font-size: 1.8rem; font-weight: bold;
    width: 64px;
    height: 64px;
    border-radius: 50% !important; /* Force circular */
    background: radial-gradient(circle at 30% 30%, #3d3d3d, #1a1a1a);
    border: 2px solid #2a2a2a;
    text-shadow: 
        -1px -1px 1px rgba(0,0,0,0.8), 
        1px 1px 1px rgba(255,255,255,0.2);
    font-weight: bold;
    color: #f2e8cf;
}

.control-btn {
    cursor: pointer; 
    
    font-size: 0.8rem;

    background: #2a2a2a;
    border: 2px solid #14b8a6; /* Teal/Green border */
    color: #2dd4bf;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    
    text-shadow: 0 0 8px rgba(45, 212, 191, 0.8);
    box-shadow: 
        0 0 15px rgba(45, 212, 191, 0.2), 
        inset 0 0 10px rgba(45, 212, 191, 0.1);
    transition: all 0.2s;
}

.control-btn:hover { 
    color: #fff;
    background-color: #333;
    box-shadow: 0 0 20px rgba(45, 212, 191, 0.5);
    transform: scale(1.05);
}

.control-btn, .grid-cell {
    /* 1. The Texture: Uses a transparent pattern so your background color shows through */
    background-image: url('https://www.transparenttextures.com/patterns/asfalt-dark.png');
    background-color: #2a2a2a; /* The base "stone" color */
    
    /* 2. The Shape & Border */
    border: 2px solid #1a1a1a;
    border-radius: 50%;
    
    /* 3. The "Stone" Depth (Layered Shadows) */
    box-shadow: 
        inset 2px 2px 4px rgba(255, 255, 255, 0.1), /* Top-left highlight (Bevel) */
        inset -2px -2px 4px rgba(0, 0, 0, 0.6),      /* Bottom-right shadow */
        0 4px 10px rgba(0, 0, 0, 0.5);              /* External shadow */
        
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
}
/* Wrap-Around Sliding Animations */
@keyframes slide-row-left {
    0% { transform: translateX(0); }
    100% { transform: translateX(-76px); } /* cell width (64px) + gap (12px) */
}

@keyframes slide-row-right {
    0% { transform: translateX(0); }
    100% { transform: translateX(76px); }
}

@keyframes slide-col-up {
    0% { transform: translateY(0); }
    100% { transform: translateY(-76px); }
}

@keyframes slide-col-down {
    0% { transform: translateY(0); }
    100% { transform: translateY(76px); }
}

/* Wrap exit animations - cell leaving screen */
@keyframes wrap-exit-left {
    0% { transform: translateX(0); opacity: 1; }
    50% { transform: translateX(-40px); opacity: 0; }
    50.01% { transform: translateX(40px); opacity: 0; }
    100% { transform: translateX(0); opacity: 1; }
}

@keyframes wrap-exit-right {
    0% { transform: translateX(0); opacity: 1; }
    50% { transform: translateX(40px); opacity: 0; }
    50.01% { transform: translateX(-40px); opacity: 0; }
    100% { transform: translateX(0); opacity: 1; }
}

@keyframes wrap-exit-up {
    0% { transform: translateY(0); opacity: 1; }
    50% { transform: translateY(-40px); opacity: 0; }
    50.01% { transform: translateY(40px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

@keyframes wrap-exit-down {
    0% { transform: translateY(0); opacity: 1; }
    50% { transform: translateY(40px); opacity: 0; }
    50.01% { transform: translateY(-40px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

.grid-cell.animate-row-left { animation: slide-row-left 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.grid-cell.animate-row-right { animation: slide-row-right 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.grid-cell.animate-col-up { animation: slide-col-up 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.grid-cell.animate-col-down { animation: slide-col-down 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards; }

.grid-cell.wrap-left { animation: wrap-exit-left 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.grid-cell.wrap-right { animation: wrap-exit-right 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.grid-cell.wrap-up { animation: wrap-exit-up 0.25s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.grid-cell.wrap-down { animation: wrap-exit-down 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards; }

#paper-illustration{
    font-size: 4rem;
}
.cipher-text { 
    line-height: 2.0; 
    font-size: 1.5rem; 
    text-align: center; 
    font-family: sans-serif; 
    word-spacing: 7px;
}
.encrypted {
    color: var(--accent); 
    font-weight: bold; 
    font-family: 'Vazir Code', monospaced !important;
}

.solved-text { color: var(--ink); }

/* Animation and Utility */
.fade-out { 
    width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    opacity: 0; 
    transform: translateX(-20px); 
    pointer-events: none; 
}
.hidden { display: none !important; }
.hint-active .grid-cell { color: #2a9d8f; text-shadow: 0 0 8px #2a9d8f; }

/* Gear Button */
.gear-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    font-size: 1.5rem;
    background: rgba(42, 42, 42, 0.8);
    border: 1px solid #14b8a6;
    padding: 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.3s;
}
.gear-btn:hover { transform: rotate(45deg) scale(1.1); }

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

/* Modal Container */
.modal-container {
    background: #1a1a1a;
    border: 3px solid #333;
    padding: 2rem;
    border-radius: 20px;
    max-width: 450px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 30px rgba(0,0,0,0.5), inset 0 0 15px rgba(20, 184, 166, 0.1);
    animation: fadeIn 0.3s ease-out;
    font-family: sans-serif;
}

/* Modal Buttons */
.modal-btn-primary {
    background: #14b8a6;
    color: white;
    padding: 12px 30px;
    border-radius: 8px;
    font-weight: bold;
    width: 100%;
}

.modal-btn-secondary {
    background: #2a2a2a;
    border: 1px solid #444;
    color: #f2e8cf;
    padding: 12px;
    border-radius: 8px;
    transition: all 0.2s;
}
.modal-btn-secondary:hover { border-color: #14b8a6; background: #333; }

.modal-btn-close {
    margin-top: 10px;
    color: #bc4749;
    font-size: 0.9rem;
    text-decoration: underline;
}

/* Sticky Parchment Hint */
.parchment-hint {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: #f2e8cf; /* Var parchment color */
    color: #386641; /* Var ink color */
    padding: 15px 25px;
    border-radius: 4px;
    box-shadow: 5px 5px 15px rgba(0,0,0,0.4), 
                inset 0 0 30px rgba(188, 71, 73, 0.1);
    border-left: 4px solid #bc4749;
    font-family: sans-serif;
    font-weight: bold;
    z-index: 100;
    max-width: 300px;
    animation: slideUp 0.5s ease-out;
    cursor: help;
}

.parchment-hint::before {
    content: "📌 ملحوظة:";
    display: block;
    font-size: 0.8rem;
    opacity: 0.7;
    margin-bottom: 5px;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.ending-active {
    transition: background 3s ease;
    background: radial-gradient(circle, #1a2e2c 0%, #09090b 100%);
}

.ending-active #game-root {
    filter: blur(4px);
    pointer-events: none;
    transition: filter 2s ease;
}

@keyframes final-glow {
    0% { text-shadow: 0 0 10px rgba(20, 184, 166, 0.5); }
    50% { text-shadow: 0 0 30px rgba(20, 184, 166, 0.9); }
    100% { text-shadow: 0 0 10px rgba(20, 184, 166, 0.5); }
}

.text-amber-400 {
    animation: final-glow 3s infinite ease-in-out;
}