/* ── Hexcrawl Studio — App-specific styles (hx- prefix) ──────────── */

/* ── Layout ──────────────────────────────────────────────────────── */

.hx-app {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
    overflow: hidden;
    background: #f0f0f0;
}

.hx-toolbar {
    display: flex;
    flex-direction: column;
    background: #252525;
    border-bottom: 1px solid #444;
}

.hx-toolbar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    flex-wrap: wrap;
}

.hx-toolbar-row + .hx-toolbar-row {
    border-top: 1px solid #333;
}

.hx-row-toggle {
    font-size: 11px !important;
    padding: 2px 8px !important;
    opacity: 0.6;
}

.hx-row-toggle.hx-on {
    opacity: 1;
    border-bottom: 2px solid #5af;
}

.hx-crop-wrap {
    position: relative;
    display: inline-block;
}

.hx-crop-select {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.hx-toolbar label {
    color: #aaa;
    font-size: 12px;
    white-space: nowrap;
}

.hx-toolbar input[type="number"] {
    width: 60px;
    padding: 2px 6px;
    background: #333;
    border: 1px solid #555;
    border-radius: 4px;
    color: #eee;
    font-size: 12px;
}

.hx-toolbar select {
    padding: 2px 6px;
    background: #333;
    border: 1px solid #555;
    border-radius: 4px;
    color: #eee;
    font-size: 12px;
}

.hx-toolbar button {
    padding: 4px 12px;
    background: #444;
    border: 1px solid #666;
    border-radius: 4px;
    color: #eee;
    font-size: 12px;
    cursor: pointer;
}

.hx-toolbar button:hover {
    background: #555;
}

.hx-toolbar button.hx-primary {
    background: #2d7d3a;
    border-color: #3a9d4a;
}

.hx-toolbar button.hx-primary:hover {
    background: #3a9d4a;
}

/* ── Map container ───────────────────────────────────────────────── */

.hx-map-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    cursor: default;
}

.hx-inner-wrap {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
}

/* ── SVG hex grid ────────────────────────────────────────────────── */

.hx-grid-svg {
    display: block;
}

.hx-hex {
    stroke: rgba(0, 0, 0, 0.35);
    stroke-width: 3;
    cursor: pointer;
    filter: drop-shadow(1px 1px 0 rgba(255,255,255,0.15));
}

.hx-hex-group:hover .hx-hex {
    fill-opacity: 0.8;
}

/* ── Terrain base colors ─────────────────────────────────────────── */

.hx-terrain-P   { fill: #A2CD5A; }
.hx-terrain-PD  { fill: #E6C48D; }
.hx-terrain-PF  { fill: #77A55A; }
.hx-terrain-PS  { fill: #7D8B52; }
.hx-terrain-F   { fill: #228B22; }
.hx-terrain-M   { fill: #A9A9A9; }
.hx-terrain-D   { fill: #EDC9AF; }
.hx-terrain-S   { fill: #6B8E23; }
.hx-terrain-H   { fill: #BEB55D; }
.hx-terrain-HD  { fill: #D8B76B; }
.hx-terrain-HF  { fill: #6DAA4F; }
.hx-terrain-HS  { fill: #8C8E4C; }
.hx-terrain-WF  { fill: #1E90FF; }
.hx-terrain-SS  { fill: #00BFFF; }
.hx-terrain-SD  { fill: #4169E1; }
.hx-terrain-SF  { fill: #ADD8E6; }
.hx-terrain-X   { fill: #FF69B4; }

/* ── ASCII text in hexes ─────────────────────────────────────────── */

.hx-ascii {
    fill: var(--hx-art-color, #000);
    font-family: 'Courier New', monospace;
    font-weight: bold;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    /* font-size set dynamically based on hex width */
}

/* ── PNG art images in hexes ────────────────────────────────────── */

.hx-art-image {
    pointer-events: none;
}

/* ── Art mode toggle (CSS-only switching) ───────────────────────── */
/* ASCII mode: hide art images. Any image mode: hide ASCII text. */

.hx-map-container.hx-art-ascii .hx-art-image { display: none !important; }
.hx-map-container:not(.hx-art-ascii) .hx-ascii { display: none !important; }

/* ── Hex fill color (uniform, under art — overrides terrain colors) */

.hx-grid-svg { --hx-fill-color: #ffffff; }
.hx-hex[class] { fill: var(--hx-fill-color) !important; }

/* ── Border hex (fills gaps between hexes, creates map outline) ── */

.hx-border-hex {
    fill: var(--hx-border-color, #000000);
    stroke: none;
}

/* Border hexes follow deleted hex visibility */
.hx-hex-group.deleted .hx-border-hex { display: none; }

/* ── Selection ───────────────────────────────────────────────────── */

.hx-selection {
    display: none;
    fill: #00bfff;
    fill-opacity: 0.3;
    stroke: #00bfff;
    stroke-width: 3;
}

.hx-hex-group.selected .hx-selection {
    display: inline;
}

/* ── Deleted hexes ──────────────────────────────────────────────── */

.hx-hex-group.deleted {
    display: none;
}

/* ── Color overlay ───────────────────────────────────────────────── */

.hx-color {
    pointer-events: none;
}

/* ── Functional layer toggles (CSS-only) ─────────────────────────── */
/* !important ensures toggles always win over show rules */

.hx-map-container.hide-terrain .hx-slot-terrain { display: none !important; }
.hx-map-container.hide-feature .hx-slot-feature { display: none !important; }
.hx-map-container.hide-border  .hx-slot-border  { display: none !important; }
.hx-map-container.hide-color   .hx-color        { display: none !important; }
.hx-map-container.hide-grid    .hx-hex          { stroke: none !important; filter: none !important; }
.hx-map-container.hide-meta    .hx-meta         { display: none !important; }
.hx-map-container.hide-poi     .hx-poi-name     { display: none !important; }
.hx-map-container.hide-poi     .hx-poi-dev      { display: none !important; }
.hx-map-container.hide-events  .hx-event        { display: none !important; }
.hx-map-container.hide-sprite-tint .hx-art-image { filter: none !important; }
.hx-map-container.hide-labels  .hx-idx-pill     { display: none !important; }
.hx-map-container.hide-labels  .hx-notes-icon   { display: none !important; }

/* ── Index label pills (HTML overlay) ────────────────────────────── */

.hx-idx-pill {
    display: none;
    font-size: 8px;
    padding: 1px 4px;
    border-radius: 6px;
    background: var(--hx-tag-bg, #000);
    color: var(--hx-tag-text, #fff);
    font-family: 'Courier New', monospace;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0.45;
}

.hx-map-container.idx-even   .hx-idx-even   { display: inline; }
.hx-map-container.idx-axial  .hx-idx-axial  { display: inline; }
.hx-map-container.idx-num    .hx-idx-num    { display: inline; }
.hx-map-container.idx-offset .hx-idx-offset { display: inline; }

/* ── Toolbar extras ──────────────────────────────────────────────── */

.hx-toolbar-sep {
    display: inline-block;
    width: 1px;
    height: 20px;
    background: #555;
    margin: 0 4px;
}

.hx-toolbar button.hx-toggle {
    opacity: 0.5;
    border-bottom: 2px solid transparent;
}

.hx-toolbar button.hx-toggle.hx-on {
    opacity: 1;
    background: #555;
    border-color: #888;
    border-bottom: 2px solid #5af;
}

.hx-overlay-scale-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.hx-overlay-scale-label input[type="range"] {
    width: 80px;
    accent-color: #5a9;
}

.hx-tag-color-label {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: #aaa;
    font-size: 12px;
    white-space: nowrap;
}

.hx-tag-color-label input[type="color"] {
    width: 22px;
    height: 20px;
    border: 1px solid #666;
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    padding: 0;
}

/* ── HTML overlay layer ─────────────────────────────────────────── */

.hx-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.hx-hex-overlay {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    pointer-events: none;
    transform-origin: center bottom;
}

/* ── Tag colors (CSS custom properties, set via JS) ─────────────── */

.hx-overlay {
    --hx-tag-bg: #333333;
    --hx-tag-text: #ffffff;
}

/* ── Meta info pills ────────────────────────────────────────────── */

.hx-meta {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 6px;
    color: var(--hx-tag-text);
    font-weight: 600;
    white-space: nowrap;
    background: var(--hx-tag-bg);
    opacity: 0.85;
}

/* ── Major event pill ───────────────────────────────────────────── */

.hx-event {
    font-size: 8px;
    padding: 1px 5px;
    border-radius: 6px;
    color: #fff;
    font-weight: 700;
    white-space: nowrap;
    background: #b33;
    opacity: 0.9;
}

/* ── POI markers ────────────────────────────────────────────────── */

.hx-poi-name {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 6px;
    background: var(--hx-tag-bg);
    color: var(--hx-tag-text);
    font-weight: 600;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.85;
}

.hx-poi-dev {
    font-size: 8px;
    padding: 1px 4px;
    border-radius: 4px;
    background: var(--hx-tag-bg);
    color: var(--hx-tag-text);
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.7;
}

/* ── Palette panel ──────────────────────────────────────────────── */

.hx-palette {
    position: absolute;
    top: 26px;
    right: 28px;
    width: 220px;
    max-height: calc(50% - 16px);
    overflow-y: auto;
    background: #252525;
    border: 1px solid #555;
    border-radius: 6px;
    z-index: 50;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    font-size: 11px;
}

.hx-palette-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-bottom: 1px solid #444;
    cursor: grab;
    user-select: none;
}

.hx-palette-header span {
    color: #ccc;
    font-weight: 600;
    font-size: 12px;
}

.hx-palette-close {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
}

.hx-palette-close:hover {
    color: #fff;
}

.hx-palette-list {
    padding: 4px 0;
}

.hx-palette-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 4px 8px;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    margin: 1px 4px;
}

.hx-palette-top {
    display: flex;
    align-items: center;
    gap: 6px;
}

.hx-palette-row:hover {
    background: #333;
}

.hx-palette-row.hx-palette-active {
    border-color: #5af;
    background: #2a3a4a;
}

.hx-palette-swatch {
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: 1px solid #666;
    flex-shrink: 0;
}

.hx-palette-label {
    color: #ccc;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hx-palette-code {
    color: #888;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    flex-shrink: 0;
}

.hx-palette-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
}

.hx-palette-thumb {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 3px;
    border: 2px solid transparent;
    background: #e8e8e8;
}

.hx-palette-thumb:hover {
    border-color: #888;
}

.hx-palette-thumb.hx-thumb-active {
    border-color: #5af;
    box-shadow: 0 0 4px #5af;
}

.hx-palette-roll {
    background: #333 url('icons/dice/maatlock/rolling-dices.svg') center / 80% no-repeat;
    border-color: #555;
}

.hx-palette-roll:hover {
    border-color: #aaa;
}

.hx-palette-roll.hx-thumb-active {
    border-color: #5af;
    box-shadow: 0 0 4px #5af;
}

/* Hide thumbnails in ASCII art mode */
.hx-map-container.hx-art-ascii .hx-palette-thumbs {
    display: none;
}

/* ── Paint mode cursor ──────────────────────────────────────────── */

.hx-map-container.hx-painting {
    cursor: crosshair;
}

.hx-map-container.hx-painting .hx-hex {
    cursor: crosshair;
}

.hx-toolbar button.hx-paint-active {
    background: #3a6d9d;
    border-color: #5a9ddd;
}

/* ── Curves / annotation lines ───────────────────────────────────── */

.hx-curves-svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    overflow: visible;
}

.hx-curve-line {
    pointer-events: none;
}

.hx-curve-hit {
    pointer-events: stroke;
    cursor: pointer;
}

.hx-curve-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    margin-left: -8px;
    margin-top: -8px;
    background: #5af;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: grab;
    pointer-events: all;
    z-index: 70;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
    transform: scale(var(--hx-handle-scale, 1));
}

.hx-curve-handle:hover {
    background: #8cf;
    transform: scale(1.3);
}

.hx-curve-handle:active {
    cursor: grabbing;
}

.hx-map-container.hx-drawing-curve {
    cursor: crosshair;
}

.hx-map-container.hx-drawing-curve .hx-hex {
    cursor: crosshair;
}

.hx-curve-popup {
    position: fixed;
    background: #2a2a2a;
    border: 1px solid #555;
    border-radius: 6px;
    padding: 8px;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
}

.hx-curve-popup button {
    font-size: 10px;
    padding: 2px 8px;
    background: #444;
    border: 1px solid #666;
    border-radius: 3px;
    color: #ccc;
    cursor: pointer;
}

.hx-curve-popup button:hover {
    background: #555;
    color: #fff;
}

.hx-curve-popup input[type="color"] {
    width: 24px;
    height: 20px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
}

/* ── Notes indicator ─────────────────────────────────────────────── */

/* Notes indicator icon — reuses pin-box + pin-icon styles */
.hx-notes-icon-fg {
    display: block;
    -webkit-mask-image: url('icons/utility/fountain-pen.svg');
    mask-image: url('icons/utility/fountain-pen.svg');
}

/* ── Tile cards ─────────────────────────────────────────────────── */

.hx-card-layer {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.hx-tile-card {
    position: absolute;
    width: 260px;
    background: #1a1a1a;
    border: 2px solid #666;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    color: #ddd;
    font-size: 0.8rem;
    pointer-events: all;
    z-index: 60;
    display: flex;
    flex-direction: column;
    transform: scale(var(--hx-handle-scale, 1));
    transform-origin: top left;
}

.hx-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-bottom: 1px solid #444;
    cursor: grab;
    user-select: none;
    background: #252525;
    border-radius: 4px 4px 0 0;
}

.hx-card-header:active {
    cursor: grabbing;
}

.hx-card-title {
    font-weight: 700;
    font-size: 12px;
    color: #eee;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hx-card-btn {
    background: none;
    border: 1px solid #555;
    border-radius: 3px;
    color: #aaa;
    cursor: pointer;
    font-size: 10px;
    padding: 1px 5px;
}

.hx-card-btn:hover {
    color: #fff;
    border-color: #888;
}

.hx-card-close {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
}

.hx-card-close:hover {
    color: #fff;
}

.hx-card-resize {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    z-index: 10;
    border-right: 2px solid #666;
    border-bottom: 2px solid #666;
    border-radius: 0 0 4px 0;
}

.hx-card-resize:hover {
    border-right-color: #aaa;
    border-bottom-color: #aaa;
}

.hx-card-info {
    padding: 6px 8px;
    border-bottom: 1px solid #333;
}

.hx-card-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.hx-card-key {
    color: #888;
    font-size: 10px;
}

.hx-card-val {
    color: #ddd;
    font-weight: 600;
    font-size: 10px;
}

.hx-card-input {
    flex: 1;
    min-width: 0;
    background: #333;
    border: 1px solid #555;
    color: #ddd;
    font-size: 10px;
    padding: 2px 4px;
    border-radius: 3px;
}

.hx-card-input:focus {
    border-color: #5af;
    outline: none;
}

/* ── Title card ────────────────────────────────────────────────────── */

.hx-title-card {
    position: absolute;
    pointer-events: all;
    z-index: 55;
    text-align: center;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.hx-title-header {
    display: flex;
    align-items: center;
    gap: calc(var(--hx-title-unit, 14) * 0.8px);
    padding: calc(var(--hx-title-unit, 14) * 0.8px) calc(var(--hx-title-unit, 14) * 1.2px);
}

/* Title card buttons/controls scale via --hx-title-unit set in JS */
.hx-title-card .hx-card-btn {
    font-size: calc(var(--hx-title-unit, 14) * 1px);
    padding: calc(var(--hx-title-unit, 14) * 0.35px) calc(var(--hx-title-unit, 14) * 1px);
    border-radius: calc(var(--hx-title-unit, 14) * 0.3px);
}

/* Bigger touch targets on mobile */
@media (pointer: coarse) {
    .hx-title-card .hx-card-btn {
        font-size: calc(var(--hx-title-unit, 14) * 1.4px);
        padding: calc(var(--hx-title-unit, 14) * 0.6px) calc(var(--hx-title-unit, 14) * 1.4px);
    }
    .hx-title-controls select {
        font-size: calc(var(--hx-title-unit, 14) * 1.2px);
        padding: calc(var(--hx-title-unit, 14) * 0.3px) calc(var(--hx-title-unit, 14) * 0.6px);
    }
    .hx-title-name {
        font-size: calc(var(--hx-title-unit, 14) * 1.4px);
        padding: calc(var(--hx-title-unit, 14) * 0.5px) calc(var(--hx-title-unit, 14) * 0.8px);
    }
}

/* Close button — absolute upper-right */
.hx-title-close {
    position: absolute;
    top: calc(var(--hx-title-unit, 14) * 0.3px);
    right: calc(var(--hx-title-unit, 14) * 0.3px);
    z-index: 1;
}

.hx-title-name {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    color: inherit;
    font: inherit;
    text-align: center;
    outline: none;
    padding: calc(var(--hx-title-unit, 14) * 0.3px) calc(var(--hx-title-unit, 14) * 0.6px);
}

.hx-title-name:focus {
    border-bottom-color: rgba(255,255,255,0.5);
}

.hx-title-controls {
    display: flex;
    align-items: center;
    gap: calc(var(--hx-title-unit, 14) * 0.8px);
    padding: calc(var(--hx-title-unit, 14) * 0.6px) calc(var(--hx-title-unit, 14) * 1.2px) calc(var(--hx-title-unit, 14) * 0.8px);
    flex-wrap: wrap;
    justify-content: center;
    font-size: calc(var(--hx-title-unit, 14) * 1px);
    color: #aaa;
}

.hx-title-controls select {
    background: #333;
    color: #ccc;
    border: 1px solid #555;
    border-radius: calc(var(--hx-title-unit, 14) * 0.25px);
    font-size: calc(var(--hx-title-unit, 14) * 0.85px);
    padding: calc(var(--hx-title-unit, 14) * 0.15px) calc(var(--hx-title-unit, 14) * 0.4px);
}

.hx-title-text {
    padding: 8px 16px;
    font-weight: 700;
    cursor: default;
    user-select: none;
}

/* ── Card formatting bar ─────────────────────────────────────────── */

.hx-fmt-bar {
    display: flex;
    gap: 3px;
    padding: 4px 8px;
    flex-wrap: wrap;
    border-bottom: 1px solid #333;
}

.hx-fmt-btn {
    font-size: 10px;
    padding: 1px 5px;
    border: 1px solid #555;
    border-radius: 3px;
    background: #222;
    color: #ccc;
    cursor: pointer;
    line-height: 1.2;
    font-family: inherit;
}

.hx-fmt-btn:hover {
    background: #444;
    color: #fff;
}

.hx-fmt-bold { font-weight: 700; }
.hx-fmt-italic { font-style: italic; }
.hx-fmt-underline { text-decoration: underline; }
.hx-fmt-strike { text-decoration: line-through; }

/* ── Card notes — edit mode (textarea) ──────────────────────────── */

.hx-card-notes-edit {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.hx-card-notes-edit textarea {
    width: 100%;
    min-height: 100px;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: inherit;
    line-height: 1.5;
    background: transparent;
    color: #ddd;
    overflow-y: auto;
    flex: 1;
    padding: 6px 8px;
}

.hx-card-notes-edit textarea::placeholder {
    color: #666;
}

.hx-card-notes-edit textarea::-webkit-scrollbar {
    width: 4px;
}

.hx-card-notes-edit textarea::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 2px;
}

/* ── Card notes — preview mode (rendered markdown) ──────────────── */

.hx-card-notes-preview {
    padding: 6px 8px;
    font-family: inherit;
    font-size: inherit;
    line-height: 1.5;
    color: #ddd;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    cursor: pointer;
}

.hx-card-notes-preview:empty::before {
    content: 'Double-click to add notes...';
    color: #666;
    font-style: italic;
}

.hx-card-notes-preview h3,
.hx-card-notes-preview h4,
.hx-card-notes-preview h5,
.hx-card-notes-preview h6 {
    margin: 0.3em 0;
    font-size: 0.9rem;
    color: #eee;
}

.hx-card-notes-preview p {
    margin: 0 0 0.4em;
}

.hx-card-notes-preview ul {
    padding-left: 16px;
    list-style: disc;
    margin: 0 0 0.4em;
}

.hx-card-notes-preview li {
    margin-bottom: 0.2em;
}

.hx-card-notes-preview a {
    color: #6af;
}

.hx-card-notes-preview strong {
    color: #eee;
}

.hx-card-notes-preview hr {
    border: none;
    border-top: 1px solid #444;
    margin: 0.5em 0;
}

/* ── Notes panel (compiled markdown) ─────────────────────────────── */

.hx-notes-panel {
    position: absolute;
    top: 60px;
    left: 12px;
    width: 340px;
    height: 50%;
    min-height: 200px;
    background: #1a1a1a;
    border: 1px solid #555;
    border-radius: 6px;
    z-index: 80;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
}

.hx-notes-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-bottom: 1px solid #444;
    cursor: grab;
    user-select: none;
    background: #252525;
    border-radius: 5px 5px 0 0;
}

.hx-notes-header:active {
    cursor: grabbing;
}

.hx-notes-title {
    flex: 1;
    color: #ccc;
    font-weight: 600;
    font-size: 12px;
}

.hx-notes-textarea {
    width: 100%;
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.5;
    background: transparent;
    color: #ddd;
    overflow-y: auto;
    padding: 8px 10px;
}

.hx-notes-textarea::placeholder {
    color: #666;
}

.hx-notes-textarea::-webkit-scrollbar {
    width: 6px;
}

.hx-notes-textarea::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}

.hx-notes-preview {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.6;
    color: #ddd;
}

.hx-notes-preview h1 {
    font-size: 14px;
    color: #fff;
    border-bottom: 1px solid #444;
    padding-bottom: 4px;
    margin: 16px 0 6px 0;
}

.hx-notes-preview h1:first-child { margin-top: 0; }

.hx-notes-preview h2 {
    font-size: 12px;
    color: #aaf;
    margin: 10px 0 4px 0;
}

.hx-notes-preview p { margin: 4px 0; }
.hx-notes-preview strong { color: #fff; }
.hx-notes-preview em { color: #ccc; }

.hx-notes-preview table {
    border-collapse: collapse;
    font-size: 11px;
    margin: 6px 0;
}

.hx-notes-preview th, .hx-notes-preview td {
    border: 1px solid #555;
    padding: 2px 6px;
}

.hx-notes-preview th {
    background: #333;
    color: #aaa;
}

.hx-notes-preview::-webkit-scrollbar { width: 6px; }
.hx-notes-preview::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

/* ── Icon palette panel ────────────────────────────────────────── */

.hx-icon-palette {
    position: absolute;
    top: 26px;
    left: 12px;
    width: 220px;
    max-height: calc(100% - 24px);
    overflow-y: auto;
    background: #252525;
    border: 1px solid #555;
    border-radius: 6px;
    z-index: 50;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    font-size: 11px;
}

.hx-icon-grid {
    padding: 4px;
}

.hx-icon-palette .icon-section-label {
    padding: 4px 8px;
    color: #aaa;
    font-size: 11px;
    font-weight: 600;
    border-bottom: 1px solid #333;
}

.hx-icon-palette .icon-section-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 4px;
}

.hx-icon-btn {
    width: 30px;
    height: 30px;
    padding: 3px;
    background: #333;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hx-icon-btn:hover {
    background: #444;
    border-color: #666;
}

.hx-icon-btn.active {
    border-color: #5af;
    background: #2a3a4a;
}

.hx-icon-btn img {
    width: 20px;
    height: 20px;
    filter: invert(1);
}

/* ── Pin layer (absolutely positioned icons on map) ─────────────── */

.hx-pin-layer {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 55;
}

/* Pin wrapper — anchored at pin coords, centered */
.hx-pin-wrap {
    position: absolute;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: all;
    gap: 2px;
}

/* Icon box — sized container for icon */
.hx-pin-box {
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
    border-radius: 6px;
}

/* Icon — luminance mask shows only icon paths, glow guardband via drop-shadow */
.hx-pin-icon {
    width: 100%;
    height: 100%;
    background-color: #000;
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-mode: luminance;
    mask-mode: luminance;
    cursor: grab;
    flex-shrink: 0;
}

/* Color tint overlay — plain colored div, same as hex tint */
.hx-pin-tint {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.35;
    pointer-events: none;
}

.hx-map-container.hide-color .hx-pin-tint { display: none !important; }

.hx-pin-icon:active {
    cursor: grabbing;
}

/* Resize handles — +/- buttons beside the icon */
.hx-pin-handle {
    width: 16px;
    height: 16px;
    background: rgba(0,0,0,0.7);
    border: 1px solid #888;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: all;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 14px;
    text-align: center;
    user-select: none;
    /* Position beside the icon using order + absolute */
    position: absolute;
    top: 0;
}

.hx-pin-handle-left  { right: calc(100% + 4px); }
.hx-pin-handle-right { left: calc(100% + 4px); }

/* Show handles on selection (not just hover) */
.hx-pin-selected .hx-pin-handle {
    opacity: 0.85;
}

.hx-pin-wrap:hover .hx-pin-handle {
    opacity: 0.6;
}

.hx-pin-selected:hover .hx-pin-handle,
.hx-pin-handle:hover {
    opacity: 1 !important;
}

.hx-pin-handle:hover {
    background: rgba(40,40,40,0.9);
    border-color: #5af;
}

/* Selected pin outline — on wrap, not masked icon */
/* ── Pin styles ──────────────────────────────────────────────────── */

/* Shared: solid fill-color background, rounded corners */
.hx-pin-box {
    background: var(--hx-fill-color, #fff);
    padding: 2px;
}

/* Card: drop shadow */
.hx-pin-style-card .hx-pin-box {
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.hx-pin-style-card .hx-pin-selected .hx-pin-box {
    box-shadow: 0 2px 6px rgba(0,0,0,0.4), 0 0 0 2px #5af;
}

/* Flat: no shadow */
.hx-pin-style-flat .hx-pin-selected .hx-pin-box {
    box-shadow: 0 0 0 2px #5af;
}

/* Editable label pill — reuses tag color vars */
.hx-pin-label {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 6px;
    background: var(--hx-tag-bg, #000);
    color: var(--hx-tag-text, #fff);
    font-weight: 600;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.85;
    cursor: text;
    outline: none;
    min-width: 16px;
    text-align: center;
}

.hx-pin-label:focus {
    outline: 1px solid #5af;
    overflow: visible;
    max-width: none;
}

.hx-pin-label:empty::before {
    content: '...';
    color: #888;
}

/* Pin color picker — visible only when selected */
.hx-pin-colors {
    display: none;
    gap: 3px;
    justify-content: center;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 4px;
}

.hx-pin-selected .hx-pin-colors {
    display: flex;
}

.hx-pin-colors input[type="color"] {
    width: 22px;
    height: 18px;
    border: 1px solid #666;
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    padding: 0;
}

/* ── Pin mode cursor ─────────────────────────────────────────────── */

.hx-map-container.hx-pinning {
    cursor: crosshair;
}

.hx-map-container.hx-pinning .hx-hex {
    cursor: crosshair;
}

/* ── Delete Hex mode ────────────────────────────────────────────── */

.hx-toolbar button.hx-delete-active {
    background: #9d3a3a;
    border-color: #dd5a5a;
}

.hx-map-container.hx-deleting-hex {
    cursor: crosshair;
}

.hx-map-container.hx-deleting-hex .hx-hex {
    cursor: crosshair;
}

/* ── Add Hex mode cursor ────────────────────────────────────────── */

.hx-map-container.hx-adding-hex {
    cursor: cell;
}

.hx-map-container.hx-adding-hex .hx-hex {
    cursor: cell;
}

/* ── Ghost hex indicators ───────────────────────────────────────── */

.hx-ghost-hex {
    fill: rgba(0, 0, 0, 0.5);
    stroke: #444;
    stroke-width: 2;
}

/* ── Pin notecard extras ─────────────────────────────────────────── */

.hx-pin-card-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    background-color: #ccc;
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-mode: luminance;
    mask-mode: luminance;
}

.hx-pin-label-input {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 1px solid #555;
    color: #eee;
    font-size: 12px;
    font-weight: 700;
    padding: 2px 4px;
    outline: none;
    min-width: 0;
}

.hx-pin-label-input:focus {
    border-bottom-color: #5af;
}

/* ── Zoom slider (left edge) ────────────────────────────────────── */

.hx-zoom-slider {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 201;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid #555;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.hx-zoom-slider button {
    width: 24px;
    height: 24px;
    background: #444;
    border: 1px solid #666;
    border-radius: 4px;
    color: #ccc;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.hx-zoom-slider button:hover {
    background: #555;
}

.hx-zoom-label {
    color: #999;
    font-size: 10px;
    user-select: none;
}

.hx-zoom-track {
    width: 6px;
    height: 120px;
    background: #444;
    border-radius: 3px;
    position: relative;
    cursor: pointer;
}

.hx-zoom-thumb {
    position: absolute;
    left: 50%;
    width: 14px;
    height: 10px;
    background: rgba(255, 255, 255, 0.35);
    border-radius: 3px;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.hx-zoom-pct {
    color: #aaa;
    font-size: 10px;
    user-select: none;
}

.hx-zoom-reset {
    font-size: 9px !important;
    width: auto !important;
    padding: 2px 6px !important;
}

/* ── Pan scrollbars ─────────────────────────────────────────────── */

.hx-pan-bar {
    position: absolute;
    z-index: 60;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    pointer-events: all;
}

.hx-pan-bar-h {
    top: 6px;
    left: 50px;
    right: 28px;
    height: 14px;
    cursor: grab;
}

.hx-pan-bar-v {
    right: 8px;
    top: 26px;
    bottom: 10px;
    width: 14px;
    cursor: grab;
}

.hx-pan-thumb {
    position: absolute;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    transition: background 0.15s;
}

.hx-pan-bar:hover .hx-pan-thumb,
.hx-pan-bar:active .hx-pan-thumb {
    background: rgba(0, 0, 0, 0.5);
}

/* Always show thumbs on touch devices (no hover state) */
@media (pointer: coarse) {
    .hx-pan-thumb {
        background: rgba(0, 0, 0, 0.4);
    }
    .hx-pan-bar-h { height: 18px; }
    .hx-pan-bar-v { width: 18px; }
    .hx-pan-bar-h .hx-pan-thumb { height: 14px; }
    .hx-pan-bar-v .hx-pan-thumb { width: 14px; }
}

.hx-pan-bar-h .hx-pan-thumb {
    top: 2px;
    height: 10px;
    min-width: 40px;
}

.hx-pan-bar-v .hx-pan-thumb {
    left: 2px;
    width: 10px;
    min-height: 40px;
}

/* ── Console output ──────────────────────────────────────────────── */

.hx-console {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: 8px;
    max-height: 200px;
    overflow-y: auto;
    background: rgba(0,0,0,0.85);
    color: #0f0;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    padding: 8px;
    border-radius: 4px;
    white-space: pre;
    pointer-events: all;
    z-index: 100;
}

/* ── Roll Table Editor ──────────────────────────────────────────── */

.hx-rt-editor {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    width: 560px;
    max-height: calc(100% - 80px);
    overflow-y: auto;
    background: #252525;
    border: 1px solid #555;
    border-radius: 6px;
    z-index: 55;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    font-size: 11px;
    color: #ccc;
}

.hx-rt-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-bottom: 1px solid #444;
    cursor: grab;
    user-select: none;
}

.hx-rt-header span {
    color: #ccc;
    font-weight: 600;
    font-size: 13px;
}

.hx-rt-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px 6px 0;
    border-bottom: 1px solid #444;
}

.hx-rt-tab {
    background: #333;
    border: 1px solid #555;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    color: #aaa;
    font-size: 10px;
    padding: 4px 8px;
    cursor: pointer;
}

.hx-rt-tab:hover {
    background: #3a3a3a;
    color: #fff;
}

.hx-rt-tab-active {
    background: #444;
    color: #fff;
    border-color: #666;
}

.hx-rt-content {
    padding: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.hx-rt-dice-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.hx-rt-dice-input {
    width: 60px;
    background: #333;
    border: 1px solid #555;
    color: #fff;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
}

.hx-rt-cols-input {
    width: 40px;
    background: #333;
    border: 1px solid #555;
    color: #fff;
    padding: 2px 4px;
    border-radius: 3px;
}

.hx-rt-info {
    color: #888;
    font-style: italic;
    margin-bottom: 8px;
}

.hx-rt-hdr-row {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
    font-weight: 600;
    color: #aaa;
}

.hx-rt-table {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.hx-rt-row {
    display: flex;
    gap: 4px;
    align-items: center;
}

.hx-rt-cell {
    background: #333;
    border: 1px solid #555;
    color: #ddd;
    padding: 3px 5px;
    border-radius: 3px;
    font-size: 11px;
}

.hx-rt-range {
    width: 50px;
    flex-shrink: 0;
    font-family: 'Courier New', monospace;
    text-align: center;
}

.hx-rt-val {
    flex: 1;
    min-width: 0;
}

.hx-rt-col-hdr {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    color: #aaa;
    background: #2a2a2a;
}

.hx-rt-del-row {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    flex-shrink: 0;
}

.hx-rt-del-row:hover {
    color: #c66;
}

.hx-rt-add-row {
    margin-top: 6px;
    background: #333;
    border: 1px solid #555;
    color: #aaa;
    padding: 4px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
}

.hx-rt-add-row:hover {
    background: #3a3a3a;
    color: #fff;
}

.hx-rt-bottom {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid #444;
}

.hx-rt-bottom button {
    background: #333;
    border: 1px solid #555;
    color: #ccc;
    padding: 4px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
}

.hx-rt-bottom button:hover {
    background: #3a3a3a;
    color: #fff;
}

.hx-rt-validation {
    margin-top: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 11px;
    line-height: 1.5;
}

.hx-rt-valid {
    background: rgba(80, 180, 80, 0.15);
    color: #6c6;
}

.hx-rt-invalid {
    background: rgba(200, 80, 80, 0.15);
    color: #c88;
}

/* ── Custom Sprite Upload Manager ─────────────────────────────── */

.hx-upload-manager {
    position: absolute;
    top: 60px;
    right: 20px;
    width: 420px;
    max-height: calc(100% - 80px);
    overflow-y: auto;
    background: #252525;
    border: 1px solid #555;
    border-radius: 6px;
    z-index: 55;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    font-size: 11px;
    color: #ccc;
}

.hx-upload-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-bottom: 1px solid #444;
    cursor: grab;
    user-select: none;
}

.hx-upload-header span {
    color: #ccc;
    font-weight: 600;
}

.hx-upload-table {
    display: flex;
    flex-direction: column;
}

.hx-upload-row {
    display: flex;
    align-items: center;
    gap: 0;
    border-bottom: 1px solid #333;
}

.hx-upload-label {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100px;
    flex-shrink: 0;
    padding: 4px 6px;
    font-size: 11px;
    color: #aaa;
    background: #2a2a2a;
    overflow: hidden;
    white-space: nowrap;
}

.hx-upload-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.hx-upload-strip {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: 1;
    min-height: 36px;
    padding: 3px 6px;
    flex-wrap: wrap;
}

.hx-upload-cell {
    position: relative;
}

.hx-upload-thumb {
    width: 30px;
    height: 30px;
    object-fit: cover;
    background: #fff;
    border-radius: 3px;
    border: 1px solid #555;
    display: block;
}

.hx-upload-del {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    background: #555;
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    font-size: 10px;
    line-height: 14px;
    text-align: center;
    padding: 0;
    display: none;
}

.hx-upload-cell:hover .hx-upload-del {
    display: block;
}

.hx-upload-del:hover {
    background: #c44;
}

.hx-upload-add {
    width: 30px;
    height: 30px;
    background: #333;
    color: #888;
    border: 1px solid #555;
    border-radius: 3px;
    cursor: pointer;
    font-size: 16px;
    line-height: 28px;
    text-align: center;
    padding: 0;
    flex-shrink: 0;
}

.hx-upload-add:hover {
    background: #3a7d3a;
    border-color: #5a5;
    color: #fff;
}

.hx-upload-drop-hint {
    padding: 6px 10px;
    text-align: center;
    color: #666;
    font-size: 10px;
    border-top: 1px solid #333;
}

.hx-upload-manager.hx-upload-dragover {
    outline: 2px solid #5af;
    outline-offset: -2px;
}

.hx-upload-manager.hx-upload-dragover .hx-upload-drop-hint {
    color: #5af;
}
