body {
    font-family: Arial, sans-serif;
    background: #111;
    color: #eee;
    margin: 0;
    padding: 0;
}

header {
    text-align: center;
    padding: 20px;
    background: #222;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
}

header h1 {
    margin: 0;
    flex-grow: 1;
    text-align: center;
}

.header-links {
    display: flex;
    gap: 15px;
}

.header-links a {
    color: #4ba3ff;
    text-decoration: none;
    padding: 8px 12px;
    border: 1px solid #4ba3ff;
    border-radius: 4px;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

.header-links a:hover {
    background: #4ba3ff;
    color: #222;
}

main {
    padding: 20px;
}

.compare-columns {
    display: flex;
    justify-content: space-between;
    gap: 20px;
}

.armor-column {
    flex: 1;
    background: #1a1a1a;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #333;
}

select {
    width: 100%;
    padding: 8px;
    margin-bottom: 15px;
    background: #222;
    color: #eee;
    border: 1px solid #444;
}

.upgradeLabel {
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 1.1em;
}

.stats {
    background: #222;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #333;
}

.stat-row {
    display: grid;
    align-items: center;
    padding: 4px 0;
}

.stat-row.stat-row-split {
    grid-template-columns: minmax(70px, 0.84fr) minmax(56px, 0.63fr) minmax(56px, 0.63fr) minmax(56px, 0.63fr);
    gap: 4px;
}

.stat-row.stat-row-single {
    grid-template-columns: minmax(70px, 1fr) minmax(80px, 1fr);
    gap: 10px;
}

.stat-row.stat-header {
    font-weight: bold;
    color: #ccc;
    border-bottom: 1px solid #333;
    padding-bottom: 6px;
    margin-bottom: 6px;
}

.stat-label {
    text-transform: capitalize;
}

.stat-value {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.stat-footnote {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid #555;
    font-size: 0.85em;
    color: #999;
    line-height: 1.3;
}

#comparison {
    margin-top: 40px;
}

.comparison-legend {
    display: flex;
    gap: 16px;
    align-items: center;
    margin: 8px 0 12px;
    font-size: 13px;
    color: #ccc;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid #333;
    display: inline-block;
}

.legend-a-head {
    background: #4dd0e1;
}

.legend-a-chest {
    background: #00acc1;
}

.legend-b-head {
    background: #ff8a65;
}

.legend-b-chest {
    background: #f4511e;
}

.comparison-bar {
    margin-bottom: 10px;
}

.comparison-bar-group {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 6px;
}

.comparison-bar-item {
    display: grid;
    grid-template-columns: minmax(110px, 140px) 1fr;
    align-items: center;
    gap: 8px;
}

.comparison-bar-item-label {
    font-size: 12px;
    color: #ccc;
    text-align: right;
}

.bar {
    height: 12px;
    background: #444;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    background: #00bcd4;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 1;
}

.bar-base {
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 0;
    opacity: 0.60;
    filter: saturate(0.8);
}

.bar-upgrade {
    height: 100%;
    position: absolute;
    top: 0;
    z-index: 2;
    opacity: 0.95;
}

/* Overlay grid that draws segment boundaries on top of the bar and fill. */
.bar-grid {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    display: flex;
    z-index: 3;
    pointer-events: none;
}

.bar-seg {
    flex: 1 1 0;
    border-left: 1px solid rgba(231, 221, 221, 0.822);
}

.bar-seg:first-child { border-left: none; }


/* Upgrade grid and cells */
.upgrade-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.upgrade-cost {
    margin: 4px 0 10px;
    padding: 6px 8px;
    background: #1c1c1c;
    border: 1px solid #333;
    border-radius: 4px;
    font-size: 14px;
    color: #ddd;
}

.upgrade-cell {
    position: relative;
    height: 89px;
    font-size: 17px;
    width: 305px;
    display: flex;
    align-items: stretch;
    justify-content: flex-start;
    background: #151515;
    border: 1px solid #2a2a2a;
    border-radius: 6px;
    color: #ddd;
    overflow: hidden;
}


.upgrade-cell.blank {
    flex: 0 0 auto;
    min-height: 89px;
    width: 305px;
    background: #1b1b1b;
    color: #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    border: 1px dashed #2f2f2f;
}

.upgrade-cell.has-upgrade {
    background: #1a1a1a;
    width: 305px;
    border-color: #3b3b3b;
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    cursor: pointer;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.upgrade-cell.has-upgrade:hover {
    border-color: #6c6c6c;
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(0,0,0,0.35);
}

.upgrade-cell.has-upgrade.selected {
    border-color: #7fb069;
    color: #fff;
    box-shadow: 0 0 12px rgba(127, 176, 105, 0.35);
}

.upgrade-grid {
    display: flex;
    flex-direction: column;
}

.upgrade-card-image {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;    
    pointer-events: none;
    filter: brightness(1.12) contrast(1.05);
}

.upgrade-card-image.no-image {
    background: linear-gradient(135deg, rgba(42,42,42,0.9), rgba(20,20,20,0.9));
}

.upgrade-indicator {
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background: #666;
    z-index: 3;
}

.upgrade-cell.selectable .upgrade-indicator {
    background: #c9a227;
}

.upgrade-cell.selected .upgrade-indicator {
    background: #7fb069;
}

.upgrade-cell.blocked .upgrade-indicator {
    background: #a33;
}

.upgrade-cell.requires .upgrade-indicator {
    background: #777;
}

.upgrade-cell.has-upgrade::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.35) 55%, rgba(0,0,0,0.12) 100%);
    pointer-events: none;
}

.upgrade-card-label {
    position: relative;
    z-index: 2;
    padding: 8px 14px;
    line-height: 1.2;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Visual indicators for constraint states */
.upgrade-cell.blocked {
    opacity: 0.65;
    background: #2b1515;
    color: #b88;
    cursor: not-allowed;
}
.upgrade-cell.requires {
    opacity: 0.85;
    background: #2a2116;
    color: #f4a;
    cursor: not-allowed;
}

.upgrade-cell.blocked .upgrade-card-image,
.upgrade-cell.requires .upgrade-card-image {
    filter: grayscale(0.5) brightness(0.7);
    opacity: 0.6;
}
.upgrade-cell.flash {
    outline: 2px solid rgba(255,187,0,0.9);
    box-shadow: 0 0 10px rgba(255,187,0,0.25);
}

/* Debug overlay for upgrade availability */
.upgrade-debug-overlay, #upgradeDebugOverlay {
    position: fixed;
    right: 12px;
    top: 12px;
    background: rgba(20,20,20,0.93);
    color: #eee;
    border: 1px solid #444;
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.3;
    white-space: pre-wrap;
    z-index: 9999;
    border-radius: 6px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.6);
    display: none;
}

.upgrade-section {
    border: 1px solid #2f2f2f;
    background: rgba(12,12,12,0.78);
    padding: 10px;
    margin-bottom: 12px;
    border-radius: 6px;
    position: relative;
    z-index: 1;
}

.upgrade-section h3 {
    margin: 0 0 6px 0;
    font-size: 14px;
    color: #ccc;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Styles for dynamic upgrade container with multiple armor pieces */
.upgrade-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.armor-piece-section {
    background: #1b1b1b;
    padding: 16px;
    border-radius: 8px;
    border-left: 3px solid #666;
    border: 1px solid #2a2a2a;
    position: relative;
    overflow: hidden;
}

.armor-piece-section.has-armor-image::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--armor-image);
    background-size: cover;
    background-position: center;
    opacity: 0.22;
    filter: saturate(0.85) contrast(1.1);
}

.armor-piece-section > * {
    position: relative;
    z-index: 1;
}

.armor-piece-section .piece-title {
    margin: 0 0 12px 0;
    font-size: 16px;
    color: #aaf;
    font-weight: bold;
    text-transform: capitalize;
}

.armor-piece-section .upgrade-section {
    margin-bottom: 10px;
}

.armor-piece-section .upgrade-section .section-title {
    margin: 8px 0 6px 0;
    font-size: 13px;
    color: #bbb;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Armor upgrade canvas - central image with zones around it */
.armor-upgrade-canvas {
    position: relative;
    min-height: 600px;
    margin-top: 12px;
    background: #111;
    background-size: 40px 40px;
}

.armor-center-image {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 280px;
    height: 500px;
    background-image: var(--armor-image);
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 1;
}

.armor-center-image.has-armor-image {
    opacity: 0.85;
}

.armor-upgrade-canvas.armor-type-head .armor-center-image {
    width: 220px;
    height: 320px;
}

/* Anchor points (white circles) on the armor */
.upgrade-anchor {
    position: absolute;
    width: 18px;
    height: 18px;
    background: rgba(255,255,255,0.9);
    border: 2px solid #888;
    border-radius: 50%;
    z-index: 5;
}

.upgrade-connector {
    position: absolute;
    height: 2px;
    background: linear-gradient(90deg, rgba(255,255,255,0.15), rgba(255,255,255,0.7));
    transform-origin: 0 50%;
    z-index: 6;
    pointer-events: none;
}

.upgrade-connector::after {
    content: "";
    position: absolute;
    right: -3px;
    top: -2px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255,255,255,0.85);
}

/* Anchor positions for body armor */
.anchor-head { left: 50%; top: 20%; transform: translateX(-50%); }
.anchor-neck { left: 50%; top: 40%;  transform: translateX(-50%);}
.anchor-shoulder { left: 60%; top: 37%; }
.anchor-chest { left: 50%; top: 54%; transform: translateX(-50%);}
.anchor-hip { left:58%; top: 68%; }

/* Anchor positions for head armor */
.armor-type-head .anchor-crown { left: 50%; top: 35%; transform: translateX(-50%); }
.armor-type-head .anchor-eyebrow { left: 52%; top: 42%; }
.armor-type-head .anchor-nose { left: 46%; top:48%; }
.armor-type-head .anchor-cheek { left: 75%; top: 56%; }
.armor-type-head .anchor-chin { left: 50%; top: 57%; transform: translateX(-50%); }


/* Upgrade zones - positioned around the armor */
.armor-upgrade-canvas .upgrade-zone {
    position: absolute;
    background: rgba(0,0,0,0.4);
    border: 1px solid rgba(100,100,100,0.5);
    padding: 6px;
    border-radius: 6px;
    z-index: 10;
}

.armor-upgrade-canvas .upgrade-zone .section-title {
    display: none;
}

/* Zone positions for body armor */
.zone-head { left: 50%; top: 6%; transform: translateX(-50%); }
.zone-neck { left: 0; top: 18%; }
.zone-shoulder { right: 0; top: 22%; }
.zone-chest { left: 0; top: 54%; }
.zone-hip { right: 0; top: 60%; }

/* Zone positions for head armor */
.armor-type-head .zone-crown { left: 50%; top: 22%; transform: translateX(-50%); }
.armor-type-head .zone-eyebrow { left: 59%; top: 34%; }
.armor-type-head .zone-nose { left: 22%; top: 42%; transform: translateX(-50%); }
.armor-type-head .zone-cheek { left: 70%; top: 50%; transform: translateX(-50%); }
.armor-type-head .zone-chin { left: 50%; top: 68%; transform: translateX(-50%); }

/* Smaller cards in canvas mode */
.armor-upgrade-canvas .upgrade-cell {
    width: 108px;
    height: 38px;
    font-size: 0.6rem;
    border: none;
}

.armor-upgrade-canvas .upgrade-cell.blank {
    width: 108px;
    height: 38px;
    background: transparent;
    border: none;
    min-height: auto;
}

.armor-upgrade-canvas .upgrade-row {
    gap: 3px;
    margin-bottom: 3px;
}

.armor-upgrade-canvas .upgrade-card-label {
    padding: 4px 5px;
    font-size: 0.6rem;
    line-height: 1.0;
}

.armor-upgrade-canvas .section-title {
    font-size: 13px;
    margin-bottom: 4px;
    color: #999;
}