:root {
    /* PALETTE: Old England / Tolkien / D&D */
    --bg-wood-dark: #1a120b;
    --bg-wood-light: #3e2723;
    
    --parchment-bg: #f5e6c8;
    --parchment-shadow: #d4c5a9;
    
    --ink-black: #1a0f0a;
    --ink-red: #8a1c1c;
    
    --gold-accent: #cca43b;
    --gold-dim: #8a7338;
    
    /* Character Token Colors */
    --c-frodo: #8a1c1c;   /* Crimson */
    --c-sam: #2c5d7c;     /* Faded Blue */
    --c-pippin: #d4ac0d;  /* Mustard */
    --c-gimli: #a04000;   /* Rust */
    --c-legolas: #276332; /* Forest Green */
    --c-aragorn: #143b22; /* Ranger Green */
    --c-boromir: #5b2c6f; /* Royal Purple */
    --c-gandalf: #7f8c8d; /* Slate Grey */
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, serif;
    background-color: var(--bg-wood-dark);
    color: var(--ink-black);
    height: 100vh;
    overflow: hidden;
    background-image: repeating-linear-gradient(
        45deg,
        rgba(0,0,0,0.05) 0px,
        rgba(0,0,0,0.05) 2px,
        transparent 2px,
        transparent 4px
    ); 
}

#game-layout {
    display: flex;
    height: 100vh;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.8);
}

/* --- MAP AREA --- */
#board-container {
    flex: 2;
    background: #0a0a0a;
    overflow: auto; 
    display: flex;
    justify-content: center;
    align-items: center;
    border-right: 5px solid var(--bg-wood-dark);
    box-shadow: 10px 0 20px rgba(0,0,0,0.5);
}

#map-wrapper {
    position: relative;
    width: 90vh; 
    box-shadow: 0 0 30px rgba(0,0,0,0.7);
}

#game-map {
    width: 100%;
    display: block;
    filter: sepia(0.2) contrast(1.1); 
}

#overlay-layer, #token-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; 
}

/* --- TOKENS --- */
.token {
    position: absolute;
    width: 4.5%;  
    height: 4.5%;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.4);
    box-shadow: inset 0 0 5px rgba(0,0,0,0.7), 2px 2px 4px rgba(0,0,0,0.6);
    z-index: 10;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2vw;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px black;
    font-family: 'Cinzel', serif;
    pointer-events: auto; 
    cursor: pointer;
}

.token.nazgul {
    background: radial-gradient(circle at 30% 30%, #444, #000);
    border-color: #222;
    z-index: 15; 
}

/* Character Token Colors */
.c-Frodo { background: radial-gradient(circle at 30% 30%, #c0392b, #641e16); }
.c-Sam { background: radial-gradient(circle at 30% 30%, #3498db, #1b4f72); }
.c-Pippin { background: radial-gradient(circle at 30% 30%, #f1c40f, #9a7d0a); }
.c-Gimli { background: radial-gradient(circle at 30% 30%, #d35400, #6e2c00); }
.c-Legolas { background: radial-gradient(circle at 30% 30%, #2ecc71, #145a32); }
.c-Aragorn { background: radial-gradient(circle at 30% 30%, #27ae60, #0b5345); }
.c-Boromir { background: radial-gradient(circle at 30% 30%, #8e44ad, #4a235a); }
.c-Gandalf { background: radial-gradient(circle at 30% 30%, #bdc3c7, #515a5a); }

/* --- HIGHLIGHTS --- */
.highlight {
    position: absolute;
    width: 5%; 
    height: 5%;
    transform: translate(-50%, -50%);
    cursor: pointer;
    pointer-events: auto; 
    z-index: 20;
    animation: pulse 1.5s infinite;
    background-color: rgba(255, 215, 0, 0.3); 
    border: 2px solid rgba(255, 215, 0, 0.8);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
    border-radius: 50%;
}

@keyframes pulse {
    0% { transform: translate(-50%, -50%) scale(0.9); box-shadow: 0 0 5px rgba(255, 215, 0, 0.3); }
    50% { transform: translate(-50%, -50%) scale(1.1); box-shadow: 0 0 20px rgba(255, 215, 0, 0.7); }
    100% { transform: translate(-50%, -50%) scale(0.9); box-shadow: 0 0 5px rgba(255, 215, 0, 0.3); }
}

/* --- DASHBOARD --- */
#dashboard {
    flex: 1;
    min-width: 320px;
    background-color: var(--parchment-bg);
    background-image: radial-gradient(#d4c5a9 1px, transparent 1px);
    background-size: 20px 20px;
    padding: 25px;
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--parchment-shadow);
    position: relative;
    box-shadow: inset 10px 0 30px rgba(0,0,0,0.1);
}

#dashboard::before, #dashboard::after {
    content: "";
    position: absolute;
    left: 10px; right: 10px; height: 2px;
    background: var(--gold-dim);
}
#dashboard::before { top: 10px; }
#dashboard::after { bottom: 10px; }

/* HEADER */
.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--ink-black);
    padding-bottom: 10px;
    margin-bottom: 10px;
}

header h1 {
    font-size: 1.6rem;
    margin: 0;
    text-align: left;
    font-variant: small-caps;
    color: var(--ink-red);
    text-shadow: 1px 1px 0px rgba(0,0,0,0.1);
    letter-spacing: 1px;
}

#turn-indicator {
    padding: 8px;
    color: white;
    text-align: center;
    border-radius: 4px;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
    border: 2px solid rgba(0,0,0,0.3);
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
    margin-bottom: 20px;
    font-variant: small-caps;
    font-size: 1.1rem;
}

/* Stats Panel */
#stats-panel {
    display: flex;
    justify-content: space-between;
    margin: 10px 0 20px 0;
    padding: 10px;
    border: 1px solid var(--gold-dim);
    background: rgba(255,255,255,0.3);
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-box .label { 
    font-size: 0.75rem; 
    color: var(--ink-black); 
    text-transform: uppercase; 
    letter-spacing: 1px;
    font-weight: bold;
}
.stat-box .value { 
    font-size: 1.4rem; 
    font-weight: bold; 
    color: var(--ink-red);
    font-family: 'Times New Roman', serif;
}

/* --- BUTTONS --- */
.action-btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 8px;
    border: 1px solid #1a0f0a;
    border-radius: 3px;
    background: linear-gradient(to bottom, #5d4037, #3e2723);
    color: #f5e6c8;
    font-size: 1rem;
    font-family: 'Palatino Linotype', serif;
    font-variant: small-caps;
    letter-spacing: 1px;
    cursor: pointer;
    box-shadow: 0 4px 0 #271c19, 0 5px 5px rgba(0,0,0,0.3);
    transition: all 0.1s;
    text-shadow: 1px 1px 0 black;
}

.action-btn:hover { 
    background: linear-gradient(to bottom, #6d4c41, #4e342e); 
    transform: translateY(-1px);
}
.action-btn:active {
    transform: translateY(4px);
    box-shadow: 0 0 0 #271c19, inset 0 2px 5px rgba(0,0,0,0.5);
}
.action-btn:disabled { 
    background: #555; 
    color: #999; 
    box-shadow: none; 
    transform: none; 
    cursor: not-allowed;
    border-color: #333;
}
.hidden { display: none !important; }

#btn-use-ring {
    background: linear-gradient(to bottom, #f1c40f, #b7950b);
    color: black;
    text-shadow: none;
    border-color: #7d6608;
    box-shadow: 0 4px 0 #7d6608, 0 5px 5px rgba(0,0,0,0.3);
}
#btn-use-ring:hover {
    background: linear-gradient(to bottom, #f7dc6f, #d4ac0d);
}

#btn-retreat {
    background: linear-gradient(to bottom, #7f8c8d, #2c3e50);
    border-color: #34495e;
}

/* --- CARDS --- */
#hand-area { 
    flex-grow: 1; 
    overflow-y: auto; 
    margin-top: 15px; 
    border-top: 2px solid var(--ink-black);
    padding-top: 10px;
    display: flex; 
    flex-direction: column; 
}

.hand-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.hand-header h3 { margin: 0; font-variant: small-caps; color: var(--ink-black); }

.small-btn {
    background: transparent;
    border: 1px solid var(--ink-black);
    color: var(--ink-black);
    padding: 4px 10px;
    cursor: pointer;
    font-weight: bold;
    border-radius: 3px;
    font-family: 'Palatino Linotype', serif;
    transition: background 0.2s;
}
.small-btn:hover { background: rgba(0,0,0,0.1); }

#hand-curtain {
    flex-grow: 1;
    background: #3e2723;
    background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0IiBoZWlnaHQ9IjQiPgo8cmVjdCB3aWR0aD0iNCIgaGVpZ2h0PSI0IiBmaWxsPSIjM2UyNzIzIiAvPgo8cmVjdCB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSIjNGUzNDJlIiAvPjwvc3ZnPg==');
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--gold-accent);
    min-height: 120px;
    border: 4px double var(--gold-dim);
    box-shadow: inset 0 0 20px black;
}

.card {
    background: #fffbf0;
    border: 1px solid #8b7d6b;
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s;
    font-size: 0.95rem;
    position: relative;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}
.card::after {
    content: "";
    position: absolute;
    top: 3px; bottom: 3px; left: 3px; right: 3px;
    border: 1px solid rgba(0,0,0,0.1);
    pointer-events: none;
}
.card:hover { transform: translateX(5px); border-color: var(--ink-red); }
.card strong { display: block; margin-bottom: 3px; color: var(--ink-red); font-variant: small-caps; font-size: 1rem; }

/* --- LOG --- */
#log-area {
    height: 140px;
    background: rgba(255,255,255,0.4);
    border: 1px solid var(--parchment-shadow);
    overflow-y: auto;
    padding: 10px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    margin-top: 10px;
    color: #444;
}
#game-log li { margin-bottom: 5px; border-bottom: 1px dashed #ccc; padding-bottom: 2px; }

/* --- OVERLAYS (Start / GameOver / Rules) --- */
#start-screen, #game-over-screen, #rules-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.95);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--parchment-bg);
}

.menu-box {
    text-align: center;
    background: var(--bg-wood-dark);
    padding: 50px;
    border: 4px double var(--gold-accent);
    border-radius: 8px;
    max-width: 700px;
    box-shadow: 0 0 50px rgba(197, 160, 89, 0.2);
    position: relative;
}

.victory-box {
    border-color: var(--ink-red);
    box-shadow: 0 0 50px rgba(200, 50, 50, 0.4);
}

/* Rules Specifics */
.rules-box {
    max-width: 800px;
    width: 90%;
    text-align: left;
    background: var(--parchment-bg);
    color: var(--ink-black);
    border: 10px solid var(--bg-wood-light);
    box-shadow: inset 0 0 50px rgba(0,0,0,0.5);
}
.rules-text {
    max-height: 60vh;
    overflow-y: auto;
    margin-bottom: 20px;
    padding-right: 10px;
    font-size: 1rem;
    line-height: 1.5;
}
.rules-box h2 {
    text-align: center;
    color: var(--ink-red);
    border-bottom: 2px solid var(--ink-black);
    padding-bottom: 10px;
}
.rules-box h3 { margin-top: 20px; margin-bottom: 5px; color: var(--bg-wood-light); font-variant: small-caps; border-bottom: 1px dashed #aaa; }
.rules-box ul { padding-left: 20px; }
.rules-box li { margin-bottom: 5px; }

.menu-box h1 { 
    font-family: 'Cinzel', serif; 
    font-size: 3rem;
    color: var(--gold-accent); 
    margin-bottom: 5px;
    text-shadow: 0 0 10px rgba(197, 160, 89, 0.5);
}
.menu-box h2 { margin-top: 0; font-size: 1.2rem; color: #aaa; letter-spacing: 4px; text-transform: uppercase; }

#character-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin: 30px 0;
}

.char-btn {
    padding: 15px;
    border: 2px solid var(--gold-dim);
    background: #2a1f18;
    color: var(--parchment-bg);
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-variant: small-caps;
    transition: all 0.2s;
    font-family: 'Palatino Linotype', serif;
}

.char-btn:hover { background: var(--bg-wood-light); border-color: var(--gold-accent); transform: scale(1.05); box-shadow: 0 0 15px var(--gold-accent); }
.char-btn.selected { background: var(--ink-red); color: white; border-color: white; opacity: 1; box-shadow: inset 0 0 10px black; }

#party-status { font-size: 1.1rem; margin-bottom: 20px; font-style: italic; color: var(--gold-dim); }

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--parchment-bg); }
::-webkit-scrollbar-thumb { background: var(--bg-wood-light); border: 1px solid var(--bg-wood-dark); }