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

body {
    background-color: #1a1a1a;
    color: white;
    color-scheme: dark;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: system-ui, sans-serif;
}

/* Disable centering when grid doesn't fit in viewport */
@media (max-width: 768px) {
    body {
        align-items: flex-start;
        justify-content: flex-start;
    }
}

.container {
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.grid-container {
    flex-shrink: 0;
    position: relative;
}

/* Desktop layout - stats to the right */
@media (min-width: 900px) {
    .container {
        flex-direction: row;
        justify-content: center;
    }
}

.grid {
    display: grid;
    grid-template-columns: repeat(11, 64px);
    grid-template-rows: repeat(11, 64px);
    padding: 10px;
    gap: 0;
}

.grid-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
}

/* Responsive grid for smaller viewports */
@media (max-width: 768px) {
    .grid {
        grid-template-columns: repeat(11, calc((100vw - 50px) / 11));
        grid-template-rows: repeat(11, calc((100vw - 50px) / 11));
        max-width: calc(100vw - 50px);
    }

    .grid-cell {
        width: calc((100vw - 50px) / 11);
        height: calc((100vw - 50px) / 11);
    }
}

.header-cell {
    padding-bottom: 16px;
}

.row-header {
    padding-right: 16px;
}

img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    transition: transform 0.2s ease;
}

/* Responsive images for smaller viewports */
@media (max-width: 768px) {
    img {
        width: calc((100vw - 40px) / 11 * 0.75);
        height: calc((100vw - 40px) / 11 * 0.75);
        max-width: 48px;
        max-height: 48px;
    }
}

img:hover {
    transform: scale(1.1);
}

/* Popover styles */
.popover {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 8px;
    background-color: #2a2a2a;
    border: 2px solid #444;
    border-radius: 8px;
    padding: 12px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    display: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none;
    width: max-content;
    max-width: 300px;
    grid-template-columns: 48px 1fr;
    grid-template-rows: auto auto auto;
    gap: 8px 12px;
    align-items: start;
}

.item-popover {
    grid-template-rows: auto auto auto auto auto;
}

.popover-main-img {
    width: 48px;
    height: 48px;
    grid-row: 1 / 4;
}

.popover-name {
    font-weight: bold;
    color: #fff;
    font-size: 16px;
    align-self: center;
}

.popover-stats {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: #ccc;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.popover-stats img {
    width: 14px;
    height: 14px;
}

.popover-components {
    grid-column: 1 / 3;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
}

.component-img-mini {
    width: 24px;
    height: 24px;
}

.plus-text {
    color: #ccc;
    font-size: 14px;
    font-weight: bold;
}

.popover-description {
    grid-column: 1 / 3;
    color: #ccc;
    font-size: 12px;
    line-height: 1.4;
}

.popover-description p {
    margin-bottom: 12px;
}

.popover-description ul {
    list-style-position: inside;
    margin-bottom: 12px;
}

.text-health {
    color: #259874;
    font-weight: bold;
}

.text-durability {
    color: #259874;
    font-weight: bold;
}

.text-mana {
    color: #009eff;
    font-weight: bold;
}

.text-armor {
    color: #ecb44d;
    font-weight: bold;
}

.text-magic-resist {
    color: #43c4de;
    font-weight: bold;
}

.text-attack-damage {
    color: #da7927;
    font-weight: bold;
}

.text-physical-damage {
    color: #da7927;
    font-weight: bold;
}

.text-ability-power {
    color: #5e61ef;
    font-weight: bold;
}

.text-attack-speed {
    color: #e2c443;
    font-weight: bold;
}

.text-damage-amp {
    color: #fffef3;
    font-weight: bold;
}

.text-crit {
    color: #df3e35;
    font-weight: bold;
}

.text-omnivamp {
    color: #e74143;
    font-weight: bold;
}

.text-sunder {
    color: #ecb44d;
    font-weight: bold;
    font-style: italic;
}

.text-shred {
    color: #ecb44d;
    font-weight: bold;
    font: italic;
}

.text-burn {
    color: #ecb44d;
    font-weight: bold;
    font-style: italic;
}

.text-wound {
    color: #ecb44d;
    font-weight: bold;
    font-style: italic;
}

.text-hint {
    opacity: 60%;
    font-style: italic;
}


/* Show popover when explicitly shown (for touch long-press) */
.grid-cell.show-popover .popover {
    display: grid;
    opacity: 1;
    visibility: visible;
}

/* Mobile popover modal styles */
.popover.mobile-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin-top: 0;
    z-index: 1003;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

/* Mobile modal overlay */
.mobile-popover-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1002;
    display: none;
}

.mobile-popover-overlay.show {
    display: block;
}


/* Position popover relative to grid cell */
.grid-cell {
    position: relative;
    opacity: 0.5;
    cursor: pointer;
}

/* Highlight styles for row/column hover */
.grid-cell.highlight {
    /*background-color: rgba(255, 255, 255, 0.5);*/
    opacity: 1.0;
}

.grid-cell.highlight-row {
    /*background-color: rgba(255, 255, 255, 0.4);*/
    opacity: 1.0;
}

.grid-cell.highlight-col {
    /*background-color: rgba(255, 255, 255, 0.4);*/
    opacity: 1.0;
}

/* Activated cell */
.grid-cell.activated > img {
    border: 1px solid #43e5ff;
    border-radius: 4px;
    box-shadow: 0px 0px 4px 1px #43e5ff;
}

/* Activated cell */
.grid-cell.activated {
    opacity: 1.0;
}

/* Half-activated cell */
.grid-cell.half-activated > img {
    border: 1px solid #ff8c43;
    border-radius: 4px;
    box-shadow: 0px 0px 4px 1px #ff8c43;
}

/* Half-activated cell */
.grid-cell.half-activated {
    opacity: 1.0;
}

/* Stats summary */
.stats-summary {
    display: none;
    margin-top: 20px;
    align-self: center;
}

.stats-summary.show {
    display: block;
}

.stats-list {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    line-height: 16px;
    font-size: 10px;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ccc;
}

.stat-item img {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

/* Desktop layout - stats to the right */
@media (min-width: 900px) {
    .stats-summary {
        position: absolute;
        left: calc(100% + 16px);
        top: 0;
        margin-top: 12px;
        align-self: auto;
    }

    /* The stats summary now appears to the right of the grid, so the stats list should appear as a column */
    .stats-list {
        flex-direction: column;
        font-size: 14px;
    }

    .stat-item img {
        width: 16px;
        height: 16px;
    }
}

.stat-value {
    font-weight: bold;
    color: #fff;
    transition: background-color 0.3s ease;
}

.stat-value.highlight-change {
    animation: fadeHighlight 1.5s ease-out forwards;
}

@keyframes fadeHighlight {
    0% {
        color: #ffff00;
    }
    100% {
        color: #fff;
    }
}

/* Debuffs styles */
.debuff-item {
    color: #ecb44d;
    font-style: italic;
    font-weight: bold;
    opacity: 0.9;
}

/* Help button */
.help-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #575757;
    color: #b7b7b7;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: background-color 0.2s ease;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-button:hover {
    background-color: #444;
}

/* Clear button */
.clear-button {
    position: fixed;
    bottom: 20px;
    right: 80px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #d32f2f;
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: background-color 0.2s ease;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-button:hover {
    background-color: #bb3e3e;
}

/* Button icons */
.button-icon {
    width: 24px;
    height: 24px;
    pointer-events: none;
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1002;
}

.modal-overlay.show {
    display: flex;
}

.modal-content {
    background-color: #2a2a2a;
    border: 2px solid #444;
    border-radius: 8px;
    padding: 24px;
    max-width: 450px;
    width: 90%;
    color: white;
}

.modal-title {
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 16px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-favicon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.modal-text {
    font-size: 14px;
    line-height: 1.6;
    color: #ccc;
}

.modal-text ul {
    margin: 0;
    padding-left: 20px;
}

.modal-text li {
    margin-bottom: 8px;
}

.modal-text code {
    background-color: #444;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    color: #fff;
}
