* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: #181818;
    color: white;

    display: flex;
    justify-content: center;
    align-items: flex-start;

    min-height: 100vh;

    padding: 20px;
}

#game {
    width: 100%;
    max-width: 1100px;
    text-align: center;
}


h1 {
    margin-top: 0;
}


button,
input,
select {
    font: inherit;
}


button {
    cursor: pointer;
}
button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}


.screen {
    display: none;
}
.screen.active {
    display: block;
}


/* =====================================================
    TITLE SCREEN
===================================================== */
#titleScreen button {
    display: block;

    width: 300px;

    margin: 15px auto;

    padding: 15px;

    border: 2px solid #666;
    border-radius: 10px;

    background: #292929;
    color: white;
}
#titleScreen button:hover:not(:disabled) {
    background: #3a3a3a;
}


#savedDungeons {
    margin: 30px auto;
    max-width: 500px;
}

#savedDungeons h2 {
    margin-bottom: 12px;
}


.savedDungeonRow {
    display: flex;
    align-items: stretch;
    gap: 6px;
    width: 100%;
    margin: 8px auto;
}


.savedDungeonButton {
    flex: 1;
    min-width: 0;

    display: flex !important;

    align-items: center;

    text-align: left;

    gap: 12px;

    margin: 0 !important;

    padding: 12px 15px !important;
}


.deleteDungeonButton {
    flex: 0 0 46px;
    width: 46px;
    padding: 0;

    border: 2px solid #824545;
    border-radius: 8px;

    background: #472525;
    color: white;
    font-size: 20px;
    cursor: pointer;
}


.deleteDungeonButton:hover {
    background: #643030;
}


.savedDungeonIcon {
    font-size: 28px;
    width: 35px;
    text-align: center;
    flex-shrink: 0;
}


.savedDungeonDetails {
    flex-grow: 1;
}


.savedDungeonName {
    font-weight: bold;
    font-size: 17px;
}


.savedDungeonMode {
    font-size: 12px;
    color: #aaa;
    margin-top: 3px;
}


#noSavedDungeons {
    color: #888;
    font-style: italic;
    margin: 15px;
}


#savedDungeonActions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 14px;
    margin-top: 30px;
}


#clearDataButton {
    margin-top: 0 !important;
    background: #472525 !important;
    border-color: #824545 !important;
}


#deletableDungeonsLabel {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}


#deletableDungeonsToggle {
    width: 42px;
    height: 22px;
    margin: 0;
    accent-color: #824545;
    cursor: pointer;
}


#clearDataButton:hover:not(:disabled) {
    background: #643030 !important;
}


/* =====================================================
    EDITOR HEADER
===================================================== */
#editorHeader {
    display: grid;

    grid-template-columns:
        auto
        auto
        auto
        auto
        1fr;

    align-items: center;

    gap: 10px;

    margin-bottom: 10px;
}


#backButton,
#saveButton,
#pdfButton,
#heroModeButton,
#backupDungeonButton,
#duplicateDungeonButton,
#importDungeonButton,
#fileMenu summary {
    padding: 9px 14px;

    border: 2px solid #666;
    border-radius: 8px;

    background: #292929;
    color: white;

    white-space: nowrap;
}


#backButton:hover,
#saveButton:hover,
#pdfButton:hover,
#heroModeButton:hover,
#backupDungeonButton:hover,
#duplicateDungeonButton:hover,
#importDungeonButton:hover,
#fileMenu summary:hover,
#viewModeMenu summary:hover {
    background: #3a3a3a;
}

#viewModeMenu summary {
    padding: 9px 14px;
    border: 2px solid #666;
    border-radius: 8px;
    background: #292929;
    color: white;
    white-space: nowrap;
    cursor: pointer;
    list-style: none;
}
#viewModeMenu summary::-webkit-details-marker { display: none; }
#fileMenu, #viewModeMenu { position: relative; }
#fileMenu summary, #viewModeMenu summary { list-style: none; cursor: pointer; }
#fileMenu summary::-webkit-details-marker { display: none; }
.fileMenuOptions {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    z-index: 100;
    display: grid;
    min-width: 175px;
    padding: 5px;
    border: 1px solid #666;
    border-radius: 8px;
    background: #202020;
    box-shadow: 0 8px 20px #0009;
}
#fileMenu:not([open]) .fileMenuOptions, #viewModeMenu:not([open]) .fileMenuOptions { display: none; }
#fileMenu:hover .fileMenuOptions, #fileMenu:focus-within .fileMenuOptions,
#viewModeMenu:hover .fileMenuOptions, #viewModeMenu:focus-within .fileMenuOptions { display: grid; }
.fileMenuOptions button {
    padding: 9px 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: white;
    text-align: left;
    white-space: nowrap;
}
.fileMenuOptions #backButton, .fileMenuOptions #modeBackButton, .fileMenuOptions #heroModeButton, .fileMenuOptions #storyVibesButton { width: auto; padding: 9px 10px; border: 0; border-radius: 5px; background: transparent; color: white; text-align: left; white-space: nowrap; }
.fileMenuOptions #backButton:hover, .fileMenuOptions #modeBackButton:hover, .fileMenuOptions #heroModeButton:hover, .fileMenuOptions #storyVibesButton:hover, .fileMenuOptions button:hover { background: #3a3a3a; }
.menuSeparator { height: 1px; margin: 4px 5px; background: #555; }
#localFeatureNotice {
    position: fixed;
    z-index: 10000;
    right: 22px;
    bottom: 22px;
    max-width: min(420px, calc(100vw - 44px));
    padding: 12px 16px;
    border: 1px solid #8ba56f;
    border-radius: 10px;
    background: #20291d;
    color: #f4f4e9;
    box-shadow: 0 8px 28px #0009;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}

#localFeatureNotice.visible { opacity: 1; transform: translateY(0); }


#saveButton {
    border-color: #66804d;
    background: #293523;
}


#saveButton:hover {
    background: #35452d;
}

#pdfButton { border-color: #55718b; background: #263746; }
#pdfButton:hover { background: #32495d; }

#heroModeButton { border-color: #88734a; background: #39311f; }
#heroModeButton:hover { background: #51452c; }

#heroPlayBar { display: none; position: fixed; top: 10px; right: 12px; z-index: 800; align-items: center; gap: 12px; padding: 8px 12px; border: 1px solid #666; border-radius: 10px; background: rgba(25,25,25,.96); box-shadow: 0 4px 20px rgba(0,0,0,.6); }
#gameScreen.heroPlayMode #heroPlayBar { display: flex; }
#heroRoomNavigation { display: none; position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 800; align-items: center; gap: 9px; max-width: min(46vw, 480px); padding: 7px 10px; border: 1px solid #666; border-radius: 10px; background: rgba(25,25,25,.96); box-shadow: 0 4px 20px rgba(0,0,0,.6); }
#heroRoomNavigation.visible { display: flex; }
#heroDisplayedRoomName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#heroRoomNavigation button { min-width: 34px; padding: 4px 9px; font-size: 20px; }
.heroEditorToggle { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.heroFogControl { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
#heroFogSelect { padding: 6px 8px; border-radius: 6px; background: #292929; color: #fff; }
.heroEditorToggle input { accent-color: #d6b65c; }
#heroModeModal { display: none; position: fixed; inset: 0; z-index: 1200; align-items: center; justify-content: center; padding: 18px; background: rgba(0,0,0,.82); }
#heroModeModal.open { display: flex; }
#heroModeModalDialog { position: relative; width: min(1080px, 100%); max-height: 94vh; overflow: auto; padding: 24px; border: 2px solid #655b43; border-radius: 16px; background: #202020; box-shadow: 0 12px 60px rgba(0,0,0,.9); }
#heroModeModalTitle { margin: 0 48px 16px 0; }
#heroModeModalClose { position: absolute; top: 14px; right: 14px; padding: 3px 11px; font-size: 22px; }
#heroModeModalBody { min-height: 180px; }
#heroModeActions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 18px; padding-top: 12px; border-top: 1px solid #444; }
#heroModeFeedback { flex: 1; color: #f0c54a; font-size: 13px; }
.heroSetupGrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.heroModeChoiceButtons { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; padding: 28px 0; }
.heroModeChoiceButton { min-height: 150px; font-size: 24px; font-weight: bold; border: 2px solid #88734a; background: #39311f; }
.heroSetupCard { padding: 13px; border: 1px solid #4e4e4e; border-radius: 10px; background: #292929; }
.heroSetupCard h3 { margin: 0 0 10px; font-size: 15px; }
.heroSetupCard label { display: block; margin: 7px 0 4px; font-size: 12px; color: #ccc; }
.heroSetupCard input, .heroSetupCard select, #heroStartRoomSelect, #heroPlacementSelect { width: 100%; padding: 8px; border-radius: 6px; }
.heroNameRow { display: flex; align-items: stretch; gap: 6px; }
.heroNameRow input { min-width: 0; flex: 1; }
.heroNameRow button { flex: 0 0 auto; padding: 6px 9px; font-size: 12px; }
.heroAddButton { margin-top: 12px; padding: 8px 12px; }
.heroRemoveButton { margin-top: 10px; padding: 5px 8px; color: #ffd5d1; border-color: #805050; }
.heroDmLayout { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 18px; align-items: start; }
.heroDmControls { padding: 12px; border: 1px solid #484848; border-radius: 10px; background: #292929; }
.heroDmControls label { display: block; margin: 8px 0 5px; font-size: 13px; }
#heroDmMap { display: grid; gap: 4px; width: max-content; max-width: 100%; overflow: auto; padding: 3px; }
.heroDmTile { position: relative; width: 58px; height: 58px; padding: 3px; overflow: hidden; border: 2px solid #222; border-radius: 5px; background-color: #333; color: white; }
.heroDmTile:hover { border-color: #f0c54a; }
.heroDmTileContents { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(2,1fr); grid-template-rows: repeat(2,1fr); align-items: center; justify-items: center; font-size: 16px; pointer-events: none; text-shadow: 0 1px 3px #000; }
.heroDmTileHeroes { position: absolute; inset: auto 1px 1px auto; z-index: 2; display: flex; flex-wrap: wrap; justify-content: flex-end; max-width: 44px; pointer-events: none; }
.heroDmTileHeroes span { padding: 1px; border-radius: 5px; background: rgba(0,0,0,.8); font-size: 15px; line-height: 1; }
#heroDmAssignmentStatus { margin-top: 10px; font-size: 12px; color: #ccc; line-height: 1.5; }
#heroMovementSidebar { display: none; width: 225px; flex: 0 0 205px; padding: 14px; border: 1px solid #555; border-radius: 12px; background: #202020; }
#gameScreen.heroPlayMode #heroMovementSidebar { display: block; }
#heroMovementSidebar h2 { margin: 0 0 10px; font-size: 18px; }
#playHeroSelect { width: 100%; margin-bottom: 10px; padding: 8px; }
#moveHeroRoomButton { width: 100%; margin: 0 0 10px; padding: 8px; }
.heroDirectionGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.heroDirectionGrid button, .heroDirectionGrid span { width: 100%; min-height: 42px; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.heroDirectionGrid span { font-size: 25px; }
#heroMoveStatus { min-height: 34px; margin-top: 10px; color: #ccc; font-size: 12px; line-height: 1.4; }
.heroTokenStack { position: absolute; z-index: 5; right: 2px; bottom: 2px; display: grid; grid-template-columns: repeat(3, 19px); gap: 1px; max-width: 59px; pointer-events: none; }
.heroToken { display: flex; align-items: center; justify-content: center; width: 19px; height: 19px; border: 1px solid #fff; border-radius: 6px; background: rgba(0,0,0,.82); font-size: 15px; line-height: 1; }

#heroMoveRoomModal { display: none; position: fixed; inset: 0; z-index: 1250; align-items: center; justify-content: center; padding: 18px; background: rgba(0,0,0,.82); }
#heroMoveRoomModal.open { display: flex; }
#heroMoveRoomDialog { width: min(760px, 100%); max-height: 92vh; overflow: auto; padding: 22px; border: 2px solid #655b43; border-radius: 16px; background: #202020; box-shadow: 0 12px 60px rgba(0,0,0,.9); }
#heroMoveRoomDialog h2 { margin: 0 0 8px; }
#heroMoveRoomDescription, #heroMoveRoomInstructions { margin: 8px 0; color: #ccc; }
#heroMoveRoomSelect { width: 100%; margin: 5px 0 12px; padding: 9px; border-radius: 6px; }
#heroMoveRoomMap { display: grid; gap: 4px; width: max-content; max-width: 100%; overflow: auto; padding: 3px; }
.heroMoveRoomTile.selected { border-color: #f0c54a; box-shadow: 0 0 0 2px #f0c54a; }
#heroMoveRoomFeedback { min-height: 20px; margin-top: 8px; color: #f0c54a; }
#heroMoveRoomActions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; padding-top: 12px; border-top: 1px solid #444; }

#gameScreen.heroSetupActive > #editorHeader,
#gameScreen.heroSetupActive > #validationMessage,
#gameScreen.heroSetupActive > #buildControls,
#gameScreen.heroSetupActive > #dungeonArea { display: none !important; }
#gameScreen.heroPlayMode:not(.heroEditorControlsVisible) > #editorHeader,
#gameScreen.heroPlayMode:not(.heroEditorControlsVisible) > #buildControls,
#gameScreen.heroPlayMode:not(.heroEditorControlsVisible) #roomsPanel,
#gameScreen.heroPlayMode:not(.heroEditorControlsVisible) #contentPanel,
#gameScreen.heroPlayMode:not(.heroEditorControlsVisible) .directionControls { display: none !important; }
#gameScreen.heroPlayMode:not(.heroEditorControlsVisible) #dungeonArea { display: flex; justify-content: center; gap: 22px; padding-top: 20px; }
#gameScreen.heroPlayMode:not(.heroEditorControlsVisible) #dungeonBuilder { display: block; }

@media (max-width: 760px) {
    #heroRoomNavigation { top: 8px; left: 8px; transform: none; max-width: calc(100vw - 16px); }
    #gameScreen.heroPlayMode #heroPlayBar { top: 58px; right: 8px; }
    .heroDmLayout { grid-template-columns: 1fr; }
    #heroDmMap { max-width: 100%; }
    #heroMovementSidebar { width: auto; flex-basis: 100%; }
    #gameScreen.heroPlayMode:not(.heroEditorControlsVisible) #dungeonArea { flex-wrap: wrap; }
}


#dungeonName {
    width: 100%;

    padding: 9px 12px;

    border: 2px solid #555;
    border-radius: 8px;

    background: #222;
    color: white;

    font-size: 21px;
    font-weight: bold;

    text-align: center;
}


#dungeonName:focus {
    outline: none;

    border-color: white;

    box-shadow:
        0 0 8px rgba(255, 255, 255, 0.35);
}


/* =====================================================
    AUTO SAVE TOGGLE
===================================================== */

#autoSaveControl {
    display: flex;

    align-items: center;

    gap: 7px;

    white-space: nowrap;

    padding: 5px 7px;
}


#autoSaveLabel {
    font-size: 14px;
}


.switch {
    position: relative;

    display: inline-block;

    width: 44px;
    height: 24px;
}


.switch input {
    opacity: 0;

    width: 0;
    height: 0;
}


.slider {
    position: absolute;

    inset: 0;

    cursor: pointer;

    background: #555;

    border-radius: 24px;

    transition: 0.2s;
}


.slider:before {
    content: "";

    position: absolute;

    width: 18px;
    height: 18px;

    left: 3px;
    top: 3px;

    background: white;

    border-radius: 50%;

    transition: 0.2s;
}


.switch input:checked + .slider {
    background: #5d913f;
}


.switch input:checked + .slider:before {
    transform: translateX(20px);
}


/* =====================================================
    SAVE VALIDATION MESSAGE
===================================================== */
#validationMessage {
    display: none;

    margin: 0 auto 15px;

    max-width: 700px;

    padding: 12px 16px;

    border: 2px solid #9b4d4d;
    border-radius: 10px;

    background: #461f1f;

    color: #ffd6d6;

    font-weight: bold;

    box-shadow:
        0 0 15px rgba(180, 50, 50, 0.3);
}


#validationMessage.visible {
    display: block;
}


/* =====================================================
    GAME AREA
===================================================== */
#gameScreen {
    position: relative;
}

#buildControls {
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
#buildControls label {
    margin: 0 5px;
}
#buildControls select {
    margin-right: 15px;

    padding: 6px;
}

#buildControls .roomNarrativeControls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#roomNameInput { width: 180px; padding: 6px; }
#roomNarrativeModal { display: none; position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.72); align-items: center; justify-content: center; padding: 16px; }
#roomNarrativeModal.open { display: flex; }
.roomNarrativeDialog { position: relative; width: min(760px, 100%); max-height: 92vh; overflow-y: auto; padding: 24px; border: 1px solid #666; border-radius: 12px; background: #202020; box-shadow: 0 8px 35px rgba(0,0,0,.8); }
.roomNarrativeDialog h2 { margin: 0 42px 20px 0; }
.roomNarrativeClose { position: absolute; top: 12px; right: 12px; padding: 4px 10px; font-size: 20px; }
.roomNarrativeSection { margin: 18px 0; padding: 14px; border: 1px solid #444; border-radius: 9px; background: #252525; }
.roomNarrativeSection h3 { margin: 0 0 8px; font-size: 16px; }
.roomNarrativeSection p { margin: 0 0 9px; color: #c8c8c8; font-size: 13px; }
.roomNarrativeSection textarea { box-sizing: border-box; width: 100%; min-height: 90px; max-height: 240px; resize: vertical; overflow-y: auto; padding: 9px; border: 1px solid #555; border-radius: 6px; background: #171717; color: #fff; font: inherit; }
.roomNarrativeSenseField { margin-top: 10px; }
.roomNarrativeSenseField label { display: block; margin-bottom: 5px; font-weight: 600; }
.roomNarrativeInputWithCloud { display: grid; grid-template-columns: minmax(0, 1fr) minmax(180px, .55fr); gap: 12px; align-items: stretch; }
.roomNarrativeWordCloud { display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 3px 8px; min-height: 90px; padding: 7px; border: 1px dashed #4a4a4a; border-radius: 7px; background: #1d1d1d; }
.roomNarrativeWordCloud button { padding: 1px 3px; border: 0; background: transparent; color: #d7c58d; line-height: 1.25; }
.roomNarrativeWordCloud button:hover { color: #fff1b8; text-decoration: underline; }
.roomNarrativeActions { display: flex; justify-content: flex-end; margin-top: 18px; }
#heroRoomNarrativeModal { display: none; position: fixed; inset: 0; z-index: 1300; align-items: center; justify-content: center; padding: 18px; background: rgba(0,0,0,.82); }
#heroRoomNarrativeModal.open { display: flex; }
#heroRoomNarrativeDialog { position: relative; width: min(640px, 100%); max-height: 90vh; overflow-y: auto; padding: 24px; border: 2px solid #655b43; border-radius: 14px; background: #202020; box-shadow: 0 12px 60px rgba(0,0,0,.9); }
#heroRoomNarrativeDialog h2 { margin: 0 42px 8px 0; }
#heroRoomNarrativeHero { margin: 0 0 14px; color: #ddd; }
#heroNarrativeScoreSelect { min-width: 180px; padding: 8px; border-radius: 6px; }
#heroRoomNarrativeDescription { min-height: 70px; margin: 14px 0 20px; white-space: pre-wrap; }
.heroRoomNarrativeActions { display: flex; justify-content: flex-end; }
@media (max-width: 680px) { .roomNarrativeInputWithCloud { grid-template-columns: 1fr; } .roomNarrativeWordCloud { min-height: 55px; } }


#dungeonArea {
    position: relative;

    display: flex;

    justify-content: center;

    align-items: flex-start;

    gap: 30px;
}

#roomsPanel {
    width: 240px;
    max-height: 70vh;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid #444;
    border-radius: 10px;
    background: #202020;
    flex: 0 0 220px;
}

#roomsPanel h2 { margin: 0 0 10px; font-size: 20px; }
#roomMiniGridToggle { display: flex; align-items: center; gap: 7px; margin: 0 0 10px; font-size: 13px; }
#roomList { display: flex; flex-direction: column; gap: 8px; }
.roomListItem { padding: 7px; border: 1px solid #484848; border-radius: 8px; background: #292929; cursor: pointer; }
.roomListItem.active { border-color: #f0c54a; box-shadow: 0 0 0 1px #f0c54a; background: #383323; }
.roomListTop { display: flex; align-items: center; gap: 4px; flex-wrap: wrap;}
.roomSelectButton {width: 98%; text-align: left; padding: 5px 7px; background: transparent; color: white; border: 0; }
.roomSelectButton[aria-current="true"] { font-weight: 700; }
.roomOrderButton { min-width: 30px; padding: 3px; font-size: 13px; }
.roomDuplicateButton { min-width: 30px; padding: 3px; font-size: 13px; }
.roomDeleteButton { min-width: 30px; padding: 3px; font-size: 13px; color: #ffb4a9; }
.roomMiniGrid { display: grid; width: max-content; max-width: 100%; gap: 2px; margin: 7px 0 0 7px; }
.roomMiniTile { width: 9px; height: 9px; border: 1px solid rgba(0,0,0,.55); }
.roomMiniTile.hasContent { outline: 1px solid rgba(255,255,255,.85); outline-offset: -2px; }
#addRoomButton { width: 100%; margin-top: 10px; }


/* =====================================================
    DUNGEON GRID
===================================================== */
#dungeon {
    display: grid;
    position: relative;

    gap: 3px;

    justify-content: center;

    align-content: start;

    flex-shrink: 0;
}

/*classes for each amount of columns*/
.c1 { grid-template-columns: repeat(1, 80px); }
.c2 { grid-template-columns: repeat(2, 80px); }
.c3 { grid-template-columns: repeat(3, 80px); }
.c4 { grid-template-columns: repeat(4, 80px); }
.c5 { grid-template-columns: repeat(5, 80px); }
.c6 { grid-template-columns: repeat(6, 80px); }
.c7 { grid-template-columns: repeat(7, 80px); }

/*classes for each amount of rows*/
.r1 { grid-template-rows: repeat(1, 80px); }
.r2 { grid-template-rows: repeat(2, 80px); }
.r3 { grid-template-rows: repeat(3, 80px); }
.r4 { grid-template-rows: repeat(4, 80px); }
.r5 { grid-template-rows: repeat(5, 80px); }
.r6 { grid-template-rows: repeat(6, 80px); }
.r7 { grid-template-rows: repeat(7, 80px); }


.dungeonTile {
    width: 80px;
    height: 80px;

    border: 2px solid #222;
    position: relative;

    cursor: pointer;
    overflow: hidden;
    display: flex;

    justify-content: center;
    align-items: center;
}


.dungeonTile.selected {
    border: 3px solid white;
    box-shadow:
        0 0 0 2px #000,
        0 0 15px rgba(255, 255, 255, 0.8);
}
.dungeonTile.focused { outline: 2px solid #f0c54a; outline-offset: 1px; }
.dungeonTile.fogHidden::before { content: ""; position: absolute; inset: 0; z-index: 4; background: #101010; border: 1px solid #444; }


.tileContent {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    width: 100%;
    height: 100%;
    align-items: center;
    justify-items: center;
    font-size: 25px;
    line-height: 1;
    pointer-events: none;
    text-shadow:
        0 2px 4px rgba(0, 0, 0, 0.8);
}

.tileContentItem { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
.tileContentItem.fullTile { position: absolute; inset: 0; z-index: 3; font-size: 64px; }
.tileContentOversizeLayer { position: absolute; inset: 0; z-index: 3; overflow: visible; pointer-events: none; }
.tileContentOversize { position: absolute; display: flex; align-items: center; justify-content: center; line-height: 1; font-size: 126px; text-shadow: 0 2px 5px rgba(0,0,0,.85); }
.tileContentOversize.nineTiles { font-size: 189px; }
#currentTileContentActions button.selected { border-color: #f0c54a; box-shadow: 0 0 0 1px #f0c54a; }
.contentSizeControls { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.contentOrientationControls { display: flex; flex: 1 0 100%; align-items: center; flex-wrap: wrap; gap: 5px; margin-top: 2px; }
.contentOrientationControls button { padding: 4px 7px; font-size: 12px; }
.contentRotationControl { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.contentRotationControl input { width: 58px; padding: 4px; }
#currentTileContentsPanel { margin: 8px 0 12px; }
#contentSearch { box-sizing: border-box; width: 100%; margin: 8px 0 10px; padding: 10px; border: 1px solid #555; border-radius: 7px; background: #171717; color: #fff; font: inherit; }
#currentTileContentsTitle { font-size: 13px; font-weight: bold; margin-bottom: 5px; }
#currentTileContentsHint { font-size: 11px; color: #bbb; margin-bottom: 6px; }
#currentTileContentsButtons, #currentTileContentActions { display: flex; flex-wrap: wrap; gap: 5px; min-height: 28px; }
#currentTileContentsButtons button { padding: 4px 7px; font-size: 12px; }
#currentTileContentsButtons button.selected { border-color: #f0c54a; box-shadow: 0 0 0 1px #f0c54a; }
#currentTileContentActions { margin-top: 5px; }
#currentTileContentActions[hidden] { display: none; }
#tileClipboardControls { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
#tileClipboardControls button { padding: 5px 9px; font-size: 12px; }
#tileClipboardStatus { flex: 1 1 100%; color: #bbb; font-size: 11px; }


.stairsSymbol {
    font-size: 1.45em;
    line-height: 1;
    font-family: "Noto Sans Egyptian Hieroglyphs", "Segoe UI Historic", serif;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95);
}
.stairsIvory { color: #fff2c7; }
.stairsGold { color: #ffd447; }
.stairsCrimson { color: #ff6262; }
.stairsAzure { color: #69c7ff; }

.collapsibleTitle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}
.collapsibleTitle:hover {
    background: rgba(255, 255, 255, 0.08);
}

#terrainToggleIcon {
    font-size: 12px;
}

/* =====================================================
    TERRAIN STYLES
===================================================== */
.terrain-slate { background: linear-gradient( 135deg, #59616b, #343a40 ); } 
.terrain-dirt { background: linear-gradient( 135deg, #806044, #4b3322 ); } 
.terrain-moss { background: linear-gradient( 135deg, #667744, #29391f ); } 
.terrain-water { background: linear-gradient( 135deg, #287ca8, #123c61 ); } 
.terrain-lava { background: linear-gradient( 135deg, #ff8a00, #a90000 60%, #3a0500 ); } 
.terrain-slime { background: linear-gradient( 135deg, #b7e83f, #4c9b25 55%, #205414 ); } 
.terrain-roots { background: radial-gradient( ellipse at 30% 20%, #80603c 0 8%, transparent 9% ), 
    repeating-radial-gradient( ellipse at 50% 50%, #4d321f 0 3px, #24170e 4px 8px, #392318 9px 13px ); } 
.terrain-sand { background: radial-gradient( circle at 20% 30%, rgba(255,255,255,0.12) 0 2px, transparent 3px ), radial-gradient( circle at 70% 70%, rgba(100,70,25,0.12) 0 2px, transparent 3px ), linear-gradient( 135deg, #d9bc70, #a88948 ); } 
.terrain-snow { background: linear-gradient( 135deg, #ffffff, #dce8ef ); } 
.terrain-ice { background: linear-gradient( 135deg, #d9fbff, #72cfe5 55%, #367fa5 ); } 
.terrain-webs { background: radial-gradient( circle at 50% 50%, transparent 0 8px, rgba(255,255,255,0.75) 9px 10px, transparent 11px 18px ), repeating-conic-gradient( from 0deg, transparent 0deg 10deg, rgba(255,255,255,0.65) 11deg 12deg, transparent 13deg 30deg ), #29242d; } 
.terrain-blood { background: radial-gradient( circle at 25% 30%, #c90000 0 12%, transparent 13% ), radial-gradient( circle at 75% 65%, #8b0000 0 18%, transparent 19% ), linear-gradient( 135deg, #8e0000, #3d0000 ); } 
.terrain-quicksand { background: repeating-radial-gradient( ellipse at 50% 50%, #d0a83d 0 7px, #a57d22 8px 13px, #c0952f 14px 19px ); } 
.terrain-bones { background: radial-gradient( ellipse at 25% 30%, #eee4c8 0 6px, transparent 7px ), radial-gradient( ellipse at 70% 65%, #d7ccb0 0 7px, transparent 8px ), #514a3c; } 
.terrain-ash { background: radial-gradient( circle at 30% 25%, #777 0 2px, transparent 3px ), radial-gradient( circle at 75% 65%, #999 0 2px, transparent 3px ), linear-gradient( 135deg, #575757, #252525 ); } 
.terrain-milk { background: radial-gradient( ellipse at 30% 35%, rgba(255,255,255,0.8) 0 8%, transparent 9% ), radial-gradient( ellipse at 70% 65%, rgba(220,220,220,0.5) 0 10%, transparent 11% ), #f5f2df; } 
.terrain-mushroom { background: radial-gradient( ellipse at 25% 30%, #d94a4a 0 8px, transparent 9px ), radial-gradient( ellipse at 70% 65%, #9b4bd3 0 10px, transparent 11px ), linear-gradient( 135deg, #573d62, #241b29 ); } 
.terrain-marble { background: repeating-linear-gradient( 135deg, #eeeeea 0px, #eeeeea 12px, #c4c4c0 14px, #f7f7f2 19px, #d2d2ce 23px ); } 
.terrain-mosaic { background: linear-gradient( 45deg, #d33 25%, transparent 25% ), linear-gradient( -45deg, #3478c9 25%, transparent 25% ), linear-gradient( 45deg, transparent 75%, #4caf50 75% ), linear-gradient( -45deg, transparent 75%, #e3b341 75% ); background-size: 24px 24px; background-position: 0 0, 0 12px, 12px -12px, -12px 0; } 
.terrain-madness { background: conic-gradient( from 0deg at 50% 50%, #ff0055, #ffcc00, #00ff88, #00aaff, #8844ff, #ff0055 ); } 
.terrain-gold-pile { background: radial-gradient( circle at 20% 30%, #fff28a 0 5px, #d6a500 6px 10px, transparent 11px ), radial-gradient( circle at 55% 55%, #ffe45c 0 6px, #bd8900 7px 11px, transparent 12px ), radial-gradient( circle at 80% 30%, #fff09a 0 5px, #c99500 6px 10px, transparent 11px ), linear-gradient( 135deg, #b27c00, #5b3d00 ); } 
.terrain-red-carpet { background: linear-gradient( 135deg, #d92b2b, #741010 ); } 
.terrain-green-carpet { background: linear-gradient( 135deg, #35a853, #155d27 ); } 
.terrain-blue-carpet { background: linear-gradient( 135deg, #3b82f6, #173b8f ); } 
.terrain-groovy { background: repeating-conic-gradient( from 0deg, #ff2e9f 0deg 18deg, #ffd500 18deg 36deg, #20e0ff 36deg 54deg, #8b4dff 54deg 72deg ); position: relative; } 
.terrain-groovy::after { content: ""; position: absolute; inset: -25%; background: repeating-radial-gradient( circle at 50% 50%, transparent 0 8px, rgba(255,255,255,0.28) 9px 11px, transparent 12px 20px ); transform: rotate(18deg); pointer-events: none; }


/* =====================================================
    CONTENT PANEL
===================================================== */
#contentPanel {
    width: 360px;
    background: #242424;
    border: 2px solid #555;
    border-radius: 12px;
    padding: 12px;
    text-align: left;
    flex-shrink: 0;
    max-height:
        calc(100vh - 150px);
    overflow-y: auto;
}


#panelTitle {
    font-size: 20px;
    margin-bottom: 12px;
    text-align: center;
}


/* =====================================================
    TERRAIN SECTION
===================================================== */
.terrainSection {
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 2px solid #444;
}


.sectionTitle {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 8px;
}


.terrainChoices {
    display: grid;
    grid-template-columns:
        repeat(5, 1fr);
    gap: 6px;
}


.terrainChoice {
    min-height: 58px;
    border: 2px solid #444;
    border-radius: 7px;
    cursor: pointer;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    overflow: hidden;

    font-size: 11px;
    font-weight: bold;
    color: white;
    text-shadow:
        0 1px 3px rgba(0, 0, 0, 0.9);
}


.terrainChoice.selected {
    border: 3px solid white;
    box-shadow:
        0 0 0 2px #000,
        0 0 10px rgba(255, 255, 255, 0.9);
}


.terrainChoice span {
    position: relative;
    z-index: 2;
    padding: 2px;
}


/* =====================================================
    CONTENT FOLDERS
===================================================== */
.contentFolder {
    margin-bottom: 8px;
    border: 1px solid #444;
    border-radius: 8px;
    overflow: hidden;
    background: #1e1e1e;
}


.folderHeader {
    width: 100%;
    border: 0;
    padding: 10px;
    background: #303030;
    color: white;            
    text-align: left;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.folderHeader:hover {
    background: #3b3b3b;
}


.folderArrow {
    width: 20px;
}


.folderChoices {
    display: grid;
    grid-template-columns:
        repeat(5, 1fr);
    gap: 6px;
    padding: 8px;
    background: #202020;
}


.choice {
    min-height: 58px;
    border: 2px solid #444;
    border-radius: 7px;
    background: #2d2d2d;
    color: white;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    gap: 3px;
}
.choice:hover {
    background: #393939;
}
.choice.selected {
    border-color: white;
    box-shadow:
        0 0 0 2px #000,
        0 0 10px rgba(255, 255, 255, 0.8);
}

.choiceIcon {
    font-size: 26px;
    line-height: 1;
}

.choiceName {
    font-size: 10px;
}

.removeChoice {
    border-color: #8b3d3d;
}


.removeChoice:hover {
    background: #5c2929;
}


/* =====================================================
    TILE VALUES
===================================================== */
#tileValues {
    margin-top: 12px;
    padding: 10px;
    border: 1px solid #444;
    border-radius: 8px;
    background: #1d1d1d;
    font-size: 14px;
    line-height: 1.4;
}


/* =====================================================
    DUNGEON EXPANSION CONTROLS
===================================================== */
#dungeonBuilder {
    display: grid;
    grid-template-columns: 70px auto 70px;
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
        ". top ."
        "left middle right"
        ". bottom ."
        ". resize .";
    align-items: center;
    justify-items: center;
    flex-shrink: 0;
}

#dungeonTopControls { grid-area: top; }
#dungeonLeftControls { grid-area: left; }
#dungeonMiddle { grid-area: middle; }
#dungeonRightControls { grid-area: right; }
#dungeonBottomControls { grid-area: bottom; }
#dungeonResizeControls { grid-area: resize; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 8px; }
#dungeonResizeControls label { display: flex; align-items: center; gap: 5px; margin: 0; }
#dungeonResizeControls select { padding: 5px; }

.directionControls {
    display: flex;
    gap: 5px;
    align-items: center;
    justify-content: center;
}

.verticalControls { flex-direction: column; }

.addTileButton,
.removeTileButton {
    width: 62px;
    min-height: 34px;
    padding: 5px 3px;
    border: 2px solid #555;
    border-radius: 7px;
    background: #292929;
    color: white;
    font-size: 11px;
    line-height: 1.1;
}

.addTileButton {
    border-color: #66804d;
    background: #293523;
}

.addTileButton:hover:not(:disabled) { background: #35452d; }

.removeTileButton {
    border-color: #805050;
    background: #3a2929;
}

.removeTileButton:hover:not(:disabled) { background: #4a3030; }
.removeTileButton:disabled { opacity: 0.32; cursor: default; }

/* =====================================================
    DEFAULT TERRAIN
===================================================== */
#freeBuildDefaultTerrain {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 7px;
    margin-left: 10px;
    vertical-align: middle;
}

.mainTerrainShortcuts { display: flex; flex-wrap: wrap; gap: 6px; }
.mainTerrainShortcutGroup { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: bold; }
.mainTerrainShortcut { width: 84px; min-height: 42px; padding: 3px; }
.mainTerrainShortcut .terrainName { position: relative; z-index: 2; }
.mainTerrainShortcut:disabled { opacity: 1; cursor: default; filter: saturate(.75); }
.mainTerrainShortcut.selected { border: 3px solid white; box-shadow: 0 0 0 2px #000, 0 0 10px rgba(255,255,255,.9); }
#changeRoomDefaultsButton{
    margin: 2px;
    height: 60px;
    width: 80px;
    border-radius: 9%;
}
#changeRoomDefaultsButton.active { border-color: #f0c54a; background: #383323; }
.mainTerrainSettings { 
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}
.mainTerrainSetting { 
    width: 324px;
    margin: 6px 10px;
    padding: 4px;
}
.mainTerrainSetting label { display: block; margin-bottom: 7px; font-weight: bold; }
.mainTerrainSetting .defaultTerrainTile { margin-bottom: 8px; }
.mainTerrainChoices { 
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    border: rgb(154, 152, 138) dashed 2px;
    padding: 2px;
}
.mainTerrainChoices .terrainChoice { 
    width: 58px; 
    height: 58px; 
}

@media (max-width: 600px) { .mainTerrainSettings { grid-template-columns: 1fr; } }

.defaultTerrainLabel { font-weight: bold; }

.defaultTerrainTile {
    width: 58px;
    height: 58px;
    border: 3px solid #555;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    color: white;
    font-size: 10px;
    font-weight: bold;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
    box-shadow: 0 0 8px rgba(255,255,255,0.25);
}

#newTerrainTile.selectedTerrainTool { border-color: white; box-shadow: 0 0 0 2px #000, 0 0 12px rgba(255,255,255,.85); }

.defaultTerrainTile span { position: relative; z-index: 2; }
.defaultTerrainTile:hover { box-shadow: 0 0 0 2px #000, 0 0 12px rgba(255,255,255,0.75); }

/* =====================================================
    GENERAL LAIR VIBES
===================================================== */
#vibeScreen { max-width: 850px; margin: 0 auto; }

.vibeIntro {
    color: #bbb;
    margin: 0 auto 25px;
    max-width: 680px;
    line-height: 1.5;
}

.vibeQuestions { display: grid; gap: 18px; text-align: left; }

.vibeQuestion {
    padding: 15px;
    border: 2px solid #444;
    border-radius: 10px;
    background: #222;
}

.vibeQuestion label { display: block; font-weight: bold; margin-bottom: 9px; }
.vibeQuestion select, .vibeQuestion input {
    width: 100%;
    padding: 9px 10px;
    border: 2px solid #555;
    border-radius: 7px;
    background: #181818;
    color: white;
}
.vibeQuestion input { margin-top: 7px; }

#vibeActions, #vibeModalActions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 25px;
}

#vibeActions button, #storyVibesButton, #vibeModalActions button {
    padding: 9px 14px;
    border: 2px solid #666;
    border-radius: 8px;
    background: #292929;
    color: white;
}

#vibeContinueButton, #vibeModalSave {
    border-color: #66804d !important;
    background: #293523 !important;
}

#vibeModal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0,0,0,0.75);
    padding: 20px;
    overflow-y: auto;
}

#vibeModal.visible {
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

#vibeModalContent {
    width: min(850px, 100%);
    margin: 20px auto;
    padding: 20px;
    border: 2px solid #555;
    border-radius: 14px;
    background: #242424;
    box-shadow: 0 10px 50px rgba(0,0,0,0.8);
}

#vibeModalContent h2 { margin-top: 0; }
#vibeModalActions { justify-content: flex-end; }

/* =====================================================
    SMALL SCREENS
===================================================== */
@media (max-width: 900px) {
    #editorHeader {
        grid-template-columns:
            auto auto 1fr;
        gap: 7px;
    }


    #dungeonName {
        grid-column: 1 / -1;
        font-size: 20px;
    }
    #autoSaveControl {
        justify-self: end;
    }
    #dungeonArea {
        display: block;
    }

    #roomsPanel { width: auto; max-height: 260px; margin-bottom: 16px; }

    #dungeonBuilder {
        grid-template-columns: 1fr;
        grid-template-areas:
            "top"
            "left"
            "middle"
            "right"
            "bottom";
        gap: 8px;
    }

    .directionControls {
        flex-direction: row;
    }


    #contentPanel {
        position: relative;
        top: 0px;
        left: 50%;
        transform:
            translateX(-50%);
        z-index: 10;
        width:
            min(
                360px,
                calc(100vw - 20px)
            );

        box-shadow:
            0 8px 35px
            rgba(0, 0, 0, 0.8);
    }

}

#pdfExportView { display: none; }

@media print {
    @page { size: A4 landscape; margin: 4mm; }
    html, body { background: #fff !important; color: #111 !important; margin: 0 !important; padding: 0 !important; }
    body > *:not(#pdfExportView) { display: none !important; }
    #pdfExportView { display: block !important; font-family: Arial, sans-serif; color: #111; }
    .pdfDungeonTitle { font-size: 14pt; margin: 0 0 3mm; }
    .pdfRoom { break-after: page; page-break-after: always; }
    .pdfRoom:last-child { break-after: auto; page-break-after: auto; }
    .pdfRoomTitle { font-size: 11pt; margin: 0 0 2mm; }
    .pdfRoomDefaults { font-size: 7pt; margin: 0 0 2mm; }
    .pdfRoomGrid { position: relative; display: grid; gap: 0; width: max-content; }
    .pdfTile { position: relative; width: 1in; height: 1in; min-width: 1in; min-height: 1in; padding: 0; border: 1px solid #444; border-radius: 1mm; box-sizing: border-box; color: #fff; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
    .pdfTileContents { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
    .pdfContent { display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; font-size: 22pt; line-height: 1; text-shadow: 0 1px 2px #000; }
    .pdfContent.fullTile { position: absolute; inset: 0; z-index: 3; font-size: 52pt; }
    .pdfContent.fullTile:nth-child(n) { border: 0; }
    .pdfOversizeLayer { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
    .pdfOversizeContent { position: absolute; display: flex; align-items: center; justify-content: center; width: 2in; height: 2in; font-size: 96pt; line-height: 1; text-shadow: 0 1px 2px #000; }
    .pdfOversizeContent.nineTiles { width: 3in; height: 3in; font-size: 144pt; }
    .pdfContent:nth-child(1), .pdfContent:nth-child(2) { border-bottom: 1px solid rgba(0,0,0,.25); }
    .pdfContent:nth-child(1), .pdfContent:nth-child(3) { border-right: 1px solid rgba(0,0,0,.25); }
}


@media (max-width: 420px) {

    body {
        padding: 10px;
    }


    #editorHeader {
        grid-template-columns:
            1fr 1fr;
    }


    #backButton,
    #saveButton,
    #pdfButton,
    #heroModeButton {
        width: 100%;
    }


    #autoSaveControl {
        grid-column: 1 / -1;

        justify-self: center;
    }


    .terrainChoices,
    .folderChoices,

    .terrainChoice,
    .choice {
        min-height: 52px;
    }


    .choiceIcon {
        font-size: 22px;
    }

}