/* Devin's Dungeon — Dark Fantasy Theme */

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

:root {
    --bg-dark: #1a1a2e;
    --bg-medium: #16213e;
    --bg-light: #0f3460;
    --bg-card: #1e2a4a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-dim: #6a6a7a;
    --accent: #e94560;
    --accent-gold: #d4a017;
    --accent-green: #2ecc71;
    --accent-blue: #3498db;
    --border: #2a2a4a;
    --success: #2ecc71;
    --failure: #e74c3c;
    --crit: #f39c12;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

/* Screens */
.screen {
    display: none;
    height: 100vh;
}
.screen.active {
    display: flex;
}

/* Login */
#login-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #0a0a1a 100%);
}

.login-box {
    text-align: center;
    padding: 3rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    min-width: 360px;
}

.login-box h1 {
    font-size: 2.5rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

input[type="password"],
input[type="text"] {
    padding: 0.75rem 1rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-primary, #login-form button, #action-form button {
    background: var(--accent);
    color: white;
}

.btn-primary:hover, #login-form button:hover, #action-form button:hover {
    background: #c0392b;
}

.btn-primary:disabled, #action-form button:disabled {
    background: var(--text-dim);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-light);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--accent-blue);
}

.error {
    color: var(--failure);
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

/* Character Creation */
#creation-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #0a0a1a 100%);
}

.creation-box {
    padding: 2.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    min-width: 420px;
    max-width: 500px;
}

.creation-box h1 {
    color: var(--accent-gold);
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

.creation-step {
    margin-bottom: 1.5rem;
}

.creation-step label {
    display: block;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
}

.creation-step select,
.creation-step input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 0.8rem;
}

.hint {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 0.8rem;
}

.stat-grid .stat-box {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem;
    text-align: center;
}

.stat-box .stat-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
}

.stat-box .stat-val {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent-gold);
}

.stat-box .stat-mod {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.stat-summary {
    background: var(--bg-dark);
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-line;
    display: none;
}

#create-char-btn {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
    margin-top: 0.5rem;
}

/* Game Layout */
.game-layout {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Chat Panel */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.chat-header {
    padding: 1rem 1.5rem;
    background: var(--bg-medium);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h2 {
    font-size: 1.2rem;
    color: var(--accent);
}

.location-badge {
    background: var(--bg-light);
    color: var(--accent-gold);
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.85rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 90%;
    padding: 1rem;
    border-radius: 10px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message.dm {
    background: var(--bg-card);
    border-left: 3px solid var(--accent);
    align-self: flex-start;
}

.message.player {
    background: var(--bg-light);
    border-left: 3px solid var(--accent-blue);
    align-self: flex-end;
}

.message.system {
    background: transparent;
    color: var(--text-dim);
    font-style: italic;
    text-align: center;
    align-self: center;
    font-size: 0.9rem;
    border: none;
    padding: 0.5rem;
}

.dice-result {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    margin-top: 0.8rem;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.dice-result .roll-success {
    color: var(--success);
    font-weight: 700;
}

.dice-result .roll-failure {
    color: var(--failure);
    font-weight: 700;
}

.dice-result .roll-crit {
    color: var(--crit);
    font-weight: 700;
}

.action-bar {
    display: flex;
    padding: 1rem;
    gap: 0.5rem;
    background: var(--bg-medium);
    border-top: 1px solid var(--border);
}

.action-bar input {
    flex: 1;
    padding: 0.75rem 1rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
}

.action-bar button {
    min-width: 80px;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-medium);
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sidebar-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
}

.sidebar-section h3 {
    color: var(--accent-gold);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.8rem;
}

.stat-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    font-size: 0.9rem;
}

.stat-value {
    color: var(--accent-gold);
    font-weight: 700;
}

/* HP Bar */
.hp-bar {
    flex: 1;
    margin-left: 0.5rem;
    height: 22px;
    background: var(--bg-dark);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.hp-fill {
    height: 100%;
    background: var(--success);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.hp-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.8rem;
    font-weight: 700;
    text-shadow: 0 0 3px rgba(0,0,0,0.8);
}

.hp-bar-label {
    min-width: 25px;
}

/* XP Bar */
.xp-bar {
    flex: 1;
    margin-left: 0.5rem;
    height: 22px;
    background: var(--bg-dark);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.xp-fill {
    height: 100%;
    background: var(--accent-gold);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.xp-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 700;
    text-shadow: 0 0 3px rgba(0,0,0,0.8);
}

.xp-bar-label {
    min-width: 25px;
}

.xp-bar.level-up {
    animation: xpGlow 1.5s ease-in-out;
}

@keyframes xpGlow {
    0% { box-shadow: 0 0 5px rgba(212, 160, 23, 0.3); }
    50% { box-shadow: 0 0 20px rgba(212, 160, 23, 0.8), 0 0 40px rgba(212, 160, 23, 0.4); }
    100% { box-shadow: 0 0 5px rgba(212, 160, 23, 0.3); }
}

/* Ability Grid */
.ability-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
}

.ability {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem;
    background: var(--bg-dark);
    border-radius: 4px;
}

.ability-label {
    color: var(--text-dim);
    font-weight: 600;
}

.ability-value {
    color: var(--text-primary);
    font-weight: 700;
}

/* Inventory */
#inventory-text {
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

#combat-text {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text-secondary);
    white-space: pre-wrap;
}

/* Spell Sidebar */
.slot-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.4rem;
}

.slot-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    min-width: 30px;
    font-weight: 600;
}

.slot-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--accent-blue);
    background: transparent;
    transition: background 0.3s, box-shadow 0.3s;
}

.slot-dot.filled {
    background: var(--accent-blue);
    box-shadow: 0 0 4px rgba(52, 152, 219, 0.5);
}

.spell-group {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
    line-height: 1.4;
}

/* Death Saves */
.ds-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}

.ds-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    min-width: 48px;
    font-weight: 600;
}

.ds-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: transparent;
    transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
}

.ds-dot.success.filled {
    background: var(--success);
    border-color: var(--success);
    box-shadow: 0 0 6px rgba(46, 204, 113, 0.6);
}

.ds-dot.failure.filled {
    background: var(--failure);
    border-color: var(--failure);
    box-shadow: 0 0 6px rgba(231, 76, 60, 0.6);
}

@keyframes reviveGlow {
    0% { box-shadow: 0 0 5px rgba(46, 204, 113, 0.3); }
    50% { box-shadow: 0 0 25px rgba(46, 204, 113, 0.9), 0 0 50px rgba(46, 204, 113, 0.4); }
    100% { box-shadow: 0 0 5px rgba(46, 204, 113, 0.3); }
}

@keyframes failFlash {
    0% { box-shadow: 0 0 5px rgba(231, 76, 60, 0.3); }
    50% { box-shadow: 0 0 25px rgba(231, 76, 60, 0.9), 0 0 50px rgba(231, 76, 60, 0.4); }
    100% { box-shadow: 0 0 5px rgba(231, 76, 60, 0.3); }
}

#death-saves-section.revive-glow {
    animation: reviveGlow 1.5s ease-in-out;
}

#death-saves-section.fail-flash {
    animation: failFlash 0.8s ease-in-out;
}

/* Dice Display */
.dice-display {
    text-align: center;
    padding: 0.5rem;
}

.dice-display .die {
    display: inline-block;
    width: 50px;
    height: 50px;
    background: var(--bg-dark);
    border: 2px solid var(--accent-gold);
    border-radius: 8px;
    line-height: 50px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent-gold);
    margin: 0.2rem;
}

.dice-display .die.crit {
    border-color: var(--crit);
    color: var(--crit);
    box-shadow: 0 0 10px rgba(243, 156, 18, 0.4);
}

.dice-display .die.fumble {
    border-color: var(--failure);
    color: var(--failure);
}

.dice-display .roll-detail {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* --- Roll Button & Dice Animation --- */
.roll-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    padding: 1.5rem;
    margin: 0.5rem 0;
    background: linear-gradient(135deg, var(--bg-card) 0%, #1a1a3e 100%);
    border: 2px solid var(--accent-gold);
    border-radius: 12px;
    align-self: center;
    max-width: 300px;
    width: 100%;
}

.die-preview {
    width: 80px;
    height: 80px;
    background: var(--bg-dark);
    border: 3px solid var(--accent-gold);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--accent-gold);
    font-family: 'Courier New', monospace;
    user-select: none;
}

.die-preview.tumbling {
    animation: diceShake 0.15s ease-in-out infinite;
    border-color: var(--accent-blue);
    color: var(--text-secondary);
}

.die-preview.revealed {
    animation: diceReveal 0.4s ease-out forwards;
    font-size: 2.8rem;
}

.die-preview.result-crit {
    border-color: var(--crit);
    color: var(--crit);
    box-shadow: 0 0 20px rgba(243, 156, 18, 0.6), 0 0 40px rgba(243, 156, 18, 0.3);
}

.die-preview.result-fumble {
    border-color: var(--failure);
    color: var(--failure);
    box-shadow: 0 0 20px rgba(231, 76, 60, 0.5);
}

.die-preview.result-success {
    border-color: var(--success);
    color: var(--success);
    box-shadow: 0 0 15px rgba(46, 204, 113, 0.4);
}

.die-preview.result-failure {
    border-color: var(--failure);
    color: var(--failure);
}

.roll-container.result-crit {
    border-color: var(--crit);
    background: linear-gradient(135deg, #2a2010 0%, #1a1a2e 100%);
}

.roll-container.result-fumble {
    border-color: var(--failure);
}

.roll-btn {
    padding: 0.8rem 2rem;
    background: linear-gradient(135deg, var(--accent) 0%, #c0392b 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
}

.roll-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(233, 69, 96, 0.4);
}

.roll-btn:active {
    transform: scale(0.98);
}

.roll-btn:disabled {
    background: var(--text-dim);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.roll-info {
    font-size: 0.85rem;
    color: var(--text-dim);
    text-align: center;
}

.roll-result-text {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: var(--text-primary);
    text-align: center;
    margin-top: 0.3rem;
    font-weight: 600;
}

.roll-prompt-msg {
    text-align: center;
    font-weight: 600;
    color: var(--accent-gold);
    border-left-color: var(--accent-gold);
}

@keyframes diceShake {
    0% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(-8deg) scale(1.05); }
    50% { transform: rotate(8deg) scale(1); }
    75% { transform: rotate(-4deg) scale(1.03); }
    100% { transform: rotate(0deg) scale(1); }
}

@keyframes diceReveal {
    0% { transform: scale(1.3); }
    50% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

/* Loading indicator */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-dim);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* Responsive */
@media (max-width: 768px) {
    .game-layout {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        max-height: 200px;
        flex-direction: row;
        flex-wrap: wrap;
        overflow-x: auto;
    }
    .sidebar-section {
        min-width: 200px;
    }
    .chat-panel {
        border-right: none;
    }
}
