/* D&D layer styles - dice tray, character sheet, modal */

/* ----- Dice Tray ----- */
.dice-tray {
    position: fixed;
    right: 20px;
    bottom: 20px;
    min-width: 200px;
    padding: 16px;
    text-align: center;
    z-index: 200;
    transition: transform 0.3s, box-shadow 0.3s;
}
.dice-tray.rolling {
    box-shadow: 0 0 24px var(--primary-color);
}
.dice-tray.crit {
    box-shadow: 0 0 32px gold, 0 0 64px gold;
    border-color: gold;
    animation: critFlash 0.5s ease-out;
}
.dice-tray.fumble {
    box-shadow: 0 0 32px var(--error-color), 0 0 64px var(--error-color);
    border-color: var(--error-color);
    animation: fumbleShake 0.5s ease-out;
}
@keyframes critFlash {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}
@keyframes fumbleShake {
    0%,100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}
.dice-label {
    color: var(--text-secondary);
    font-size: 0.85em;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.die {
    width: 80px; height: 80px;
    margin: 0 auto 8px;
    background: linear-gradient(135deg, #1a2752, #0a0e27);
    border: 2px solid var(--primary-color);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 2.4em; font-weight: bold;
    color: var(--primary-color);
    transition: transform 0.2s;
}
.die.tumbling {
    animation: tumble 0.15s linear infinite;
}
.die.settled {
    animation: settle 0.4s ease-out;
}
@keyframes tumble {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(1.1); }
    100% { transform: rotate(360deg) scale(1); }
}
@keyframes settle {
    0% { transform: scale(1.4) rotate(20deg); }
    60% { transform: scale(0.9); }
    100% { transform: scale(1) rotate(0deg); }
}
.dice-tray.crit .die { color: gold; border-color: gold; }
.dice-tray.fumble .die { color: var(--error-color); border-color: var(--error-color); }
.dice-total { font-size: 1.1em; }
.dice-total .kept { color: var(--primary-color); }
.dice-total .mod { color: var(--text-secondary); }
.dice-total strong { color: var(--text-primary); font-size: 1.3em; }

/* ----- Character Panel ----- */
.character-panel {
    position: fixed;
    left: 20px;
    bottom: 20px;
    width: 320px;
    z-index: 50;
}
.char-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.char-header h3 { margin: 0; color: var(--primary-color); }
.char-sub { color: var(--text-secondary); font-size: 0.85em; text-transform: capitalize; }
.char-vitals { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.hp { flex: 1; }
.hp-bar { width: 100%; height: 12px; background: rgba(255,68,68,0.2); border-radius: 6px; overflow: hidden; }
.hp-fill { height: 100%; background: linear-gradient(90deg, #c92626, #ff6464); transition: width 0.4s; }
.hp-text { font-size: 0.85em; color: var(--text-secondary); margin-top: 2px; }
.ac { background: rgba(100,200,255,0.15); border: 1px solid var(--border-color); border-radius: 6px; padding: 8px 12px; font-size: 0.9em; }
.ac strong { color: var(--primary-color); font-size: 1.3em; }

.char-abilities { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.abil {
    background: rgba(100,200,255,0.08);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s;
}
.abil:hover { background: rgba(100,200,255,0.2); transform: translateY(-1px); }
.abil-name { font-size: 0.7em; color: var(--text-secondary); letter-spacing: 0.5px; }
.abil-score { font-size: 1.2em; font-weight: bold; }
.abil-mod { font-size: 0.85em; color: var(--primary-color); }

.char-quickrolls { display: flex; gap: 6px; flex-wrap: wrap; }
.char-quickrolls button {
    flex: 1; padding: 6px 10px; font-size: 0.85em;
    background: var(--panel-bg); border: 1px solid var(--border-color);
    color: var(--text-primary); border-radius: 4px; cursor: pointer;
}
.char-quickrolls button:hover { border-color: var(--primary-color); }

/* ----- Roll Requests inside narrative ----- */
.roll-requests {
    display: flex; flex-wrap: wrap; gap: 8px;
    margin: 12px 0;
    padding: 10px;
    background: rgba(255,215,0,0.06);
    border-left: 3px solid gold;
    border-radius: 4px;
}
.roll-request-btn {
    background: linear-gradient(135deg, #3a2f00, #1a1500);
    border: 1px solid gold;
    color: gold;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.15s;
}
.roll-request-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, gold, #b89000);
    color: #1a1500;
    transform: translateY(-1px);
}
.roll-request-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ----- Scene Window (draggable + resizable) ----- */
.scene-window {
    position: fixed;
    z-index: 50;
    min-width: 200px;
    min-height: 140px;
    background: rgba(8, 12, 30, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(100, 200, 255, 0.25);
    border-radius: 10px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.04) inset;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
    transition: box-shadow 0.2s;
}
.scene-window.dragging,
.scene-window.resizing { box-shadow: 0 18px 48px rgba(0,0,0,0.7), 0 0 0 1px var(--primary-color) inset; }
.scene-window-header {
    flex: 0 0 auto;
    height: 32px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(180deg, rgba(40,60,100,0.6), rgba(20,30,55,0.6));
    border-bottom: 1px solid rgba(100,200,255,0.15);
    cursor: grab;
    font-size: 0.85em;
    color: var(--text-secondary);
}
.scene-window-header:active { cursor: grabbing; }
.scene-window-title { font-weight: 600; letter-spacing: 0.3px; }
.scene-window-controls { display: flex; gap: 4px; }
.scene-window-btn {
    background: transparent;
    border: 1px solid rgba(100,200,255,0.2);
    color: var(--text-secondary);
    width: 22px; height: 22px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95em;
    line-height: 1;
    padding: 0;
}
.scene-window-btn:hover { background: rgba(100,200,255,0.15); color: var(--primary-color); }
.scene-window-body {
    position: relative;
    flex: 1 1 auto;
    background: #0a0e22;
    overflow: hidden;
}
.scene-window.minimized .scene-window-body,
.scene-window.minimized .scene-window-resize { display: none; }
.scene-window.minimized { height: auto !important; }
.scene-image-empty {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    text-align: center; padding: 16px;
    color: var(--text-secondary); opacity: 0.7;
    font-size: 0.85em; font-style: italic;
    pointer-events: none;
}
.scene-window-body.has-image .scene-image-empty { display: none; }
.scene-image-layer {
    position: absolute; inset: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0;
    transition: opacity 1.2s ease-in-out;
}
.scene-image-layer.visible { opacity: 1; animation: kenBurns 40s ease-in-out infinite alternate; }
@keyframes kenBurns {
    from { transform: scale(1.02) translate(-0.5%, -0.3%); }
    to   { transform: scale(1.08) translate(0.8%, 0.5%); }
}
.scene-image-indicator {
    position: absolute;
    top: 8px; left: 50%;
    transform: translateX(-50%);
    background: rgba(8,12,30,0.85);
    backdrop-filter: blur(6px);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 0.75em;
    display: none;
    align-items: center;
    gap: 6px;
    border: 1px solid rgba(100,200,255,0.2);
    z-index: 2;
}
.scene-image-indicator.visible { display: inline-flex; }
.scene-image-indicator .dot {
    display: inline-block; width: 5px; height: 5px;
    background: var(--primary-color); border-radius: 50%;
    animation: pulse 1.2s infinite ease-in-out;
}
.scene-image-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.scene-image-indicator .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.1); }
}
.scene-window-resize {
    position: absolute; bottom: 0; right: 0;
    width: 16px; height: 16px;
    cursor: nwse-resize;
    background:
        linear-gradient(135deg, transparent 0 50%, rgba(100,200,255,0.4) 50% 60%, transparent 60% 70%, rgba(100,200,255,0.4) 70% 80%, transparent 80%);
}

/* ----- Cinematic Story Overlay -----
   Story panel becomes a glassy, bottom-anchored overlay so the 3D world
   shows through. Each new turn fades in. */
/* ===== Realm Background ===== */
body.cinematic {
    background:
        linear-gradient(180deg, rgba(8,12,30,0.35) 0%, rgba(8,12,30,0.55) 60%, rgba(8,12,30,0.75) 100%),
        url('../img/realm-bg.png') center/cover no-repeat fixed,
        #08081a;
}
/* When realm bg is active, hide the 3D canvas (keep DOM around for re-enable) */
body.cinematic.with-realm-bg #canvas-container {
    opacity: 0;
    pointer-events: none;
}

body.cinematic #story-panel {
    position: fixed !important;
    top: auto !important;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%);
    width: min(880px, 92vw);
    max-height: 42vh;
    overflow-y: auto;
    background: linear-gradient(180deg,
        rgba(8, 12, 30, 0.0) 0%,
        rgba(8, 12, 30, 0.55) 18%,
        rgba(8, 12, 30, 0.78) 100%) !important;
    backdrop-filter: blur(8px) saturate(1.1);
    border: none !important;
    border-top: 1px solid rgba(100, 200, 255, 0.18) !important;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.4);
    border-radius: 14px 14px 4px 4px;
    padding: 22px 28px !important;
    z-index: 30;
}
body.cinematic #story-panel::-webkit-scrollbar { width: 6px; }
body.cinematic #story-panel::-webkit-scrollbar-thumb {
    background: rgba(100,200,255,0.3); border-radius: 3px;
}
body.cinematic #input-panel {
    position: fixed !important;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: min(880px, 92vw);
    background: rgba(8, 12, 30, 0.85) !important;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(100, 200, 255, 0.25) !important;
    border-radius: 10px;
    padding: 12px 16px !important;
    z-index: 40;
}
body.cinematic #input-panel textarea {
    background: rgba(255,255,255,0.04) !important;
    border-color: rgba(100,200,255,0.2) !important;
}
body.cinematic #world-info {
    top: 16px; right: 16px; left: auto;
    background: rgba(8, 12, 30, 0.6) !important;
    backdrop-filter: blur(6px);
    font-size: 0.85em;
    opacity: 0.7;
    transition: opacity 0.2s;
}
body.cinematic #world-info:hover { opacity: 1; }

/* ----- Story turn rendering ----- */
.story-turn {
    margin-bottom: 18px; padding-bottom: 12px;
    border-bottom: 1px dashed rgba(100,200,255,0.15);
    animation: storyFadeIn 0.6s ease-out;
}
.story-turn:last-child { border-bottom: none; }
@keyframes storyFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
.player-prompt {
    color: var(--text-secondary); font-style: italic;
    margin-bottom: 10px; font-size: 0.9em;
    padding-left: 10px; border-left: 2px solid rgba(100,200,255,0.3);
}
.dm-response {
    line-height: 1.65;
    font-size: 1.02em;
    color: #e8edff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.dm-response .chapter {
    display: inline-block; font-size: 0.7em;
    background: var(--primary-color); color: var(--dark-bg);
    padding: 1px 6px; border-radius: 3px; margin-right: 6px;
    vertical-align: middle; font-weight: bold;
}
.dm-response p { margin: 0 0 10px; }
.dm-response p:last-child { margin-bottom: 0; }

/* Subtle vignette so text readability holds against any backdrop */
body.cinematic #ui-overlay::before {
    content: '';
    position: fixed; inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center,
        transparent 40%,
        rgba(0,0,0,0.4) 100%);
    z-index: 1;
}

/* ----- Modal ----- */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-card {
    background: var(--dark-bg); border: 1px solid var(--primary-color);
    border-radius: 10px; padding: 24px;
    width: 420px; max-width: 92vw; max-height: 90vh; overflow-y: auto;
}
.modal-card h2 { margin-top: 0; color: var(--primary-color); }
.modal-card label { display: block; margin: 10px 0; }
.modal-card input, .modal-card select {
    display: block; width: 100%; box-sizing: border-box;
    padding: 6px 10px; margin-top: 4px;
    background: rgba(100,200,255,0.05);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
}
.abil-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
    border: 1px solid var(--border-color); border-radius: 6px; padding: 10px;
}
.abil-grid legend { color: var(--text-secondary); font-size: 0.8em; padding: 0 6px; grid-column: 1/-1; }
.abil-grid label { font-size: 0.85em; }
#ch-reroll { grid-column: 1/-1; padding: 6px; background: var(--panel-bg); border: 1px solid var(--border-color); color: var(--text-primary); cursor: pointer; border-radius: 4px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.modal-actions button { padding: 8px 16px; border-radius: 5px; cursor: pointer; border: 1px solid var(--border-color); background: var(--panel-bg); color: var(--text-primary); }
.modal-actions button.primary { background: linear-gradient(135deg, var(--secondary-color), var(--accent-color)); border-color: var(--accent-color); }

#char-create-btn.primary {
    background: linear-gradient(135deg, var(--secondary-color), var(--accent-color));
    border: none; color: white; padding: 8px 14px; border-radius: 5px; cursor: pointer; width: 100%;
}
