/**
 * Velutan Battle Tracker - Battlefield Styles
 *
 * This file contains all battlefield-related styles including:
 * - Battlefield container and layout
 * - Grid overlay
 * - Token/character styles
 * - HP indicators
 * - Status effects
 * - Resize handles
 * - Toolbar
 */

/* ==================== Battlefield Container ==================== */
/**
 * Main battlefield area where tokens are placed
 * Adjusts margin based on sidebar visibility
 */
.battlefield-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    padding-bottom: 90px; /* Space for initiative bar */
    margin-left: 320px; /* Space for sidebar */
    transition: margin-left 0.3s ease;
}

.battlefield-container.sidebar-hidden {
    margin-left: 0;
}

.battlefield {
    width: 100%;
    height: 100%;
    position: relative;
    transition: background 0.3s ease;
}

/* ==================== Grid Overlay ==================== */
/**
 * Optional grid overlay for the battlefield
 * Dynamic grid size controlled by gridSize state (inline style)
 * Grid lines use CSS variables for dynamic sizing
 */
.battlefield.grid::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Grid applied via inline style with dynamic size */
    pointer-events: none;
    z-index: 10;
}

/* ==================== Toolbar ==================== */
/**
 * Top-right toolbar with utility buttons
 * (Grid toggle, Undo, Clear All, Notes toggle)
 */
.toolbar {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    z-index: 100;
}

.toolbar-btn {
    background: rgba(20, 20, 30, 0.95);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-btn:hover {
    background: rgba(99, 102, 241, 0.4);
    border-color: #6366f1;
}

.toolbar-btn.active {
    background: rgba(99, 102, 241, 0.6);
    border-color: #6366f1;
}

/* ==================== Character Tokens ==================== */
/**
 * Tokens representing characters on the battlefield
 * Circular tokens with images, HP rings, and info
 */
.token {
    position: absolute;
    cursor: move;
    user-select: none;
    transition: transform 0.1s, box-shadow 0.2s;
    z-index: 100;
    transform: translate(-50%, -50%);
}

.token:hover {
    transform: translate(-50%, -50%) scale(1.05);
    z-index: 1000;
}

.token.dragging {
    opacity: 0.8;
    z-index: 2000;
}

.token.dead {
    opacity: 0.4;
    filter: grayscale(100%);
}

.token-inner {
    position: relative;
    width: 100%;
    height: 100%;
}

/* ==================== Token Images ==================== */
/**
 * Character portrait images in circular tokens
 * Different border colors for ally/enemy/neutral
 */
.token-image {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 6px solid;
    font-size: 1em; /* Reset font size */
}

/* Ally - Green border */
.token.ally .token-image {
    border-color: #10b981;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.7), inset 0 0 20px rgba(16, 185, 129, 0.3);
    border-width: 6px;
}

/* Enemy - Red border */
.token.enemy .token-image {
    border-color: #ef4444;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.7), inset 0 0 20px rgba(239, 68, 68, 0.3);
    border-width: 6px;
}

/* Neutral - Yellow border */
.token.neutral .token-image {
    border-color: #fbbf24;
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.7), inset 0 0 20px rgba(251, 191, 36, 0.3);
    border-width: 6px;
}

/* ==================== Token Placeholder ==================== */
/**
 * Placeholder when no image is set (shows first letter of name)
 */
.token-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--token-size, 80px) * 0.5); /* 50% of token size */
    font-weight: bold;
    border: 6px solid;
    background: rgba(50, 50, 70, 0.9);
}

.token.ally .token-placeholder {
    border-color: #10b981;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.7), inset 0 0 20px rgba(16, 185, 129, 0.3);
    border-width: 6px;
}

.token.enemy .token-placeholder {
    border-color: #ef4444;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.7), inset 0 0 20px rgba(239, 68, 68, 0.3);
    border-width: 6px;
}

.token.neutral .token-placeholder {
    border-color: #fbbf24;
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.7), inset 0 0 20px rgba(251, 191, 36, 0.3);
    border-width: 6px;
}

/* Structure - No circle, no background (just the icon) */
.token.structure .token-placeholder {
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

/* ==================== HP Ring ==================== */
/**
 * Circular HP indicator around ally tokens
 * Shows current HP percentage as a colored ring
 */
.token-hp-ring {
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    pointer-events: none;
    z-index: 1;
}

/* ==================== Token Info ==================== */
/**
 * Name and HP text displayed below token
 * Scales with token size and positioned further away
 */
.token-info {
    position: absolute;
    bottom: calc(var(--token-size, 80px) * -0.55); /* 55% of token size below */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    font-size: calc(var(--token-size, 80px) * 0.16); /* 16% of token size */
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ==================== Status Effects ==================== */
/**
 * Status effect badges displayed above token
 * (Stunned, Poisoned, Blessed, etc.)
 * Scales with token size and positioned further away
 */
.status-effects {
    position: absolute;
    top: calc(var(--token-size, 80px) * -0.55); /* 55% of token size above */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 3px;
}

.status-badge {
    background: rgba(0, 0, 0, 0.8);
    padding: 3px 6px;
    border-radius: 4px;
    font-size: calc(var(--token-size, 80px) * 0.14); /* 14% of token size */
    border: 1px solid;
}

/* ==================== Damage Tooltip ==================== */
/**
 * Tooltip showing damage log for enemies on hover
 */
.damage-tooltip {
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%);
    background: rgba(20, 20, 30, 0.98);
    border: 2px solid #ef4444;
    border-radius: 8px;
    padding: 12px 14px;
    margin-left: 15px;
    font-size: 12px;
    z-index: 3000;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    min-width: 250px;
    max-width: 300px;
    white-space: normal;
}

.damage-tooltip::before {
    content: '';
    position: absolute;
    top: 50%;
    right: 100%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: #ef4444;
}

.damage-entry {
    padding: 3px 0;
    color: #fca5a5;
}

.damage-entry:not(:last-child) {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 3px;
}

/* ==================== Resize Handle ==================== */
/**
 * Draggable handle to resize tokens
 * Appears in bottom-right corner on hover
 */
.resize-handle {
    position: absolute;
    top: -18px;
    left: -18px;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s, filter 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
}

.rotate-handle {
    position: absolute;
    top: -18px;
    right: -18px;
    width: 16px;
    height: 16px;
    cursor: grab;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s, filter 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.8));
}

.token:hover .resize-handle,
.token:hover .rotate-handle {
    opacity: 1 !important;
}

.resize-handle:hover {
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 1));
    transform: scale(1.2);
}

.rotate-handle:hover {
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 1));
    transform: scale(1.2);
}

/* ==================== HP Bar (Legacy) ==================== */
/**
 * Linear HP bar (currently using ring instead)
 * Kept for potential future use
 */
.hp-bar {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 8px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.hp-fill {
    height: 100%;
    background: linear-gradient(90deg, #10b981 0%, #34d399 100%);
    transition: width 0.3s;
}

.hp-fill.low {
    background: linear-gradient(90deg, #f59e0b 0%, #fbbf24 100%);
}

.hp-fill.critical {
    background: linear-gradient(90deg, #ef4444 0%, #f87171 100%);
}
