#world-viewport {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: auto;
    scrollbar-width: none;
    cursor: grab;
    touch-action: none;
    background-color: #244b3a;
    background-image:
        radial-gradient(ellipse at center, #5f895139, transparent 70%),
        repeating-linear-gradient(0deg, #102d2610 0 2px, transparent 2px 6px);
}

#world-viewport.theme-cyberpunk {
    background-color: #140b1b;
    background-image:
        radial-gradient(ellipse at 80% 15%, #e638a633, transparent 45%),
        radial-gradient(ellipse at 15% 85%, #00c8e522, transparent 50%),
        repeating-linear-gradient(135deg, #ff59d80d 0 2px, transparent 2px 22px);
}
#world-viewport.theme-tron {
    background-color: #031322;
    background-image:
        radial-gradient(ellipse at center, #0879aa44, transparent 65%),
        repeating-linear-gradient(0deg, transparent 0 23px, #00bfff16 23px 24px),
        repeating-linear-gradient(90deg, transparent 0 23px, #00bfff16 23px 24px);
}
#world-viewport.theme-retro {
    background-color: #322316;
    background-image:
        radial-gradient(ellipse at 50% 20%, #ca853544, transparent 60%),
        repeating-linear-gradient(90deg, #f0bf6708 0 3px, transparent 3px 8px);
}
#world-viewport.theme-minimal {
    background-color: #d9dfd9;
    background-image:
        radial-gradient(ellipse at center, #ffffffaa, transparent 75%),
        repeating-linear-gradient(0deg, #52645c0a 0 1px, transparent 1px 8px);
}
#world-viewport.theme-nature {
    background-color: #244b3a;
    background-image:
        radial-gradient(ellipse at center, #5f895139, transparent 70%),
        repeating-linear-gradient(0deg, #102d2610 0 2px, transparent 2px 6px);
}
#world-viewport.theme-space {
    background-color: #08091b;
    background-image:
        radial-gradient(ellipse at 50% 45%, #5140ba44, transparent 55%),
        radial-gradient(circle, #ffffffa6 1px, transparent 1.5px),
        radial-gradient(circle, #b6a8ff80 1px, transparent 1.5px);
    background-size: auto, 47px 47px, 71px 71px;
}
#world-viewport.theme-steampunk {
    background-color: #25180f;
    background-image:
        radial-gradient(ellipse at 50% 50%, #a45b254d, transparent 60%),
        repeating-linear-gradient(45deg, #d994450b 0 2px, transparent 2px 14px);
}
#world-viewport.theme-fantasy {
    background-color: #120d20;
    background-image:
        radial-gradient(ellipse at 25% 25%, #a249d144, transparent 48%),
        radial-gradient(ellipse at 80% 75%, #5140ba55, transparent 50%),
        radial-gradient(circle, #e6d5ff70 1px, transparent 1.5px);
    background-size: auto, auto, 67px 67px;
}
#world-viewport.theme-city {
    background-color: #26333b;
    background-image:
        radial-gradient(ellipse at center, #64778055, transparent 70%),
        repeating-linear-gradient(0deg, transparent 0 31px, #b9c9cd12 31px 32px),
        repeating-linear-gradient(90deg, transparent 0 31px, #b9c9cd12 31px 32px);
}
#world-viewport.theme-spain {
    background-color: #9c6845;
    background-image:
        radial-gradient(ellipse at 50% 30%, #f6d59488, transparent 70%),
        repeating-linear-gradient(45deg, #f8e6bf12 0 2px, transparent 2px 18px);
}

#world-viewport::-webkit-scrollbar { display: none; }
#world-viewport.dragging { cursor: grabbing; }
#world-viewport.indoors { display: grid; place-items: center; }

.world-grid {
    display: grid;
    grid-template-columns: repeat(var(--columns, 60), var(--tile-size));
    grid-auto-rows: var(--tile-size);
    width: max-content;
    border: 6px solid var(--world-border, #715b36);
    outline: 4px solid var(--world-outline, #e8c66c);
    outline-offset: -10px;
    background: #c9dfa9;
    user-select: none;
    box-shadow: 0 0 0 5px #1c372c, 0 12px 40px #101e1a99;
}

.world-grid.interior {
    border-color: var(--world-border, #715b36);
    outline-color: var(--world-outline, #e8c66c);
    box-shadow: 0 0 0 5px #1c372c, 0 16px 70px #101e1a99;
}

.world-grid.theme-matrix { --world-border: #176d3c; --world-outline: #8dff9f; --tile-sprite: url("images/themes/matrix.svg"); }
.world-grid.theme-cyberpunk { --world-border: #842b87; --world-outline: #ff59d8; --tile-sprite: url("images/themes/cyberpunk.svg"); }
.world-grid.theme-tron { --world-border: #14568d; --world-outline: #55eaff; --tile-sprite: url("images/themes/tron.svg"); }
.world-grid.theme-retro { --world-border: #80613d; --world-outline: #f0bf67; --tile-sprite: url("images/themes/retro.svg"); }
.world-grid.theme-minimal { --world-border: #737c77; --world-outline: #d7dfd8; --tile-sprite: url("images/themes/minimal.svg"); }
.world-grid.theme-nature { --world-border: #315d3b; --world-outline: #a4d16a; --tile-sprite: url("images/themes/nature.svg"); }
.world-grid.theme-space { --world-border: #38346f; --world-outline: #9c8cff; --tile-sprite: url("images/themes/space.svg"); }
.world-grid.theme-steampunk { --world-border: #744629; --world-outline: #d99445; --tile-sprite: url("images/themes/steampunk.svg"); }
.world-grid.theme-fantasy { --world-border: #563b79; --world-outline: #c894ff; --tile-sprite: url("images/themes/fantasy.svg"); }
.world-grid.theme-city { --world-border: #455660; --world-outline: #b6c8c8; --tile-sprite: url("images/themes/city.svg"); }
.world-grid.theme-spain { --world-border: #9b5539; --world-outline: #f0d091; --tile-sprite: url("images/themes/spain.svg"); }

.tile {
    position: relative;
    display: grid;
    place-items: center;
    width: var(--tile-size);
    height: var(--tile-size);
    overflow: visible;
    background-image: var(--tile-sprite, url("images/tiles.svg"));
    background-size: 400% 300%;
    background-repeat: no-repeat;
    image-rendering: pixelated;
}

.tile.grass { background-position: 0 0; }
.tile.forest.grass { background-position: 33.333% 0; }
.tile.village.grass { background-position: 66.667% 0; }
.tile.sand { background-position: 100% 0; }
.tile.desert.sand { background-position: 0 50%; }
.tile.port.sand { background-position: 33.333% 50%; }
.tile.water { background-position: 66.667% 50%; }
.tile.shore { background-position: 100% 50%; }
.tile.wall { background-position: 0 100%; }
.tile.floor { background-position: 33.333% 100%; }
.tile.door { background-position: 66.667% 100%; }

.tile.tree {
    z-index: 1;
    background-position: 0 0;
}

.tile.tree::before {
    position: absolute;
    z-index: 2;
    bottom: 1px;
    left: 50%;
    width: calc(var(--tile-size) * 1.65);
    height: calc(var(--tile-size) * 1.65);
    transform: translateX(-50%);
    background-image: var(--tile-sprite, url("images/tiles.svg"));
    background-position: 100% 100%;
    background-size: 400% 300%;
    background-repeat: no-repeat;
    content: "";
    image-rendering: pixelated;
    pointer-events: none;
}

.item-marker {
    position: absolute;
    top: 5px;
    left: 3px;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 4px;
    width: var(--item-width, calc(var(--tile-size) - 8px));
    min-width: 22px;
    min-height: 22px;
    height: var(--item-height, 22px);
    padding: 0 3px;
    overflow: hidden;
    border: 2px solid #fff0b5;
    border-radius: 0;
    color: #fffdf6;
    font-size: 13px;
    box-shadow: 2px 3px 0 #263820b3;
    cursor: grab;
    touch-action: none;
}

.item-marker.item-dragging { opacity: 0.25; }
.item-marker.item-drag-preview {
    position: fixed;
    z-index: 100;
    top: 0;
    left: 0;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0.9;
}
.tile.drop-target {
    z-index: 3;
    outline: 3px solid #fff4a8;
    outline-offset: -4px;
}
.animal {
    position: absolute;
    z-index: 3;
    top: calc(50% + var(--animal-y));
    left: calc(50% + var(--animal-x));
    display: grid;
    place-items: center;
    width: 26px;
    height: 28px;
    transform: translate(-50%, -70%);
    font-size: 22px;
    line-height: 1;
    filter: drop-shadow(1px 2px 1px #172318bb);
    pointer-events: none;
}

.animal.animal-moving {
    animation: animal-walk 0.45s steps(2, end) infinite;
}

.animal.animal-petting {
    animation: animal-pet 0.7s ease-in-out infinite;
}

@keyframes animal-walk {
    50% { transform: translate(-50%, -70%) translateY(-4px); }
}

@keyframes animal-pet {
    0%, 100% { transform: translate(-50%, -70%) rotate(0) scale(1); }
    50% { transform: translate(-50%, -70%) rotate(-12deg) scale(1.08); }
}

@media (prefers-reduced-motion: reduce) {
    .animal.animal-moving,
    .animal.animal-petting,
    .player.player-walking {
        animation: none;
    }
}

.item-marker-symbol { flex: 0 0 auto; }
.item-marker-title {
    overflow: hidden;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.item-marker[data-width="1"]:not(.link):not(.heading) .item-marker-title { display: none; }

.item-marker.idea { background: #ce8855; }
.item-marker.note { background: #668aa7; }
.item-marker.task { background: #8374a9; }
.item-marker.link { background: #bf7263; }
.item-marker.link .item-marker-title {
    color: inherit;
    cursor: pointer;
    text-decoration: underline;
}

.item-marker.heading {
    min-height: 22px;
    padding: 0;
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
    color: #263d2b;
    font-size: 17px;
    font-weight: 700;
    text-shadow: 1px 1px #fff4cf;
}

.item-marker.heading .item-marker-title {
    display: block;
    overflow: hidden;
    font-size: inherit;
}

.player {
    position: absolute;
    z-index: 2;
    top: 50%;
    left: 50%;
    width: calc(var(--tile-size) * 0.72);
    height: calc(var(--tile-size) * 0.9);
    transform: translate(-50%, -68%);
    background: url("images/player.svg") center / contain no-repeat;
    filter: drop-shadow(1px 2px 1px #172318bb);
    image-rendering: pixelated;
    pointer-events: none;
}

.player.player-walking {
    background-image: url("images/player-walk.svg");
    background-size: 400% 100%;
    background-position: 0 0;
    animation: player-walk 0.6s steps(4, jump-none) infinite;
    animation-delay: var(--walk-animation-delay, 0ms);
    filter: brightness(1.1) saturate(1.15) drop-shadow(1px 2px 1px #172318bb);
}

@keyframes player-walk {
    from { background-position: 0 0; }
    to { background-position: 100% 0; }
}
