    :root {
        --ink: #d6e2cf;
        --bg: #0a0c0a;
        --frame: #141614;
        --accent: #9ef7a0;
        --muted: #7a8a7a;
        --panelW: 440px;
    }

    input::placeholder,
    textarea::placeholder {
        color: var(--muted);
        opacity: 0.8;
    }

input[type="text"],
input[type="number"],
select,
textarea {
  background: #0e110e;
  border: 1px solid #283228;
  border-radius: 6px;
  color: var(--ink);
  padding: 4px 6px;
  font: inherit;
}

input[type="range"] {
  accent-color: var(--accent);
  background: none;
  border: none;
  padding: 0;
}

    html,
    body {
        height: 100%;
        margin: 0;
        background: radial-gradient(circle at top, #141614 0%, var(--bg) 70%);
        color: var(--ink);
        overscroll-behavior-y: none;
        font: 14px/1.5 'Pixelify Sans', sans-serif;
    }

    .wrap {
        display: flex;
        gap: 16px;
        padding: 16px;
        box-sizing: border-box;
        height: 100%;
    }

    canvas {
        background: #000;
        border: 1px solid #2a382a;
        border-radius: 8px;
        box-shadow: 0 0 0 2px #000 inset, 0 0 40px #000;
        image-rendering: pixelated;
        filter: contrast(1.06) saturate(1.1);
    }

    .panel {
        width: 440px;
        background: #0b0d0b;
        border: 1px solid #2a382a;
        border-radius: 8px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
        position: relative;
        z-index: 15;
        image-rendering: pixelated;
    }

    #panelToggle {
        position: fixed;
        top: 50%;
        right: 0;
        transform: translateY(-50%);
        background: #0b0d0b;
        border: 1px solid #2a382a;
        border-right: none;
        border-radius: 8px 0 0 8px;
        padding: 8px;
        display: none;
        z-index: 30;
        cursor: pointer;
    }

    .panel h1 {
        font-size: 18px;
        margin: 0;
        padding: 10px 12px;
        background: #0f120f;
        border-bottom: 1px solid #1a1f1a;
        color: #c7ff9e;
        font-weight: 800;
        letter-spacing: .6px;
    }

    .panel .content {
        padding: 12px;
        flex: 1;
        overflow: auto
    }

    .hud {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 8px
    }

    .weather-banner {
        text-align: center;
        font-size: 13px;
        margin-bottom: 4px
    }

    .badge {
        border: 1px solid #283228;
        padding: 6px 8px;
        border-radius: 8px;
        background: #0e110e;
        display: flex;
        flex-direction: column;
        gap: 4px
    }

    .hud .label {
        font-weight: 700
    }

    .hud .hydration {
        margin-left: 4px;
        font-size: 12px;
    }

    .hudbar {
        position: relative;
        width: 100%;
        height: 6px;
        background: #273027;
        border-radius: 4px;
        overflow: hidden
    }

    .hudbar .fill {
        height: 100%;
        background: #8bd98d;
        transition: width .2s
    }

    .hudbar .ghost {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        background: #3a493a;
        transition: width .4s
    }

    .hudbar.adr .fill {
        background: #d98b8b
    }

    .hudbar.hurt .fill {
        background: #f55
    }


    .status-row {
        display: flex;
        gap: 1px;
        margin-top: 2px;
        min-height: 8px
    }

    .status-row span {
        width: 8px;
        height: 8px;
        background: #8bd98d;
        border-radius: 2px;
        filter: contrast(1.2);
    }

    #game {
        position: relative;
        filter: var(--fxBloom, none) var(--fxFilter, none)
    }

    #game.scanlines::after {
        content: '';
        position: absolute;
        inset: 0;
        pointer-events: none;
        background-image: linear-gradient(rgba(0, 0, 0, .1) 50%, transparent 50%);
        background-size: 100% 2px;
        animation: scanlines 5s linear infinite;
        mix-blend-mode: overlay
    }

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

    #game.shear {
        transform: skewX(2deg)
    }

    #game.color-bleed {
        filter: drop-shadow(0 0 2px #9ef7a0) drop-shadow(0 0 6px #9ef7a0) drop-shadow(2px 0 0 red) drop-shadow(-2px 0 0 cyan) var(--fxBloom, none) var(--fxFilter, none)
    }

    body.hp-critical #game {
        filter: grayscale(.8) var(--fxBloom, none) var(--fxFilter, none)
    }

    body.hp-critical::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        pointer-events: none;
        box-shadow: inset 0 0 40px 20px rgba(0, 0, 0, .6)
    }

    body.hp-out #game {
        filter: grayscale(1) brightness(.5)
    }

    body.hp-out::after {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        pointer-events: none;
        background: #000;
        opacity: .8
    }

    .hudBadge {
        margin-left: 4px;
        color: var(--accent);
        font-weight: 700;
        animation: hudFade 1s ease-out forwards
    }

    @keyframes hudFade {
        from {
            opacity: 1;
            transform: translateY(0);
        }

        to {
            opacity: 0;
            transform: translateY(-8px);
        }
    }

    .muted {
        color: var(--muted)
    }

    .btn {
        display: inline-block;
        text-align: center;
        padding: 8px 10px;
        margin: 6px 6px 0 0;
        border-radius: 6px;
        background: #121612;
        border: 1px solid #2a372a;
        color: var(--ink);
        cursor: pointer;
        transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
        font-size: 14px;
        font-family: inherit;
    }

    .btn:hover {
        border-color: #4f6b4f;
        background: #151b15;
        transform: translateY(-2px);
    }

    .tabs {
        display: flex;
        gap: 6px;
        margin: 8px 0
    }

    .tab {
        padding: 6px 8px;
        border: 1px solid #273027;
        border-radius: 6px;
        cursor: pointer;
        background: #0f120f
    }

    .tab.active {
        outline: 1px solid #4f6b4f
    }

    .tab:focus-visible {
        outline: 2px solid #4f6b4f;
        outline-offset: 2px;
    }

    #inv {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 6px;
        align-content: start;
    }

    .tabwrap {
        margin-top: 8px;
    }

    .slot {
        padding: 6px 8px;
        border: 1px dashed #2b382b;
        border-radius: 6px;
        background: #0c0f0c;
    }

    .equip-line {
        white-space: nowrap;
    }

    .slot.better {
        border-color: #00ff00;
        background: #003300;
    }

    .slot.clickable {
        cursor: pointer;
    }

    #party {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
        gap: 8px;
        align-content: start;
        align-items: start;
    }

    .pcard {
        border: 1px solid #273027;
        border-radius: 8px;
        background: #0f120f;
        padding: 8px;
        cursor: pointer
    }
    .pcard.selected {
        box-shadow: 0 0 0 2px #8bd98d;
    }
    #party .stats {
        white-space: nowrap
    }

.xpbar {
  position: relative;
  width: 100%;
  height: 4px;
  background: #273027;
  border-radius: 4px;
  overflow: hidden;
  transition: height .2s;
}
.xpbar .fill {
  height: 100%;
  background: #d9b98b;
  transition: width .2s;
}
.xpbar:hover {
  height: 16px;
}
.xpbar:hover::after {
  content: attr(data-xp) ' xp';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  color: #fff;
}

    .row {
        display: flex;
        flex-wrap: wrap;
        gap: 8px
    }

    #quests {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
        gap: 8px
    }

    .q {
        border: 1px solid #273027;
        border-radius: 8px;
        background: #0f120f;
        padding: 8px
    }

    .q .status {
        color: #9ab09a
    }

    @media (min-width: 1600px) {
        .panel {
            width: 840px;
        }
        :root {
            --panelW: 840px;
        }

        .tabs {
            display: none;
        }

        .tabwrap {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 12px;
        }

        .tabwrap > #inv,
        .tabwrap > #party,
        .tabwrap > #quests {
            display: grid !important;
        }
    }

    @media (max-width: 900px) {
        .panel {
            position: fixed;
            top: 0;
            right: 0;
            height: 100%;
            width: 80vw;
            max-width: 440px;
            transform: translateX(100%);
            transition: transform .2s;
        }
        :root {
            --panelW: 0;
        }
        .panel.show {
            transform: translateX(0);
        }
        #panelToggle {
            display: block;
            padding: 12px;
            font-size: 24px;
        }
        :root { --ctrlH: 180px; }
        body.mobile-on .wrap { height: calc(100% - var(--ctrlH)); }
        body.mobile-on .crt-wrap { align-items: flex-start; }
        body.mobile-on .panel { height: calc(100% - var(--ctrlH)); }
        #mobileControls { touch-action: manipulation; }
        #mobileControls button { touch-action: manipulation; }
    }

    .overlay {
        position: fixed;
        inset: 0;
        display: none;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, .6);
        z-index: 20
    }

    .overlay.shown {
        display: flex
    }

    @media (max-width: 900px) {
        body.mobile-on .overlay,
        body.mobile-on #settings,
        body.mobile-on #start,
        body.mobile-on #creator,
        body.mobile-on #moduleLoader,
        body.mobile-on #shopOverlay {
            bottom: var(--ctrlH);
            height: calc(100% - var(--ctrlH));
        }
    }

    .dialog {
        width: min(680px, 92vw);
        background: #0b0d0b;
        border: 1px solid #2a382a;
        border-radius: 10px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, .5)
    }

    .dialog header {
        padding: 10px 12px;
        border-bottom: 1px solid #223022;
        display: flex;
        align-items: center;
        gap: 8px
    }

.portrait{
  width:64px; height:64px;
  border-radius:6px; /* square-ish, keep a little rounding */
  background:#274227;              /* fallback color */
  border:1px solid #1c261c;
  image-rendering: pixelated;      /* preserve chunky pixels */
  background-repeat:no-repeat;
  background-size:100% 100%;       /* 2×2 grid */
  position:relative;
}

.spbadge{
  position:absolute;
  top:-4px; right:-4px;
  background:#8bd98d;
  color:#0f120f;
  border-radius:8px;
  padding:2px 4px;
  font-size:10px;
  line-height:1;
  box-shadow:0 0 4px #8bd98d;
}

    .dialog main {
        padding: 12px
    }

    .choices {
        padding: 0 12px 12px
    }

    .choice {
        padding: 8px 10px;
        border: 1px solid #253525;
        margin: 8px 0;
        border-radius: 6px;
        background: #0f120f;
        cursor: pointer
    }

    .choice:hover {
        border-color: #5c8a5c;
        background: #111711
    }

    .choice.sel {
        border-color: #5c8a5c;
        background: #111711
    }

/* Combat UI */
#combatOverlay {
  background:rgba(0,0,0,.8);
  pointer-events:auto;
  z-index:10;
  right:var(--panelW);
  --telegraphIntensity:1;
  --telegraphDuration:1000ms;
}
#combatOverlay.warning {
  animation:bossWarn .3s steps(1) 4,
    screenShake .1s steps(2) infinite,
    crtDistort var(--telegraphDuration) ease-in-out;
  --shakeMag:calc(var(--telegraphIntensity)*2px);
}
@keyframes bossWarn { 50% { background:rgba(80,80,0,.8); } }
@keyframes screenShake {
  0%,100% { transform:translate(0,0); }
  25% { transform:translate(var(--shakeMag),var(--shakeMag)); }
  50% { transform:translate(calc(var(--shakeMag)*-1),var(--shakeMag)); }
  75% { transform:translate(var(--shakeMag),calc(var(--shakeMag)*-1)); }
}
@keyframes crtDistort {
  0%,100% { filter:none; }
  50% { filter:contrast(2) saturate(1.5) hue-rotate(10deg); }
}
#combatOverlay .combat-window {
  pointer-events:auto;
  width:min(640px,92vw);
  height:min(480px,92vh);
  background:#0b0d0b;
  border:1px solid #2a382a;
  border-radius:10px;
  padding:16px;
  display:flex;
  flex-direction:column;
  justify-content:space-between;
  box-shadow:0 0 8px #000;
}
#combatOverlay .battlefield {
  flex:1;
  display:flex;
  justify-content:space-between;
  align-items:flex-end;
}
#combatOverlay .enemy-row, #combatOverlay .party-row {
  display:flex;
  flex-direction:column;
  gap:12px;
}
#combatOverlay .enemy-row { align-items:flex-start; }
#combatOverlay .party-row { align-items:flex-end; }
#combatOverlay .member { position:relative; display:flex; flex-direction:column; align-items:center; }
#combatOverlay .enemy .hudbar, #combatOverlay .member .hudbar { width:48px; margin-top:2px; }
#combatOverlay .label { margin-top:4px; text-align:center; }
#combatOverlay .enemy.active .portrait, #combatOverlay .member.active .portrait { border-color:#5c8a5c; }
#combatOverlay .turn { text-align:center; margin-bottom:4px; }
#combatOverlay .command-row { margin-top:8px; }
#combatOverlay .cmd {
  display:none;
  background:#000;
  border:2px solid #5c8a5c;
  padding:8px 16px;
  border-radius:6px;
  min-width:120px;
  font-family:system-ui, sans-serif;
  font-size:14px;
  color:#fff;
  box-shadow:0 0 8px #000 inset;
}
#combatOverlay .cmd div { padding:2px 0; white-space:nowrap; }
#combatOverlay .cmd div::before { content:''; display:inline-block; width:1em; }
#combatOverlay .cmd div.sel::before { content:'>'; }
#combatOverlay .cmd div.disabled { color:#666; }

    .help {
        cursor: help;
        color: var(--muted);
    }

    .small {
        font-size: 12px;
        color: #9ab09a
    }

    .crt-wrap {
        position: relative;
        perspective: 1200px
    }

    .crt-wrap .tube {
        transform: rotateX(0.6deg) rotateY(-0.6deg);
        border-radius: 18px;
        overflow: hidden;
        box-shadow: 0 20px 60px rgba(0, 0, 0, .6)
    }

    .crt-wrap:before {
        content: "";
        position: absolute;
        inset: 0;
        pointer-events: none;
        background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, .05) 0px, rgba(255, 255, 255, .05) 1px, rgba(0, 0, 0, 0) 2px);
        mix-blend-mode: overlay;
        opacity: .12
    }

    .crt-wrap:after {
        content: "";
        position: absolute;
        inset: -2px;
        pointer-events: none;
        border-radius: 22px;
        box-shadow: inset 0 0 120px rgba(0, 0, 0, .95), inset 0 0 10px rgba(158, 247, 160, .25)
    }

    .glow {
        filter: drop-shadow(0 0 2px #9ef7a0) drop-shadow(0 0 6px #9ef7a0)
    }

    #creator {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .8);
        display: none;
        align-items: center;
        justify-content: center;
        z-index: 25
    }

.shop-window {
  width: 600px;
  background: #0f120f;
  border: 1px solid #2b3b2b;
  border-radius: 8px;
  box-shadow: 0 0 20px #000;
  max-height: min(480px, 92vh);
  display: flex;
  flex-direction: column;
}

.shop-window header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid #2b3b2b;
}

.shop-panels {
  display: flex;
  padding: 12px;
  gap: 24px;
  flex: 1;
  min-height: 0;
}

.shop-inv, .player-inv {
  flex: 1;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.shop-window .slot {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.shop-window .slot button {
  margin-left: 8px;
}

#personaOverlay .persona-window {
  width: 260px;
  background: #0f120f;
  border: 1px solid #2b3b2b;
  border-radius: 8px;
  box-shadow: 0 0 20px #000;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#personaOverlay .persona-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#personaOverlay .persona-list .btn {
  width: 100%;
}

#workbenchOverlay .workbench-window {
  width: 300px;
  background: #0f120f;
  border: 1px solid #2b3b2b;
  border-radius: 8px;
  box-shadow: 0 0 20px #000;
  max-height: min(480px, 92vh);
  display: flex;
  flex-direction: column;
}

#workbenchOverlay .workbench-window header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid #2b3b2b;
}

#workbenchOverlay .slot {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#workbenchOverlay .slot button {
  margin-left: 8px;
}

#workbenchOverlay .slot ul {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  font-size: 12px;
}

.slot-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  overflow-y: auto;
  flex: 1;
}

    #creator .win {
        width: min(820px, 92vw);
        background: #0b0d0b;
        border: 1px solid #2a382a;
        border-radius: 14px;
        box-shadow: 0 20px 80px rgba(0, 0, 0, .7);
        overflow: hidden
    }

    #creator header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 12px;
        border-bottom: 1px solid #223022
    }

    #creator main {
        display: grid;
        grid-template-columns: 300px 1fr;
        gap: 12px;
        padding: 12px
    }

    @media (max-width: 600px) {
        #creator main {
            grid-template-columns: 1fr;
            grid-template-rows: auto auto;
        }
    }

    .pbox {
        height: 220px;
        border: 1px solid #273027;
        border-radius: 10px;
        background: #0f120f;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative
    }

    .pbox:after {
        content: "";
        position: absolute;
        inset: 0;
        background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, .05) 0px, rgba(255, 255, 255, .05) 1px, rgba(0, 0, 0, 0) 2px);
        mix-blend-mode: overlay;
        opacity: .15;
        pointer-events: none
    }

    .p {
        width: 120px;
        height: 120px;
        border-radius: 50%;
        border: 2px solid #293629;
        background: #203320;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 800
    }

    .grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px
    }

    .field {
        display: flex;
        flex-direction: column;
        gap: 4px
    }

    .range {
        display: flex;
        align-items: center;
        gap: 6px
    }

    .range button {
        width: 24px;
        height: 24px
    }

    .row {
        display: flex;
        gap: 8px;
        align-items: center;
        flex-wrap: wrap
    }

    .pill {
        padding: 4px 8px;
        border: 1px solid #2a372a;
        border-radius: 999px;
        cursor: pointer
    }

    .pill.sel {
        background: #121812
    }

    .footer {
        padding: 10px 12px;
        border-top: 1px solid #223022;
        display: flex;
        justify-content: space-between;
        gap: 8px;
        align-items: center;
        flex-wrap: wrap
    }

    .footer .right {
        display: flex;
        gap: 8px;
        align-items: center
    }

    #start {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .8);
        display: none;
        align-items: center;
        justify-content: center;
        z-index: 30
    }

    #start .win {
        width: min(420px, 92vw);
        background: #0b0d0b;
        border: 1px solid #2a382a;
        border-radius: 12px;
        box-shadow: 0 20px 80px rgba(0, 0, 0, .7);
        overflow: hidden
    }

    #start header {
        padding: 10px 12px;
        border-bottom: 1px solid #223022;
        font-weight: 700
    }

    #start main {
        padding: 12px
    }

    #settings {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .8);
        display: none;
        align-items: center;
        justify-content: center;
        z-index: 40
    }

    #settings .win {
        width: min(340px, 92vw);
        background: #0b0d0b;
        border: 1px solid #2a382a;
        border-radius: 12px;
        box-shadow: 0 20px 80px rgba(0, 0, 0, .7);
        overflow: hidden
    }

    #settings header {
        padding: 10px 12px;
        border-bottom: 1px solid #223022;
        font-weight: 700
    }

    #settings main {
        padding: 12px;
        display: flex;
        flex-direction: column;
        gap: 8px
    }

    #settings .field--toggle {
        flex-direction: row;
        align-items: center;
        gap: 8px
    }

    #settings .field--toggle label {
        font-size: 14px;
        color: #c8f7c9
    }

    #settings .field--toggle input[type=checkbox] {
        width: 18px;
        height: 18px;
        accent-color: #9ef7a0;
        cursor: pointer
    }

    #fxPanel {
        position: fixed;
        top: 10px;
        left: 10px;
        display: none;
        z-index: 40
    }

    #fxPanel .win {
        width: min(340px, 92vw);
        background: #0b0d0b;
        border: 1px solid #2a382a;
        border-radius: 12px;
        box-shadow: 0 20px 80px rgba(0, 0, 0, .7);
        overflow: hidden
    }

    #fxPanel header {
        padding: 10px 12px;
        border-bottom: 1px solid #223022;
        font-weight: 700;
        cursor: move
    }

    #fxPanel main {
        padding: 12px;
        display: flex;
        flex-direction: column;
        gap: 8px
    }

    #perfPanel {
        position: fixed;
        top: 10px;
        left: 10px;
        display: none;
        z-index: 40
    }

    #perfPanel .win {
        width: min(340px, 92vw);
        background: #0b0d0b;
        border: 1px solid #2a382a;
        border-radius: 12px;
        box-shadow: 0 20px 80px rgba(0, 0, 0, .7);
        overflow: hidden
    }

    #perfPanel header {
        padding: 10px 12px;
        border-bottom: 1px solid #223022;
        font-weight: 700;
        cursor: move
    }

    #perfPanel main {
        padding: 12px;
        display: flex;
        flex-direction: column;
        gap: 8px
    }

    #nanoStatus {
        position: fixed;
        top: 6px;
        right: 6px;
        display: flex;
        gap: 6px;
        align-items: center;
        z-index: 40;
        font-size: 12px
    }

    .nano-progress {
        width: 18px;
        height: 18px;
        border-radius: 50%;
        border: 1px solid #273027;
        background: conic-gradient(var(--accent) 0%, #273027 0);
        display: none
    }

    .nano-badge {
        width: 18px;
        height: 18px;
        border: 1px solid #273027;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #0f120f;
        color: var(--accent);
        font-weight: 700;
        image-rendering: pixelated
    }

    .nano-badge.on {
        background: #0c0;
        color: #021
    }

    .nano-badge.off {
        background: #333;
        color: #666
    }

    .nano-badge.failed {
        background: #800;
        color: #fff
    }

    .nano-badge.busy {
        animation: nano-pulse 1s steps(2) infinite
    }

    @keyframes nano-pulse {
        0%, 100% {
            transform: scale(1)
        }
        50% {
            transform: scale(1.2)
        }
    }

    /* -- Adventure Kit layout -- */
    body.adventure-kit {
        min-width: 100vw;
    }

    body.adventure-kit #game {
        display: none;
    }

    .ak-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
        padding: 16px;
        box-sizing: border-box;
        align-items: flex-start;
        justify-items: center;
        width: 100%;
        max-width: 1280px;
        margin: 0 auto;
    }

    .map-card {
        width: min(640px, 100%);
    }

    .map-card canvas {
        width: 100%;
        height: auto;
        display: block;
        max-width: 640px;
    }

    .editor-panel {
        flex: 1 1 320px;
        width: 100%;
        min-width: 0;
        background: #0b0d0b;
        border: 1px solid #273027;
        border-radius: 10px;
        box-shadow: 0 0 12px #000, 0 0 8px var(--accent, #9ef7a0);
        display: flex;
        flex-direction: column;
        max-height: none;
        overflow: hidden;
        resize: none;
    }

    @media (min-width: 1100px) {
        .ak-layout {
            grid-template-columns: minmax(0, 640px) minmax(0, 1fr);
            justify-items: stretch;
        }

        .map-card {
            justify-self: start;
        }

        .editor-panel {
            width: auto;
            min-width: 320px;
            max-height: calc(100vh - 32px);
            resize: horizontal;
        }
    }

    @media (max-width: 768px) {
        .editor-panel {
            box-shadow: 0 0 12px #000, 0 0 6px rgba(158, 247, 160, 0.4);
        }
    }

    /* -- Tabs -- */
    .tabs2 {
        display: flex;
        gap: 6px;
        padding: 8px;
        background: #0f120f;
        border-bottom: 1px solid #1a1f1a;
        position: sticky;
        top: 0;
        z-index: 2;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x
    }

    .tab2 {
        flex: 0 0 auto;
        padding: 8px 10px;
        text-align: center;
        cursor: pointer;
        border: 1px solid #273027;
        border-radius: 6px;
        background: #121712;
        color: var(--ink);
        font-size: 13px;
        font-weight: 600;
    }

    .tab2:hover {
        border-color: #4f6b4f
    }

    .tab2.active {
        outline: 1px solid #4f6b4f;
        background: #141a14
    }

    /* -- Scroll area for cards -- */
    .tabpanes {
        overflow: auto;
        padding: 8px;
    }

    /* Elevate active card when focused */
    .card:has(:focus) {
        box-shadow: 0 0 12px #000, 0 0 10px rgba(158, 247, 160, .4);
        border-color: #4f6b4f
    }

    /* Button hierarchy */
    .btn--primary {
        border-color: #5ea05e;
        background: #1a271a;
        font-weight: 700;
    }

    .btn--primary:hover {
        background: #1d2d1d;
        border-color: #78c078
    }

    /* Accessibility: visible focus ring */
    button:focus,
    input:focus,
    select:focus,
    textarea:focus {
        outline: 2px solid #78c078;
        outline-offset: 2px;
    }

    /* Make small destructive buttons safer to click */
    .btn.is-danger {
        border-color: #6b2a2a;
        background: #221212
    }

    .btn.is-danger:hover {
        border-color: #a34;
        background: #2a1515
    }

    /* Reset the old absolute positioning for cards when placed in the right panel */
    #editorPanel [data-pane].card,
    #editorPanel #npcCard,
    #editorPanel #itemCard,
    #editorPanel #bldgCard,
    #editorPanel #questCard {
        position: static !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        bottom: auto !important;
        width: auto !important;
        margin: 8px 8px 12px !important;
    }

    /* Make long editors (e.g., dialog tree) scroll nicely within the panel */
    #editorPanel .card {
        box-sizing: border-box;
    }

    #editorPanel #treeEditor,
    #editorPanel #dialogPreview {
        max-height: 40vh;
        overflow: auto;
    }

    /* Show all editor panes side-by-side when the panel is wide */
    .editor-panel.wide {
        width: auto;
        flex: 1;
        max-height: none;
    }

    .editor-panel.wide .tabs2 {
        display: none;
    }

    .editor-panel.wide .tabpanes {
        display: flex;
        flex-wrap: wrap;
        gap: 16px;
        padding: 16px;
        overflow: visible;
    }

    .editor-panel.wide .tabpanes .card {
        flex: 1 1 320px;
        margin: 0 8px 16px !important;
    }

#intPalette button,
#bldgPalette button,
#worldPalette button { width:20px; height:20px; border:none; margin:2px; }
#intPalette button.active,
#bldgPalette button.active,
#worldPalette button.active { outline:2px solid #fff; }
#paletteWrap { display:flex; flex-direction:column; align-items:center; }
#paletteLabel { color:#fff; font-family:system-ui, sans-serif; margin-top:4px; }

.cache-slot {
  display:flex;
  justify-content:center;
  align-items:center;
  height:40px;
}
.cache-icon {
  width:24px;
  height:24px;
  border:1px solid #283228;
  border-radius:4px;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
}
.cache-icon.rusted { background:#5a3a2e; }
.cache-icon.sealed { background:#3e4a5a; }
.cache-icon.armored { background:#4a545a; }
.cache-icon.vaulted { background:#563e5a; }
.cache-icon.open { animation: cachePop .2s forwards; }
@keyframes cachePop {
  to {
    transform: scale(1.4) rotate(10deg);
    opacity:0;
  }
}
.cache-count, .stack-count { margin-left:4px; font-weight:700; }
.jitter { animation:jitter .3s infinite; }
@keyframes jitter {
  0%{ transform:translate(0,0); }
  25%{ transform:translate(-1px,0); }
  50%{ transform:translate(1px,0); }
  75%{ transform:translate(-1px,0); }
  100%{ transform:translate(0,0); }
}

.signal-compass {
  position:relative;
  width:40px;
  height:40px;
  border:2px solid var(--accent);
  border-radius:50%;
}
.signal-compass .arrow {
  position:absolute;
  bottom:50%;
  left:50%;
  width:2px;
  height:16px;
  background:var(--accent);
  transform-origin:50% 100%;
}
