:root {
    --paper-color: #fdfbf7;
    --paper-shadow: #d1c7b7;
    --ink-color: #2b2b2b;
    --red-stamp: #aa2e25;
    --censor-bar: #0f0f0f;
}

* {
    box-sizing: border-box;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Special Elite', cursive;
    background-color: #2c1e12;
    /* Complex Wood Texture */
    background-image:
        /* Wood grain */
        repeating-linear-gradient(85deg,
            rgba(0, 0, 0, 0.1) 0px,
            rgba(0, 0, 0, 0.1) 2px,
            transparent 2px,
            transparent 4px),
        repeating-linear-gradient(175deg,
            rgba(0, 0, 0, 0.15) 0px,
            rgba(0, 0, 0, 0.15) 1px,
            transparent 1px,
            transparent 5px),
        /* Noise overlay for texture */
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.08'/%3E%3C/svg%3E"),
        /* Vignette */
        radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0) 20%, rgba(0, 0, 0, 0.8) 100%);
    background-blend-mode: multiply, multiply, overlay, multiply;
}

#desk {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    perspective: 1200px;
}

/* Vignette overlay (extra depth) */
#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, transparent 40%, rgba(10, 5, 0, 0.6) 100%);
    pointer-events: none;
    z-index: 10;
}

/* Visual Letter Piles */
.letter-pile {
    position: fixed;
    width: 200px;
    height: 140px;
    bottom: 40px;
    border: 3px dashed rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.letter-pile .pile-label {
    font-family: 'Special Elite', cursive;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 2px;
    pointer-events: none;
}

#approved-pile {
    left: 40px;
    border-color: rgba(46, 204, 113, 0.5);
}

#approved-pile .pile-label {
    color: rgba(46, 204, 113, 0.6);
}

#rejected-pile {
    left: 280px;
    border-color: rgba(231, 76, 60, 0.5);
}

#rejected-pile .pile-label {
    color: rgba(231, 76, 60, 0.6);
}

/* Envelope Styling */
.envelope {
    position: absolute;
    width: 240px;
    height: 150px;
    background-color: #f0e6d2;
    /* Paper Texture */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='paperNoise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23paperNoise)' opacity='0.15'/%3E%3C/svg%3E");
    border: 1px solid #d4c5a9;
    box-shadow:
        1px 1px 0 rgba(0, 0, 0, 0.1),
        3px 3px 8px rgba(0, 0, 0, 0.3),
        10px 10px 20px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 15px;
    transform-origin: center;
    z-index: 1;
}

.envelope::before {
    /* Fold line hint */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    border: 1px solid rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

.envelope:hover {
    transform: scale(1.1) rotate(0deg) !important;
    box-shadow:
        0 20px 30px rgba(0, 0, 0, 0.4),
        0 0 0 2px rgba(255, 255, 255, 0.1);
    z-index: 100;
}

.envelope-stamp {
    border: 3px double var(--red-stamp);
    color: var(--red-stamp);
    padding: 8px 12px;
    font-size: 0.9rem;
    transform: rotate(-12deg);
    opacity: 0.85;
    margin-bottom: 12px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 2px;
    mix-blend-mode: multiply;
    /* Stamp grunge effect */
    mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' fill='white'/%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.3'/%3E%3C/svg%3E");
}

.envelope-name {
    font-family: 'Courier Prime', monospace;
    font-size: 1.1rem;
    color: var(--ink-color);
    text-align: center;
    letter-spacing: 1px;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

/* Modal Styling */
#letter-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(10, 5, 0, 0.85);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

#letter-modal:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    position: relative;
    width: 90%;
    max-width: 750px;
    height: 85vh;
    perspective: 1000px;
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(50px) rotateX(10deg);
        opacity: 0;
    }

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

.paper {
    background-color: var(--paper-color);
    width: 100%;
    height: 100%;
    padding: 60px;
    box-shadow:
        0 0 50px rgba(0, 0, 0, 0.7),
        inset 0 0 60px rgba(189, 172, 139, 0.3);
    overflow-y: auto;
    font-family: 'Courier Prime', monospace;
    font-size: 1.15rem;
    line-height: 1.8;
    color: var(--ink-color);
    /* Realistic Paper Texture */
    background-image:
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='paperNoise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.5' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23paperNoise)' opacity='0.12'/%3E%3C/svg%3E"),
        linear-gradient(to bottom right, rgba(255, 255, 255, 0.8) 0%, rgba(0, 0, 0, 0.05) 100%);
}

.close-btn {
    position: absolute;
    top: -15px;
    right: -15px;
    background: var(--red-stamp);
    color: #f0e6d2;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    text-align: center;
    line-height: 36px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.2rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    z-index: 1001;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: transform 0.2s;
}

.close-btn:hover {
    transform: scale(1.1);
    background: #c0392b;
}

.letter-header {
    border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    padding-bottom: 25px;
    margin-bottom: 30px;
    position: relative;
}

.letter-header h2 {
    margin: 0;
    font-family: 'Special Elite', cursive;
    text-transform: uppercase;
    font-size: 2rem;
    letter-spacing: 2px;
    color: #111;
}

.letter-header h3 {
    margin: 8px 0 0;
    font-size: 1rem;
    opacity: 0.8;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stamp {
    position: absolute;
    top: 0;
    right: 0;
    border: 4px solid var(--red-stamp);
    color: var(--red-stamp);
    padding: 8px 20px;
    font-family: 'Special Elite', cursive;
    font-size: 1.4rem;
    transform: rotate(8deg);
    opacity: 0.7;
    mix-blend-mode: multiply;
    mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' fill='white'/%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.4'/%3E%3C/svg%3E");
}

/* Censored Text Effect */
.censored {
    background-color: var(--censor-bar);
    color: var(--censor-bar);
    padding: 2px 4px;
    margin: 0 2px;
    cursor: help;
    transition: all 0.4s ease;
    border-radius: 1px;
    /* Rough edges for marker look */
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

.censored:hover {
    background-color: transparent;
    color: var(--ink-color);
    text-decoration: none;
    background-image: linear-gradient(to right, rgba(192, 57, 43, 0.2), rgba(192, 57, 43, 0.1));
}

/* Scrollbar styling for the letter */
.paper::-webkit-scrollbar {
    width: 8px;
}

.paper::-webkit-scrollbar-track {
    background: transparent;
}

.paper::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

/* Letter Specific Formatting */
.letter-meta {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 20px;
}

.letter-date {
    font-family: 'Courier Prime', monospace;
    font-size: 1rem;
    color: var(--ink-color);
    opacity: 0.8;
}

.letter-salutation {
    font-family: 'Courier Prime', monospace;
    font-size: 1.2rem;
    margin-bottom: 20px;
    font-weight: bold;
}

.letter-signoff {
    font-family: 'Special Elite', cursive;
    /* Handwriting style */
    font-size: 1.4rem;
    margin-top: 40px;
    text-align: right;
    padding-right: 40px;
    transform: rotate(-2deg);
}

.letter-content-wrapper {
    position: relative;
    z-index: 2;
}

/* Intelligence Dossier - Paper Clip Note */
.paper-clip-note {
    position: absolute;
    top: 40px;
    right: -20px;
    width: 240px;
    background: #fdf6e3;
    padding: 15px;
    border: 1px solid #d6cfc2;
    box-shadow: 2px 4px 10px rgba(0, 0, 0, 0.2);
    font-family: 'Courier Prime', monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    transform: rotate(2deg);
    z-index: 10;
}

.paper-clip-note h4 {
    margin: 0 0 10px 0;
    border-bottom: 2px solid #aa2e25;
    color: #aa2e25;
    font-family: 'Special Elite', cursive;
    font-size: 1rem;
    letter-spacing: 1px;
}

.paper-clip-note p {
    margin: 0;
    color: #2b2b2b;
}

/* The Paperclip Visual */
.clip {
    position: absolute;
    top: -15px;
    left: 20px;
    width: 15px;
    height: 35px;
    border: 3px solid #666;
    border-radius: 10px;
    border-bottom: none;
    z-index: 11;
}

.clip::after {
    content: '';
    position: absolute;
    top: 8px;
    left: -3px;
    width: 15px;
    height: 25px;
    border: 3px solid #666;
    border-radius: 10px;
    border-top: none;
    z-index: 9;
}

/* Toolbar Styling */
.modal-toolbar {
    position: absolute;
    bottom: -80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 40px;
    align-items: center;
    width: 100%;
    justify-content: center;
    pointer-events: auto;
}

.tool-btn {
    background: #333;
    color: #fff;
    border: 2px solid #555;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Courier Prime', monospace;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.tool-btn.active {
    background: var(--censor-bar);
    border-color: #000;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.action-btn {
    padding: 12px 30px;
    font-family: 'Special Elite', cursive;
    font-size: 1.2rem;
    border: none;
    cursor: pointer;
    border-radius: 4px;
    transition: transform 0.2s, box-shadow 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.action-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.action-btn.approve {
    background-color: #2ecc71;
    color: #fff;
    box-shadow: 0 4px 0 #27ae60;
}

.action-btn.approve:active {
    transform: translateY(4px);
    box-shadow: none;
}

.action-btn.reject {
    background-color: #e74c3c;
    color: #fff;
    box-shadow: 0 4px 0 #c0392b;
}

.action-btn.reject:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* Score Display */
#score-display {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

#score-display:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.score-card {
    background: #fdfbf7;
    padding: 40px;
    border: 1px solid #d4c5a9;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    text-align: center;
    transform: rotate(-2deg);
    max-width: 400px;
    width: 90%;
}

.score-card h3 {
    font-family: 'Special Elite', cursive;
    margin: 0 0 20px;
    border-bottom: 2px solid #333;
    padding-bottom: 10px;
}

.grade {
    font-size: 6rem;
    font-weight: bold;
    color: var(--red-stamp);
    font-family: 'Special Elite', cursive;
    border: 5px solid var(--red-stamp);
    display: inline-block;
    padding: 10px 30px;
    margin: 20px 0;
    transform: rotate(-5deg);
    mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' fill='white'/%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.4'/%3E%3C/svg%3E");
}

.feedback {
    font-family: 'Courier Prime', monospace;
    font-size: 1.1rem;
    margin-bottom: 30px;
    line-height: 1.5;
}

#close-score {
    background: #333;
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-family: 'Courier Prime', monospace;
    cursor: pointer;
    text-transform: uppercase;
}

#close-score:hover {
    background: #111;
}

/* Dragging State */
.envelope.dragging {
    cursor: grabbing;
    transform: scale(1.15) rotate(0deg) !important;
    box-shadow: 0 30px 50px rgba(0, 0, 0, 0.5);
    z-index: 1000 !important;
    transition: none;
    /* Remove transition for smooth dragging */
}

/* Interactive Redaction */
.interactive-word {
    cursor: pointer;
    padding: 0 2px;
    border-radius: 2px;
    transition: background-color 0.2s;
    pointer-events: auto !important;
    position: relative;
    z-index: 5;
    user-select: none;
    /* Prevent text selection */
}

.interactive-word:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.interactive-word.censored-active {
    background-color: var(--censor-bar) !important;
    color: var(--censor-bar) !important;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
    transform: scale(1.05);
    z-index: 10;
    position: relative;
}

.interactive-word.censored-active:hover {
    background-color: var(--censor-bar);
    /* Keep it black on hover */
    color: rgba(255, 255, 255, 0.2);
    /* Hint at text */
}

/* Interactive Stamping Animation */
.stamp-mark {
    position: absolute;
    font-family: 'Special Elite', cursive;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 4rem;
    border: 5px solid;
    padding: 10px 30px;
    opacity: 0;
    transform: scale(2) rotate(-15deg);
    pointer-events: none;
    z-index: 100;
    mix-blend-mode: multiply;
    transition: all 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.stamp-mark.stamped {
    opacity: 0.8;
    transform: scale(1) rotate(-15deg);
}

.stamp-approve {
    color: #27ae60;
    border-color: #27ae60;
}

.stamp-reject {
    color: #c0392b;
    border-color: #c0392b;
}